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

Refactored RemovePlayerItemEx and Extended DestroyItem in CBasePlayerItem #864

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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