Game weapon manager: Difference between revisions
Jump to navigation
Jump to search

Note: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.
(Added Lang template. Added more explanations about this entity. Added missing input SetMaxPieces and FGD code. Used new KV/I/O BaseEntity templates.) |
m (Replacing {{base point}} with {{this is a}}. This operation was performed by a bot.) |
||
Line 1: | Line 1: | ||
{{lang|game_weapon_manager}} | {{lang|game_weapon_manager}} | ||
{{toc-right}} | {{toc-right}} | ||
{{ | {{this is a|point entity|name=game_weapon_manager}} | ||
{{code class|CGameWeaponManager|gameweaponmanager.cpp}} | {{code class|CGameWeaponManager|gameweaponmanager.cpp}} |
Revision as of 22:58, 6 January 2024


game_weapon_manager
is a point entity available in all Source games.
Entity description
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.
- 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 likeweapon_*
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.

Keyvalues
- 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.
Outputs
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
]