Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gauss gun sometimes sets player uranium ammo to -1 #3343

Open
SamVanheer opened this issue Mar 31, 2023 · 0 comments
Open

Gauss gun sometimes sets player uranium ammo to -1 #3343

SamVanheer opened this issue Mar 31, 2023 · 0 comments

Comments

@SamVanheer
Copy link

When using the Gauss gun's secondary attack, the player's uranium ammo can be set to -1 if the player has only 1 unit of ammo left and holds the secondary attack key down.

The cause is here:

halflife/dlls/gauss.cpp

Lines 229 to 256 in c7240b9

// during the charging process, eat one bit of ammo every once in a while
if ( UTIL_WeaponTimeBase() >= m_pPlayer->m_flNextAmmoBurn && m_pPlayer->m_flNextAmmoBurn != 1000 )
{
#ifdef CLIENT_DLL
if ( bIsMultiplayer() )
#else
if ( g_pGameRules->IsMultiplayer() )
#endif
{
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.1;
}
else
{
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.3;
}
}
if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
{
// out of ammo! force the gun to fire
StartFire();
m_fInAttack = 0;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0;
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1;
return;
}

When using secondary attack the weapon first uses up one unit of ammo, then the next time it checks it uses up another unit of ammo before checking if the player is out of ammo.

If the player only has 1 unit of ammo left to begin with then the first time it thinks while charging it will go from 0 ammo to -1.

To fix this an additional check is needed to prevent the ammo consumption from occurring:

		if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0)
		{
			// during the charging process, eat one bit of ammo every once in a while
			if (UTIL_WeaponTimeBase() >= m_pPlayer->m_flNextAmmoBurn && m_pPlayer->m_flNextAmmoBurn != 1000)
			{
#ifdef CLIENT_DLL
				if (bIsMultiplayer())
#else
				if (g_pGameRules->IsMultiplayer())
#endif
				{
					m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
					m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.1;
				}
				else
				{
					m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
					m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.3;
				}
			}
		}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants