Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Giving Replacements Custom Attributes

A Tutorial for Half-Life 2

Members see zero ads. Membership is 100% free

How to make your weapons have custom stats, sounds, and HUD icons

1. Welcome to the Breakdown



Howdy! Today I'm going to break down how I personally make custom weapon scripts & sound files for HL2.



As a preface, you're going to need to know some basic editing of the scripts found in HL2, how to create/edit script files, and to have some basic replacements for HL2. I'll leave you to find your own content here on the site, or elsewhere.


1.1. Breaking It Down



To start with, I'm going to break down the essentials of what we're going to be doing, and what it means.
  1. Giving weapons custom damage/ammo - editing the skill_manifest.cfg file.
  2. Giving weapons custom properties - editing the relevant weapon_*.txt files.
  3. Giving weapons custom sound script files - editing the game_sounds_manifest.txt file.
  4. Giving weapons custom fonts - editing the clientscheme.res file.

1.2. Why We're Breaking It Down


Now, I'll go into the reasons on why we need to break these steps down:

  • The ammo/damage commands are skill console commands (commonly prefixed with sk_*), and as such the easiest way to set these on launch is using a config file. As we're editing skill commands, we're going to add our custom stuff to skill_manifest.cfg
  • The weapon scripts control the magazine sizes of the weapons, the ammo type used, and the sounds just to name a few. We can edit most of the functions related to the weapon's appearance here, even changing the default model paths. However, the accuracy and fire rate are off limits via these scripts, so we can't edit those.
  • To add additional sound script files in the least destructive way possible to the base game, we need to add additional entries to the game_sounds_manifest.txt file. The manifest is essentially the master file that controls what the game will load and what it won't load. Anything not cached in the manifest will likely not load.
  • To add or edit additional HUD icons for the weapons in HL2, you'll need to edit the clientscheme.res file. Adding a font to this file is one of the easiest things to do when editing this file, and I'll go into that.


2. First Steps


This entire tutorial is largely reliant on the SteamPipe custom folder feature. Each custom folder can have an entire setup for itself, which means you can keep your SMG stuff in one, your Pistol in another, and your Shotgun in a third, and so on. This enables us to use the skill commands, weapon scripts, and sound script files independently with each weapon. Modularity is our friend here.

For the sake of this tutorial, create a folder in your hl2/custom folder named weapon_tutorial. Create folders inside the weapon_tutorial folder named cfg and scripts. For now, we're going to keep the weapon editing just down to the basics for the sake of simplicity.


3. Adding Custom Settings to the Weapons



First, we need to open up our skill_manifest.cfg file inside our hl2/cfg/ folder. It should only contain the following by default:

exec skill.cfg

In either case, add the following lines to the skill_manifest.cfg file:

// Slot 0
exec skill/crowbar
exec skill/physcannon
exec skill/stunstick

// Slot 1
exec skill/pistol
exec skill/357
exec skill/alyxgun

// Slot 2
exec skill/smg1
exec skill/ar2

// Slot 3
exec skill/shotgun
exec skill/crossbow
exec skill/annabelle

// Slot 4
exec skill/frag
exec skill/slam
exec skill/rpg

// Slot 5
exec skill/bugbait

Each of these lines independently control the weapons in HL2, to prevent them from being overlapped by another weapon. The exec command tells the skill_manifest.cfg file to run another config file; in this case, one for each weapon in HL2. Modularity is our friend in the case that you want to only edit one weapon and not the rest.



You probably noticed I included alyxgun, annabelle, slam, and stunstick. While these aren't included as player-usable weapons in HL2 by default, editing them will affect the NPCs that use them. Annabelle is used by Father Grigori and uses the .357 weapon settings, and the Stunstick is used by the Civil Protection NPCs in the early chapters. Having these entries allows you to control their use in game for the NPCs.

The additional perks of this are that if the specified config file doesn't exist, it will simply be ignored on game load.



Here's an example of what one of these files would contain; in this case, the cfg/skill/shotgun.cfg file:

sk_plr_dmg_buckshot 15
sk_npc_dmg_buckshot 3
sk_max_buckshot 32

This would set the damage players do with shotgun ammo to 15, the damage NPCs do to 3, and the max amount of ammo carried to 32 shells. Each weapon in HL2 has their own set of commands, so search the sk_* prefix for them.


