Adding weapons: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 182: Line 182:




==Setup deafaults weapons==
==Setup defaults weapons==


You can set it so you start with the guns by editing:
You can set it so you start with the guns by editing:
Line 201: Line 201:




It is late I will work on this tomorrow --[[User:Mmiloff90@hotmail.com|SexualPotatoes]] 19:05, 2 Dec 2006 (PST)
 
 
I probably missed some stuff, post in discussion if something is left out.

Revision as of 21:26, 2 December 2006

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_yourweaponnamehere.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/


Scripts

weapon_yourweaponname.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_ak47.txt file:


// AK47

WeaponData {

// Weapon data is loaded by both the Game and Client DLLs.

"printname": "#HL2_ak47"

"viewmodel"
"models/weapons/v_rif_ak47.mdl" //"models/weapons/v_ryourweapons.mdl"
"playermodel"
"models/weapons/w_rif_ak47.mdl"
"anim_prefix"
"ar2"
"bucket"
"2"
"bucket_position"
"1"
"clip_size" "30"
"default_clip" "90"
"clip2_size" "-1"
"default_clip2" "-1"
"primary_ammo" "AK47"
"secondary_ammo" "None"
"weight" "5"
"item_flags" "0"
"BuiltRightHanded" "0" //These makes sure you can have right-
"AllowFlipping" "1" //handed weapons
"damage" "35"
// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds)
SoundData
{
"special1" "Weapon_CombineGuard.Special1"
"empty" "Weapon_IRifle.Empty"
//"double_shot" "Weapon_IRifle.Single"
"reload" "Weapon_AR2.Reload"
"single_shot" "Weapon_ak47.Single"
// NPC SECTION
"single_shot_npc" "Weapon_AR2.NPC_Single"
"reload_npc" "Weapon_AR2.NPC_Reload"
"double_shot_npc" "Weapon_AR2.NPC_Double"
}
// Weapon Sprite data is loaded by the Client DLL.
TextureData
{
"weapon"
{
"font" "WeaponIcons"
"character" "l"
}
"weapon_s"
{
"font" "WeaponIconsSelected"
"character" "l"
}
"ammo"
{
"font" "WeaponIcons"
"character" "u"
}
"ammo2"
{
"font" "WeaponIcons"
"character" "z"
}
"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

"primary_ammo" "AK47" - Name the ammo, you will create your ammo later in this guide

replace v_ak47.mdl and w_ak47.mdl with your model names




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" []

Create C++ files

Go to File -> New -> File...

Click Visual C++ on the left and select .cpp


Pick the first template from http://www.hl2coding.com/forums/viewtopic.php?t=1659

Follow the instructions there... be careful not to copy the second template.

Save as weapon_yourweapon.cpp and add it to the solution explorer:

Save the code files where ever you want, I would recommend your C:/modname/src folder. When you

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

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)


Setup defaults weapons

You can set it so you start with the guns by editing:

c:\yourmod\src\dlls\hl2mp_dll\hl2mp_player.cpp


void CHL2MP_Player::GiveDefaultItems( void ) Line 198







I probably missed some stuff, post in discussion if something is left out.