-
Notifications
You must be signed in to change notification settings - Fork 9
Custom Weapons
Custom Weapons can be created two ways. The classic method is to create a new subclass of CBasePlayerWeapon and recompile the server. If you want the weapon to hit what you're aiming at and not feel laggy, you would also need recompile and distribute a new version of the client. This is a hassle when porting dozens of weapons used only once per map/mod port.
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 mapping or coding experience is required.
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 add 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.
To create a new weapon, add a new .txt file to the valve_downloads/weapons/ folder and register in the map CFG. The following CFG line will register a weapon using the config at weapons/my_map/my_new_weapon.txt.
custom_weapon my_map/my_new_weapon
You can then add a my_new_weapon 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. Just type in new settings and watch how the weapon changes. 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