Intro to Scripting.

Ever asked yourself why some guys change weapons so fast,
or how they are able to Sprint, Strafe, Reload, Jump and call for Ammo
at the same time??

Why some guys seem to move around like they must have 18 fingers??
Well, (no offence on 18 fingered people) they probly use Binds & Scripts,
to optimize their keyboard setup.

Binds & Scripts can be verry usefull for Playing RTCW. (or other games)
Binds & Scripts i.e. enable you to put a command like v-2-2
(I need Ammo) on 1 key, so you'll only need to press 1 key once
i.o. pressing several keys, several times.

Binds & Scripts also enable you to put several command on 1 key
so you'll only need to press 1 key to execute several commands
or bind 1 key to execute a sequence of commands.

Although you could be a perfectly good ET player without any knowledge of scripting, it's a good idea to learn at least the basics, for the following reasons:

  • Tweaking game settings
  • Do things you couldn't do before
  • Make playing easier
  • Take advantage of cheap exploits ;)

Creating a config file.

Before you start writing scripts, you need to put your scripts somewhere! That place is called your config file. 

STEP 1: Create autoexec.cfg

Enemy Territory automatically checks for a file called autoexec.cfg every time it runs. If it exists, then ET runs whatever scripts are in that file. If you just installed ET though, it doesn't exist so you have to create it.

To create it, follow these steps:

1. Run notepad
 - Click on the Start button, then click on "Run", and type in Notepad

2. Go to File, then Save As...

3. Type the following line of text exactly as it appears below:

"C:\Program Files\Wolfenstein - Enemy Territory\etmain\autoexec.cfg"

- MAKE SURE to include the quotes:
        Good: "C:\Program Files\Wolfenstein - Enemy Territory\etmain\autoexec.cfg"
        Bad: C:\Program Files\Wolfenstein - Enemy Territory\etmain\autoexec.cfg

- If you installed ET in some other directory, then obviously change your path accordingly
    -e.g. "D:\MyGames\FavoriteGames\ET\etmain\autoexec.cfg"

4. Now, save the file!

STEP 2: Add an example script

Simply add "bind M vsay Cheer" to your autoexec.cfg file as shown below, and then save the file. For now don't worry about what this script actually does, we'll go into that soon enough :)

STEP 3: Test it out on a real server to make sure it works

Now, join a server (or host your own game, whatever). Then, open the console by pressing ~, and type "/exec autoexec.cfg" (without the quotes). If it works correctly, then you will see it say 'execing autoexec.cfg' as it does in the picture below:

If you made a mistake in saving your autoexec.cfg, it will say "couldn't exec autoexec.cfg". In this case, make sure that you saved it in the right directory, with the right filename.

Now, get out of the console (press ~ again) and try pressing the "M" key. Now when you press it, you will hear cheering (as if you'd pressed v56). Congratulations, you just got your first script working :) The rest is easy, really!

Advanced scripting.

Now that you know a couple of basic commands, you're ready to learn more about scripting. These "advanced" topics will help you write really cool scripts that go beyond just spitting some text to the screen. Don't worry, it's not hard.

Running multiple commands at once
You can string together multiple commands on one line using semicolons. So for example, you can do something like:

bind "K" "say We won!; say We really kicked your ass!; say Man, you guys really suck!"

I call this the "obnoxious cheering script". You just press one key and it says all this stuff :) I also call it the "get banned really quickly" script.

Using multiple config files
You can have other config files besides your autoexec.cfg, although they won't run automatically on startup. However, there's a command to run a config file called "exec". So, for example, if you want to be really organized, then you could have 3 different config files: "graphics.cfg" which would contain all your graphics settings, "chat.cfg" which would contain shortcuts for teamchat messages, and "misc.cfg" which would contain everything else.

Then, just stick these cfg files in your etmain folder (where the autoexec.cfg is). And, then in your autoexec.cfg, add these 3 lines:

exec "graphics.cfg"
exec "chat.cfg"
exec "misc.cfg"

Then whenever your game starts up, all the scripts in those files will be executed.

Running a script from a script
You can create a variable that holds a script. Then you can run that script using a command called vstr. Here's an example of how that would work:

set SuicideScript "kill"
bind "K" "vstr SuicideScript"

So, I just made up some variable called SuicideScript and set its text to "kill". This is just like setting a cvar, except "SuicideScript" is just some name I made up. Then, we bind the K key to the action "vstr SuicideScript". vstr is a command which runs some script stored in a variable.

This example's pretty trivial but soon I'll show you how to use vstr to do some cool things.

The echo command writes some text on your screen. For example:

echo "Autoexec.cfg has been loaded!"

