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:
Before 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
- 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!
The 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.
The 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.:
set name "Homer Simpson"
If the variable you are setting is a cvar, you
can even omit the set command, and just type:
name "Homer Simpson"
Most 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.
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:
NOTE: some of these might be leftovers from RTCW
EnemyDisguised: "Enemy in disguise!"
PathCleared: "Path cleared."
EnemyWeak: "The enemy is weakened."
AllClear: "All clear."
Incoming: "Incoming!"
FireInTheHole: "Fire in the hole!"
OnDefense: "I'm on defense."
OnOffense: "I'm attacking."
TakingFire: "Taking fire!"
MinesCleared: "Mines cleared."
NeedBackup: "I need backup!"
CoverMe: "Cover me!"
NeedEngineer: "We need an engineer!"
NeedOps: "We need Covert Ops!"
Medic: "Medic!"
NeedAmmo: "I need ammo!"
NeedTarget: "I need a target!"
WhereTo: "Where to?"
FollowMe: "Follow me!"
LetsGo: "Let's go!"
Move: "Move!"
ClearPath: "Clear the path!"
HoldFire: "Hold fire!"
DefendObjective: "Defend our objective!"
DisarmDynamite: "Disarm the dynamite!"
ClearMines: "Clear the mines!"
ReinforceDefense: "Reinforce the defense!"
ReinforceOffense: "Reinforce the offense!"
DestroyPrimary: "Destroy the primary objective!"
DestroySecondary: "Destroy the secondary objective!"
DestroyConstruction: "Destroy the construction!"
ObjectiveDestroyed: "Objective destroyed!"
RepairVehicle: "Repair the vehicle!"
DestroyVehicle: "Destroy the vehicle!"
EscortVehicle: "Escort the vehicle!"
FireOnTarget: "Fire on my target!"
CommandAcknowledged: "Command acknowledged!"
CommandDeclined: "Command declined!"
CommandCompleted: "Command completed!"
ConstructionCommencing: "Construction underway!"
ConstructionCompleted: "Construction completed!"
ConstructionDestroyed: "Construction destroyed!"
ObjectiveFailed: "Objective failed!"
ObjectiveCompleted: "Objective completed!"
Affirmative: "Yes!"
Negative: "No!"
Thanks: "Thanks a lot!"
Welcome: "You're welcome."
Oops: "Oops!"
Sorry: "Sorry!"
Hi: "Hi!"
Bye: "Bye."
Cheer: "Yeah!"
GreatShot: "Great shot!"
GoodGame: "Good game!"
IamSoldier: "I'm a soldier."
IamMedic: "I'm a medic."
IamEngineer: "I'm an engineer."
IamFieldOps: "I'm a field ops."
IamCovertOps: "I'm a covert ops."
FTMeetWaypoint: "Meet at waypoint!"
FTAttackWaypoint: "Attack waypoint!"
FTchecklandmines: "Check for landmines!"
FTDefendWaypoint: "Defend waypoint"
FTAttack: "Attack!"
FTFallBack: "Fall back!"
FTCheckLandMines: "Check for landmines!"
FTCoverMe: "Cover me!"
FTCoveringFire: "Soldier, covering fire!"
FTMortar: "Deploy mortar!"
FTHealSquad: "Heal the squad!"
FTHealMe: "Heal me!"
FTReviveTeamMate: "Revive team mate!"
FTReviveMe: "Revive me!"
FTDestroyObjective: "Destroy objective!"
FTRepairObjective: "Repair objective!"
FTConstructObjective: "Construct the objective!"
FTDisarmDynamite: "Disarm the dynamite!"
FTDeployLandmines: "Deploy landmines!"
FTDisarmLandmines: "Disarm landmines!"
FTCallAirStrike: "Call airstrike!"
FTCallArtillery: "Call artillery!"
FTMortarBarrage: "Call mortar barrage!"
FTResupplySquad: "Resupply squad!"
FTResupplyMe: "Resupply me!"
FTExploreArea: "Explore area!"
FTExploreAtCoordinates: "Explore at co-ordinates!"
FTSatchelObjective: "Destroy satchel objective!"
FTInfiltrate: "Infiltrate!"
FTGoUndercover: "Go undercover!"
FTProvideSniperCover: "Provide sniper cover!"
Thanks to <R0F/NicK> for this tip!
You can change the text that gets displayed for vsays. For example, the default
text for NeedEngineer is "We need an engineer!". You can change the text
though, for example, "We need a ninja deer!".
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!!!"
bind K "vsay_team EnemyDisguised
Enemy in the skies!"
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!"
set db_1 "cg_novoicetext 1; vsay EnemyDisguised; vstr EnemyDisguisedSay"
set db_2 "cg_novoicetext 0"
bind K "+vstr db_1 db_2"
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".
You 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!"
bind "K" vstr BackDoorMessage
This is a little advanced. Basically vstr is a
command which executes another command. You'll learn more about vstr in the next
section.
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.
Echo
The echo command writes some text on your screen. For example:
echo "Autoexec.cfg has been loaded!"
Wait
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 :)
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
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!