Improved game player equip

From Valve Developer Community
Jump to navigation Jump to search
Improved game player equip.png

Hey! This tutorial is going to help you improve the “game_player_equip” because, let's be honest, it's a pain having to use SmartEdit over and over again gets tedious. Let's get started! This modification has been made on Mapbase but it should perfectly work with the basic SDK.

Open maprules.cpp Then look for:

bool CGamePlayerEquip::KeyValue( const char *szKeyName, const char *szValue )
{
	if ( !BaseClass::KeyValue( szKeyName, szValue ) )
	{
		for ( int i = 0; i < MAX_EQUIP; i++ )
		{
			if ( !m_weaponNames[i] )
			{
				char tmp[128];

				UTIL_StripToken( szKeyName, tmp );

				m_weaponNames[i] = AllocPooledString(tmp);
				m_weaponCount[i] = atoi(szValue);
				m_weaponCount[i] = MAX(1,m_weaponCount[i]);
				return true;
			}
		}
	}

	return false;
}

Simply change:

m_weaponCount[i] = MAX(1,m_weaponCount[i]);

To:

m_weaponCount[i] = MAX(0,m_weaponCount[i]);

Compile the code !

IT'S NOT DONE YET, one last step !

Open your base.fgd and replace:


@PointClass base(Targetname) size(-8 -8 -8, 8 8 8) = game_player_equip : 
	"An entity that gives equipment to the player who activates it. To use, add new keys to this entity, where each key is the classname of a weapon/item, and the corresponding value is the number of those weapons/items to give to the player who uses this entity. If the 'Use Only' spawnflag isn't set, then players can just touch this entity to get the equipment."
[
	spawnflags(flags) =
	[
		1: "Use Only" : 0
	]
	master(string) : "Team Master (Obsolete)" : : "Legacy support: The name of a master entity. If the master hasn't been activated, this entity will not activate."	
]

By this:

@PointClass base(Targetname) size(-8 -8 -8, 8 8 8) = game_player_equip : 
	"An entity that gives equipment to the player who activates it. To use, add new keys to this entity, where each key is the classname of a weapon/item, and the corresponding value is the number of those weapons/items to give to the player who uses this entity. If the 'Use Only' spawnflag isn't set, then players can just touch this entity to get the equipment."
[
	spawnflags(flags) =
	[
		1: "[1] Use Only" : 0
	]
	
	item_suit(choices) : "Give HEV Suit" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_crowbar(choices) : "Give Crowbar" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_pistol(choices) : "Give Pistol" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_357(choices) : "Give 357 Magnum" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_smg1(choices) : "Give SMG1" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_ar2(choices) : "Give AR2" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_shotgun(choices) : "Give Shotgun" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_crossbow(choices) : "Give Crossbow" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_frag(choices) : "Give Frag Grenade" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]
	
	weapon_rpg(choices) : "Give RPG" : 0 =
	[
		0 : "No"
		1 : "Yes"
	]

	//master(target_destination) : "Team Master (Obsolete)" : : "Legacy support: The name of a master entity. If the master hasn't been activated, this entity will not activate."	
]

Now it's done ! Don't forget to trigger the game_player_equip in hammer for example:

OnTrigger ---> game_player_equip ---> Use

Enjoy !