weapon_pistol.cpp
, under the "HL2 DLL" project folder. The first thing you'll notice is that both the class declaration and the implementation are in the same file. This is because there isn't any other object in the game that relies on the Pistol weapon declaration, and thus it can be put directly above the implementation.CWeaponPistol
is derived from a class named CBaseHLCombatWeapon
. This is a base class of all the single-player Half-Life 2 weapons on the server. While the details of this inheritance structure are beyond the scope of this article, every new single-player weapon you create should derive from CBaseHLCombatWeapon
at some point in its inheritance hierarchy. It should then override the methods it needs. Examining the current weapon code will give you a good idea of what is usually overridden, and for what purpose.
c_weapon__stubs_hl2.cpp
. A macro named STUB_WEAPON_CLASS
creates a basic client-side class declaration for your weapon that does nothing but serve as the instantiable object on the client.
weapon_<newname>.cpp
, where <newname>
is the name of your weapon. I used "killer" in place of <newname>, although you can use whatever in want in place of "killer." You can place the file anywhere, although the best place is probably with the rest of the weapon code (src dlls hl2_dll).
weapon_pistol.cpp
) and copy all the code to your new file.
weapon_pistol
to weapon_killer
. Change all instances of CWeaponPistol
to CWeaponKiller
. There will be a bunch of #define
statements that use the word PISTOL
. Change them to use KILLER
instead - don't forget to change where they're referenced in the file as well. Lastly, change the console variable declared at the top of the file (of type ConVar
) to use "killer" as well, and change all references to this variable.
c_weapon__stubs_hl2.cpp
. Add your weapon to the list of stubs, following a similar format as the rest of them.
weapon_pistol.txt
. Copy the file and name the new copy weapon_killer.txt
. Open the file for editing. From here you can edit certain properties of your weapon. The most important change for the weapon to function properly in-game is for you to set up the bucket and position correctly. I left the bucket the same, and changed the position to 2 (since the Pistol and 357 Magnum occupy positions 0 and 1, respectively).give weapon_killer
in the console. You should receive your new weapon! Typing impulse 101
at this point won't work because we haven't set up the gun to be given during that command, however you can do an impulse 101
followed by the give weapon_killer
command to play around with the weapon for a while.
You must log in to post a comment. You can login or register a new account.