Weapons on Spawn

From Valve Developer Community
Jump to: navigation, search

This is a copy and paste tutorial that will allow you to give a player weapons on spawn.

This has been tested with Source 2007 Single Player (Orange Box). This may work in Source 2006 Single Player (Episode 1). This tutorial does NOT apply to multiplayer mods since the player already spawns with weapons (see hl2mp_player.cpp for more information).

Note.pngNote:This will also work for Source 2013 Singleplayer. (Steampipe)
Warning.pngWarning:This will affect background maps, so that's why we have a ConVar .

Requirements

  • Source 2007 Single Player (Orange Box), Source 2006 Single Player (Episode 1) OR Source 2013 Single Player (Steampipe)

Implementing

Open up player.cpp in your server project and find this line:

ConVar  player_debug_print_damage( "player_debug_print_damage", "0", FCVAR_CHEAT, "When true, print amount and type of all damage received by player to console." );

Under it add:

ConVar	sk_player_weapons( "sk_player_weapons","0" );

Then find:

void CBasePlayer::Spawn( void )

And add this at the end of it:

if (sk_player_weapons.GetBool())
{
	// Give the player everything!
	GiveAmmo( 255,	"Pistol");
	GiveAmmo( 255,	"AR2");
	GiveAmmo( 255,	"SMG1");
	GiveAmmo( 255,	"Buckshot");
	GiveAmmo( 32,	"357" );
	//#ifdef HL2_EPISODIC
	//GiveAmmo( 5,	"Hopwire" );
	//#endif		
	GiveNamedItem( "weapon_smg1" );
	GiveNamedItem( "weapon_crowbar" );
	GiveNamedItem( "weapon_pistol" );
	GiveNamedItem( "weapon_ar2" );
	GiveNamedItem( "weapon_shotgun" );
	GiveNamedItem( "weapon_357" );	
}

Here's all weapons and all ammo types (from line 6055 in player.cpp)

		GiveAmmo( 255,	"Pistol");
		GiveAmmo( 255,	"AR2");
		GiveAmmo( 5,	"AR2AltFire");
		GiveAmmo( 255,	"SMG1");
		GiveAmmo( 255,	"Buckshot");
		GiveAmmo( 3,	"smg1_grenade");
		GiveAmmo( 3,	"rpg_round");
		GiveAmmo( 5,	"grenade");
		GiveAmmo( 32,	"357" );
		GiveAmmo( 16,	"XBowBolt" );
		
		GiveNamedItem( "weapon_smg1" );
		GiveNamedItem( "weapon_frag" );
		GiveNamedItem( "weapon_crowbar" );
		GiveNamedItem( "weapon_pistol" );
		GiveNamedItem( "weapon_ar2" );
		GiveNamedItem( "weapon_shotgun" );
		GiveNamedItem( "weapon_physcannon" );
		GiveNamedItem( "weapon_bugbait" );
		GiveNamedItem( "weapon_rpg" );
		GiveNamedItem( "weapon_357" );
		GiveNamedItem( "weapon_crossbow" );

Of course, you can include custom weapons you made for your mod as well.