
Binding Commands in Half-Life 2
By: [TNE]
Genison
Download the AUTOEXEC.CFG file here!
Using a couple of key elements in a regular text file, you can set up just about any stream of commands together to give you an edge when playing. First, there are a few statements in the bind files that would be helpful to know:
alias - This will allow you to specify a name or identifier and then let you string together everything you want to happen when that alias is executed.
A Semicolon ";" - it's like a pause or separator so you can add another command after it
wait - I'm not completely certain the extent of using "wait" but you need it if you want a complete action to take place before going to the next one. I'll explain later.
The file that Half-Life 2 reads to add your binds is called "autoexec.cfg" and it must be present in the same directory as your config.cfg which is the file where Half-Life 2 puts all the settings including your key command choices. Since Half-Life 2 keeps your game modes separate, that means autoexec.cfg will have to be duplicated into your single player directory, deathmatch, and any mod folders if you installed a mod in order for you to use them no matter what you play. These will all be located in the \cfg directories. So:
IN SINGLE PLAYER
Drive Letter:\>program files\valve\steam\SteamApps\<account name>\half-life 2\hl2\cfg
IN DEATHMATCH
Drive Letter:\>program files\valve\steam\SteamApps\<account name>\half-life 2 deathmatch\hl2mp\cfg
And a mod will likely follow the same path assignments except they will be placed in the "SourceMod" directory with their own name. Additionally, if you are creating your autoexce.cfg file for the first time, you may have to run a command in your console window to load that file, but only one time. More on that later.
Installing Autoexec.cfg
When you download our "autoexec.cfg" file (top of the page), you will need to unzip the pre-configured autoexec.cfg file and place it in all of the \cfg directories for every mode you want to play (single, multiplayer, and mods). You can use any basic text editor, but Notepad is recommended so it doesn't change the filename by default. You can get to Notepad from Start--> Programs--> Accessories and open the autoexec.cfg from there, or follow the steps below.
1. Using Explorer, go to the directory with your autoexec.cfg file. Once there, Right-Click on it and highlight "Open With" which should then give you other options. You will want "Choose Program..."
2. A list of programs will come up and you can scroll to Notepad. Click on that, and you have the choice of "Always use the selected program to open this kind of file" by checking that so that you can just double-click to open it next time. Your choice.
3. No matter how you opened autoexec.cfg you should now be looking at this:
//Crouch Toggle
alias "crouch_tog" "crouch_on"
alias "crouch_on" "+duck; alias crouch_tog crouch_off"
alias "crouch_off" "-duck; alias crouch_tog crouch_on"
bind "KEY" "crouch_tog"
//Best Weapon
alias bestweap "qw1;qw2;qw3;echo best weapon..."
alias qw1 "use weapon_frag;wait;use weapon_pistol;wait;use weapon_smg1"
alias qw2 "use weapon_shotgun;wait;use weapon_crossbow;wait;use weapon_357"
alias qw3 "use weapon_ar2;wait;use weapon_rpg"
bind "KEY" "bestweap"
//Duck Jump
alias +lj "+duck;wait;+jump"
alias -lj "-duck;wait;-jump"
bind "KEY" "+lj"
4. Each of the three bind scripts ends with a command to bind the alias to a key of your choice. Delete the KEY text and add whatever button you choose for that function (LEAVE the quotes). For Example, if you want your Best Weapon bind to be initiated with your G key, it would look like this:
bind "g" "bestweap"
5. When you've made your changes, Choose File and Save just like any other program, then exit. Your binds may not work until you first load them through a console command. Start Half-Life 2, get into the game, and press your "~" key that sits above the TAB key. If you have your console option toggled, you should see a window pop up with lots of text and a cursor to enter a command. If not, ESC to your menu, and choose OPTIONS --> click the KEYBOARD tab --> click the ADVANCED button --> click the box next to "Enable developer mode (console)."
6. Now, with your console window up, type in "exec autoexec.cfg" and press enter. Pressing "~" again should close out your console and you can resume the game. If all went well, your bind scripts should now be working!
WARNING. Note with the crouch toggle if you get KILLED while crouched you will not be able to RESPAWN until you uncrouch by pressing the crouch button again.
Tweaking Your Binds
If you want to change or add stuff in your autoexec.cfg, it's very simple. Let's try to understand what autoexec.cfg is doing and you'll be able to know how to change it to your liking. We'll use the Best Weapon bind as an example.
//best weapon
alias bestweap "qw1;qw2;qw3;echo best weapon..."
The //best weapon is simply a tidy way of separating the scripts and giving it a name. The two // tells the text to be ignored when it is processed by the game. The alias statement makes "bestweap" a designated command name and when it is called it is suppose to do qw1 pause qw2 pause qw3 pause, and finally print "best weapon..." on the screen which I believe will actually just go to your console.
alias qw1 "use weapon_frag;wait;use weapon_pistol;wait;use weapon_smg1"
Now we are getting to the meat! This sets qw1 as another command name, and it is told to switch to the Frag Grenade weapon, then to the pistol, then to the sub machine gun. In between each weapon is that wait command which is like telling the game "do this before going to the next thing."
alias qw2 "use weapon_shotgun;wait;use weapon_crossbow;wait;use weapon_357"
Again, qw2 is set to choose the shotgun, crossbow, then the 357.
alias qw3 "use weapon_ar2;wait;use weapon_rpg"
bind "KEY" "bestweap"
Finally, qw3 chooses the AR2 Pulse Rifle, and the RPG last. At the end we bind a key to the alias command bestweap.
Ok, now for the lightbulb moment. What happens when you hit that button you just bound to that alias is it cycles through all your weapons in the order: frag, pistol, smg1, shotgun, crossbow, 357, AR2, and RPG. It will try to cycle through all of them but if you don't have an RPG, then it will stop at AR2. Or if you just picked up an RPG after spawning with only an SMG, it will go directly to the RPG. Now, knowing this, you can edit those alias commands to choose your own weapon hierarchy and simply change around the order of the use weapon_X commands.
In order to be thorough, I'll briefly explain the other two.
//crouch toggle
alias "crouch_tog" "crouch_on"
alias "crouch_on" "+duck; alias crouch_tog crouch_off"
alias "crouch_off" "-duck; alias crouch_tog crouch_on"
bind "KEY" "crouch_tog"
This bind script will allow you to press and release a button to stay in a permanent crouch until you press and release that same button again. The only thing I'll mention about this is you are basically telling the game to press and hold the crouch key for you and when you press the button again, it is letting go. Because of this, you will get the issue I had highlighted above where you won't be able to respawn if you get killed in a crouch toggle until you press the crouch key again.
//Duck Jump
alias +lj "+duck;wait;+jump"
alias -lj "-duck;wait;-jump"
bind "KEY" "+lj"
There are some ledges, boxes, or railings in half-life 2 that can not be reached unless you do a duck/jump combination. This requires hitting your duck key, releasing, and quickly hitting your jump key right after. With this bind, all you must do is press and release one key. I recommend allowing this to take the place of your normal jump key as the extra boost is always welcomed. This bind script defines what happens when you press down the button and what happens when you let go. The "+" in +jump (and anywhere else) is the execution of the button and the "-" is the release. If you notice, this is how your crouch button works in Half-Life 2 by default and why you have to hold it down to keep crouched without using a bind script. You can imagine how this would be a useful thing for other binds, like say, a button that when pressed down would switch to your gravity gun and picks up whatever you are pointing at, then when released would shoot the object and immediately go back to your previous weapon. LOL!
Hopefully, that will allow you to start some scripting on your own. Once you have buttons setup like this, you will want to try others!