Wavelength Logo
tl.jpg (2351 bytes) blank.gif (837 bytes) tr.jpg (2446 bytes)
blank.gif (837 bytes)
Weapons in the HUD Tutorial by Blake Grant
blank.gif (837 bytes)
Made a weapon and can't figure out how in the hell to get it into the HUD? Well, hopefully this will help!
I'll pretend we're creating a weapon with the entity name weapon_gun for demonstration purposes

1) Create your weapon
2) Make sure the GetItemInfo function has the proper values set for iSlot and iPosition.
Both values start at 0 (i.e. for slot 1, iSlot = 0), and you have to be sure you don't duplicate the same slot and position as another weapon (my fatal error).
So for example, to add something to Slot 5, Position 5 (right after the snark), have these lines in there:

p->iSlot = 4;
p->iPosition = 4;

3) Edit weapons.cpp to precache your weapon. This happens in the W_Precache function, and you need to add a call like this:
 

UTIL_PrecacheOtherWeapon( "weapon_gun" );

If you have a new type of ammo, you'll have to do a similar thing in the same function:

UTIL_PrecacheOther( "ammo_gunclip" );

4) This is enough to get it working, but the sprite it displays is going to be ugly, so you need to create a "sprites" subdirectory under your mod's directory (e.g. C:\Half-Life\MyMod\sprites\).
In there you need to add a text file called:

weapon_gun.txt

Place all of your new sprites for the gun in this directory as well (check the SDK's sprites directory for instructions on creating sprites).
The easiest thing to do here is copy a similar .txt file out of valve's pak0.pak and modify it

Lets say you copy out weapon_glock.txt and for now choose to use its sprites. Just rename it weapon_gun.txt and put it in your sprites directory, and you're done.

5) If you do need to modify the text file so that it shows a new sprite, this is the general format of the file:

First Line: The first number in the .txt file is the number of actual lines in the file, not including blank lines.

Each successive line specifies one sprite, and is in the format as follows (each field separated by a tab):
kind of sprite
screen resolution
sprite name
4 numbers indicating its size and position


The kind of sprite can be many values, including:
weapon weapon_s
crosshair
ammo


The difference between the weapon and weapon_s sprite is that one is selected and the other is not. In HL, the selected sprites looked like overbright versions of the unselected ones.

The screen resolution is the resolution at which this bitmap is to be used. There are only 2 possible values: 320 and 640. I think it means that anyone using anything under 640x480 uses the 320 sprite and anyone over uses 640. Hence, you'll need two different sprites for everything (the higher res ones would probably be too big on a 320x200 screen).

The sprite name is just the name of the sprite file, without the .spr extension. Note that you can use the ones in the original .pak file without having to extract them to your directory.

The final 4 numbers: The first two are the x and y co-ordinates (in that order) of the upper left corner of the sprite in the .spr file. The next two are the width and height (in that order) of that sprite.

Hope this helps, and let me know if I have anything amiss here.

 

blank.gif (837 bytes)
bl.jpg (2471 bytes) blank.gif (837 bytes) br.jpg (2132 bytes)