Difference between revisions of "Creating A Multiplayer Weapon"

From Valve Developer Community
Jump to: navigation, search
 
m (Formatting)
Line 1: Line 1:
 
== Creating A HL2 Multiplayer Weapon ==
 
== Creating A HL2 Multiplayer Weapon ==
<blockquote>
+
Ok so let's get this straight, you're wanting to create a Whole <b>NEW</b> 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
Ok so let's get this straight, you're wanting to create a Whole <b>NEW</b> 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
 
</blockquote>
 
  
 
== weapon_357.cpp ==
 
== weapon_357.cpp ==
  
<blockquote>
+
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 <b>CTRL + H</b> which brings up the Replace box/tab (depending on how you have it) now what i first of all do is this
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 <b>CTRL + H</b> which brings up the Replace box/tab (depending on how you  
 
 
 
have it) now what i first of all do is this
 
</blockquote>
 
 
 
Replace all instances of <b>CWeapon357</b> with <b>CWeaponRifle</b>    In total i get a
 
 
 
result of 15 replaced accurances which seem's good to me but you might think thats it
 
  
right? <b>WRONG</b>
+
Replace all instances of <b>CWeapon357</b> with <b>CWeaponRifle</b>     In total i get a result of 15 replaced accurances which seem's good to me but you might think thats it right?
  
Look for where ever the Weapon357 is replace it with WeaponRifle becareful, C++ syntax is
+
<b>WRONG!</b>
 
 
very case sensitive Once you've got that done move on to the next part =D
 
  
 +
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 ==
 
== weapon_rifle.cpp ==
  
Ok, this is main part so be very careful here ok? Follow exactly what i do. Hit CTRL A +  
+
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 <b>No</b> 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?  
 
 
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 <b>No</b> 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.
 
Boom move onto the next part.
Line 63: Line 20:
 
== weapon_rifle.TXT ==
 
== weapon_rifle.TXT ==
  
Ok so now your probabley happy and dandy that theres no errors right? WELL YOU SHOULD BE!  
+
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 :)
  
that's probabley the hardest part over and done with in my opinion. Right so let's get the
+
<pre>
 +
// Rifle - Wiki tutorial :D
  
weapon in game now shall we? open up weapon_357.txt which is located in
+
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"
  
MyMod/Scripts/weapon_357.txt. Copy it all, and paste it into a new notepad document edit
+
"weight" "2"
 +
"item_flags" "0"
  
what you like in here here's mine for this tutorial :)
+
// 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"
 +
}
  
<blockquote>
+
// Weapon Sprite data is loaded by the Client DLL.
// Rifle - Wiki tutorial :D<br />
+
TextureData
 
+
{
WeaponData<br />
+
"weapon"
{<br />
+
{
// Weapon data is loaded by both the Game and Client DLLs.<br />
+
"file" "sprites/w_icons2"
"printname" "#HL2_Rifle"<br />
+
"x" "0"
"viewmodel" "models/weapons/v_shotgun.mdl"<br />
+
"y" "128"
"playermodel" "models/weapons/w_annabelle.mdl"<br />
+
"width" "128"
"anim_prefix" "shotgun"<br />
+
"height" "64"
"bucket" "2"<br />
+
}
"bucket_position" "1"<br />
+
"weapon_s"
"clip_size" "2"<br />
+
{
"primary_ammo" "357"<br />
+
"file" "sprites/w_icons2b"
"secondary_ammo" "None"<br />
+
"x" "0"
<br />
+
"y" "128"
"weight" "2"<br />
+
"width" "128"
"item_flags" "0"<br />
+
"height" "64"
<br />
+
}
// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16
+
"ammo"
 
+
{
"single_shot" sounds)<br />
+
"file" "sprites/a_icons1"
SoundData<br />
+
"x" "55"
{<br />
+
"y" "90"
<br />
+
"width" "73"
"empty" "Weapon_Shotgun.Empty"<br />
+
"height" "20"
"reload" "Weapon_Shotgun.Reload"<br />
+
}
"special1" "Weapon_Shotgun.Special1"<br />
+
"crosshair"
"single_shot" "Weapon_Shotgun.Single"<br />
+
{
"double_shot" "Weapon_Shotgun.Double"<br />
+
"file" "sprites/crosshairs"
// NPC WEAPON SOUNDS<br />
+
"x" "0"
"reload_npc" "Weapon_Shotgun.NPC_Reload"<br />
+
"y" "48"
"single_shot_npc" "Weapon_Shotgun.NPC_Single"<br />
+
"width" "24"
}<br />
+
"height" "24"
<br />
+
}
// Weapon Sprite data is loaded by the Client DLL.<br />
+
"autoaim"
TextureData<br />
+
{
{<br />
+
"file" "sprites/crosshairs"
"weapon"<br />
+
"x" "0"
{<br />
+
"y" "48"
"file" "sprites/w_icons2"<br />
+
"width" "24"
"x" "0"<br />
+
"height" "24"
"y" "128"<br />
+
}
"width" "128"<br />
+
}
"height" "64"<br />
+
}
}<br />
+
</pre>
"weapon_s"<br />
 
{ <br />
 
"file" "sprites/w_icons2b"<br />
 
"x" "0"<br />
 
"y" "128"<br />
 
"width" "128"<br />
 
"height" "64"<br />
 
}<br />
 
"ammo"<br />
 
{<br />
 
"file" "sprites/a_icons1"<br />
 
"x" "55"<br />
 
"y" "90"<br />
 
"width" "73"<br />
 
"height" "20"<br />
 
}<br />
 
"crosshair"<br />
 
{<br />
 
"file" "sprites/crosshairs"<br />
 
"x" "0"<br />
 
"y" "48"<br />
 
"width" "24"<br />
 
"height" "24"<br />
 
}<br />
 
"autoaim"<br />
 
{<br />
 
"file" "sprites/crosshairs"<br />
 
"x" "0"<br />
 
"y" "48"<br />
 
"width" "24"<br />
 
"height" "24"<br />
 
}<br />
 
}<br />
 
}<br />
 
</blockquote>
 
  
  
 
== Other Usefull Stuff ==
 
== Other Usefull Stuff ==
  
Want it to be a default weapon? Open up Hl2mp_player.cpp Find this function<br />
+
Want it to be a default weapon? Open up Hl2mp_player.cpp Find this function
 
 
'''void CHL2MP_Player::GiveDefaultItems( void )'''<br />
 
<br />
 
Add your weapon to the list.<br />
 
  
i.e GiveNamedItem( "weapon_rifle" );<br />
+
'''void CHL2MP_Player::GiveDefaultItems( void )'''
 +
Add your weapon to the list.
  
 +
i.e GiveNamedItem( "weapon_rifle" );
  
 
== Enjoy Your New Weapon ==
 
== Enjoy Your New Weapon ==

Revision as of 17:21, 28 November 2006

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