4. Editing the Weapon Script



We're going to be editing the Shotgun for this section as well, so open up your hl2/scripts/weapon_shotgun.txt file. You'll see all the settings used to control the weapon script that we can change here.



In my case, I have replaced my Shotgun with a proper SPAS-12. I have changed my weapon script accordingly:

//////////////////////////////
// SPAS-12
//////////////////////////////

weapondata
{

    printname "SPAS-12"
    viewmodel models/weapons/v_shotgun.mdl
    playermodel models/weapons/w_shotgun.mdl
    anim_prefix shotgun
    bucket 3
    bucket_position 0
    bucket_360 1
    bucket_position_360 1

    clip_size 8
    default_clip 0
    primary_ammo buckshot

    weight 0
    rumble 5
    item_flags 38

    sounddata
    {

        // When the player fires
        single_shot Weapon_Shotgun.Single

        // When an NPC fires
        single_shot_npc Weapon_Shotgun.Single

        // When a player fire both barrels / alt-fire
        double_shot Weapon_Shotgun.Single

        // When an NPC fires both barrels / alt-fire
        double_shot_npc Weapon_Shotgun.Single

        // When the player reloads
        reload Weapon_Shotgun.Reload

        // When an NPC reloads
        reload_npc Weapon_Shotgun.Reload

        // Dry-fire
        empty Weapon_Shotgun.Empty

        // Special sound 1
        special1 Weapon_Shotgun.Special1

    }

    texturedata
    {

        weapon
        {

            font weaponicons
            character b

        }

        weapon_s
        {

            font weaponiconsselected
            character b

        }

        weapon_small
        {

            font weaponiconssmall
            character b

        }

        ammo
        {

            font weaponiconssmall
            character s

        }

        crosshair
        {

            font crosshairs
            character Q

        }

        autoaim
        {

            file sprites/crosshairs
            x 0
            y 48
            width 24
            height 24

        }

    }

}



The weapon script function of Source is an entirely different part of the engine that is outside the scope of this tutorial, so some additional research on the part of the end user would be prudent to squeeze the most out of your custom content.


5. Adding Custom Sound Scripts


As I mentioned, the game_sounds_manifest.txt file is incredibly important. How important? If you have a file replacing the root folder's manifest, no other manifest file will load. Some custom weapons on GameBanana are guilty of this, and it can at times cause the entire library of episodic sounds from EP1 & EP2 to not load. It's really important not to fuck this up.



The easiest way to follow this tutorial, would be just to find the game_sounds_manifest.txt file inside the hl2/scripts/ folder and add the following at the very bottom before the closing bracket:

// Custom Weapon Scripts
precache_file "scripts/sounds/crowbar.txt"
precache_file "scripts/sounds/physcannon.txt"
precache_file "scripts/sounds/stunstick.txt"
precache_file "scripts/sounds/pistol.txt"
precache_file "scripts/sounds/357.txt"
precache_file "scripts/sounds/alyxgun.txt"
precache_file "scripts/sounds/smg1.txt"
precache_file "scripts/sounds/ar2.txt"
precache_file "scripts/sounds/shotgun.txt"
precache_file "scripts/sounds/crossbow.txt"
precache_file "scripts/sounds/annabelle.txt"
precache_file "scripts/sounds/frag.txt"
precache_file "scripts/sounds/slam.txt"
precache_file "scripts/sounds/rpg.txt"
precache_file "scripts/sounds/bugbait.txt"

These lines tell the manifest to look inside hl2/scripts/sounds/ for individual sound script files for each weapon. As in the case of the skill_manifest.cfg commands, if the file isn't found - it simply doesn't load. You'll see a red line for each missing file in the console on load, and that's all.



You'll need to edit EP1 & EP2's manifest files as well at some point. If you're an advanced user who knows what they're doing, you could merge the episodic manifest files with the HL2 manifest to make editing them simpler, but I won't ask that here as it's outside the scope of this tutorial.


6. Custom HUD Fonts



