-
Notifications
You must be signed in to change notification settings - Fork 9
Custom Weapons
A new weapon system in this mod can create new weapons without a client update, without introducing input lag, and without breaking lag compensation. This is done through config files that define the attributes and event-based behavior for the weapon. It is more limiting than a scripting system, but easier to for newbies to get started with. No coding experience is required.
To create a new weapon, add a new .txt file to the valve_downloads/weapons/ folder and register it in the map CFG. The following CFG line will register a weapon using the config at weapons/my_map/weapon_big.txt.
custom_weapon my_map/weapon_big
You can then add a weapon_big entity somewhere in the map or add it to the map CFG equipment. You'll probably want to start by copying settings from an existing config so that the weapon is registered without errors, then edit it from there. Only the [general] section is required.
After creating a new weapon config and loading it into a map, type in the autoreloadweps command in your client console. This will automatically scan all loaded weapon configs for updates and refresh your settings live. No need to restart the server or rejoin (unless you added new models or sounds that aren't precached yet). If you want to reload the configs manually then type in reloadweps instead.
Configs are in the INI format and are usually organized by action (Primary attack, Secondary attack, Reload). Here's an example config. Comments can begin with ; or // or #. Commented text is ignored by the weapon parser.
For explanations of each section and attribute, see these guides:
Custom Weapon Attributes
Custom Weapon Events
Let's say you've created a new weapon called weapon_good_glock and you want it to completely replace weapon_9mmhandgun. That is, a SevenKewp player should never be able to pick up a normal glock - it must always be the custom version. To do that, add the following lines to your map CFG:
custom_weapon my_map/weapon_good_glock
custom_weapon_alias weapon_good_glock weapon_9mmhandgun
entity_remap weapon_9mmhandgun weapon_custom_ini
hl_weapon_remap weapon_9mmhandgun weapon_good_glock
-
custom_weaponregisters your weapon, which you should already have in your CFG. -
custom_weapon_aliasenables the weapon to be spawned with the classname of the weapon you want to replace. -
entity_remapforces the stock weapon to be created as a custom weapon. Once that happens, your alias logic kicks in and loads your custom weapon settings. -
hl_weapon_remapforces all glocks picked up by SevenKewp players to be replaced by the good version. This is necessary because Half-Life clients can drop the Half-Life glock if you've configured that as thehl_client_classnamefor your weapon. You can possibly skip this if you allow Half-Life clients to use your custom glock, but I don't recommend that for hitscan weapons.
weapon_custom_ini is the generic weapon class that all config-based weapons are created with by default. If you had a custom implementation for your glock then you would remap to that instead of weapon_custom_ini, as seen below:
custom_weapon my_map/weapon_good_glock weapon_good_glock
custom_weapon_alias weapon_good_glock weapon_9mmhandgun
entity_remap weapon_9mmhandgun weapon_good_glock
hl_weapon_remap weapon_9mmhandgun weapon_good_glock
Weapon data is sent to clients on demand, meaning you can edit weapon behavior live, even if the weapon is being used by a player. An example of this is a weapon that has a silencer attachment. You could update the sounds, accuracy, recoil, etc. when the silencer is added. Or maybe you want an experience mod where the fire rate and reload speed increases with your power level.
This and other server-side logic can be added by creating a subclass of CWeaponCustom for your weapon. Register the weapon using the classname override, like so:
custom_weapon my_map/weapon_good weapon_good
and then link your C++ class to the weapon_good classname. Check the virtual methods in CWeaponCustom.h to see where you can inject your custom logic.