TF2 scripts: how to write them, with a null movement script
A TF2 script is a text file of console commands that the game runs for you. Scripts bind keys, change settings and join several commands into one key press. This page shows where the files go, the commands scripts are made of, and scripts you can copy: null movement, crouch jump, chat binds, voice commands and the resupply bind.
Where TF2 scripts go
A script is a file that ends in .cfg, in the cfg folder inside tf. A cfg folder inside a folder of your own in tf/custom works too. Three kinds of file run without you asking:
- autoexec.cfg runs when the game starts.
- A class file runs when you change to that class:
scout.cfg,soldier.cfg,pyro.cfg,demoman.cfg,heavyweapons.cfg,engineer.cfg,medic.cfg,sniper.cfgandspy.cfg. - Any other file runs when a line says so:
exec myscriptin the console or in another file, or+exec myscript.cfgin the launch options.
On a class change, Valve's code runs that one file and nothing else. A bind made in scout.cfg stays in place when you play another class, until another file binds the key again.
TF2 script commands: bind, alias, exec and wait
| Command | What it does |
|---|---|
bind <key> "<command>" | Makes a key run a command. |
unbind <key> | Takes the bind off a key. |
alias <name> "<commands>" | Gives a list of commands a name. The name then works as a command of its own. |
exec <file> | Runs a config file. |
echo <text> | Prints text to the console. |
toggle <setting> | Switches a setting between 0 and 1, or steps through the values you list after it. |
BindToggle <key> <setting> | Binds a key to switch a setting between 0 and 1. |
incrementvar <setting> <min> <max> <step> | Adds the step to a setting and starts over at the other end when it passes a limit. |
wait <number> | Makes the game wait before it runs the next command. A larger number is a longer wait. |
key_listboundkeys | Lists the keys that have a bind. |
key_findbinding <command> | Finds the key that is bound to a command. |
- A semicolon separates commands.
bind f "voicemenu 1 7; say_team Charge is ready"runs two commands from one key. - Quotes hold a command with spaces together. Quotes inside quotes do not work: the wiki's example of a wrong line is a
saywith its own quotes inside abind. - A plus alias has a minus twin. A key bound to an alias named
+somethingruns it when you press the key and runs-somethingwhen you let go. The two scripts below are built on this. - wait can be turned off by the server. The server setting
sv_allow_wait_commandis 1 by default. The wiki notes that some servers turn it off, and that scripts withwaitin them fail there.
TF2 null movement script
Hold two opposite movement keys and your character stops. A null movement script, also called null-cancelling movement, makes the key you pressed last win instead. mastercomfig ships it as an addon and credits the script to povohat:
alias +mf "-back;+forward;alias cf +forward"
alias +mb "-forward;+back;alias cb +back"
alias +ml "-moveright;+moveleft;alias cl +moveleft"
alias +mr "-moveleft;+moveright;alias cr +moveright"
alias -mf "-forward;cb;alias cf"
alias -mb "-back;cf;alias cb"
alias -ml "-moveleft;cr;alias cl"
alias -mr "-moveright;cl;alias cr"
alias cf
alias cb
alias cl
alias cr
bind w +mf
bind s +mb
bind a +ml
bind d +mrEach key is bound to a plus alias. Pressing W lets go of back, presses forward and stores forward in the alias cf. Letting go of S later runs cf, so you move forward again if W is still held. The last four lines bind the keys; change them if you do not move with W, A, S and D.
TF2 crouch jump script
This script follows the plus and minus pattern above. It presses jump and crouch together while the key is held and lets go of both when you release it:
alias +crouchjump "+jump;+duck"
alias -crouchjump "-duck;-jump"
bind space +crouchjumpThe wiki's page on jumping explains what a crouch jump gains. Your crouch key keeps working on its own.
TF2 chat binds
say sends a message to everyone and say_team sends it to your team. Bind either to a key:
bind k "say Good game"
bind l "say_team Spy behind us"The message goes after the command without quotes of its own.
TF2 voice command binds
voicemenu takes two numbers, the menu and the line, and both count from 0. bind e "voicemenu 0 0" calls for a Medic. The commands voice_menu_1, voice_menu_2 and voice_menu_3 open the three menus.
| Command | What your character says |
|---|---|
voicemenu 0 0 | MEDIC! |
voicemenu 0 1 | Thanks! |
voicemenu 0 2 | Go! Go! Go! |
voicemenu 0 3 | Move Up! |
voicemenu 0 4 | Go Left |
voicemenu 0 5 | Go Right |
voicemenu 0 6 | Yes |
voicemenu 0 7 | No |
voicemenu 0 8 | Pass to me! |
voicemenu 1 0 | Incoming |
voicemenu 1 1 | Spy! |
voicemenu 1 2 | Sentry Ahead! |
voicemenu 1 3 | Teleporter Here |
voicemenu 1 4 | Dispenser Here |
voicemenu 1 5 | Sentry Here |
voicemenu 1 6 | Activate Charge! |
voicemenu 1 7 | MEDIC: ÜberCharge Ready |
voicemenu 1 8 | Pass to me! |
voicemenu 2 0 | Help! |
voicemenu 2 1 | Battle Cry |
voicemenu 2 2 | Cheers |
voicemenu 2 3 | Jeers |
voicemenu 2 4 | Positive |
voicemenu 2 5 | Negative |
voicemenu 2 6 | Nice Shot |
voicemenu 2 7 | Good Job |
TF2 resupply bind
load_itempreset equips a loadout preset: 0 is preset A, 1 is B, 2 is C and 3 is D. When tf_respawn_on_loadoutchanges is 1, which is the default, Valve's code follows the command with a request to respawn you if you are in a respawn room. A key bound to it is the resupply bind:
bind f5 "load_itempreset 0"- It works inside a respawn room only.
- The command does nothing while you taunt.
- The game refuses a second preset change within half a second of the last one.
- The setting is in the advanced multiplayer options as Automatically respawn after loadout changes in respawn zones.
Quickswitch and fast weapon switch
+quickswitch opens the loadout quick switch menu while you hold the key and closes it when you let go. The menu lists the items that fit the slot of the weapon in your hands, and a weapon slot key changes the slot it shows. It does not open in training. Bind it with bind q +quickswitch.
Fast weapon switch is a different setting: hud_fastswitch 1 changes weapons without the weapon selection menu. It is 0 by default and is in the advanced multiplayer options as Fast weapon switch.
Put a script in your config
The TF2 config maker writes autoexec.cfg and the class files, and its bind editor lists common commands, voice lines and loadout presets among them. Each file has a box named Your own lines: paste a script there and it goes into that file. For a key that kills your character, see the kill bind.
Where this comes from
The folders, the file names and the rules for quotes, aliases and wait are from the Team Fortress 2 wiki. The null movement aliases are from mastercomfig (MIT licence, © mastercoms). The class files, load_itempreset, the respawn request and the quick switch menu are read from Valve's published TF2 source code. The voice commands are from the game's own menu file, as extracted in TF2-Default-HUD.
Next
Look up single commands in the TF2 console commands guide, set your FOV and viewmodel, or pick a TF2 HUD.