The scalable vectors used in HL2 & other Source games for their weapon HUD bucket icons are made through custom font files. This allows them to work on a variety of resolutions and look as crisp as normal on either a 4:3 or a 21:9 screen. Adding these fonts takes a bit more work, as they have to made in a dedicated font creation program. Creating fonts is another school of thought for
another time, but adding custom fonts for each weapon is not impossible.

I've saved this step for last, as it'll likely be the least used portion of this tutorial, but I'm including it for the sake of completeness.



To add custom fonts, you first need to open up the hl2/resource/clientscheme.res file. To Valve's credit, you can actually easily add fonts in a specialized block at the bottom:
//////////////////////// CUSTOM FONT FILES /////////////////////////////
//
// specifies all the custom (non-system) font files that need to be loaded to service the above described fonts
CustomFontFiles
{
"1" "resource/HALFLIFE2.ttf"
"2" "resource/HL2crosshairs.ttf"
}

The trick here, is that each of these fonts are loaded via their file names. Adding this to the table is how I changed mine up:

CustomFontFiles
{
1 "resource/HALFLIFE2.ttf"
2 "resource/HL2crosshairs.ttf"
3 "resource/crowbar.ttf"
4 "resource/physcannon.ttf"
5 "resource/stunstick.ttf"
6 "resource/pistol.ttf"
7 "resource/357.ttf"
8 "resource/alyxgun.ttf"
9 "resource/smg1.ttf"
10 "resource/ar2.ttf"
11 "resource/shotgun.ttf"
12 "resource/crossbow.ttf"
13 "resource/annabelle.ttf"
14 "resource/frag.ttf"
15 "resource/slam.ttf"
16 "resource/rpg.ttf"
17 "resource/bugbait.ttf"
}

The custom fonts will now load, but they won't have a corresponding HUD entry.



You'll also need to add one of these for each set of glyphs as well. Around line 278 in the default clientscheme.res file you'll see the following bits:

WeaponIcons
{
"1"
{
"name" "HalfLife2"
"tall" "64"
"tall_hidef" "58"
"weight" "0"
"antialias" "1"
"additive" "1"
"custom" "1"
}
}
WeaponIconsSelected
{
"1"
{
"name" "HalfLife2"
"tall" "64"
"tall_hidef" "58"
"weight" "0"
"antialias" "1"
"blur" "5"
"scanlines" "2"
"additive" "1"
"custom" "1"
}
}
WeaponIconsSmall
{
"1"
{
"name" "HalfLife2"
"tall" "32"
"weight" "0"
"antialias" "1"
"additive" "1"
"custom" "1"
}
}

For the sake of your own time, I'll paste the entire section of code I wrote below.



I personally recommend adding yours at the very bottom of the block right before where the CustomFontFiles section starts, as it'll make finding the relevant code easier on yourself.

