Left 4 Dead 2

Left 4 Dead 2

31 ratings
Custom HUD Icons
By Doktor haus
Want to make a HUD icon for your guns or melee weapons? Learn how here. Don't worry if it looks intimidating; it's a lot of explanation and a little work.

At the time of writing, using HUD icons will get you kicked from consistency-enabled servers.
It's because icons require weapon scripts to be enabled, and those can be used to change weapon damage, clip size etc, so obviously servers don't want those. However, the only thing we change in this tutorial is... adding an icon.
So, either play on servers with sv_consistency set to 0, disable the icon before you connect or just deal with it.

Special thanks to Urik Kane for figuring out the gun scripts and Splinks for figuring out the melee scripts
Taking the screenshot
First, you're going to need a good screenshot of your weapon. There are two ways I do this.

3ds Max
It's simple to set up an icon render in Max. Load a scene with good lighting (although none at all works decently enough). Next, rotate your weapon so that it faces upright, and either left or right.

Next, render your weapon. Make sure it's at a high resolution and once you're satisfied, export it as a PNG, RGB 48 bit with alpha channel.

Half-Life Model Viewer
Not everyone has 3ds Max, but everyone has access to Half-Life Model Viewer, which will I refer to as HLMV. If you don't already have it, download Left 4 Dead 2 Authoring Tools from the tools section of your Steam client.

Start Left 4 Dead 2 Authoring Tools and select Half-Life Model Viewer from the list. From the menu, select Options > Background Color. I usually go with green, but the important thing is that the bakground color is nowhere close to any of the colors on your weapon. For instance, if I had a green weapon, I'd instead choose blue or red.

Now, with HLMV, models from the game's resources always have higher priority. Basically, that means that if you try to load a model which already exists in the game, HLMV will load the default one every time. To get around this, you temporarily view it under a new name.

