|
News | Getting Started | Weapons | Equipment | Terrorists | CounterTerrorists | Files | Servers | Maps | Message Board |
|
|
|
|
Counter Strike - Scripting CS Scripting guide by ethereal Half-Life
Counter-Strike Scripting
Welcome to the Counter-Strike scripting guide. This guide is meant for all the people who want to optimize their config and use clever and useful script to enhance their Counter-Strike game. This guide covers the scripting aspect from the very simple and general up to the advanced and specific. You can go as far as you want in this, but if you finish reading the guide you should be able to make your own advanced scripts. The
Scripting Environment
Before
we start playing around with the scripting language, it is important to
know how to actually enter these scripts and use them in Counter-Strike.
The main scripting command processor is the console. When you press the ~
or ` key on your keyboard, it brings down the console and shows you all
past commands and happenings in the game. You could consider it the raw
text format of everything you do in the game. The console is also used to
enter text commands into. All scripts discussed below can be entered
straight into the console and used thereafter. However, to prevent you
from having to type slabs of text, it is easier to use configs. A config
file will be of the format <name>.cfg and placed into your cstrike
dir. It can be simply opened with the Windows text file editor, and can be
created by making a new text document <name>.txt and changing it to
<name>.cfg. Counter-Strike itself uses the file config.cfg to store
all the binds, keys and settings. However, since Counter-Strike creates
this file and is not able to store elaborate scripts in it, you are
advised to make your own config file. A
config file is actually not much more than a list of commands that will be
entered into the console. In stead of typing in all the commands in your
config one by one, you simply type: exec
<configname>.cfg into the console, and the console will then execute all the commands in the config file. Alternatively, if you want Half-Life to automatically execute your personal config file on startup, you should add the following command to your command line: +exec
<configname>.cfg If you have the Half-Life icon on your desktop, right-click it, press properties and edit the “Target” box. It will be something alike to: D:\games\halflife\halflife.exe –game cstrike. Simply add +exec <configname>.cfg
to the end and the game will run your config on startup. Now
that you know how to use config files and execute scripting commands into
the console, it’s time to get scriptin’! The
Bind and the Alias
We
start off with the most basic of scripting commands: the bind and the
alias. A bind is a command that links a keypress to a command. If you open
your config.cfg in the cstrike directory with the text editor, you will
see it starts off with a whole list of binds. All binds are in the same
format: bind
“<key>” “<action>” or,
if more actions have to be bound to the same key, the ; can be used to
seperate actions: bind
“<key>”
“<action1>;<action2>;<action3>;…;<actionx>” as
an example, you could warn teammates about you going to throw a flashbang: bind
“c” “use weapon_flashbang; say_team Watch it! I’m throwing a
flashbang!” The
list of keys that can be used to bind actions to, can be found here. It is usually wise
to assign the most important binds (the ones you use most often) to key
that are easy to reach. All the different actions that can be bound will
be described in the next piece of this guide. First, we have to take a
look at the alias. The AliasAn
alias is a actually a way of grouping commands under a new name, which
allows for more advanced scripting as we will see lateron. This new alias
name is also a new command word, which executes all the actions in the
bind. The alias is used in the following format: alias
“<aliasname>”
“<action1>;<action2>;<action3>;…;<actionx>” Pretty
much the same as a bind, only it allows you to make a new name for it in
stead of immediately binding it. The aliasname could be anything you can
think of, but two things should be kept in mind. First of all the alias
name should be discriptive, so you know by looking at the name, what alias
it is and what it is used for. Second, you should never use existing
commands or keys for an alias name. The flashbang warning and selection
bind as shown above, can be rewritten using the alias command: alias
“select_fb_grenade” “use weapon_flashbang” alias
“give_fb_warning” “say_team Watch it! I’m throwing a flashbang!” bind
“c” “select_fb_grenade; give_fb_warning” The C key is now bound to execute the
select_fb_grenade alias, and then execute the give_fb_warning alias. In
this example, it may all seem a bit elaborate since the simple bind works
just as well. However, aliasing allows more advanced and comprehensive
scripting as we will see lateron.
The Comment
The
last basic scripting command that should be discussed is the comment. You
can add comments to your command lines in your config file, by simply
adding whatever text you like after two slashes: //. The console ignores
all text written after two slashes. For examply, you could comment on the
flashbang script: //
This is the flashbang script, which warns my team before throwing a
flashbang alias
“select_fb_grenade” “use weapon_flashbang” alias
“give_fb_warning” “say_team Watch it! I’m throwing a flashbang!” bind
“c” “select_fb_grenade; give_fb_warning” The
Basic Commands
Every
action you do in the game can also be done executing a command in the
console. You could actually play Counter-Strike simply by typing commands
into the console. It probably wouldn’t get you very far though ;-). What
you do have to realise is that every keypress you make in the game can
actually be automated. If you find yourself making the same series of
keypresses time and time again in the game, then why not automate it? For
instance, to buy an MP5 you would press the “buy” key, the “3” key
and the “1” key. Why not simply assign one key to buy an MP5 for you?
And why not add a kevlar vest, HE grenade and primary ammo to that as
well? All
you really need is a list of keys and a
list
of commands, and your own imagination to link the
keys to the commands. The command list provides
you with most of the commands used in common scripting. I haven’t added
every last video and setting command since the list could go on for ages.
The current command list should fulfill all your scripting and automating
needs. However, some commands aren’t as simple as your standard say and
say_team, and will be discussed below. The Press/Release commandFirst
of all there is the + and – type command. For instance, the attack
command comes as “+attack” and not simply “attack”. Why? Well the
+ indicates that the following command will be executed at keypress, while
it’s – counterpart will be executed at key release. This means that
when you press your attack key (most likely mouse button 1), the console
executes the +attack command (fire the gun) and when you release the mouse
button, the console executes the –attack command (stop firing the gun).
The +attack command actually keeps firing until the –attack command is
given. Try typing +attack into the console just for fun, you will see that
you will remain firing forever! Well until you run out of ammo that is
(this doesn’t work with the pistols as they don’t have continuous
firing). The same is true for the duck command. If you type +duck in the
console, you will remain in crouching position until the –duck command
is given. The Menu Selection commandsNext
there is the menuselect and slot10 commands. The menuselect command
selects a menu item by toggling the correct number. The command
“menuselect 2” selects the 2nd item from the menu. This menu includes
teamchoosing menus, buying menus and radio sound menus. The “slot10”
command is used to close any menus that are still open. So the script to
buy an MP5 would be: //
An MP5 buying script alias
“mp5_buy” “buy; menuselect 3; menuselect 1; slot10” bind
F1 “mp5_buy” // Binds the
script to the F1 key The Echo commandThe
third special command type is the “echo” command. This command echoes
the text written behind it directly to the console. It is most often used
to confirm the loading of a config. You are advised to add something like
this to the end of your new config file: //
Confirm Config Loaded echo
<myconfigname>.cfg has been loaded
The Wait commandThe
last special command type is the “wait” command. This command forms a
delay of one game tick, which is actually a very short period of time. Why
wait would you say. Well sometimes a whole line of commands in a row will
get a bit clogged up and especially if your connection is a bit laggy, you
might find that some commands in your script have been skipped or
lost. If your script is malfunctioning, remember to try and put some waits
in. They can be considered the ‘oil’ of a script. More waits generally
make it run smoother. Waits can also be used to actually put some time in
between commands. One can think of a script that plants the C4 bomb
(requiring some time to plant the bomb) which says “guarding the bomb”
after it has been planted. However, since a wait is a very short time, you
are advised to make a longwait, as discribed in the Easy Scripting section
below. Toggle,
Cycle and Press/Release Scripts
There are three special types of scripts that can be used to fulfill your advanced scripting needs. They will be discussed below The
Toggle Script
The first is the toggle script. This
type of script can be used to switch a certain setting on or off with only
assigning one key to it. Pressing it once put the setting on, pressing it
again puts the setting off. It can be considered as a switch. The setup
for this type of script is quite simple // Toggle Script alias
“toggle_on” “<command to switch setting on>; alias toggle
toggle_off” alias
“toggle_off” “<command to switch setting off>; alias toggle
toggle_on” alias “toggle” “toggle_on” // Initiate the first keypress to be Toggle ON bind
“<key>” “toggle” // Bind a key to the toggle script Take a look at this script and try to
understand it. The key bound to “toggle” will execute the “toggle”
alias when pressed. The first time the key is pressed, the toggle alias
will in its turn execute the “toggle_on” alias, as Initiated in the
script. The toggle_on alias actually executes the desired command, and
changes the “toggle” alias to execute the “toggle_off” alias the
next time it is used. The next time the key is pressed, the
“toggle_off” alias is executed, which itself changes the script to
execute the “toggle_on” alias the next time again. The switching
script has been made. A common usage for the toggle script is to assign a
key to changing the weapon from the right to the left hand and back. This
script would look like this: // Weapon Handedness Toggle Script alias
“handtoggle_right” “setinfo lefthand 0; alias handtoggle
handtoggle_left” alias
“handtoggle_left” “setinfo lefthand 1; alias handtoggle
handtoggle_right” alias “handtoggle” “handtoggle_left” // Initiate first keypress to change to left hand bind “v” “handtoggle” // Bind the V key to the handtoggle Script The
Cycle Script
The next type of script is the cycle
script. This script cycles between a range of options and returns to the
first option after the last one has been reached. Quite similar to the
toggle script, it will look like this: // Cycle Script alias
“cycleoption1” “<command for option 1>; alias cycle
cycleoption2” alias
“cycleoption2” “<command for option 1>; alias cycle
cycleoption3” alias
“cycleoption3” “<command for option 1>; alias cycle
cycleoption4” … alias
“cycleoptionx” “<command for option x>; alias cycle
cycleoption1” alias “cycle” “cycleoption1” // Initiate the Cycle at cycleoption1 bind
“<key>” “cycle” // Bind a key to the cycle script As you can see, a toggle script is
actual a cycle script with only 2 options. A common usage for the cycle
script is to cycle between the different types of grenades you are
holding. It would look like this: alias
“cycle_he” “use weapon_hegrenade; alias grencycle cycle_fb” alias
“cycle_fb” “use weapon_flashbang; alias grencycle cycle_sg” alias
“cycle_sg” “use weapon_smokegrenade; alias grencycle cycle_he” alias “grencycle” “cycle_he” // Initiate script to start at selecting HE bind “g” “grencycle” The
Press/Release Script
The last type of special script is
the press/release script. This script is used like the press/release
commands in Half-Life (like +attack and +duck). It executes a range of
commands on keypress, and executes another range of commands on the
release of that same key. It will look like this: // Press/Release Script alias “+scriptname” “<command1>;<command2>;…;<commandx>” alias “-scriptname” “<command2-1>;<command2-2>;…;<command2-x>” bind
“<key>” “+scriptname” Counter-Strike itself will
automatically execute the –scriptname alias when the key is released,
preventing you from having to make the link yourself. One of the best
press/release scripts I have come upon is the C4 planting script: // C4 Planting Script alias
“+plant_c4” “weapon_knife; weapon_c4; +duck; wait; +attack; say_team
I am planting the bomb!; slot10” // Plant the C4 alias
“-plant_c4” “-attack; -duck” // Get up after planting the C4 bind
“backspace” “+plant_c4” // Bind a key to the C4 planting script The script selects the knife first to be sure that you don’t waste any ammo, should the script skip the weapon_c4 selection part. It ducks, places the bomb while the backspace key is held and gives a warning to the team. At key release it gets up again. Easy Scripting
There are a couple of smaller scripts
that make life a bit easier for the scripter. First of all there is the
longwait. In stead of having to type wait;wait;wait;wait etc in your
scripts, you can alias it to make it all a bit easier: alias “longwait” “wait; wait; wait; wait; wait” alias “longerwait” “longwait; longwait; longwait; longwait; longwait” alias
“verylongwait” “longerwait; longerwait; longerwait; longerwait;
longerwait” The average mathematician can see
that the verylongwait encompasses 125 waits, which is actually STILL a
very short time in-game. Another time and text saver is the shortening of the menuselect commands: alias
ms1 “menuselect 1” It’s easier to make buying scripts
by just using the ms0-9 commands. Also when closing a menu, you will often
find that when you just use the “slot10” command, it will skip it and
leave the menu open. To be sure your scripts operate smoothly, use the
clmenu alias: alias
clmenu “slot10; wait; slot10; wait; slot10; wait; slot10; wait; slot10;
wait; slot10; slot10; slot10; slot10; slot10” By adding the clmenu command at the end of all menu-using scripts, you are ensured the menu closes after the script has finished. Still not closing? Just put two clmenu commands at the end ;-). Conclusion
Keylist
Click
here for the keylist table Commandlist
Click
here for the commandlist table
Back to top
^^ |
|