Skip to content

Commit

Permalink
Fix: Grenade weaponbox not deploying on unarmed player (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm committed Sep 5, 2023
1 parent 728f1fc commit 1aae57f
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,12 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
pPlayer->OnTouchingWeapon(this);

bool bRemove = true;
bool bEmitSound = false;

#ifdef REGAMEDLL_FIXES
CBasePlayerItem *givenItem = nullptr;
#else
bool givenItem = false;
#endif

// go through my weapons and try to give the usable ones to the player.
// it's important the the player be given ammo first, so the weapons code doesn't refuse
Expand Down Expand Up @@ -1974,7 +1979,7 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
if (pPlayer->AddPlayerItem(pItem))
{
pItem->AttachToPlayer(pPlayer);
bEmitSound = true;
givenItem = pItem;
}

// unlink this weapon from the box
Expand Down Expand Up @@ -2011,7 +2016,7 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
// there we will see only get one grenade. Next step - pick it up, do check again `entity_dump`,
// but this time we'll see them x2.

bEmitSound = true;
givenItem = true;

This comment has been minimized.

Copy link
@Vaqtincha

Vaqtincha Sep 5, 2023

Contributor

givenItem = pPlayer->GiveNamedItem(grenadeName);
???

This comment has been minimized.

Copy link
@dystopm

dystopm Sep 5, 2023

Author Contributor

@Vaqtincha check where REGAMEDLL_FIXES macros is defined ...

This comment has been minimized.

Copy link
@Vaqtincha

Vaqtincha Sep 5, 2023

Contributor

Ok

pPlayer->GiveNamedItem(grenadeName);

// unlink this weapon from the box
Expand All @@ -2033,7 +2038,11 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
if (pPlayer->AddPlayerItem(pItem))
{
pItem->AttachToPlayer(pPlayer);
bEmitSound = true;
#ifdef REGAMEDLL_FIXES
givenItem = pItem;
#else
givenItem = true;
#endif
}

// unlink this weapon from the box
Expand Down Expand Up @@ -2067,9 +2076,21 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
}
}

if (bEmitSound)
if (givenItem)
{
EMIT_SOUND(ENT(pPlayer->pev), CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM);

#ifdef REGAMEDLL_FIXES
// BUGBUG: weaponbox links gun to player, then ammo is given
// so FShouldSwitchWeapon's CanHolster (which checks ammo) check inside AddPlayerItem
// return FALSE, causing an unarmed player to not deploy any weaponbox grenade
if (pPlayer->m_pActiveItem != givenItem && CSGameRules()->FShouldSwitchWeapon(pPlayer, givenItem))
{
// This re-check is done after ammo is given
// so it ensures player properly deploys grenade from floor
pPlayer->SwitchWeapon(givenItem);
}
#endif
}

if (bRemove)
Expand Down

0 comments on commit 1aae57f

Please sign in to comment.