Coding a new weapon

Tutorial collection, comprehensive listings on main site.

Coding a new weapon

Postby Tutorial on Tue Mar 20, 2007 10:37 pm

category
Miscellaneous

description
Adding your own weapon isn't all that hard.

keywords
code, coding, new, weapon, gun, weapons.

Since every single tutorial on coding has really long explanation things that nobody wants to read, and the fact they don't tell you how to get to the weapon coding in the first place, I'll explain it all.

First off, you'll need Microsoft Visual C++ 2005 Express, which can be found Here.

Then, once that's installed, you'll need to download the Platform SDK, and the DirectX SDK.

Platform SDK
DirectX SDK

Now that you have all of those installed (They should be in an easy place like Program Files and the such) you can start setting up VS2005.

Open up VS2005, and go to tools -> options -> projects and solutions -> VC++ Directories and in the top right of the window there should be a dropdown box, select Executable Files, and click on the New Line button and browse for the location C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin

Image

Now click on the dropdown and select include, make two new lines and browse to these two locations
C:\Program Files\Microsoft DirectX SDK (February 2006)\Include
and
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include

Image

Now click on the dropdown and select library, make two new lines and browse to these two locations
C:\Program Files\Microsoft DirectX SDK (February 2006)\Lib\x86
and
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib

Image

Now that that's all done, you'll need to either download an edited corewin_express file from Here or edit it yourself. (That usually ends up badly)

Place the new corewin_express file into the "C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults" folder.

Now that all this is done, open the hl2 2005 source solution file, which you would get from the SDK when you create a mod, and when the solution is open, go up to the top and change "Debug HL2" to "Release HL2"

Image

Now go to "Build -> Build Solution"

You should get a clean no error build, don't worry about the warnings.

Now to get the new gun into your mod.

Now you should keep VS2005 open, and you should have this menu on the left.

Image

Now, keeping VS2005 open, go to your folder that has all your code in it, for me it's "C:/Program Files/Steam/SteamApps/SourceMods/Code" While in your code folder, go to the "dlls/hl2_dll" folder, and copy the "weapon_pistol.cpp" then paste it, and name it "weapon_killer.cpp" now open your new .cpp file and replace all instances of CWeaponPistol, DTWeaponPistol and all the console commands with Killer. (So, CWeaponKiller, DTWeaponKiller, etc.)
If you cannot get that working, I did it for you, and here's a download.

Now, drag weapon_killer.cpp into VS2005, and drag that into the Solution Explorer, which is that little box on the left, and make it go into "Server_hl2 -> Source Files -> HL2_DLL" and drop it there.

Now keeping VS2005 open, go to your source code again, then go to "cl_dll/hl2_hud" and open "c_weapon__stubs_hl2.cpp"

Now while in that, you should see:

"STUB_WEAPON_CLASS( weapon_pistol, WeaponPistol, C_BaseHLCombatWeapon );"

Copy that, and paste it under itself, and change the newly pasted line of code to:

"STUB_WEAPON_CLASS( weapon_killer, WeaponKiller, C_BaseHLCombatWeapon );"

Save it, and save the whole Solution. Now, go to "Build -> Build Solution" It should compile with no errors, and now your coding it finished.

To cap it all off, go into your actual mod directory, and go into the "scripts" folder. Then copy weapon_pistol.txt and paste it, and change that to weapon_killer.txt.

Change the inside of weapon_killer.txt to say this:

Code: Select all
// Killer

WeaponData
{
   // Weapon data is loaded by both the Game and Client DLLs.
   "printname"   "Killer"
   "viewmodel"      "models/weapons/v_pistol.mdl"
   "playermodel"      "models/weapons/w_pistol.mdl"
   "anim_prefix"      "pistol"
   "bucket"         "1"
   "bucket_position"   "2"

   "clip_size"         "20"
   "primary_ammo"      "Pistol"
   "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
   {

      "reload"      "Weapon_Pistol.Reload"
      "reload_npc"   "Weapon_Pistol.NPC_Reload"
      "empty"         "Weapon_Pistol.Empty"
      "single_shot"   "Weapon_Pistol.Single"
      "single_shot_npc"   "Weapon_Pistol.NPC_Single"
      "special1"      "Weapon_Pistol.Special1"
      "special2"      "Weapon_Pistol.Special2"
      "burst"         "Weapon_Pistol.Burst"
   }

   // Weapon Sprite data is loaded by the Client DLL.
   TextureData
   {
      "weapon"
      {
            "font"      "WeaponIcons"
            "character"   "d"
      }
      "weapon_s"
      {   
            "font"      "WeaponIconsSelected"
            "character"   "d"
      }
      "ammo"
      {
            "font"      "WeaponIcons"
            "character"   "p"
      }
      "crosshair"
      {
            "font"      "Crosshairs"
            "character"   "Q"
      }
      "autoaim"
      {
            "file"      "sprites/crosshairs"
            "x"         "0"
            "y"         "48"
            "width"      "24"
            "height"   "24"
      }
   }
}


Now run your mod and you should see that your new gun is in there. The only really annoying thing is that Valve does not include Episode 1 content into the solution, you have to do that yourself, so if you're using EP1 dll's prior to doing this tutorial, you will not have any EP1 content, that includes upgraded lighting, zombine, and hopwire grenades.

