Skip to content

Commit

Permalink
Refactored RemovePlayerItemEx and Extended DestroyItem in CBasePlayer…
Browse files Browse the repository at this point in the history
…Item (#864)
  • Loading branch information
Javekson authored Sep 28, 2023
1 parent ee34b06 commit d7b4409
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
36 changes: 9 additions & 27 deletions regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,38 +217,20 @@ EXT_FUNC bool CCSPlayer::RemovePlayerItemEx(const char* pszItemName, bool bRemov
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;
}
}

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->m_rgAmmo[pItem->PrimaryAmmoIndex()] = 0;
}

pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
// No more weapon
if ((pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) {
pPlayer->m_iHideHUD |= HIDEHUD_WEAPONS;
}

pItem->Kill();

if (!pPlayer->m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]) {
pPlayer->m_bHasPrimary = false;
if (pItem == pPlayer->m_pActiveItem) {
((CBasePlayerWeapon *)pItem)->RetireWeapon();

if (pItem->CanHolster() && pItem != pPlayer->m_pActiveItem && !(pPlayer->pev->weapons &(1 << pItem->m_iId))) {
return true;
}
}

return true;
}

return pItem->DestroyItem();
}

return false;
Expand Down
1 change: 0 additions & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8494,7 +8494,6 @@ void CStripWeapons::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE

if (slot == ALL_OTHER_ITEMS)
{
pPlayer->CSPlayer()->RemovePlayerItem("item_thighpack");
pPlayer->CSPlayer()->RemovePlayerItem("item_longjump");
pPlayer->CSPlayer()->RemovePlayerItem("item_assaultsuit");
pPlayer->CSPlayer()->RemovePlayerItem("item_kevlar");
Expand Down
19 changes: 17 additions & 2 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,27 +1128,42 @@ void EXT_FUNC CBasePlayerWeapon::__API_HOOK(ItemPostFrame)()
}
}

void CBasePlayerItem::DestroyItem()
bool CBasePlayerItem::DestroyItem()
{
bool success = false;

if (m_pPlayer)
{
// if attached to a player, remove.
if (m_pPlayer->RemovePlayerItem(this))
{

#ifdef REGAMEDLL_FIXES
if (m_iId == WEAPON_C4) {
m_pPlayer->m_bHasC4 = false;
m_pPlayer->pev->body = 0;
m_pPlayer->SetBombIcon(FALSE);
m_pPlayer->SetProgressBarTime(0);
}

m_pPlayer->pev->weapons &= ~(1 << m_iId);

// No more weapon
if ((m_pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) {
m_pPlayer->m_iHideHUD |= HIDEHUD_WEAPONS;
}
#endif

if (!m_pPlayer->m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]) {
m_pPlayer->m_bHasPrimary = false;
}
#endif
success = true;
}
}

Kill();

return success;
}

int CBasePlayerItem::AddToPlayer(CBasePlayer *pPlayer)
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class CBasePlayerItem: public CBaseAnimating
virtual int iItemSlot() { return 0; } // return 0 to MAX_ITEMS_SLOTS, used in hud

public:
void EXPORT DestroyItem();
bool EXPORT DestroyItem();
void EXPORT DefaultTouch(CBaseEntity *pOther);
void EXPORT FallThink();
void EXPORT Materialize();
Expand Down

0 comments on commit d7b4409

Please sign in to comment.