If you're a compiler this is very easy. Edit the world model QC, add "$origin 0 0 0 -90" above any $model and $body lines (use "$origin 0 0 0 180" if it's a decompiled model), change the $modelname to something new (For example, "$modelname custom/mything" creates a model called "mything" in the models/custom directory.) and compile. Load your model in HLMV, choose Options > Center View and your weapon should be directly facing right or left (change the 4th origin # to 0, 90, -90 or 180 to change it). Make sure your weapon's oriented the way it should appear in the final icon.

If all you have are the MDL files, you can hex them. First, rename all the model files (MDL, VTX, SW and PHY) by changing just one letter. For example, I'd change v_rifle to v_rofle. Just make sure they're all named the same. Also, open the MDL in a text editor. Near the very beginning of the file, you'll see a path to the model. Change its model name in the same way and save it.

Now you can open your model in HLMV by choosing Open > Load Model. Remember that your model needs a NEW name or else it will just load the default. If HLMV says "File blahblah doesn't exist.", you'll have to manually create the folder you're trying to access in your left4dead2/models directory.

Next, you'll need to take a screenshot. I use Fraps for this, but it doesn't matter as long as your screen capturing software can export to BMP, TGA or other lossless formats. And, uh... take a screenshot.
Editing and saving the screenshot
I'll be using Photoshop for this. Gimp probably has the same capabilities, but I don't use it so it's up to you. Anyway... How you edit your screenshot depends on how you took it.

3ds Max
Open the PNG; It should already have a transparent background.

Half-Life Model Viewer
Open the TGA, right click-the background layer and choose layer from background.
Next, choose Select > Color Range and click anywhere on the background color. Delete it.

At any rate..
Select Image > Trim to delete excess background.

Next, start with Image > Image Size. Your final icon will be in the VTF format of course, and what you have to keep in mind VTFs is their width and height must be a power of 2: 64, 128, 256, 512, 1024, 2048 etc. With that in mind, I find 128 a good value; it's still slightly scaled down for the HUD icon, but not excessive.

Anyway, select the higher value, whether it's width or height, and change it to 128 pixels.
Next, select Image > Canvas size and change that as well. If your icon is rectangular in shape, you can change it to 64 pixels. If it wont' fit though, it can also be 128 pixels.

Optional: Add a shadow if you want. Under the layers panel, click "FX", choose Drop Shadow and play with the values until you find something you like.

And now...
Select Image > Mode and make sure it's RGB Color with an 8 bits channel.
Save as a VTF. These are the settings I go with. They're uncompressed, high quality and have made many flawless icons in my experience.

Format: BGRA888
Mipmap Filter: Box
Sharpen Filter: None
Checks: Mipmaps off, Thumbnail on
Flags: Anisotropic, No Mipmap, No Level of Detail, Eight Bit Alpha
Right then. If you already have a folder for your addon (that is, a folder in the addons directory with an addoninfo.txt), paste your new VTF in the materials/vgui/hud directory.

Next, you'll need to create a VMT. You can create a new text document in the same directory and either rename its extension to .txt, or open it in Notepad, save as, choose the "all file types" extension and add .txt to end of the file name.

First, make sure your VMT has the same exact name as your icon VTF. Then, open it up in a text editor (Notepad++ is great). Inside, you'll want something like this:
"UnlitGeneric" { "$baseTexture" "vgui\hud\YourVTFHere" "$translucent" "1" "$alpha" "1" "$vertexalpha" "1" "$ignorez" "1" "$no_fullbright" "1" "$vertexcolor" "1" }
The weapon script
With your VMT and VTF in place, create a "scripts" folder inside left4dead2/addons/YourAddonFolderHere.

Then you'll want to extract the default weapon script of the weapon you're replacing. If you don't already have it, download and install GCFScape[nemesis.thewavelength.net]. With the program, you should open pak_01.dir (in Program Files/Steam/steamapps/common/left 4 dead 2/left4dead2).

If you're replacing a gun, you'll see weapon_autoshotgun.txt, weapon_rifle.txt and so on in the scripts folder.
If you're replacing a melee weapon, you'll see katana.txt, machete.txt etc in scripts/melee.
Either way, extract the script of the weapon you're replacing and place it in your addon's scripts folder.

Now we have to open the thing in a text editor.

Gun replacements
For guns, scroll down to this:
TextureData { "weapon" { "file" "vgui/hud/YourVTFHere" "x" "0" "y" "0" "width" "128" "height" "64" } }
Make sure to change the "file" to the name of your icon VTF.
X and Y should always be 0
and the width and height match that of your icon's. Mine was 128 x 64.

Also for guns, find this:
"CharacterViewmodelAddon" { "Coach" "models/weapons/arms/v_arms_coach_new.mdl" "Mechanic" "models/weapons/arms/v_arms_mechanic_new.mdl" "Producer" "models/weapons/arms/v_arms_producer_new.mdl" "Gambler" "models/weapons/arms/v_arms_gambler_new.mdl" }
and replace it with this:
"CharacterViewmodelAddon" { "Coach" "models/weapons/arms/v_arms_coach_new.mdl" "Mechanic" "models/weapons/arms/v_arms_mechanic_new.mdl" "Producer" "models/weapons/arms/v_arms_producer_new.mdl" "Gambler" "models/weapons/arms/v_arms_gambler_new.mdl" "Namvet" "models/weapons/arms/v_arms_bill.mdl" "Biker" "models/weapons/arms/v_arms_francis.mdl" "Manager" "models/weapons/arms/v_arms_louis.mdl" "TeenGirl" "models/weapons/arms/v_arms_zoey.mdl" }
If you don't do this, you'll have invisible arms in first-person while playing as the L4D1 survivors.

Melee weapon replacements
For melees, scroll to the very bottom and replace sprite_active with:
"TextureData" { "sprite_active" { "file" "vgui/hud/YourVTFHere" "x" "0" "y" "0" "width" "128" "height" "64" } }
Once again, change the file, x, y, width and height values to match your icon.

That's it. Jesus, that took a century and half and a Greek epic's worth of text, didn't it? Anyway, all you have to do now is drag your addon folder over left 4 dead 2/bin/vpk.exe and it's ready for release.
< >
addbue Sep 7, 2013 @ 12:01am 
I like you doktor haus
s11ava Sep 6, 2013 @ 6:34am 
MLG Tohru Sep 4, 2013 @ 4:38pm 
I Will Throw A Chainsaw At You For That! :chainsaw:
business man 2018 Sep 1, 2013 @ 6:12pm 
FUUU:witch::witch::witch:TO MANY WITCHS
StonedWarrior Sep 1, 2013 @ 1:14pm 
nice, i'll try that out later.
thanks for useful info! :health: