Half-Life Console Help

Basic Script Types: Momentary-To-Toggle
One simple but very useful type of script is what I call the "Momentary-To-Toggle" script. Some commands (+commands) are only active while you hold down the key bound to them (they stop when you release the key because the corresponding -command is executed automatically), these are "momentary". A "toggle" command is one that you can press a key to activate it continuously and then press they key again (or a different key) to stop activating it. Sometimes you may want to change a momentary command (such as +duck) into a toggle command so that, for example, you can hide crouched without holding down the duck key. Here's how:
alias duckdown "+duck; bind x standup"
alias standup "-duck; bind x duckdown"
bind x "duckdown"
This little script defines two aliases and one bind. In this case, pressing 'x' the first time will cuse the player to duck and stay ducked, even when the key is released. This happens because pressing 'x' executes the alias command "duckdown", which activates ducking (+duck) but does NOT de-activate it (-duck). The alias "duckdown" also changes the key binding so that 'x' will do something different the next time it is pressed. That something (executed by calling alias standup), is to un-duck (-duck), and then change the key bind again, back to the original, so that the 'x' key will duck again the next time, and so on.

That example works fine, but if you wanted to change the special toggle-ducking key to something besides 'x', you'd have to edit the key name in both of the alias definitions. This can get tedious and time-consuming in more complex scripts where the aliases can be much longer. It's nice and convenient to have all of your binds in one section of your config files and your alias definitions in another, so here's a form that does the exact same thing as the above, but makes it easier to separate into sections and modify. (The lines beginning with // are comments and will be ignored by the console):

//bind section
alias makeitstand "bind x standup"
alias makeitduck "bind x duckdown"
//alias section
alias duckdown "+duck; makeitstand"
alias standup "-duck; makeitduck"
makeitduck
This one works basically the same way; we've just added another set of aliases (makeitstand and makeitduck) to make it easy to separate the aliases from the binds. Note that, since there's no stand-alone bind in this one (the binds are all in alias definitions), we need to execute one of the aliases (the one we want for default) by putting that alias name on a line by itself (just as you would execute a regular command), in this case makeitduck.
 
[Previous Page] [Back to Console Index] [Next Page]