Adding weapons
Multiplayer
- This guide assumes that you started out with HL2MP and VC++ Express Edition (It's FREE)***
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 known 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.
You can make your own or use the CSS one's.
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. For pistols start with pistol.txt, and for SMGs MGs, and assault rifle use smg1.txt as a template. This is an example of the weapon_pistol.txt file:
Code: // 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/
"printname" "#HL2_Pistol" --Make this whatever you want
Making your weapon show in Hammer -- Not Tested sorry 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" []
Make the code for your weapons
Open:==
C:\yourmod\src\cl_dll\hl2_hud\c_weapon__stubs_hl2.cpp
add your gun under #ifndef HL2MP (line 27)
just copy and paste one of the lines renaming the relevant information
Example:
STUB_WEAPON_CLASS( weapon_ar2, WeaponAR2, C_HLMachineGun );
changed to
STUB_WEAPON_CLASS( weapon_m249, WeaponM4A1, C_HLMachineGun );
Open:
C:\yourmod\src\game_shared\hl2mp\hl2mp_gamerules.cpp
Find CAmmoDef *GetAmmoDef() (Line 910)
Copy and paste the line that is closest to your weapon type, I chose
def.AddAmmoType("MP5NAVY",DMG_BULLET,TRACER_LINE_AND_WHIZ,0,0,225,BULLET_IMPULSE(200,1225),0 );
Replace MP5NAVY with the ammo name in your script file (weapon_???.txt)
Make the code files where ever you want, I would recommend your C:/modname/src folder. When you complete the code expand under Server -> Sources Files -> HL2MP -> Weapons, right-click on Weapons then Add -> Existing Item and find your .cpp file
Do the same for Client -> Sources Files -> HL2MP -> Weapons
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 _________________ - Don't send PM's to this user -
I noticed that there were no decent up-to-date guides hence this wiki -Iliketofrolic666