This article's documentation is for anything that uses the Source engine. Click here for more information.

game_weapon_manager

From Valve Developer Community
Jump to: navigation, search
English (en)
... Icon-Important.png
class hierarchy
CGameWeaponManager defined in gameweaponmanager.cpp
CBaseEntity

game_weapon_manager is a point entity available in all Source Source games. It is used to limit the number of a particular weapon class in the world. Useful in places where NPCs are spawning rapidly, dying, and dropping weapons.

Note.pngNote:The properties of this entity apply to the whole map. Multiple instances of this entity within a map may cause errors.
  • On spawn, this entity will try to create an entity of the classname specified in the KeyValue weaponname. If this fails, this entity removes itself. That's why wildcards like weapon_* cannot be used.
  • This entity thinks every 2 seconds, potentially removing weapons.
  • Every time this entity thinks, it conducts a count of all the weapons in the world of the specified class and checks if there is a surplus. If so, it tries to find suitable candidates for removal, namely all weapons of the specified class that satisfy ( !weapon->IsEffectActive( EF_NODRAW ) && weapon->IsRemoveable() ).
    • Singleplayer games: It removes the first candidates that are found behind the player, or are out of the player's PVS.
    • Multiplayer games: This entity removes the candidates with the lowest entity index, regardless of the players' PVS. That's because this entity is designed using UTIL_GetLocalPlayer, which returns NULL in any type of multiplayer game.
Note.pngNote:This code is designed to not remove weapons that are hand-placed by level designers. It should only clean up weapons dropped by dead NPCs, which is useful in situations where enemies are spawned in for a sustained period of time.

Keyvalues


Targetname:
Name (targetname) <string>
The targetname that other entities refer to this entity by.
Weapon Classname (weaponname) <string>
Classname of the weapon type to limit.
Max Allowed in Level (maxpieces) <integer>
The maximum amount of the specified weapon type allowed in the world.
Ammo modifier (ammomod) <float>
Modifier for amount of ammo dropped by a weapon.

Inputs

SetAmmoModifier <float>
Adjust the ammo modifier.
SetMaxPieces <integer> !FGD
Adjust the maximum number of specified weapons in the map.

FGD Code

This code adds the missing input SetMaxPieces (namely the penultimate line) in Hammer and must be pasted in the corresponding place of base.fgd.

@PointClass base(Targetname) = game_weapon_manager : 
	"An entity used to limit the number of a particular weapon type in the world. Useful in places where NPCs are spawning rapidly, dying, and dropping weapons." 
[
	weaponname(string) : "Weapon Classname" : "" : "Classname of the weapon type to limit."
	maxpieces(integer) : "Max Allowed in Level"	: 0 : "The maximum amount of the specified weapon type allowed in the world."
	ammomod(float)	   : "Ammo modifier" : 1 : 	"Modifier for ammount of ammo dropped by a weapon."

	// Inputs
	input SetAmmoModifier(float): "Adjust the ammo modifier."
	input SetMaxPieces(integer): "Adjust the maximum number of specified weapons in the map." // added
]