Skip to content

Commit

Permalink
Implement dropall client command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikk155 committed Sep 24, 2024
1 parent f5f21f7 commit 27bb03a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/game/server/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,13 @@ void SV_CreateClientCommands()
player->GiveNamedItem(STRING(iszItem)); },
{.Flags = ClientCommandFlag::Cheat});

g_ClientCommands.Create("dropall", [](CBasePlayer* player, const auto& args) { player->DropPlayerWeapon( "all" ); });
g_ClientCommands.Create("drop", [](CBasePlayer* player, const auto& args)
{
// player is dropping an item.
player->DropPlayerWeapon(args.Argument(1)); });


g_ClientCommands.Create("fov", [](CBasePlayer* player, const auto& args)
{
if (0 != g_psv_cheats->value && args.Count() > 1)
Expand Down
52 changes: 34 additions & 18 deletions src/game/server/entities/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4600,6 +4600,11 @@ void CBasePlayer::DropPlayerWeapon(const char* pszItemName)
// match!
break;
}
else if( FStrEq( pszItemName, "dropall" ) )
{
// Drop all items!
break;
}
}
else
{
Expand All @@ -4624,34 +4629,45 @@ void CBasePlayer::DropPlayerWeapon(const char* pszItemName)

UTIL_MakeVectors(pev->angles);

ClearWeaponBit(weapon->m_iId); // take item off hud

CWeaponBox* pWeaponBox = (CWeaponBox*)CBaseEntity::Create("weaponbox", pev->origin + gpGlobals->v_forward * 10, pev->angles, this);
pWeaponBox->pev->angles.x = 0;
pWeaponBox->pev->angles.z = 0;
pWeaponBox->PackWeapon(weapon);
pWeaponBox->pev->velocity = gpGlobals->v_forward * 300 + gpGlobals->v_forward * 100;

// drop half of the ammo for this weapon.
int iAmmoIndex;
while( weapon )
{
ClearWeaponBit(weapon->m_iId); // take item off hud

iAmmoIndex = GetAmmoIndex(weapon->pszAmmo1()); // ???
pWeaponBox->PackWeapon(weapon);

if (iAmmoIndex != -1)
{
// this weapon weapon uses ammo, so pack an appropriate amount.
if ((weapon->iFlags() & ITEM_FLAG_EXHAUSTIBLE) != 0)
{
// pack up all the ammo, this weapon is its own ammo type
pWeaponBox->PackAmmo(MAKE_STRING(weapon->pszAmmo1()), m_rgAmmo[iAmmoIndex]);
m_rgAmmo[iAmmoIndex] = 0;
}
else
// drop half of the ammo for this weapon.
int iAmmoIndex;

iAmmoIndex = GetAmmoIndex(weapon->pszAmmo1()); // ???

if (iAmmoIndex != -1)
{
// pack half of the ammo
pWeaponBox->PackAmmo(MAKE_STRING(weapon->pszAmmo1()), m_rgAmmo[iAmmoIndex] / 2);
m_rgAmmo[iAmmoIndex] /= 2;
// this weapon weapon uses ammo, so pack an appropriate amount.
if ((weapon->iFlags() & ITEM_FLAG_EXHAUSTIBLE) != 0)
{
// pack up all the ammo, this weapon is its own ammo type
pWeaponBox->PackAmmo(MAKE_STRING(weapon->pszAmmo1()), m_rgAmmo[iAmmoIndex]);
m_rgAmmo[iAmmoIndex] = 0;
}
else
{
// pack half of the ammo
pWeaponBox->PackAmmo(MAKE_STRING(weapon->pszAmmo1()), m_rgAmmo[iAmmoIndex] / 2);
m_rgAmmo[iAmmoIndex] /= 2;
}
}

// Break if not dropall
if( !FStrEq( pszItemName, "dropall" ) )
break;

weapon = weapon->m_pNext;
}

return; // we're done, so stop searching with the FOR loop.
Expand Down

0 comments on commit 27bb03a

Please sign in to comment.