Fix RPG not playing empty sound when attempting to fire with no ammo left

Resolves #196
This commit is contained in:
Sam V 2023-04-12 14:33:06 +02:00
parent 36b7ee28e6
commit c6b5b617b3
4 changed files with 21 additions and 3 deletions

View file

@ -18,6 +18,7 @@
* Fixed cycler_wreckage storing time value in int instead of float * 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 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 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 ## Changes in V1.0.0 Beta 014

View file

@ -480,6 +480,12 @@ void CRpg::SecondaryAttack()
void CRpg::WeaponIdle() void CRpg::WeaponIdle()
{ {
// Reset when the player lets go of the trigger.
if ((m_pPlayer->pev->button & (IN_ATTACK | IN_ATTACK2)) == 0)
{
ResetEmptySound();
}
UpdateSpot(); UpdateSpot();
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase()) if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
@ -508,7 +514,6 @@ void CRpg::WeaponIdle()
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 6.1; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 6.1;
} }
ResetEmptySound();
SendWeaponAnim(iAnim); SendWeaponAnim(iAnim);
} }
else else
@ -542,6 +547,16 @@ void CRpg::UpdateSpot()
#endif #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 class CRpgAmmo : public CBasePlayerAmmo
{ {

View file

@ -799,6 +799,8 @@ public:
void UpdateSpot(); void UpdateSpot();
bool ShouldWeaponIdle() override { return true; } bool ShouldWeaponIdle() override { return true; }
bool IsUseable() override;
CLaserSpot* m_pSpot; CLaserSpot* m_pSpot;
bool m_fSpotActive; bool m_fSpotActive;
int m_cActiveRockets; // how many missiles in flight from this launcher right now? int m_cActiveRockets; // how many missiles in flight from this launcher right now?

View file

@ -170,18 +170,18 @@ void CBasePlayerWeapon::ItemPostFrame()
m_fFireOnEmpty = false; m_fFireOnEmpty = false;
#ifndef CLIENT_DLL
if (!IsUseable() && m_flNextPrimaryAttack < (UseDecrement() ? 0.0 : gpGlobals->time)) if (!IsUseable() && m_flNextPrimaryAttack < (UseDecrement() ? 0.0 : gpGlobals->time))
{ {
#ifndef CLIENT_DLL
// weapon isn't useable, switch. // weapon isn't useable, switch.
if ((iFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) == 0 && g_pGameRules->GetNextBestWeapon(m_pPlayer, this)) if ((iFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) == 0 && g_pGameRules->GetNextBestWeapon(m_pPlayer, this))
{ {
m_flNextPrimaryAttack = (UseDecrement() ? 0.0 : gpGlobals->time) + 0.3; m_flNextPrimaryAttack = (UseDecrement() ? 0.0 : gpGlobals->time) + 0.3;
return; return;
} }
#endif
} }
else else
#endif
{ {
// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing // 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)) if (m_iClip == 0 && (iFlags() & ITEM_FLAG_NOAUTORELOAD) == 0 && m_flNextPrimaryAttack < (UseDecrement() ? 0.0 : gpGlobals->time))