Skip to content

Commit

Permalink
* fix bug when picking weaponbox grenades with ammo > 1 (#669)
Browse files Browse the repository at this point in the history
* fix bug pickup sound (if the player has ammo > 0)
  • Loading branch information
Vaqtincha authored Mar 31, 2023
1 parent 4a7a635 commit c756bf8
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1920,19 +1930,35 @@ 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())
{
auto pNext = m_rgpPlayerItems[i]->m_pNext;
if (pPlayer->AddPlayerItem(pItem))
if (m_rgAmmo[boxAmmoSlot] > 1 && playerGrenades > 0)
{
pItem->AttachToPlayer(pPlayer);
bEmitSound = true;
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;

// unlink this weapon from the box
m_rgpPlayerItems[i] = pItem = pNext;
continue;
if (pPlayer->AddPlayerItem(pItem))
{
pItem->AttachToPlayer(pPlayer);
bEmitSound = true;
}

// unlink this weapon from the box
m_rgpPlayerItems[i] = pItem = pNext;
continue;
}
}
#else

Expand Down

0 comments on commit c756bf8

Please sign in to comment.