* fix bug when picking weaponbox grenades with ammo > 1 (#669)

* fix bug pickup sound (if the player has ammo > 0)
This commit is contained in:
Vaqtincha 2023-03-31 23:03:03 +05:00 committed by GitHub
parent 4a7a63533c
commit c756bf89d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1595,7 +1595,17 @@ int CBasePlayerWeapon::ExtractClipAmmo(CBasePlayerWeapon *pWeapon)
iAmmo = m_iClip;
}
return pWeapon->m_pPlayer->GiveAmmo(iAmmo, pszAmmo1(), iMaxAmmo1());
int iIdAmmo = pWeapon->m_pPlayer->GiveAmmo(iAmmo, pszAmmo1(), iMaxAmmo1());
#ifdef REGAMEDLL_FIXES
if (iIdAmmo > 0 && IsGrenadeWeapon(m_iId))
{
// grenades have WEAPON_NOCLIP force play the "got ammo" sound.
EMIT_SOUND(pWeapon->m_pPlayer->edict(), CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM);
}
#endif
return iIdAmmo;
}
// RetireWeapon - no more ammo for this gun, put it away.
@ -1920,10 +1930,25 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
int playerGrenades = pPlayer->m_rgAmmo[pGrenade->m_iPrimaryAmmoType];
#ifdef REGAMEDLL_FIXES
auto info = GetWeaponInfo(pGrenade->m_iId);
if (info && playerGrenades < info->maxRounds)
// sorry for hardcode :(
const int boxAmmoSlot = 1;
if (playerGrenades < pGrenade->iMaxAmmo1())
{
if (m_rgAmmo[boxAmmoSlot] > 1 && playerGrenades > 0)
{
if (!FStringNull(m_rgiszAmmo[boxAmmoSlot])
&& pPlayer->GiveAmmo(1, STRING(m_rgiszAmmo[boxAmmoSlot]), pGrenade->iMaxAmmo1()) != -1)
{
m_rgAmmo[boxAmmoSlot]--;
EMIT_SOUND(pPlayer->edict(), CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM);
}
}
else
{
auto pNext = m_rgpPlayerItems[i]->m_pNext;
if (pPlayer->AddPlayerItem(pItem))
{
pItem->AttachToPlayer(pPlayer);
@ -1934,6 +1959,7 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
m_rgpPlayerItems[i] = pItem = pNext;
continue;
}
}
#else
int maxGrenades = 0;