The wait command will pause your script for "x / 2" frames. So for example, if you say "wait 60" and your FPS is 60, then it will wait 30 frames, i.e. for half a second.

Here is an example script demonstrating the wait command, which was suggested to me by <R0F/NicK>:

name G; wait 20
name G0; wait 20
name G00; wait 20
name G00G; wait 20
name G00G1; wait 20
name G00G13

So, this will make your name appear over a period of 50 frames or so. Unfortunately, since everyone runs ET at a different FPS, that makes it really difficult to do something like "wait for exactly 1 second", all you can usually do is "wait 120" and hope their FPS is around 60!

Writing a toggle script
Here's a short example showing you how to toggle between a mouse sensitivity of 2.0 and 4.0.

set sens2 "echo Sensitivity set to 2.0!; sensitivity 2.0; set switch_sens vstr sens4"
set sens4 "echo Sensitivity set to 4.0!; sensitivity 4.0; set switch_sens vstr sens2"
set switch_sens "vstr sens2"
bind "n" "vstr switch_sens"

Just read it and hopefully it will make sense :) Basically we are just using vstr in a very clever way that lets us press the "n" key to toggle between running sens2 and sens4. Note, since sensitivity is a cvar, I omitted the "set" command.

A better way of writing a toggle script uses one less cvar:

set sens2 "echo Sensitivity set to 2.0!; sensitivity 2.0; bind n vstr sens4"
set sens4 "echo Sensitivity set to 4.0!; sensitivity 4.0; bind n vstr sens2"
bind "n" "vstr sens2"

If you just want to toggle a value between 1 and 0, you can just use the toggle command. Doing this is really simple. So, for example if you want to toggle atmospheric effects (like rain) on and off by hitting F5, you can say:

bind F5 toggle cg_atmosphericeffects

Writing a cycle script.

To write a script to cycle between several values of some variable, you could do it using set and vstr, similar to the sensitivity script above. There's also a handy command to cycle through values. For example:

bind "K" "cycle sensitivity 3 7 2"

This will change the mouse sensitivity every time you press K, going from 3 to 7 in steps of 2. (So, 3,5,7,3,5,7,3,5,7,etc).

Personally I don't like cycle scripts because they don't echo the value to the screen. I usually just use set and vstr so I can use echo.

The +vstr command

You can bind a key to do one thing when you press it, and something else when you release it. Here's an example which hides your gun as long as K is held down, and makes it reappear when you let go of K:

set script1 "cg_drawgun 0"
set script2 "cg_drawgun 1"
bind "K" "+vstr script1 script2"

So, hopefully this is pretty obvious. After +vstr, you write the name of 2 scripts that should be run. The first script will be executed on the key press, and the other will be executed on the key release. Here we're using the cg_drawgun cvar which shows the gun if it's set to 1, hides it if it's 0.

You might think that when you press a key, script1 is executed once, and then when you release a key, script2 is executed once. This isn't true. Although the "release" script is always guaranteed to run only once, script1 will keep running again and again while the key is pressed. So, make sure you don't put anything in script1 that can't be run multiple times. For example, putting an echo statement in script1 would be really stupid because then that message might get echo'ed hundreds of times.

And now for a real-life example that uses all this scripting crap!
Say you're playing on Seawall Battery and you're an engineer. Suppose you're the kind of guy who likes to play defense, so you usually either guard the backdoor or guard the gun controls. You often find yourself having to type out messages like "Allies are planting at the gun controls!". That's a lot of typing, so it would be nice to just bind that to a key.

What you can do is create a config file for Battery, call it battery.cfg. You can do this for every map, and then in your autoexec, just have some lines like this:

bind "F5" "echo loading battery.cfg!; exec battery.cfg"
bind "F6" "echo loading radar.cfg!; exec radar.cfg"
bind "F7" "echo loading oasis.cfg!; exec oasis.cfg"

This is probably how I would do it: just bind each map config to a function key. I think if you're playing on a server with ETPro though, you can just create files called autoexec_battery.cfg, autoexec_radar.cfg, etc. And it will automatically read those those and apply those settings. As far as I know, that only works on ETPro though, so I'd just do it with the function keys like I've shown here.

Now, let's say that you're a guy who only likes to play defense. The two things you defend are the gun controls or the backdoor. So, to safe yourself some typing, you decide to bind two keys: A and B. A will be the key you hit if everything's ok. B will be the key you hit if there's trouble.

You could set up the following script... Note I've abbreviating backdoor with BD and gun controls with GC:

set BDBinds "bind A say_team All clear @ BD!; bind B say_team Allies are in @ BD!"
set GCBinds "bind A say_team All clear @ GC!; bind B say_team Allies are in @ GC!"

