![]() |
|
Intro to ScriptingAlthough 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:
Creating a config fileBefore you start writing scripts, you need to put your scripts somewhere! That place is called your config file. I'm going to go through this process very slowly because I've gotten a lot of e-mails asking for help, so just follow these directions exactly and you should be okay ;) 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!
Using the consoleThe console allows you to enter scripting commands. (As you saw above, when you ran the "exec" command). All you have to do is add a slash, and then add a line of script. Make sure to add the slash first, otherwise you'll just end up SAYING the command in the chat, and everyone will laugh at your noobness. Of course, you don't want to type "/vsay Cheer" every time you want to cheer. It'd be smarter to add "bind M vsay cheer" to your autoexec.cfg, and then press M whenever you want to cheer... But, the console is still useful if you're testing a new script and you want to get it working before adding it into your config, or if you want to run some occasional command that isn't in your config, etc. Setting variablesThe most basic command in ET is the set command. The most common use for the "set" command is for setting cvars (standard ET variables). You can get a list of cvars included in ET by going to the console, and typing "/cvarlist". As an example, there is a cvar called "name",
which (obviously) lets you change your name... e.g.: If the variable you are setting is a cvar, you
can even omit the set command, and just type:
How to bind keysMost scripts work by pressing a certain key to execute them. So, you need to know how to bind a script to a key. To do this, you insert a line like this: bind <key> <action> For example, bind K kill. This line in your config file will make it so you can press "K" to commit suicide. Or, bind M vsay Cheer, that will make you cheer every time you press M. Here is a list of things you can put for <key>:
As for <action>, it is basically any valid command. So far you know 2 commands: kill and vsay. Quickchat hotkeys ("vsays")You can assign keys to quickchat commands, which can be useful if you want to be able to just tap a key to say "thanks" or "sorry" and things like that. You can do it like this: bind M "vsay GoodGame" This lets you say "Good game" by pressing M. Note, if you want to say the message to your own team only, then use vsay_team instead of vsay. Here is a list of all the things you can use with
vsay:
EnemyDisguised: "Enemy in disguise!" Double bindingThanks to <R0F/NicK> for this tip! How to double bind on an etpro server It's very simple, just add the replacement text after the command, as shown below in green:
bind K "vsay_team NeedEngineer
We need a ninja deer!!!" How to double bind on an etmain/shrub server There is a workaround, but it's a bit complicated. Here is the script I made up, I haven't tested it much so you might have to tweak it to get it to work properly: set EnemyDisguisedSay "say Enemy in the skies!" The cvar, cg_novoicetext lets you turn off the default text that gets shown for a vsay, that's all... By the way, if you ever want to turn off the SOUND for voice chats, just do "cg_novoicechats 1". Text message hotkeysYou can assign keys to text messages. I really really recommend doing this for common messages that you may need to say to your team, like, "Don't go out the fucking backdoor!" To do this, you do: bind "K" "say_team DO NOT go out the fucking backdoor!" As you can guess, say_team puts the message in team chat, and say is for public chat. Unfortunately the say and say_team commands have a little bug. They don't do capital letters. So the message above will show up as "do not go out the fucking backdoor!". If you want your messages to show up with capital letters, there's a workaround you can use: set BackDoorMessage "say_team DO NOT go out the
fucking backdoor!" This is a little advanced. Basically vstr is a
command which executes another command. You'll learn more about vstr in the next
section. Advanced scriptingNow 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: exec "graphics.cfg" 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 echo "Autoexec.cfg has been loaded!" Wait 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 battery.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!" 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" 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: /reset cg_crosshairsize How config files workEvery 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! |