From c6b5b617b37ce49be1d13ce1c7ce51bee94b2fb2 Mon Sep 17 00:00:00 2001 From: Sam V Date: Wed, 12 Apr 2023 14:33:06 +0200 Subject: [PATCH] Fix RPG not playing empty sound when attempting to fire with no ammo left Resolves #196 --- CHANGELOG.md | 1 + dlls/rpg.cpp | 17 ++++++++++++++++- dlls/weapons.h | 2 ++ dlls/weapons_shared.cpp | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be6eec1..cb3f3c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Fixed cycler_wreckage storing time value in int instead of float * Fixed limit in world weapons (e.g. Hand Grenade) respawning at wrong time if server is near edict limit * Fixed shotgun starting idle animations too quickly after exhausting all ammo using primary attack [#195](https://github.com/SamVanheer/halflife-updated/issues/195) (Thanks Ronin4862) +* Fixed RPG not playing empty sound when attempting to fire with no ammo left [#196](https://github.com/SamVanheer/halflife-updated/issues/196) (Thanks Ronin4862) ## Changes in V1.0.0 Beta 014 diff --git a/dlls/rpg.cpp b/dlls/rpg.cpp index eddf86c..adebc50 100644 --- a/dlls/rpg.cpp +++ b/dlls/rpg.cpp @@ -480,6 +480,12 @@ void CRpg::SecondaryAttack() void CRpg::WeaponIdle() { + // Reset when the player lets go of the trigger. + if ((m_pPlayer->pev->button & (IN_ATTACK | IN_ATTACK2)) == 0) + { + ResetEmptySound(); + } + UpdateSpot(); if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase()) @@ -508,7 +514,6 @@ void CRpg::WeaponIdle() m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 6.1; } - ResetEmptySound(); SendWeaponAnim(iAnim); } else @@ -542,6 +547,16 @@ void CRpg::UpdateSpot() #endif } +bool CRpg::IsUseable() +{ + // The client needs to fall through to WeaponIdle so check the ammo here. + if (m_pPlayer->ammo_rockets <= 0) + { + return false; + } + + return CBasePlayerWeapon::IsUseable(); +} class CRpgAmmo : public CBasePlayerAmmo { diff --git a/dlls/weapons.h b/dlls/weapons.h index 6f18c7f..417dc83 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -799,6 +799,8 @@ public: void UpdateSpot(); bool ShouldWeaponIdle() override { return true; } + bool IsUseable() override; + CLaserSpot* m_pSpot; bool m_fSpotActive; int m_cActiveRockets; // how many missiles in flight from this launcher right now? diff --git a/dlls/weapons_shared.cpp b/dlls/weapons_shared.cpp index 42749f4..97d7065 100644 --- a/dlls/weapons_shared.cpp +++ b/dlls/weapons_shared.cpp @@ -170,18 +170,18 @@ void CBasePlayerWeapon::ItemPostFrame() m_fFireOnEmpty = false; -#ifndef CLIENT_DLL if (!IsUseable() && m_flNextPrimaryAttack < (UseDecrement() ? 0.0 : gpGlobals->time)) { +#ifndef CLIENT_DLL // weapon isn't useable, switch. if ((iFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) == 0 && g_pGameRules->GetNextBestWeapon(m_pPlayer, this)) { m_flNextPrimaryAttack = (UseDecrement() ? 0.0 : gpGlobals->time) + 0.3; return; } +#endif } else -#endif { // weapon is useable. Reload if empty and weapon has waited as long as it has to after firing if (m_iClip == 0 && (iFlags() & ITEM_FLAG_NOAUTORELOAD) == 0 && m_flNextPrimaryAttack < (UseDecrement() ? 0.0 : gpGlobals->time))