Skip to content

Commit

Permalink
RemovePlayerItemEx: Do not remove the grenade weapons until it runs o…
Browse files Browse the repository at this point in the history
…ut of ammo
  • Loading branch information
s1lentq committed Apr 27, 2023
1 parent 4b4cd88 commit 94bf705
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,33 +211,38 @@ EXT_FUNC bool CCSPlayer::RemovePlayerItemEx(const char* pszItemName, bool bRemov
auto pItem = GetItemByName(pszItemName);
if (pItem)
{
if (FClassnameIs(pItem->pev, "weapon_c4")) {
pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0;
pPlayer->SetBombIcon(FALSE);
pPlayer->SetProgressBarTime(0);
}

if (pItem->IsWeapon())
{
// These weapons have a unique type of ammo that is used only by them
// If a weapon is removed, its ammo is also reduced, unless the ammo can be used by another weapon
if (!bRemoveAmmo && (IsGrenadeWeapon(pItem->m_iId) || pItem->m_iId == WEAPON_C4))
{
if (pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()] > 0)
pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]--;

// Hold the weapon until it runs out of ammo
if (pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()] > 0)
return true; // ammo was reduced, this will be considered a successful result
}

if (pItem == pPlayer->m_pActiveItem) {
((CBasePlayerWeapon *)pItem)->RetireWeapon();
}

if (bRemoveAmmo) {
pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0;
} else {
// These weapons have a unique type of ammo that is used only by them
// If a weapon is removed, its ammo is also reduced, unless the ammo can be used by another weapon
if (IsGrenadeWeapon(pItem->m_iId) || pItem->m_iId == WEAPON_C4)
{
if (pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()] > 0)
pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()]--;
}
}
}

if (pPlayer->RemovePlayerItem(pItem)) {
if (pPlayer->RemovePlayerItem(pItem))
{
if (FClassnameIs(pItem->pev, "weapon_c4")) {
pPlayer->m_bHasC4 = false;
pPlayer->pev->body = 0;
pPlayer->SetBombIcon(FALSE);
pPlayer->SetProgressBarTime(0);
}

pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
// No more weapon
if ((pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) {
Expand Down

0 comments on commit 94bf705

Please sign in to comment.