Intro to Scripting.
Ever asked yourself why some guys change weapons so fast,
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
2. Go to File, then Save As...
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!
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
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
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:
Then whenever your game starts up, all the scripts in those files will be executed.
Running a script from a script
set SuicideScript "kill"
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.
echo "Autoexec.cfg has been loaded!"
Here is an example script demonstrating the wait command, which was suggested to me by <R0F/NicK>:
name G; wait 20
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
set sens2 "echo Sensitivity set to 2.0!; sensitivity
2.0; set switch_sens vstr sens4"
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.
set sens2 "echo Sensitivity set to 2.0!; sensitivity
2.0; bind n vstr sens4"
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"
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!
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
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!"
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
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
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:
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:
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!