Creating A Multiplayer Weapon

From Valve Developer Community
Revision as of 17:10, 28 November 2006 by Tommygun.9mm (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Creating A HL2 Multiplayer Weapon

Ok so let's get this straight, you're wanting to create a Whole NEW weapon for your

new Half Life 2 Multiplayer game right? Now your stuck and need a little tutorial which

will tell you what to do right? Well luck is here as i shall teach you how to impliment a

new weapon ready to use for your multiplayer game =D

weapon_357.cpp

Ok so what i first of like to do is open up weapon_357.cpp on the server side, and once

that's open i hit CTRL + H which brings up the Replace box/tab (depending on how you

have it) now what i first of all do is this

Replace all instances of CWeapon357 with CWeaponRifle In total i get a

result of 15 replaced accurances which seem's good to me but you might think thats it

right? WRONG

Look for where ever the Weapon357 is replace it with WeaponRifle becareful, C++ syntax is

very case sensitive Once you've got that done move on to the next part =D


weapon_rifle.cpp

Ok, this is main part so be very careful here ok? Follow exactly what i do. Hit CTRL A +

CTRL C now in your solution just where your 357 is located, right click the Weapons folder

then select Add> Add New Item. Now select CPP in the name part add weapon_rifle.cpp click

ok now it will be created and in there ready and 2003 edition is what i use, open's the new

file up for you straight away. NOW in the weapon_rifle.cpp hit CTRL + V hit save (ctrl + s)

now don't be silly and go save the 357 file just hit CTRL + Z until the instanes are all

the same, or just close it and if it ask's you to save say No Wow, we're getting

somewhere now aint we =D. Now if you were to compile this in game you'll get a database

error in your console which is what we do not want at all, open back up your compiler for

me it's Microsoft Visual Studio .NET 2003 (best imo) now right click on your new weapon

item, click Copy move over to the Client side, locate where your weapons are there same

folder i guess sourcefiles/weapons right click the weapons folder and click Paste now if

you were to run the game now it wont work you'll see soon enough, Compiled fine? no errors?

Boom move onto the next part.

weapon_rifle.TXT

Ok so now your probabley happy and dandy that theres no errors right? WELL YOU SHOULD BE!

that's probabley the hardest part over and done with in my opinion. Right so let's get the

weapon in game now shall we? open up weapon_357.txt which is located in

MyMod/Scripts/weapon_357.txt. Copy it all, and paste it into a new notepad document edit

what you like in here here's mine for this tutorial :)

// Rifle - Wiki tutorial :D

WeaponData
{
// Weapon data is loaded by both the Game and Client DLLs.
"printname" "#HL2_Rifle"
"viewmodel" "models/weapons/v_shotgun.mdl"
"playermodel" "models/weapons/w_annabelle.mdl"
"anim_prefix" "shotgun"
"bucket" "2"
"bucket_position" "1"
"clip_size" "2"
"primary_ammo" "357"
"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
{

"empty" "Weapon_Shotgun.Empty"
"reload" "Weapon_Shotgun.Reload"
"special1" "Weapon_Shotgun.Special1"
"single_shot" "Weapon_Shotgun.Single"
"double_shot" "Weapon_Shotgun.Double"
// NPC WEAPON SOUNDS
"reload_npc" "Weapon_Shotgun.NPC_Reload"
"single_shot_npc" "Weapon_Shotgun.NPC_Single"
}

// Weapon Sprite data is loaded by the Client DLL.
TextureData
{
"weapon"
{
"file" "sprites/w_icons2"
"x" "0"
"y" "128"
"width" "128"
"height" "64"
}
"weapon_s"
{
"file" "sprites/w_icons2b"
"x" "0"
"y" "128"
"width" "128"
"height" "64"
}
"ammo"
{
"file" "sprites/a_icons1"
"x" "55"
"y" "90"
"width" "73"
"height" "20"
}
"crosshair"
{
"file" "sprites/crosshairs"
"x" "0"
"y" "48"
"width" "24"
"height" "24"
}
"autoaim"
{
"file" "sprites/crosshairs"
"x" "0"
"y" "48"
"width" "24"
"height" "24"
}
}
}


Other Usefull Stuff

Want it to be a default weapon? Open up Hl2mp_player.cpp Find this function

void CHL2MP_Player::GiveDefaultItems( void )

Add your weapon to the list.

i.e GiveNamedItem( "weapon_rifle" );


Enjoy Your New Weapon

Hey, thanks for viewing my tutorial and i hope it helps and teaches your for the future my

friends =D