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

Grenade weaponbox ammo pickup fix #669

Merged
merged 1 commit into from
Mar 31, 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
46 changes: 36 additions & 10 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,17 @@ int CBasePlayerWeapon::ExtractClipAmmo(CBasePlayerWeapon *pWeapon)
iAmmo = m_iClip;
}

return pWeapon->m_pPlayer->GiveAmmo(iAmmo, pszAmmo1(), iMaxAmmo1());
int iIdAmmo = pWeapon->m_pPlayer->GiveAmmo(iAmmo, pszAmmo1(), iMaxAmmo1());

#ifdef REGAMEDLL_FIXES
if (iIdAmmo > 0 && IsGrenadeWeapon(m_iId))
{
// grenades have WEAPON_NOCLIP force play the "got ammo" sound.
EMIT_SOUND(pWeapon->m_pPlayer->edict(), CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM);
}
#endif

return iIdAmmo;
}

// RetireWeapon - no more ammo for this gun, put it away.
Expand Down Expand Up @@ -1918,19 +1928,35 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
int playerGrenades = pPlayer->m_rgAmmo[pGrenade->m_iPrimaryAmmoType];

#ifdef REGAMEDLL_FIXES
auto info = GetWeaponInfo(pGrenade->m_iId);
if (info && playerGrenades < info->maxRounds)
// sorry for hardcode :(
const int boxAmmoSlot = 1;

if (playerGrenades < pGrenade->iMaxAmmo1())
{
auto pNext = m_rgpPlayerItems[i]->m_pNext;
if (pPlayer->AddPlayerItem(pItem))
if (m_rgAmmo[boxAmmoSlot] > 1 && playerGrenades > 0)
{
pItem->AttachToPlayer(pPlayer);
bEmitSound = true;
if (!FStringNull(m_rgiszAmmo[boxAmmoSlot])
&& pPlayer->GiveAmmo(1, STRING(m_rgiszAmmo[boxAmmoSlot]), pGrenade->iMaxAmmo1()) != -1)
{
m_rgAmmo[boxAmmoSlot]--;

EMIT_SOUND(pPlayer->edict(), CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM);
}
}
else
{
auto pNext = m_rgpPlayerItems[i]->m_pNext;

// unlink this weapon from the box
m_rgpPlayerItems[i] = pItem = pNext;
continue;
if (pPlayer->AddPlayerItem(pItem))
{
pItem->AttachToPlayer(pPlayer);
bEmitSound = true;
}

// unlink this weapon from the box
m_rgpPlayerItems[i] = pItem = pNext;
continue;
}
}
#else

Expand Down