TUTORIAL : Add the physgun to your MP mod from scratch

V

vk_phoenixfr

Guest
Importing the SP gravity gun into a MP mod from scratch.
--------------------------------------------------------

Hi there !

I make this tutorial because i finally managed to have my GGun in my MP mod,
and would have been pleased to find such a guide to help me. So i share with you ;)

There are two steps to get this working (well three in fact but two coding ones).

Let's have a look at the non coding step first: You must exctract from the halflife2 gcf file
the sounds/scripts/models and put them into your mod, so you can find them when you need them.
For example, it will give you the sounds when you walk, jump, and...shoot the GGun :)
Use GCFScape for this.

Now the coding.

For the GGun to appear in your mod, you must have code for it in both the client and server dll's.
So the 2 steps are obviously :
1. import GGun into client dll;
2. import GGun into server dll.

1. Client DLL
-------------

This step is quite easy.
You will see in you client source directory a c_weapon_physgun.cpp. This is not the one you must use.
Actually, there is another GGun source file called c_weapon_gravitygun.cpp.
You must add it to your solution (client project).
In VS 2003, go to the client/HL2_DLL node, right click then choose "add an existing element".
Then in the file browser window, go to src/cl_dll/hl2_hud then select c_weapon_gravitygun.cpp.
Build your client project. you're done for the first step. But we'll be back to the client side soon.

2. Server DLL
-------------

Now comes the tricky part.
First, go to the hl project (server) then in the HL2_DLL node, select weapon_physcannon.cpp, right click, properties
and include it into the build (Excluded from Build : No)
Now compile, you'll have many errors.

Now look into the include section of this file. You have to change some include files.
Change : #include "hl2_player.h" to #include "sdk_player.h"
Change : #include "basehlcombatweapon.h" to #include "basecombatweapon.h"

Basicly, each time you find a reference to hl in an include file, you must either remove the hl or replace the
file by an sdk equivalent (see the hl2_player >> sdk_player example).

Now, you'll find other errors, because of class use in the weapon_physcannon.cpp file.
Actually it uses the CHL2_Player class, which is defined in hl2_player.h/cpp. But we removed this file remember?
So you must remove this class by the SDK equivalent (defined in sdk_player) : CSDKPlayer.
Use the "replace all" feature, no bad replacement will be made (i checked that).

The same problem will araise with the CBaseHLCombatWeapon (again a replaced header file, now missing).
Do the same job, replace all with CBaseCombatWeapon.

Now another problem. The EnableSprint (bool) method doesn't exist in the sdk_player.
I removed the calls to this method because i don't need in my mod by now, but you can take it from HL2_Player and add it to
the sdk_player (don't forget to add its declaration in the sdk_player.h if you choose this solution).

Last problem i remember about before compilation and linkage works, the extern links.
weapon_physcannon makes use of the hl2_normspeed, hl2_sprintspeed and hl2_walkspeed.
Two of them are externs, the last is not but not defined in sdk_player.
Two solution to this. Replace the references to these vars by their values (320.0f for sprint, 190.0f for norm, and 150.0f for walk).
Or create these vars in sdk_player.

You can find them in HL2_Player, under a #ifdef HL2DM /* values */ #else /* hl2 var definition */
Then remove the declaration of links to these extern vars in weapon_physcannon ( look for : extern ConVar hl2_normspeed )

Now if you compile, it should work.
But in game, doesn't work.

You get the errors :
Datatable Warning: No matching RecvTable for SendTable 'DT_WeaponGravityGun'.
Client missing DT class CWeaponGravityGun
Host_EndGame: CL_ParseClassInfo_EndClasses: CreateDecoders Failed.

First, in the c_weapon_gravitygun.cpp (and .h) rename the class CWeapon_GravityGun by CWeapon_PhysCannon (check the name in
the server side weapon_physcannon, and make it the same). Not so usefull, but cleaner.
Then in the client c_weapon_gravitygun.cpp, find the DECLARE_DATA... statement, one of them will declare the DT_WeaponGravityGun
table. Make it the same name as declared in the server weapon_physcannon.cpp.
Finally, in c_weapon_physcannon.cpp take the property declaration (RecvProp) about m_bIsUpgrading or something like that, then add it to
the props definition of c_weapon_gravitygun.cpp (if you don't you'll get another in-game error).

compile, link, launch, and smile ;)