-Jman
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Postby mr greenfish on Tue Mar 20, 2007 10:52 pm

Nice tutorial, it should go well with the overview that i did:
http://www.interlopers.net/forum/viewtopic.php?t=14587
Image Available now
User avatar
mr greenfish
1337 p0st3r
1337 p0st3r
 
Joined: Sat Dec 04, 2004 12:05 pm

Postby Haxel on Sun Apr 22, 2007 1:14 am

Thanks man very useful :-D
User avatar
Haxel
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Fri Oct 08, 2004 4:36 pm
Location: UK

Re: Coding a new weapon

Postby Grantax on Sat Jul 14, 2007 6:05 pm

Tutorial wrote:Since every single tutorial on coding has really long explanation things that nobody wants to read, and the fact they don't tell you how to get to the weapon coding in the first place, I'll explain it all.


First of all people (or, at least I) like to read why I am doing what I am instructed to do, and it's called learning, second, it doesn't seem like any weapon coding is done, except copying the pistol and changing it's name. (Where the latter part was achieved by scripting)
Grantax
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Tue Mar 14, 2006 1:33 pm
Location: Norway

Postby Psy on Sat Jul 14, 2007 7:08 pm

It's not even a new weapon...
User avatar
Psy
Veteran
Veteran
 
Joined: Sat Dec 03, 2005 5:41 pm
Location: United Kingdom

Postby Jman on Fri Aug 03, 2007 1:21 am

I just made this to pretty much be a working version of that annoying VERC tutorial that doesn't work too well.
User avatar
Jman
Veteran
Veteran
 
Joined: Wed Mar 30, 2005 11:01 pm

Halp?

Postby bovinepro on Fri Oct 12, 2007 12:33 am

You lost me when you mentioned the "hl2 2005 source solution file"
where is this created? How is it created?
help?
O_O
bovinepro
Dumpling
Dumpling
 
Joined: Fri Oct 12, 2007 12:31 am

Postby Mr. Happy on Fri Oct 12, 2007 5:27 am

When you clicked "create a mod" you gave it two directories. The first directory you entered is where the source code is installed.

In there (maybe in a subfolder) are several files with the .sln extension, which stands for solution.
Image
-You've just been happified!?
User avatar
Mr. Happy
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sat Dec 30, 2006 9:20 am
Location: Flyin' thru "da cloud" in the MotherShip

Postby bovinepro on Fri Oct 12, 2007 6:05 am

Thanks! XD
O_O
bovinepro
Dumpling
Dumpling
 
Joined: Fri Oct 12, 2007 12:31 am

Postby bovinepro on Fri Oct 12, 2007 10:22 pm

Quick question :
Is there any way to edit a mods .cpp files without having the .sln file?
And is there anyway I can create a .sln file,
etc etc
I just want a way to edit a already "out" mod.
O_O
bovinepro
Dumpling
Dumpling
 
Joined: Fri Oct 12, 2007 12:31 am

Postby Ale on Mon Oct 15, 2007 3:54 pm

No its not possible
Image
User avatar
Ale
May Contain Skills
May Contain Skills
 
Joined: Fri Jul 29, 2005 9:03 am
Location: Earth

Postby Mangopork on Fri Oct 26, 2007 12:51 am

Nice. Interesting.

Does this same principle apply to multiplayer weapons?
Strangely Delicious.
User avatar
Mangopork
Been Here A While
Been Here A While
 
Joined: Wed Jan 11, 2006 4:50 am

Re: Coding a new weapon

Postby thenub641 on Tue Nov 04, 2008 10:21 pm

The link to the edited edited corewin_express file is down . Could you please fix it or at least let us know where we can find another one?
thenub641
Dumpling
Dumpling
 
Joined: Tue Apr 17, 2007 4:09 am
Location: Santas house

Re: Coding a new weapon

Postby sovietpt on Fri Jul 02, 2010 10:20 pm

Hey there,
I know to use VC++ Directories in Visual C++ 2010, and if i come up with any trouble I'll switch to VS2008.

My question is, can we "code a new weapon" using the most up-to-date platform and directx sdk's?

"...Steam/SteamApps/SourceMods/Code", i don't have this folder, is it because I'm creating my SP mod with "Source engine 2007" version? Should I've had selected the 2006 version?

Sorry for my bad English, and probably for dumb questions, I'm confused by the way Source SDK shows stuff now. For example, I was used to create maps for DODS, HL2 and HL2DM, and the engine selected was Episode's 1 engine, but now there is like a 2006, a 2007 and a 2009 versions of the engine, and I find older games in the 2009 version :S

By the way, "What would i have to google/search for if i wanted, aside from a new "coded weapon", make the weapon's model different?"
From what I've understood so far, I need to model it, and animate it, but then how do i put "it" in an HL2 Mod or even HL2?
sovietpt
Just Joined
Just Joined
 
Joined: Fri Jul 02, 2010 10:02 pm

Re: Coding a new weapon

Postby Cpl Bradley on Fri Sep 17, 2010 6:13 pm

Missing RecvProp for DT_WeaponG18 - DT_BaseCombatWeapon/baseclass
Host_EndGame: CL_ParseClassInfo_EndClasses: CreateDecoders failed.


Error i get in console.
Cpl Bradley
Member
Member
 
Joined: Fri Jul 30, 2010 11:32 pm
Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users