Users Guide - Page 3
Article Index
Users Guide
Start up
Scripting Overview
Creating a buy script
Editing buy scripts
Edit configuration settings
Misc.
All Pages

Scripting in Half-Life Mods (such as Counter-Strike and Condition Zero) can be broken down into 2 different parts.

  1. Binds
  2. Aliases
Binds are a way to tie a command to a key.

Aliases are a way to create a command from one or more other commands. Aliases are often used with binds to connect a key being pressed to a command or sequence of commands.

Simply put, you use these combination's of binds and aliases every time you play any Half-Life Mod (whether you know it or not). It is what is used to tie your keyboard key to a command. using the (default) W or Up Arrow key will advance my player forward. This is done so because there is a command for this action in my config.cfg file in my game directory.

Lets look at a bind.

bind "w" "+forward"

the first word in this is the word "bind" this lets the game know that when ever the letter to its right is pressed it needs to execute the forward command. the + symbol plays a special role in binding and is a symbol that denotes "while the key is pressed down, do this command. when the key is released (comes back up) stop doing this command." We'll talk more about this when we discuss aliases.
forward is a command that ships standard with half life. there are other commands that you can bind keys to. Weapons are purchased at the beginning of each round. Usually players have to navigate through a series of menu's to purchase the items he or she needs for that round. One popular form of scripting is known as "buy scripts."
The original intent of CZ Bind Maker was to make buy scripts. I had originally intended to replace the entire in-game options menu, but after a while I decided that this would be tedious and boring, so I focused on configuration settings not available in the in-game menu (lets not re-invent the wheel).

CZ Bind Maker allows you to make buy scripts by selecting a key to bind, to one or more items from the bind items list. More detail on creating buy scripts with Bind Maker can be found on the link titled "creating a buy script." Buy scripts allow you to buy a weapon (or your entire setup) with a press of a single button.

bind "F1" "deagle; secammo; vesthelm;vest;"

This script will purchase a desert eagle, full secondary ammo, a vest and helmet (or if you're too poor for that, just a Kevlar vest). This script can very easily be made using CZ Bind Maker.


The second part of scripting is the alias. Aliases are a way of executing multiple built in or made up commands with a single word (and thus the name "alias" meaning a word substituted for another). There are 2 main kinds of aliases: the toggle and the key press alias (+ & -). The following is an example of a toggle.

alias walk_t walk_on
alias walk_on "alias walk_t walk_off; +speed;"
alias walk_off "alias walk_t walk_on; -speed;"

As its name suggests this alias toggles the name "walk_t" (short for walk_toggle) between "walk_on" and "walk_off." walk_on and walk_off are also aliases. the main thing that walk_on does is execute the +speed command. In Counter-Strike and Condition Zero, this command allows you to walk when you hold down the walk button. If you were to type +speed in your console, you would notice that your player would continuously walk. This happens because you used a key up/down alias without pressing a key. when you script in a +command it does the same as a built in toggle. So here we're toggling the walk command. walk_on starts the walking and walk_off stops it (-speed).
The rest of the line is used to set the value of "walk_t" each time the key is pressed. if we bound the "o" key to "walk_t" the first time the key was pressed it would rename walk_t to execute the stop walking command, and it would start your player model walking. the second time you press the "o" key, it would rename the "walk_t" alias to "walk_on" so that the next time you pressed the button you would start to walk again, and then it would stop your walking. since we use more than one command for our aliases we have to put a semicolon after each command so that the game knows that each sentence that ends in a semicolon is the same as a single line if we were to type it into the console. when more than one command is used we have to wrap the whole thing in quotation marks to let the game know that the word we are aliasing included everything included inside the quotes.

The next type of alias is the key up / down ( + & - ) alias. Again this is a special naming convention. It tells the game that when the key is pressed down to do a certain command and to do another set of commands when the key goes back up. Here's an example of a key up / down alias:

alias +clean_scores "+showscores; hud_saytext_internal 0;"
alias -clean_scores "-showscores; hud_saytext_internal 1;"

"+showscores" shows the score board when you press the button. hud_saytext_internal is an in-game variable (0 for off, 1 for on) that determines whether or not the in-game chat is shown. This alias shows the scores and turns off the chat board while the button is pressed down. when you let go of the button the chat board comes back up and the score board goes away.
simple, clean, & easy.

These 2 things can be combined to create powerful and useful scripts. They form the basis for every script used in any Half-Life mod.