By now, only the primary attack works, but i'm working on it. I'll update this tutorial when i make it grab things.

Have fun, and i hope you find it usefull !

Comments welcome of course.
 
I get 105 errors. First of all it can't find 'sdk_player.cpp", I fixed this by moving weapon_physgun to the server SDK directory but then I still get this:
--------------------Configuration: client - Win32 Release SDK--------------------
Compiling...
weapon_physcannon.cpp
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(165) : error C2061: syntax error : identifier 'CRagdollProp'
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(192) : error C2039: 'VPhysicsSwapObject' : is not a member of 'C_BaseEntity'
E:\Killzone\src\cl_dll\c_baseentity.h(210) : see declaration of 'C_BaseEntity'
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(467) : error C2065: 'PhysGetEntityMass' : undeclared identifier
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(522) : error C2065: 'PhysicsImpactSound' : undeclared identifier
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(527) : error C2065: 'Pickup_GetPreferredCarryAngles' : undeclared identifier
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(590) : error C2061: syntax error : identifier 'CRagdollProp'
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(591) : error C2143: syntax error : missing ';' before '{'
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(594) : error C2181: illegal else without matching if
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(600) : error C2065: 'CPhysicsProp' : undeclared identifier
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(600) : error C2065: 'pProp' : undeclared identifier
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(600) : error C2061: syntax error : identifier 'CPhysicsProp'
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(603) : error C2227: left of '->GetPreferredCarryAngles' must point to class/struct/union
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(667) : error C2027: use of undefined type 'IPhysicsFrictionSnapshot'
.\..\Public\vphysics_interface.h(66) : see declaration of 'IPhysicsFrictionSnapshot'
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(667) : error C2227: left of '->IsValid' must point to class/struct/union
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(667) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(19): Could not find the file sdk_player.h.
E:\Killzone\src\dlls\hl2_dll\weapon_physcannon.cpp(20): Could not find the file te_firebullets.h.

weapon_physcannon.obj - 15 error(s), 0 warning(s)

And shouldn't you have this in the header (like every server gun thingy)?:
#if defined( CLIENT_DLL )

#include "c_sdk_player.h"

#else

#include "sdk_player.h"

#endif
 
For the #ifdef part, well actually i made this tut with my memory, but i wanted to say that every instance of hl2_player should be replaced by sdk_player. And now that i read this, i think i remember replacing such a ifdef thing.

You speak about weapon_physgun, so i assume it's the server one.
Don't move it, it works well where it is.

The sdk_player.h/cpp is in the hl/hl2_dll/sdk server side, cl_dll/hl2_dll/sdk for client side.

Check if the file it can't find are excluded from build, but it would surprise me about sdk_player.
 
Basicly, each time you find a reference to hl in an include file, you must either remove the hl or replace the
file by an sdk equivalent (see the hl2_player >> sdk_player example).

I knew i wrote this ;)
 
Now the final point, the secondary attack (or grab things ;) )
It's very simple actually.
In src/dlls/player.cpp, line 2438, in the method CanPickUpObject, there is a #ifdef HL2_DLL and in the #else just a "return false;"

It means if you're not playing HL2 (it's our case, because we're playing our mod), this method returns false, so no pickup with the GGun.

So remove the #ifdef and the #else at the end of the method body.

You'll have a compilation problem, the class CBounceBomb is not found.
Once again, i removed the part of code talking about this, as in my mod there is no such bombs. But you can try to include it to the project, so that it might work.

Whatever your solution is, now you can build the hl dll again, and launch your mod.

It works !!!
 
Back
Top