Creating A Multiplayer Weapon: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{cleanup}}
{{cleanup}}
----
This article DOES NOT Work for HL2MP it creates an error about the Network table. Trying to find a fix for it. [[User:Johnyb|Johnyb]]
----




Line 25: Line 17:
== 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 + 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?
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 MAKE sure you change the save location down the bottom to [mod dir]\src\game_shared\hl2mp as it is a common file between the server and client. Now click ok and 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 to add the same file to the client side, open up the client/Source Files/hl2mp/weapons and right click on the folder and select add existing. Select the same file '''weapon_rifle.cpp''' that is in the game_share dir (from before) and click add. Compile and your done.


Boom move onto the next part.


== weapon_rifle.TXT ==
== weapon_rifle.TXT ==

Revision as of 07:49, 27 December 2006

Broom icon.png
This article or section needs to be cleaned up to conform to a higher standard of quality.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.


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 MAKE sure you change the save location down the bottom to [mod dir]\src\game_shared\hl2mp as it is a common file between the server and client. Now click ok and 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 to add the same file to the client side, open up the client/Source Files/hl2mp/weapons and right click on the folder and select add existing. Select the same file weapon_rifle.cpp that is in the game_share dir (from before) and click add. Compile and your done.


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