WeaponIconsCrowbar
{
1
{
name crowbar
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedCrowbar
{
1
{
name crowbar
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallCrowbar
{
1
{
name crowbar
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsPhysCannon
{
1
{
name physcannon
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedPhysCannon
{
1
{
name physcannon
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallPhysCannon
{
1
{
name physcannon
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsStunstick
{
1
{
name stunstick
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedStunstick
{
1
{
name stunstick
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallStunstick
{
1
{
name stunstick
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsPistol
{
1
{
name pistol
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedPistol
{
1
{
name pistol
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallPistol
{
1
{
name pistol
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIcons357
{
1
{
name 357
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelected357
{
1
{
name 357
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmall357
{
1
{
name 357
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsAlyxGun
{
1
{
name alyxgun
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedAlyxGun
{
1
{
name alyxgun
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallAlyxGun
{
1
{
name alyxgun
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsSMG1
{
1
{
name smg1
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedSMG1
{
1
{
name smg1
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallSMG1
{
1
{
name smg1
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsAR2
{
1
{
name ar2
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedAR2
{
1
{
name ar2
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallAR2
{
1
{
name ar2
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsShotgun
{
1
{
name shotgun
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedShotgun
{
1
{
name shotgun
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallShotgun
{
1
{
name shotgun
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsCrossbow
{
1
{
name crossbow
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedCrossbow
{
1
{
name crossbow
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallCrossbow
{
1
{
name crossbow
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsAnnabelle
{
1
{
name annabelle
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedAnnabelle
{
1
{
name annabelle
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallAnnabelle
{
1
{
name annabelle
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsFrag
{
1
{
name frag
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedFrag
{
1
{
name frag
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallFrag
{
1
{
name frag
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsSLAM
{
1
{
name slam
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedSLAM
{
1
{
name slam
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallSLAM
{
1
{
name slam
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsRPG
{
1
{
name rpg
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedRPG
{
1
{
name rpg
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallRPG
{
1
{
name rpg
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}

WeaponIconsBugBait
{
1
{
name bugbait
tall 64
tall_hidef 58
weight 0
antialias 1
additive 1
custom 1
}
}
WeaponIconsSelectedBugBait
{
1
{
name bugbait
tall 64
tall_hidef 58
weight 0
antialias 1
blur 5
scanlines 2
additive 1
custom 1
}
}
WeaponIconsSmallBugBait
{
1
{
name bugbait
tall 32
weight 0
antialias 1
additive 1
custom 1
}
}


If you haven't guessed yet, you'll be better off putting your custom fonts for each weapon inside the custom folder for it. If you guessed they'd be inside custom/weapon_tutorial/resource/* you get a cookie, because you're right.



There's one last step involved in adding custom fonts to your weapons, though. You might recall a whole section of code in the previously edited weapon_shotgun.txt that started with TextureData - this is what we need to edit next.

Open up your hl2/custom/weapon_tutorial/scripts/weapon_shotgun.txt file, and scroll down to the following:

"weapon"
{
"font" "WeaponIcons"
"character" "b"
}
"weapon_s"
{
"font" "WeaponIconsSelected"
"character" "b"
}
"weapon_small"
{
"font" "WeaponIconsSmall"
"character" "b"
}

Replace it with the following HUD entries we just made based on the weapon you're editing. In this case, I'm editing the Shotgun, so I added the Shotgun suffix to the entries.

weapon
{

font weaponiconsshotgun
character b

}

weapon_s
{

font weaponiconsselectedshotgun
character b

}

weapon_small
{

font weaponiconssmallshotgun
character b

}



Your custom weapon script will now load the entries you previously defined for the custom HUD glyphs. Keep in mind that depending on how the font file was made, you may need to edit the icon entries. This is out of the scope of this tutorial, but if your custom icons are being clipped or cut off, this is why.


7. Things to Watch For



A good many authors package their own manifest files into their .VPK or loose add-ons for HL2, so you might need to open up their content and remove/adjust their custom scripts to align with this method. How you do that is up to you, as there are many different personal ways people do it. If you follow the basic gist of this tutorial, you'll be able to see the similarities between my method described here, and their own. Learning how to see the similarities between the methods will allow you to easily modify them.


8. Conclusion


If you have any questions, or are confused about any sections of this tutorial, please comment below and ask. I'll do my best to clear up any potential confusion.

Good luck out there.


9. Links


Download via BitPit Files: hl2-weapon-tutorial.7z

Comments

Sign up to access this!

Embed

menu
Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

Key Authors
Reverend V92 avatar
Reverend V92 username pic Joined 9y ago
HL2 Manager
Offline
10,504 points Ranked 555th
31 medals 6 rare
  • 2nd Place - A Bananite's Guide to... Contest Medal icon
  • 6 years a member Medal icon
  • Returned 1000 times Medal icon
  • Received thanks 50 times Medal icon
  • 10 submissions featured Medal icon
  • Achieved Game Manager clearance Medal icon
Creating my own personal method, writing the method up

Submitter

Reverend V92 avatar
Reverend V92 username pic Joined 9y ago
HL2 Manager
Away
10,504 points Ranked 555th
31 medals 6 rare
  • 2nd Place - A Bananite's Guide to... Contest Medal icon
  • 6 years a member Medal icon
  • Returned 1000 times Medal icon
  • Received thanks 50 times Medal icon
  • 10 submissions featured Medal icon
  • Achieved Game Manager clearance Medal icon
Reverend V92 avatar
Reverend V92

Creator
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

Details

Difficulty Level
Медиу

Attributes

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • favorite 1
  • remove_red_eye 312
  • mode_comment 2
  • access_time 1mo
  • access_time 1mo

More from Submitter

menu

WiPs by Submitter

menu

More Scripting Tutorials