Skip to content

Commit 5ad9505

Browse files
committed
Add ability to override impulse 101 + new giveammo/givehealth cheat commands
1 parent 6cc2937 commit 5ad9505

1 file changed

Lines changed: 98 additions & 3 deletions

File tree

sp/src/game/server/player.cpp

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ ConVar player_debug_print_damage( "player_debug_print_damage", "0", FCVAR_CHEAT
205205

206206
#ifdef MAPBASE
207207
ConVar player_use_visibility_cache( "player_use_visibility_cache", "0", FCVAR_NONE, "Allows the player to use the visibility cache." );
208+
ConVar player_override_impulse_101( "player_override_impulse_101", "0", FCVAR_NONE, "Makes cfg/impulse_101.cfg override the original command, rather than running both." );
209+
ConVar player_override_give( "player_override_give", "0", FCVAR_NONE, "If enabled, the 'give' command will overwrite occupied weapon slots." );
208210
#endif
209211

210212

@@ -250,6 +252,74 @@ void CC_GiveCurrentAmmo( void )
250252
static ConCommand givecurrentammo("givecurrentammo", CC_GiveCurrentAmmo, "Give a supply of ammo for current weapon..\n", FCVAR_CHEAT );
251253

252254

255+
#ifdef MAPBASE
256+
void CC_GiveSpecificAmmo( const CCommand &command )
257+
{
258+
if ( command.ArgC() < 2 )
259+
{
260+
Msg( "Usage: giveammo <name> <opt: amount> <opt: no sound>\n" );
261+
return;
262+
}
263+
264+
CBasePlayer *pPlayer = UTIL_GetCommandClient();
265+
if ( !pPlayer )
266+
pPlayer = UTIL_PlayerByIndex(1);
267+
268+
if( pPlayer )
269+
{
270+
int iAmmoType = GetAmmoDef()->Index( command.Arg( 1 ) );
271+
272+
if ( iAmmoType > -1 )
273+
{
274+
int iAmmoToGive = 0;
275+
if ( command.ArgC() > 2 )
276+
iAmmoToGive = atoi( command.Arg( 2 ) );
277+
278+
if ( iAmmoToGive == 0 )
279+
{
280+
iAmmoToGive = GetAmmoDef()->MaxCarry( iAmmoType );
281+
}
282+
283+
bool bSuppressSound = false;
284+
if ( command.ArgC() > 3 )
285+
bSuppressSound = atoi( command.Arg( 3 ) ) ? true : false;
286+
287+
pPlayer->GiveAmmo( iAmmoToGive, iAmmoType, bSuppressSound );
288+
}
289+
else
290+
{
291+
Warning( "Unknown ammo type \"%s\"\n", command.Arg( 1 ) );
292+
}
293+
}
294+
}
295+
static ConCommand giveammo("giveammo", CC_GiveSpecificAmmo, "Give a supply of ammo for a specific type.\n\tUsage: giveammo <name> <opt: amount> <opt: no sound>\n", FCVAR_CHEAT );
296+
297+
void CC_GiveHealth( const CCommand &command )
298+
{
299+
CBasePlayer *pPlayer = UTIL_GetCommandClient();
300+
if ( !pPlayer )
301+
pPlayer = UTIL_PlayerByIndex(1);
302+
303+
if( pPlayer )
304+
{
305+
int flHealthToGive = 25.0f;
306+
if ( command.ArgC() > 1 )
307+
flHealthToGive = atof( command.Arg( 1 ) );
308+
309+
int iDamageType = 0;
310+
if ( command.ArgC() > 2 )
311+
iDamageType = atoi( command.Arg( 2 ) );
312+
313+
if ( pPlayer->GetHealth() < pPlayer->GetMaxHealth() || flHealthToGive < 0.0f )
314+
{
315+
pPlayer->TakeHealth( flHealthToGive, iDamageType );
316+
}
317+
}
318+
}
319+
static ConCommand givehealth("givehealth", CC_GiveHealth, "Give health if not at max.\n\tUsage: givehealth <amount, default 25> <opt: damage type>\n", FCVAR_CHEAT );
320+
#endif
321+
322+
253323
// pl
254324
BEGIN_SIMPLE_DATADESC( CPlayerState )
255325
// DEFINE_FIELD( netname, FIELD_STRING ), // Don't stomp player name with what's in save/restore
@@ -6052,9 +6122,17 @@ CBaseEntity *CBasePlayer::GiveNamedItem( const char *pszName, int iSubType )
60526122
// Make sure it matches the subtype
60536123
if ( m_hMyWeapons[i]->GetSubType() == iSubType )
60546124
{
6055-
// Don't use this weapon if the slot is already occupied
6056-
UTIL_Remove( pWeapon );
6057-
return NULL;
6125+
if ( player_override_give.GetBool() )
6126+
{
6127+
// Remove the existing weapon
6128+
UTIL_Remove( m_hMyWeapons[i] );
6129+
}
6130+
else
6131+
{
6132+
// Don't use this weapon if the slot is already occupied
6133+
UTIL_Remove( pWeapon );
6134+
return NULL;
6135+
}
60586136
}
60596137
}
60606138
}
@@ -6528,6 +6606,23 @@ void CBasePlayer::CheatImpulseCommands( int iImpulse )
65286606
case 101:
65296607
gEvilImpulse101 = true;
65306608

6609+
#ifdef MAPBASE
6610+
// Mod-specific impulse 101
6611+
// If you're trying to add new weapons to impulse 101, consider using this file instead.
6612+
if ( g_pFullFileSystem->FileExists( "cfg/impulse_101.cfg", "MOD" ) )
6613+
{
6614+
engine->ClientCommand( edict(), "exec impulse_101" );
6615+
6616+
// Use this cvar to suppress default impulse 101 items.
6617+
// (NOTE: The impulse_101 cfg cannot reliably set this on its own, so you may need to put it in your autoexec instead)
6618+
if ( player_override_impulse_101.GetBool() )
6619+
{
6620+
gEvilImpulse101 = false;
6621+
break;
6622+
}
6623+
}
6624+
#endif
6625+
65316626
EquipSuit();
65326627

65336628
// Give the player everything!

0 commit comments

Comments
 (0)