Then you could write a toggle script to switch between these two "modes". So let's write a script that lets you press "C" to toggle between them:

set BD "echo Backdoor mode!;vstr BDBinds; set switch vstr GC"
set GC "echo Gun controls mode!;vstr GCBinds; set switch vstr BD"
set switch "vstr BD"
bind "C" "vstr switch"

Sorry for the confusing names like BD and GC! Normally you should keep your names longer and more descriptive, but I'm trying to make all these long scripts fit the width of your browser. Anyways, hopefully what this script does is clear enough. If you press "C" then it will run switch. Switch will run either BD or GC. Say it runs BD. Then it will echo the text "Backdoor mode!", and then run BDBinds, which sets up all the binds for defending the backdoor, and then it makes it so the next time you run switch, it will call GC instead of BD.

Pretty crazy, huh :)

Fixing your config (if something goes wrong!)

If you accidentally change some settings in your config file, there's no easy way to reset them back to defaults. For example, say you bind your "L" key to suicide... Then every time you try to go into Limbo, you die! You can't just remove the bind from your config, because once you change a setting, it gets permanently registered into your master config.

So, one way to fix the problem is to reset your config to all the defaults, and then apply the settings you DO actually want.

  1) Remove all offending lines from the autoexec.cfg
  2) In console, type "/exec etconfig.cfg". Now all your settings are reset
  3) In console, type "/exec autoexec.cfg". Now your config settings are set.
  4) Go to the options menu and re-enter your options (got wiped out in step 2)

Another way to fix your config is to edit the master config directly, as you'll learn below in the "How config files work" section.

Note that if you just set one variable to the wrong thing, like say you change the cg_crosshairsize to something you don't like, you can reset it to the default by doing:

/reset cg_crosshairsize

How config files work.

Every time you enter a command into your autoexec.cfg or into the console, it registers a permanent change into your "master config". Unfortunately, the way that configs work in ET are kind of confusing, and there isn't really one "master config" file! In fact, there are several config files and to make matters worse, all those files have the same name! (They're just in different directories).

Here are some of the config files I have:

C:\Program files\Wolfenstein - Enemy Territory\etmain\etconfig.cfg
C:\Program files\Wolfenstein - Enemy Territory\etmain\profiles\Raj\etconfig.cfg
C:\Program files\Wolfenstein - Enemy Territory\etpro\profiles\Raj\etconfig.cfg
C:\Program files\Wolfenstein - Enemy Territory\shrubet\profiles\Raj\etconfig.cfg

The first one, in the "etmain" directory is not really ever used. It's simply a backup copy of the original config, and contains all the default settings. So, if you ever mess up your config, what you can do is copy lines from this backup config into your "active" config files-- basically every "etconfig.cfg" except the backup one is an "active" config file.

The next config file on the list is in "etmain\profiles\Raj\". That config basically stores whatever changes you make on the options menu.

The last couple of config files hold whatever settings you change during an actual game. They are in the "etpro" and "shrubet" folders. Etpro and shrubet are two of the most popular variations of ET. Depending on what server you play on, the mod of ET it's running might be different. In that case, you might have additional directories. You can find out what type of game a server is running by going to the options menu and clicking on "Server Info".

Each mod acts like a whole new game. When you connect to a server running a particular mod, that mod (and therefore that config file) are applied. This also happens when you manually start a mod from the mods menu.

So, say you're on a shrubet server, and you go to the console and say "/set name Bob". Then, when you play on a shrub server, your name will be Bob. However, when you play on something else, you will have some other name, because it uses a different config file for each kind of ET modification!

Obviously this can get really confusing having all these config files. Especially for things like your name, you don't want that changing depending on what mod the server you're playing on is running! So, what I'd recommend is store important settings like your name in your autoexec.cfg (use "set name ...."), and then just create a key bind for "exec autoexec.cfg". Then when you join a server, you can just run your autoexec and be done with it.

So, how does ET decide which config file to run at which time? There are so many of them! Well, when you start up the game, the config file at "\etmain\profiles\Raj\" is applied. Immediately after that, your autoexec.cfg is applied. Then when you join a server (say it's a server running the etpro mod), then the mod-specific config file is applied (like the one for shrubet or etpro). So as you can see it's really a messy process - that's why I recommend just sticking all the important stuff in autoexec and having a keybind to easily execute your autoexec after you join a game.

*phew* I hope I didn't confuse you too much! Config files in ET are really weird, it took me a while to figure them out so don't worry if you don't understand every single detail... As long as you can write your own scripts and change settings, that's good!