Miscellaneous
description
A guide on what it takes to add your own weapons to HL2.
keywords
adding, add, new, weapons, weapon, models, model, code, coding.
Adding a weapon into Half-Life 2 can be a complicated task, some people assume you just create a model and then the rest takes care of itself; this is not the case. Adding 1 weapon requires you to make and/or edit many files.
This guide will NOT teach you how to model a weapon; it is simply an overview of the process showing which files are affected, giving you an understanding of how to begin adding your own new weapons.
The models
Weapons consist of 2 models, each with their own prefix. A model named v_???.mdl is a view model this is the model that is seen from the players perspective, this normally consists of not only the weapon model but also the player hands.
Next is the w_???,mdl; this is know as the world model these models are used for weapons laying on the ground and also for weapons that you can see in other characters/players hands.
Lets look at the pistol for example:
-- Pic of v_pistol --
-- Pic of w_pistol --
As you can see the world model is considerably uglier, this is for optimisation reasons. You will rarely notice the quality of a world model in-game, as it is not in the players view to the same extent as the view model.
Once you have made the relevant models, they go into the folder:
/nameofmodfolder/models/weapons/
The Textures
The textures/skins for the weapons also need to be placed in the correct folder so once the textures are done, they need to be placed in:
/nameofmodfolder/materials/models/weapons/
weapon_???.txt
Each weapon has its own script file which can be edited in any .txt program, the weapon script file has many different purposes, which include:- model file names, bucket info, clip size, ammo type, weight, sounds, icons, crosshairs.
This is an example of the weapon_pistol.txt file:
- Code: Select all
// Pistol
WeaponData
{
// Weapon data is loaded by both the Game and Client DLLs.
"printname" "#HL2_Pistol"
"viewmodel" "models/weapons/v_pistol.mdl"
"playermodel" "models/weapons/w_pistol.mdl"
"anim_prefix" "pistol"
"bucket" "1"
"bucket_position" "0"
"clip_size" "18"
"primary_ammo" "Pistol"
"secondary_ammo" "None"
"weight" "2"
"item_flags" "0"
// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds)
SoundData
{
"reload" "Weapon_Pistol.Reload"
"reload_npc" "Weapon_Pistol.NPC_Reload"
"empty" "Weapon_Pistol.Empty"
"single_shot" "Weapon_Pistol.Single"
"single_shot_npc" "Weapon_Pistol.NPC_Single"
"special1" "Weapon_Pistol.Special1"
"special2" "Weapon_Pistol.Special2"
"burst" "Weapon_Pistol.Burst"
}
// Weapon Sprite data is loaded by the Client DLL.
TextureData
{
"weapon"
{
"font" "WeaponIcons"
"character" "d"
}
"weapon_s"
{
"font" "WeaponIconsSelected"
"character" "d"
}
"ammo"
{
"font" "WeaponIcons"
"character" "p"
}
"crosshair"
{
"font" "Crosshairs"
"character" "Q"
}
"autoaim"
{
"file" "sprites/crosshairs"
"x" "0"
"y" "48"
"width" "24"
"height" "24"
}
}
}
so create your weapon_nameofweapon.txt file in the same format as shown and save it in the following folder:
/nameofmodfolder/scripts/
Name of Weapon for HUD
Backtracking ever so slightly to the weapon script file just mentioned, look at the line:
"printname" "#HL2_Pistol"
This is setting up the name that will be shown on the HUD during the weapon selection menu. To change this you need to go to the folder:
/nameofmodfolder/resource/
and open up the hl2_english.txt (or indeed, it may be called something different depending on if you’ve made your own)
In this file scroll down and you can see this line:
"HL2_Pistol" "9MM PISTOL"
This is calling “HL2_Pistol” “9mm Pistol”, so to add your own you need to reference the name of your weapon in both files (hl2_english and weapon_???.txt)
Here is an example:
In weapon_???.txt:
"printname" "#HL2_Zapper"
so in hl2_english.txt:
"HL2_Zapper" "Tazer Gun "
To clarify; by adding the above to your hl2_english.txt, the weapon icon on the HUD will now say "Tazer Gun". If you were to not make this change then it would say "#HL2_Zapper"
Making your weapon show in Hammer
To get your weapon to show in hammer you need to add the entry to your .fgd file, which should be saved in sourcesdk/bin/
Open it up in notepad or similar, and find where the other (HL2) weapons are referenced. Add yours with them, here is an example:
@PointClass base(Weapon) studio("models/weapons/w_tazer.mdl") = weapon_tazer : "Tazer" []
Code your Weapon
When it comes to coding your weapon there are a few files that need to be created/ modified. They are as follows:
/game_shared/hl2mp/weapon_???.cpp
/dlls/hl2_dll/weapon_???.cpp
and lastly add the new weapon into
-cl_dll/chl2_hud/c_weapon__stubs_hl2.cpp
also, if you want your weapon to be given with the impulse 101 cheat, add it in this file:
/dlls/player.cpp
NOTE: some of the directory structures may be different, following SDK updates etc. this was written after the large August 2006 update
There you have it; you should now have an understanding of how to get a new weapon in-game. Be aware that there is a lot of work to be done that I have not mentioned in detail, such as the code or explaining the weapon_???,txt file fully. Most people should be able to figure out the rest.
Good luck and I hope to see some new weapons being made soon.
-Mr Greenfish










