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:

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

CommandWhat 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_listboundkeysLists the keys that have a bind.
key_findbinding <command>Finds the key that is bound to a command.

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 +mr

Each 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 +crouchjump

The 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.

CommandWhat your character says
voicemenu 0 0MEDIC!
voicemenu 0 1Thanks!
voicemenu 0 2Go! Go! Go!
voicemenu 0 3Move Up!
voicemenu 0 4Go Left
voicemenu 0 5Go Right
voicemenu 0 6Yes
voicemenu 0 7No
voicemenu 0 8Pass to me!
voicemenu 1 0Incoming
voicemenu 1 1Spy!
voicemenu 1 2Sentry Ahead!
voicemenu 1 3Teleporter Here
voicemenu 1 4Dispenser Here
voicemenu 1 5Sentry Here
voicemenu 1 6Activate Charge!
voicemenu 1 7MEDIC: ÜberCharge Ready
voicemenu 1 8Pass to me!
voicemenu 2 0Help!
voicemenu 2 1Battle Cry
voicemenu 2 2Cheers
voicemenu 2 3Jeers
voicemenu 2 4Positive
voicemenu 2 5Negative
voicemenu 2 6Nice Shot
voicemenu 2 7Good 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"

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.