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

Fix: Grenade weaponbox not deploying on unarmed player #847

Merged
merged 3 commits into from
Sep 5, 2023
Merged
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
31 changes: 26 additions & 5 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,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 @@ -1955,7 +1960,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 @@ -1992,7 +1997,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;
pPlayer->GiveNamedItem(grenadeName);

// unlink this weapon from the box
Expand All @@ -2014,7 +2019,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 @@ -2048,9 +2057,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