Pick up the crowbar of research scientist Gordon Freeman, who finds himself on an alien-infested Earth being picked to the bone, its resources depleted, its populace dwindling. Freeman is thrust into the unenviable role of rescuing the world from the wrong he unleashed back at Black Mesa. And a lot of people, people he cares about, are counting on him.

Post tutorial Report RSS Making a working multiplayer weapon

There are lots of tutorials out there that explain how you make a weapon for a singleplayer mod. Well here is one on how to add a new pistol to a multiplayer mod. The process to make it work in multiplayer is almost too simple.

Posted by on - Intermediate Server Side Coding

[page=Introduction]

Before you start :

  • This tutorial expects you to know basic c++. But you could probably do this regardless.
  • This tutorial might not work on weapons that are handled diffrently on server side vs. client side.

[page=Cloning the existing Pistol]
Add a new empty .cpp file to the client projects weapon folder as a suggestion but it doesn't really matter as long as you know where it is, and name it MyNewPistol.cpp

Open the weapon_pistol.cpp file and copy everything and paste it into the MyNewPistol.cpp file.
Rename all references to Pistol to MyPistol except those that begins with ACT_ when you finnished renaming, you may compile to see you got any errors. If you did get errors make sure you only changed the name Pisol to MyPistol in the MyNewPistol.cpp and you keept the case. That is, the text weapon_pisol should be weapon_mypistol. not weapon_MyPistol. etc.

Only one more Clientside step before the client side is complete.
Find the file c_weapon__stubs_hl2.cpp
and find the line

STUB_WEAPON_CLASS( weapon_pistol, WeaponPistol, C_BaseHLCombatWeapon );

under it, add

STUB_WEAPON_CLASS( weapon_mypistol, WeaponMyPistol, C_BaseHLCombatWeapon );

[page=Making it Serverside]

On to step two. Now you have a working clientside gun. That is the client knows how it works and so forth, but you can't add it because your server has no knowledge of the gun. To fix this. Enter the HL(Server) project instead of the Client project and locate the weapon folder. Right click and choose "Add existing file" go look for you MyNewPistol.cpp and add it to the folder. Now the server know's about the new pistol. Compile and make sure you get no errors. We are not quite done yet, there is one thing left to do

[page=The last touch]

Even after all the code is in place you still will get a "can't parse file info" error if you start the mod in it's current state. After compiling go to your steam\steamapps\sourcemods\"Your mod name"\scripts and find weapon_pistol.txt
copy it and rename the copy to weapon_mypistol.txt these files contain all the data for all the weapons in the game. Here you can change damage, bullets and models for the weapon to you liking. Don't forget to change the bucket position in the txt file so it doesn't use the same space as a allready existing gun.

[page=Conclusion]
It doesn't have to be harder than this as long as there is no diffrent way to handle things on the client vs the server side.
Hope you have no problems. Enjoy.

Post comment Comments
goneandone
goneandone - - 73 comments

I need a thread like this...
Is this only for multiplayer mods? if it is can you help me out on a singleplayer mod?
but thanks for this

Reply Good karma Bad karma+1 vote
rookiehy2
rookiehy2 - - 14 comments

Now i can have a new weapon in my multiplayer mod! THANK YOU!

Reply Good karma Bad karma+1 vote
SGTMattyW
SGTMattyW - - 12 comments

I can only find one tutorial for adding single player weapons, and that doesn't quite work. Any possibility of getting a single-player weapon adding tutorial written?

Reply Good karma Bad karma+1 vote
Chuto
Chuto - - 37 comments

ffor what game is it??

Reply Good karma Bad karma-1 votes
JoffL
JoffL - - 433 comments

Chuto: it is for half life 2

Reply Good karma Bad karma+2 votes
zombieOnion
zombieOnion - - 632 comments

Amen! this is great :)

Reply Good karma Bad karma+1 vote
Jaddori
Jaddori - - 25 comments

Can i do this with Microsoft Visual C++ 6.0 ?

Reply Good karma Bad karma+1 vote
Xyius
Xyius - - 29 comments

Awesome tutorial! Easy to follow and read. Nicely done! This will help me alot!

Reply Good karma Bad karma+1 vote
tymaxbeta
tymaxbeta - - 1,059 comments

thank god! Multiple melee weapons was just what I needed, and its easy, I cant believe this, one more thing. If I do this with NPC files, will it work the same?(I'm going to go try this out for those who want to know, I'll have an answer soon)

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: