AllowWeaponSpawn

From Valve Developer Community
Jump to navigation Jump to search
English (en)Translate (Translate)

A callback for the DirectorOptions table. When DirectorOptions is loaded, this function will be called each time for all current weapons in the map, values being strings that represent their respective weapon entities, with a majority being classnames of the weapons's entities. Return true to allow the string's respective weapon to spawn.

Its best to see all the arguments value withprintlfirst to know what to expect, especially since there are oddities for how weapon_ammo_spawn and upgrade_laser_sight are represented; Both respectively are represented asammoandupgrade_itemstrings. Like so:


This callback can be undesirable to work with in certain occasions, as it can't account for specific melees, carryable props, or mounted guns. If so, refer to this sub-section of Code Samples section for an alternative.

Parameters

bool AllowWeaponSpawn(string classname)

Type Name Description
string classname Name of a weapon's classname, though a small few aren't their exact classnames.

Expected Returns

Type Description
bool Return true to allow the respective weapon from spawning, false or none is otherwise.

Code Samples

Array Approach

The boxes are now empty... How unfortunate..

A common approach used in many mutations, including Valve's; This method makes the function find if the argument it gets called back is in theItemsToAllowarray, then it returns true if it finds it.


String Similiarity Approach

Now there's rifles and shotguns of all sorts, Rochelle's interested now!

In the example below, the function will only look for strings that contain a specific keyword in it. This is meant to be used if you need all weapons under a specific weapon category (shotguns, smgs) to be allowed, otherwise just use the above example, as you'll probably add unneeded complexity for your function.


Custom 'AllowWeaponSpawn' Implementation

Sometimes, this callback may be undesirable to use, as it can't account for specific melees, carryable props, or mounted guns. Using OnGameEvent_' prefixed functions, hook the eventround_start_post_navand make our own 'AllowWeaponSpawn' implementation.

This implementation works by comparing the items's model path names, and deleting them if their model paths match the ones in theItemstoRemove_ModelPathsarray.