Difference between revisions of "Scripting"

From Team Fortress Wiki
Jump to: navigation, search
(Cleaned up. A lot. A LOT!)
Line 1: Line 1:
'''Scripting''' is the use of configuration files (.cfg) to create new keybinds and aliases automating complex behaviors and [[console]] command sequences. Scripting is built into Team Fortress 2 and is not banned by VAC (Valve Anti Cheat).
+
'''Scripting''' is the use of configuration files (.cfg) to create new keybinds and aliases automating complex behaviors and [[console]] command sequences. Scripting is built into Team Fortress 2 and is not banned by VAC (Valve Anti Cheat). Uses of scripting vary from simply binding a key to a command to self-referential loops and nested aliases that redefine one another. Any functionality that can be created with scripting can also be accomplished without, however scripting will allow these functionalities to be used even in fast-paced battle.
  
* Keybinds connect a key to a console command, such as choosing a [[weapon]] slot or saying pre-written text in chat.
+
==Dedicated Scripting Files==
 +
''Team Fortress 2'' automatically reads several game files and executes any scripts within them. Here is the list of those files:
  
* Aliases build new commands by executing a series of console commands whenever they are used. An alias might define [[crouch]]ing and [[jump]]ing as a single [[Jumping#Crouch-jumping|crouch-jump]] command, which can then be bound to a key.
+
* config.cfg - This is the default configuration file which is edited to reflect any in-game changes to keybinds or video settings. It is safe to edit this file, but it will change to reflect any modified keybinds on startup. This config will run every time the game starts up, before any other config.
 +
** config_default.cfg - This contains a basic set of keybinds, and will be executed as a backup if config.cfg is not present.
 +
* autoexec.cfg - This is the default config file for executing custom keybinds and aliases. This config will run every time the game starts up, after config.cfg.
 +
* Scout.cfg, Soldier.cfg, Pyro.cfg, etc. - Each class has a config file which automatically runs whenever you switch to that class. Note that any settings set in one classes config file will be retained when switching classes unless explicitly rebound.
  
These scripts range in complexity from simple lists of commands to self-referential loops and nested aliases that redefine one another. With enough time and effort, you can use these tools to create almost any behavior available to the client at the press of a single key. Scripts are used mainly to help the player using them, they do not do anything automatically.
+
==Scripting Commands==
 +
The following is a list of commands which have no use apart from scripting; they do not influence gameplay directly.
 +
===Bind===
 +
The simplest command is the bind command. It will cause a certain key to execute a certain action, whether that action is a setting, a command, or a script.
  
==Basic scripting files==
+
<code>bind [KEY] [COMMAND]</code><br />
''Team Fortress 2'' automatically reads several game files and executes any keybinds and aliases within them. Here is the list of those files:
+
Quotes can be optionally placed around the key or the command.<br />
  
* config.cfg - This is the default config file which the game edits whenever you use the in-game menus to bind keys or change video settings. While editing the file is safe, it's simpler to leave it alone. It should also be noted that anything changed in another .cfg is also changed in the config.cfg file.
+
<code>bind [KEY] "[COMMAND 1]; [COMMAND 2]; [COMMAND 3]"</code><br />
 +
Quotes can be optionally placed around the key, but must be present around the commands.
  
* autoexec.cfg - This is the default config file for executing custom keybinds and aliases. You may put your keybinds directly into this file, but it is often easier to create separate .cfg files for different scripts, which you then execute within this file.
 
  
* <class>.cfg - Each class has a config file which automatically runs whenever you switch to that class. You may put your keybinds directly into this file, but it is often easier to create separate .cfg files for different scripts, which you then execute within these files. Note that keybinds put into one class's .cfg '''will''' pass through to the other classes unless explicitly unbound in those classes' .cfgs.
+
Commands come in two forms:<br />
 +
<code>bind "e" "Voicemenu 0 0"</code><br />
 +
This bind will make the player call for a medic when they press {{key|E}}.
  
==Syntax==
+
<code>bind "w" "+forward"</code><br />
Here is a list of syntactic rules:
+
This bind will make the player move forward while they have {{key|W}} held down.
  
* For any keybind or alias to work, you need to follow this format:
+
===Toggle===
 +
This command allows a setting to be toggled between two or more values.
  
:'''command <argument1> <argument2>'''
+
<code>toggle "sv_cheats 0 1"</code>
  
:* command is the kind of scripting you want. You have three choices:
+
===Bindtoggle===
 +
This works identically to toggle, but binds it to a key.
  
::* bind - Used to bind commands to a particular key.
+
<code>bindtoggle o "sv_cheats 0 1"</code>
::* alias - Used to execute commands when the alias is executed.
 
::* exec - Used to execute commands automatically when a configuration file is loaded.
 
  
:* <argument1> is either the key being bound or the name of the alias being created.
+
===Incrementvar===
 +
This allows for variables to be increased or decreased repeatedly by a set amount.
  
:* <argument2> is either the command being bound or the commands executed by the alias.
+
<code>bind MWHEELUP "incrementvar fov_desired 75 90 1"<br />
 +
bind MWHEELDOWN "incrementvar fov_desired 75 90 -1"</code><br />
 +
This will cause the [[field of view]] to increase when scrolling up, and to decrease when scrolling down.<br />
 +
Note: Incrementvar will cause the value to wrap around if it gets too large or too small. In this example, once the field of view hits 90, it will drop down to 75, and vice-versa.
  
*To run multiple commands, you must put the entire argument in quotation marks and separate the commands with semicolons, like so:
+
===Alias===
 +
An alias allows multiple commands to be referenced by a single command. This is effectively shorthand, and it is most useful when a series of commands need to be called multiple times.
 +
Note: Alias names cannot contain spaces. They may contain underscores, numbers, and symbols. Alias names are case-sensitive.<br />
  
:'''alias "spraynpray" "+attack; wait 500; -attack"'''
+
<code>alias Call_For_Medic "Voicemenu 0 0"<br />
:'''bind "mouse3" "spraynpray"
+
bind "e" "Call_For_Medic"</code><br />
 +
This script functions the same with a simple bind, meaning that when the player presses {{key|E}}, they will call for a medic.<br />
 +
===Exec===
 +
This command will execute another file. This means that complex scripts can be stored in other files, so as not to clutter up more general files.
  
:*When executed, the alias starts firing the player's weapon, continues for 500 physics frames (that is roughly five seconds if you are on a server that runs at a 100 frames per second), and then stops firing. The alias is keybound to execute when you press the middle mouse button.
+
<code>exec autoexec.cfg</code><br />
 +
This script will execute the player's autoexec script.
 +
===Echo===
 +
This command will cause text to be printed to console. This is very useful for debugging.
  
*If the set of commands in quotation marks ''itself'' contains quotation marks, you must escape the internal quotes by using a double-set of quotation marks ("") instead. Otherwise, the command is likely to be misinterpreted.
+
<code>echo Scripting is; echo very useful.</code><br />
 +
This will print out <code>Scripting isvery useful.</code> Spaces are only parsed if they are between words, or if the echoed text is between quotes, as in the next example.
  
 +
<code>echo " Scripting is very useful.  "</code><br />
 +
The extra spaces will be printed out, since the sentence is denoted by quotation marks.
  
==Keybinds==
+
Note: It is not possible to print out the " or ; characters, as their meaning will be misinterpreted.
''Team Fortress 2'' allows scripts and aliases to be bound to any key on the keyboard. The key you wish to bind a command to is placed after your bind command and before the action you want the key to execute, as in the section above. Most keys are self-explanatory, as all alphanumerics (a-z, 0-9) and function keys are simply listed by typing that key ("bind a" binds a key to 'a', "bind 5" binds to '5' and "bind F7" binds to 'F7'). Other keys require you type specific names into your .cfg file in order to access them, and these names are not all obvious. A list of these keys is provided below:
+
===Wait===
 +
This command will make the game wait a given number of frames before executing the next command.<br />
 +
Note: The amount of real time this corresponds to depends on the server's tickrate.<br />
 +
'''Warning: Wait commands are disabled on certain servers. This will cause certain scripts to fail, and may (in semi-rare cases) cause the game to crash.'''
  
====List of key names====
+
<code>echo Why did the chicken cross the road?; wait 66; echo To get to the other side!"</code><br />
 +
This script will wait 66 frames (1 second on most servers) before printing the punchline.
 +
 
 +
==List of key names==
 +
Hover over a key to see its scripting name.
 +
<code>
 
{|
 
{|
! align="left"| Keyboard Key
+
! width="45%" <!-- Main keyboard -->|
! Names of Keybind
+
! width="4%" <!-- Spacing -->|
|-
+
! width="20%" <!-- Special keys -->|
| Left Shift
+
! width="1%" <!-- Spacing -->|
| SHIFT
+
! width="25%" <!-- Keypad 1 -->|
|-
+
! width="5%" <!-- Keypad 2 -->|
| Left Ctrl
 
| CTRL
 
|-
 
| Left Alt
 
| ALT
 
|-
 
| Right Shift
 
| RSHIFT
 
|-
 
| Right Control
 
| RCTRL
 
|-
 
| Right Alt
 
| RALT
 
|-
 
| Tab
 
| TAB
 
|-
 
| Backspace
 
| BACKSPACE
 
|-
 
| Semicolon
 
| SEMICOLON
 
|-
 
| Insert
 
| INS
 
|-
 
|-
 
| Scroll Lock
 
| SCROLLLOCK
 
|-
 
| Pause/Break
 
| NUMLOCK
 
|-
 
|-
 
| Home
 
| HOME
 
|-
 
| End
 
| END
 
|-
 
| Delete
 
| DEL
 
|-
 
| Page Up
 
| PGUP
 
|-
 
| Page Down
 
| PGDN
 
|-
 
|-
 
| Up Arrow
 
| UPARROW
 
|-
 
| Down Arrow
 
| DOWNARROW
 
|-
 
| Left Arrow
 
| LEFTARROW
 
|-
 
| Right Arrow
 
| RIGHTARROW
 
|-
 
|-
 
! align="left"| Numpad Key
 
! Names of Keybind
 
|-
 
| 0
 
| KP_INS
 
|-
 
| 1
 
| KP_END
 
|-
 
| 2
 
| KP_DOWNARROW
 
|-
 
| 3
 
| KP_PGDN
 
|-
 
| 4
 
| KP_LEFTARROW
 
|-
 
| 5
 
| KP_5
 
|-
 
| 6
 
| KP_RIGHTARROW
 
|-
 
| 7
 
| KP_HOME
 
|-
 
| 8
 
| KP_UPARROW
 
|-
 
| 9
 
| KP_PGUP
 
|-
 
| Enter
 
| KP_ENTER
 
|-
 
| "."
 
| KP_DEL 
 
|-
 
| "+"
 
| KP_PLUS
 
|-
 
| "-"
 
| KP_MINUS
 
|-
 
| "*"
 
| KP_MULTIPLY
 
|-
 
| "/"
 
|KP_SLASH
 
|-
 
 
|-
 
|-
 +
|
 +
{{tooltip|{{key|ESC}}|ESC}}
 +
{{tooltip|{{key|F1}}|F1}}
 +
{{tooltip|{{key|F2}}|F2}}
 +
{{tooltip|{{key|F3}}|F3}}
 +
{{tooltip|{{key|F4}}|F4}}
 +
{{tooltip|{{key|F5}}|F5}}
 +
{{tooltip|{{key|F6}}|F6}}
 +
{{tooltip|{{key|F7}}|F7}}
 +
{{tooltip|{{key|F8}}|F8}}
 +
{{tooltip|{{key|F9}}|F9}}
 +
{{tooltip|{{key|F10}}|F10}}
 +
{{tooltip|{{key|F11}}|F11}}
 +
{{tooltip|{{key|F12}}|F12}}
 +
 +
{{tooltip|{{key|`}}|`}}
 +
{{tooltip|{{key|1}}|1}}
 +
{{tooltip|{{key|2}}|2}}
 +
{{tooltip|{{key|3}}|3}}
 +
{{tooltip|{{key|4}}|4}}
 +
{{tooltip|{{key|5}}|5}}
 +
{{tooltip|{{key|6}}|6}}
 +
{{tooltip|{{key|7}}|7}}
 +
{{tooltip|{{key|8}}|8}}
 +
{{tooltip|{{key|9}}|9}}
 +
{{tooltip|{{key|0}}|0}}
 +
{{tooltip|{{key|-}}|-}}
 +
{{tooltip|{{key|{{=}}}}|=}}
 +
{{tooltip|{{key|Delete}}|BACKSPACE}}
 +
 +
{{tooltip|{{key|TAB}}|TAB}}
 +
{{tooltip|{{key|Q}}|Q}}
 +
{{tooltip|{{key|W}}|W}}
 +
{{tooltip|{{key|E}}|E}}
 +
{{tooltip|{{key|R}}|R}}
 +
{{tooltip|{{key|T}}|T}}
 +
{{tooltip|{{key|Y}}|Y}}
 +
{{tooltip|{{key|U}}|U}}
 +
{{tooltip|{{key|I}}|I}}
 +
{{tooltip|{{key|O}}|O}}
 +
{{tooltip|{{key|P}}|P}}
 +
{{tooltip|{{key|[}}|[}}
 +
{{tooltip|{{key|]}}|]}}
 +
{{tooltip|{{key|\}}|\}}
 +
 +
{{tooltip|{{key|⇪ Caps}}|CAPSLOCK}}
 +
{{tooltip|{{key|A}}|A}}
 +
{{tooltip|{{key|S}}|S}}
 +
{{tooltip|{{key|D}}|D}}
 +
{{tooltip|{{key|F}}|F}}
 +
{{tooltip|{{key|G}}|G}}
 +
{{tooltip|{{key|H}}|H}}
 +
{{tooltip|{{key|J}}|J}}
 +
{{tooltip|{{key|K}}|K}}
 +
{{tooltip|{{key|L}}|L}}
 +
{{tooltip|{{key|;}}|SEMICOLON}}
 +
{{tooltip|{{key|'}}|'}}
 +
{{tooltip|{{key|&nbsp; ↵ &nbsp; }}|ENTER}}
 +
 +
{{tooltip|{{key|Shift}}|SHIFT}}
 +
{{tooltip|{{key|Z}}|Z}}
 +
{{tooltip|{{key|X}}|X}}
 +
{{tooltip|{{key|C}}|C}}
 +
{{tooltip|{{key|V}}|V}}
 +
{{tooltip|{{key|B}}|B}}
 +
{{tooltip|{{key|N}}|N}}
 +
{{tooltip|{{key|M}}|M}}
 +
{{tooltip|{{key|,}}|,}}
 +
{{tooltip|{{key|.}}|.}}
 +
{{tooltip|{{key|/}}|/}}
 +
{{tooltip|{{key|Shift}}|RSHIFT}}
 +
 +
{{tooltip|{{key|Ctrl}}|CTRL}}
 +
{{tooltip|{{key|⊞}}|LWIN}}
 +
{{tooltip|{{key|Alt}}|ALT}}
 +
{{tooltip|{{key| &nbsp; &nbsp; &nbsp; Spacebar &nbsp; &nbsp; &nbsp; }}|SPACE}}
 +
{{tooltip|{{key|⊞}}|RWIN}}
 +
{{tooltip|{{key|Menu}}|Cannot be bound}}
 +
{{tooltip|{{key|Ctrl}}|RCTRL}}
 +
 +
|<!-- Spacing -->
 +
|
 +
{{tooltip|{{key|PrtScn}}|Cannot be bound}}
 +
{{tooltip|{{key|ScrLk}}|SCROLLOCK}}
 +
{{tooltip|{{key|Pause}}|NUMLOCK}}
 +
 +
{{tooltip|{{key|Insert}}|INS}}
 +
{{tooltip|{{key|Home}}|HOME}}
 +
{{tooltip|{{key|PgUp}}|PGUP}}
 +
 +
{{tooltip|{{key|Delete}}|DEL}}
 +
{{tooltip|{{key|End}}|END}}
 +
{{tooltip|{{key|PgDn}}|PGDN}}
 +
 +
 +
&nbsp; &nbsp; &nbsp; &nbsp; {{tooltip|{{key|&uarr;}}|UPARROW}}
 +
 +
&nbsp; &nbsp; {{tooltip|{{key|&larr;}}|LEFTARROW}}
 +
{{tooltip|{{key|&darr;}}|DOWNARROW}}
 +
{{tooltip|{{key|&rarr;}}|RIGHTARROW}}
 +
|<!-- Spacing -->
 +
|
 +
 +
{{Scripting Numpad}}
 +
|}
 +
 +
{|
 
! align="left"| Mouse Button
 
! align="left"| Mouse Button
! Names of Keybind
+
! Name of Keybind
 
|-
 
|-
| Wheel Up
+
| Scroll Up
 
| MWHEELUP
 
| MWHEELUP
 
|-
 
|-
| Wheel Down
+
| Scroll Down
 
| MWHEELDOWN
 
| MWHEELDOWN
 
|-
 
|-
Line 195: Line 219:
 
|}
 
|}
  
Using the above keynames, you are able to place the following example command into one of your config files: <bind KP_ENTER "voicemenu 0 1">. When you hit 'Enter' on your numpad in-game, you will trigger the "Thanks" voice command.
+
</code>
 
+
==Useful commands==
==Basic commands==
+
{{Main|vdc:List_of_TF2_console_commands_and_variables|l1=List of TF2 console commands and variables}}
Most commands accept a single argument, which is whatever value you want to execute.
 
 
 
'''bind "q" "sv_alltalk 1"'''
 
 
 
A handful of important commands accept multiple arguments. Here are some examples:
 
 
 
* disguise X Y - This [[disguise]]s the [[Spy]]. X is the class numbered 1 through 9, while Y is the team numbered 1 or 2.
 
 
 
* voicemenu X Y - This executes a voice command. X is the number of the primary menu, while Y is the command position in that menu.
 
 
 
Example: "voicemenu 1 1" is the command for Spy, so:
 
 
 
'''bind "t" "voicemenu 1 1"'''
 
 
 
This command will make your character yell "Spy!" whenever you hit the key.
 
 
 
==Toggles==
 
A '''toggle''' command can be used to toggle a convar on or off, or cycle through a set of values.
 
Example:
 
<b><pre>
 
bind x "toggle viewmodel_fov 20 33 60 75 90"
 
</pre></b>
 
 
 
'''Bindtoggle''' is a short command to bind on/off toggles.
 
Example:
 
<b><pre>
 
bindtoggle z r_drawviewmodel
 
</pre></b>
 
Bindtoggle command is essentially a shorthand for "bind <key> 'incrementvar <cvar> 0 1 1'".
 
 
 
==Incrementvar==
 
This command cycles through a range of specified values whenever it executes and applies those values to another command. This has the form of:
 
 
 
:'''command "<argument1>" "incrementvar <argument2> X Y Z"'''
 
 
 
:*X and Y represent the range of values you want to execute with <argument2>.
 
:*Z is the size of the step you want to make while you cycle through the range.
 
 
 
If you wanted a value range of 1 through 10 and you wanted to increment your value by 2 each time the command was executed, you'd make X Y Z into 1 10 2. Each time it executes, <argument2> will execute with an incrementing value of 2, 4, 6, 8, 10, 2, 4, 6, 8, 10... and so forth.
 
 
 
Here is a real example of incrementvar in action:
 
 
 
:'''bind "n" "incrementvar net_graphpos 1 3 1"'''
 
 
 
This binds the key "n" to cycle to the next position in the 3 available net_graph positions.
 
 
 
==The + and - commands==
 
These commands have two states. While the bound key is pressed, the '''+''' command executes and continues to execute. When the key is released, the '''-''' command executes and continues to execute.
 
 
 
Example:
 
:'''bind "c" "+duck"
 
 
 
This + command is bound to "c" so whenever the key is pressed, the player ducks. Whenever the key is released, "+duck" is swapped to "-duck" and the player stops ducking.
 
 
 
In general, if a command or alias is bound to a key, a + tells the game to run the command as long as the key is held. Similarly, if a command or alias is bound to a key, a - tells the game to run the command when the key is released.
 
 
 
If an alias is defined with a + in front of it, the alias will be run whenever the key is pressed, as the key is pressed. The - command will then run as the key is released.
 
 
 
==Wait command==
 
If you want the game to delay for a period of time during an alias, or if you want to avoid client crashes caused by executing commands too quickly, use the '''wait''' command.
 
 
 
The wait command tells the game to delay the next command in the script by one physics frame, something like a full turn in the TF2 rules. It accepts values such as "wait 50", telling the game to wait fifty frames before the alias continues. "wait 100" is roughly a second on a 100 FPS server.
 
 
 
Some servers disable the wait command. While playing on them, wait commands will be ignored, making some scripts susceptible to crashes. A script containing an indeterminate loop spaced by wait commands will always immediately crash the client upon usage on such servers. To avoid this, a script such as the following can be added to the class.cfg file to detect if wait is enabled or disabled, and disable a script containing wait loops from its bound key to prevent a crash:
 
 
 
'''//Wait Testing Script'''
 
'''alias waiter "w_reset; wait; w_positive"''' //This line starts the script by resetting the aliases used to check
 
'''alias wait "w_negative"''' //This line sets the alias named wait to w_negative, which runs if the wait command is disabled
 
'''alias w_reset "alias w_positive w_enable"''' //This line defines what the reset alias does
 
'''alias w_negative "alias w_positive; w_disable"''' //This line runs the alias for when wait is disabled
 
'''alias w_positive "w_enable"'''  //This line runs the alias for when wait is enabled
 
'''alias w_enable "w_e_echo; w_e_custom" ''' //This line defines what happens if wait is disabled, in this case displaying text to the console and running an optional custom command
 
'''alias w_disable "w_d_echo; w_d_custom"''' //This line defines what happens if wait is enabled, in this case displaying text to the console and running an optional custom command
 
'''alias w_e_echo "echo Wait command enabled on server. Scripts will have full functionality."''' //This line notifies you that the wait command is enabled
 
'''alias w_d_echo "echo WAIT COMMAND DISABLED ON SERVER. SCRIPTS WILL HAVE LIMITED FUNCTIONALITY."'''  //This line notifies you that the wait command is disabled
 
'''alias w_e_custom "<bind the waitloop to a key>"'''   //Custom commands to run if server ALLOWS wait command
 
'''alias w_d_custom "<unbind the key or bind to a different script>"'''  //Custom commands to run if server DISALLOWS wait command
 
'''waiter''' //This line actually executes the script and returns if wait is disabled or enabled in the console
 
 
 
==Aliases==
 
An '''alias''' is like a variable that stores a series of commands which can be executed as a group. A simple alias will take the form:
 
 
 
'''alias "aliasname" "command1; command2; command3"'''
 
 
 
You can then execute the commands through a bound key:
 
 
 
'''bind "key" "aliasname"'''
 
 
 
Whenever the key is pressed, "command1", "command2", and "command3" are executed in order.
 
 
 
===Complex aliases===
 
Aliases can execute any command including other aliases. Furthermore, an alias can execute an alias in order to redefine that alias's commands. This allows you to create cycling aliases. Here is a very simple example:
 
 
 
'''bind "key" namescroll'''
 
'''alias namescroll "firstname" '''
 
'''alias firstname "setinfo name ""First_name""; alias namescroll secondname" '''
 
'''alias secondname "setinfo name ""Second_name""; alias namescroll thirdname"'''
 
'''alias thirdname "setinfo name ""Third-name""; alias namescroll firstname"'''
 
 
 
This is difficult to read, so to break it down.
 
 
 
*The first line binds "key" to an alias "namescroll" which we have yet to define.
 
*The second line creates the alias "namescroll" which executes the command "firstname"
 
*The third line defines the "firstname" alias as two commands:
 
:*The first command sets your in-game name to "First_name"
 
:*The second command redefines the alias "namescroll" as an alias for executing the alias "secondname"
 
*The fourth line defines "secondname" in the same manner.  A different in-game name is set, and then "namescroll" is redefined to another alias "thirdname"
 
*The fifth line defines "thirdname" just like the two before it, but with a twist.  It redefines the "namescroll" alias as executing the "firstname" alias.
 
 
 
This completes a loop. Each press of the key executes a command and redefines the alias bound to the key, so that when it is next pressed it will execute a different command. If there were no loop, then the alias "namescroll" wouldn't always have another alias to execute with each keypress.
 
 
 
===Alias Toggles===
 
 
 
Aliases can be used to toggle the state of some command between values (eg toggle '''cl_showfps''' between 0 and 1).  This example demonstrates creating a generic toggle:
 
 
 
'''alias ToggleStateA "do A stuff; alias ToggleControl ToggleStateB"'''
 
'''alias ToggleStateB "do B stuff; alias ToggleControl ToggleStateA"'''
 
'''alias ToggleControl ToggleStateA'''
 
'''bind {toggle button} ToggleControl'''
 
 
 
*The first line defines the first state and also tells the control to set the second state when next executed
 
*The second line defines the second state and also tells the control to set the first state when next executed
 
*The third line defines the control and initializes it to set the first state
 
*The last line binds the toggle control to the button with which you want to toggle
 
 
 
===Alias Switching===
 
 
 
You can use the states of a set of aliases to rebind a key to something and back to its original.  eg:
 
alias +AlternateBinds "bind Q do_B_stuff"
 
alias -AlternateBinds "bind Q do_A_stuff"
 
bind {bind switching key} +AlternateBinds
 
 
 
To execute do_B_stuff you would need to press both the bind switching key and Q.
 
 
 
===Alias Loops===
 
Aliases can be used in conjunction with the wait command to create looping aliases.<br>
 
 
''Warning: Not having the wait in place, or being on a server with wait disabled will cause this example to crash TF2.''<br>
 
''To detect whether a server has wait enabled or disabled without risking a crash, see the "Wait Command" section above.''<br>
 
'''alias "Loop" "echo Looping every 150 ticks.;wait 150;Loop"'''
 
'''Loop'''
 
 
 
Lets break this down into components:<br>
 
Line 1 The echo displays a message to the console, just so you know it works.
 
The wait makes it wait 150 ticks between iterations
 
Loop calls the alias again, restarting at the echo.
 
 
 
Line 2
 
Loop starts the looping alias.
 
 
 
You can also create loops of alias commands, like this example:
 
'''alias "Loop1" "echo Loop 1;wait 150;Loop2"'''
 
'''alias "Loop2" "echo Loop 2;wait 150;Loop1"'''
 
 
 
Loop1 calls Loop2 which in turn calls Loop1, etc...
 
This method can also be used for breaking a loop without clearing the loop alias:
 
'''alias "Loop1" "echo Loop1;wait 150;Loop2"'''
 
'''alias "Loop2" "Loop1"'''
 
This would create a loop, then
 
'''alias "Loop2"'''
 
would break it, by clearing the Loop2 alias.
 
 
 
You can use these for button presses(Via the +/- prefixes covered earlier) like this:
 
'''alias "Loop2" "Loop1"'''
 
'''alias "Loop1" "echo Loop1;wait 150;Loop2"'''
 
'''alias "+Loop" "alias Loop2 Loop1;Loop1"'''
 
'''alias "-Loop" "alias Loop2"'''
 
'''bind "<Key>" "+Loop"'''
 
In order of what it's doing:
 
  
1. Make Loop2 point to Loop1
+
===Disguising===
2. Set Loop1 to run the following commands: (this does not actually execute/call/use Loop1)
+
The <code>disguise</code> command takes two arguments, the first being the class and the second being the team.
      echo 'Loop1' to the console
+
:'''Class'''
      wait 150
+
:1. Scout
      call Loop2
+
:2. Sniper
3. Set +Loop to run the following commands:  
+
:3. Soldier
      make Loop2 point to Loop1 (so that Loop1 will create an infinite loop when ran)
+
:4. Demoman
      run Loop1 (to get the infinite loop started)
+
:5. Medic
4. Set -Loop to remove/clear Loop2's link, breaking the infinite loop.
+
:6. Heavy
5. Binds <Key> to run +Loop when pressed and -Loop when released.
+
:7. Pyro
 +
:8. Spy
 +
:9. Engineer
  
== Useful script commands ==
+
:'''Team'''
There are literally hundreds of different arguments for your script that can make them do almost anything. Here's a list of a few of them.
+
:1. BLU team
 +
:2. RED team
 +
:-1. Opposite team
 +
:-2. Same team
  
===Voice commands===
+
Thus, <code>disguise 5 1</code> would disguise as a BLU Medic and <code>disguise 7 -2</code> would disguise as a friendly Pyro.
A '''voice command''' is the act of making your class say something, often used in gameplay as a way of either signaling information or just for goofing-off.
+
Note: <code>disguise 8 -2</code> (Friendly spy) will cause the player to un-disguise.
  
Voice commands are used with the following syntax;
+
===Buildings===
 +
The <code>build</code> command takes two arguments, the first being the building and the second being the building type.
 +
<br /><code>build 0 0</code> will build a [[dispenser]] <small>(Engineer only)</small>
 +
<br /><code>build 1 0</code> will build a [[teleporter entrance]] <small>(Engineer only)</small>
 +
<br /><code>build 1 1</code> will build a teleporter exit <small>(Engineer only)</small>
 +
<br /><code>build 2 0</code> will build a [[sentry]] <small>(Engineer only)</small>
 +
<br /><code>build 3 0</code> will build a [[sapper]] <small>(Spy only)</small>
  
'''voicemenu <menu_number> <phrase_number>
+
Similarly, the <code>destroy</code> command will destroy buildings.
 +
<br /><code>destroy 0 0</code> will destroy a [[dispenser]] <small>(Engineer only)</small>
 +
<br /><code>destroy 1 0</code> will destroy a [[teleporter entrance]] <small>(Engineer only)</small>
 +
<br /><code>destroy 1 1</code> will destroy a teleporter exit <small>(Engineer only)</small>
 +
<br /><code>destroy 2 0</code> will destroy a [[sentry]] <small>(Engineer only)</small>
 +
<br />Note: Sappers cannot be destroyed.
  
Where <menu_number> is the one of the 3 menus where voice commands are spread out through <phrase_number> is one of the 7 voice commands that are within each <menu_number> menu.
+
===Voice Menu===
 
+
The <code>voicemenu</code> command takes two arguments, the menu number and the command number.
====Arguments for voice commands====
+
*0 (<code>voice_menu_0</code>)
*0 <phrase_number>
+
*:0: MEDIC!
*:0: Medic
+
*:1: Thanks!
*:1: Thanks
+
*:2: Go! Go! Go!
*:2: Go
+
*:3: Move Up!
*:3: Move Up
+
*:4: Go Left
*:4: Flank Left
+
*:5: Go Right
*:5: Flank Right
 
 
*:6: Yes
 
*:6: Yes
 
*:7: No
 
*:7: No
*1 <phrase_number>
+
*1 (<code>voice_menu_1</code>)
 
*:0: Incoming
 
*:0: Incoming
*:1: Cloaked Spy
+
*:1: Spy!
*:2: Sentry Ahead
+
*:2: Sentry Ahead!
 
*:3: Teleporter Here
 
*:3: Teleporter Here
 
*:4: Dispenser Here
 
*:4: Dispenser Here
 
*:5: Sentry Here
 
*:5: Sentry Here
*:6: Activate ÜberCharge
+
*:6: Activate Charge!
*:7: (Medic Only) ÜberCharge Ready
+
*:7: MEDIC: ÜberCharge Ready
*2 <phrase_number>
+
*2 (<code>voice_menu_2</code>)
*:0: Help
+
*:0: Help!
*:1: Battlecry
+
*:1: Battle Cry
 
*:2: Cheers
 
*:2: Cheers
 
*:3: Jeers
 
*:3: Jeers
Line 420: Line 290:
 
*:7: Good Job
 
*:7: Good Job
  
===Quick Spy disguises===
+
Note: These numbers are one less than as they appear in-game.
With these quick and easy commands, you can bind keys to specific disguises instead of having to flip through the disguise menu.
+
===Assorted===
 +
*<code>clear</code> will clear the console of any information.
 +
*<code>fov_desired (75-90)</code> will set your [[field of view]].
 +
*<code>lastdisguise</code> will cause the player to re-disguise as their last disguise. <small>(Spy only)</small>
 +
*<code>load_itempreset [0, 1, 2, 3]</code> will load a particular loadout preset [A, B, C, D].
 +
*<code>say "message"</code> will say a message to public chat.
 +
*<code>say_team "message"</code> will say a message to your team.
 +
*<code>+taunt</code> will cause the player to taunt.
 +
*<code>+use_action_slot_item</code> will cause the player to use their action slot item.
 +
*<code>volume (0-1)</code> will change the in-game volume.
  
Disguise commands are used with the following syntax:
+
==Advanced Scripting Techniques==
 +
===Toggles===
 +
It is possible to bind a key to toggle a command which would otherwise be a press and hold command.
  
'''disguise <class_number> <team_number>
+
<code>bind w toggle<br />
 +
alias toggle "enable"<br />
 +
alias enable "alias toggle disable; +forward"<br />
 +
alias disable "alias toggle enable; -forward"</code><br />
 +
This script will cause a press of {{key|W}} to keep the player moving forward until {{key|W}} is pressed again.
 +
===Key combinations===
 +
It is possible to create a script where pressing one button while another is held down will change the action of the first button.
  
Where <class_number> is the number of the class you wish to disguise as, and <team_number> the number of the team you wish to disguise as.
+
<code>bind e call<br />
 +
alias call Call_For_Medic<br />
 +
alias Call_For_Medic "Voicemenu 0 0"<br />
 +
alias Call_For_Ubercharge "Voicemenu 1 6"</code><br />
 +
At this point, the script will mean that every time {{key|E}} is pressed, the player will call for a Medic. It also has an unused alias to call for an [[Ubercharge]].<br />
 +
<code>bind shift +toggleState<br />
 +
alias +toggleState "alias call Call_For_Ubercharge"<br />
 +
alias -toggleState "alias call Call_For_Medic</code><br />
 +
Now, pressing {{Key|Shift}} will redirect <code>call</code> to ask for an ubercharge. Releasing {{Key|Shift}} will make <code>call</code> point back at a medic call.<br />
 +
When {{Key|Shift|E}} is pressed, the player will call for an Ubercharge, rather than for a Medic.
  
====Arguments for disguise commands====
+
===Wait-testing===
*1 <class_number>
+
Since the <code>wait</code> command is integral to some scripts, it may be necessary to test to see if a server has disabled the command.
*:1: Scout
 
*:2: Sniper
 
*:3: Soldier
 
*:4: Demoman
 
*:5: Medic
 
*:6: Heavy
 
*:7: Pyro
 
*:8: Spy
 
*:9: Engineer
 
  
*2 <team_number>
+
<code>alias waitTester "alias waitTest waitPositive; wait; waitTest"<br />
*:1: BLU team
+
alias wait "alias waitTest waitNegative"<br />
*:2: RED team
+
alias waitPositive "echo Wait is enabled on this server.; exec waitPositive.cfg"<br />
*:-1: Opposite team
+
alias waitNegative "echo Wait is DISABLED on this server!; exec waitNegative.cfg"<br />
*:-2: Same team
+
waitTester</code><br />
 +
This script relies on the fact that if the wait command is disabled on a server, the alias named <code>wait</code> can be defined by the user. Thus, the script creates an alias named <code>waitTest</code> which by default points to <code>waitPositive</code>, but if <code>wait</code> is not allowed (and can thus be defined by the user), will be redirected to <code>waitNegative</code>.
 +
===Loops===
 +
'''Warning: Loops which run without a wait command will cause the TF2 client to hang. It is highly suggested to run a script only after a wait testing script.'''<br />
 +
It is generally considered bad form to have one alias point to itself, as this loop cannot be broken out of and the reset. Therefore, looping scripts tend to include two parts to the loop: The part that waits, and the part that loops.
  
===Engineer quickbuilding===
+
<code>alias loop "+taunt; wait 132; redirect"<br />
Similar to the [[Spy]]'s quick disguise, this allows the [[Engineer]] to bypass his [[PDA]] interface and instantly destroy an existing building type, while simultaneously pulling up blueprints to place a new building of the same type. 
+
alias redirect loop<br />
 
+
bind g "redirect"<br />
Building commands are used with the following syntax:
+
bind o "alias redirect break"<br />
 
+
alias break "alias redirect loop"</code><br />
'''build <building_number><br>
+
This script will start looping once {{Key|G}} is pressed. It will then taunt every 132 frames (2 seconds on most servers). Pressing {{Key|O}} would cause the next iteration of the loop to break out. The <code>break</code> alias will then reset the loop, so that next time it is called it will loop again.
'''destroy <building_number>
 
 
 
Where <building_number> is the number of the building you wish to destroy or pull up blueprints for.
 
 
 
====Arguments for building commands====
 
*Number: Building/Destroying
 
*:0: Dispenser
 
*:1: Teleporter Entrance
 
*:2: Sentry Gun/Minisentry
 
*:3: Teleporter Exit
 
 
 
An example of how to implement the above syntax is as follows:
 
 
 
<pre>
 
alias sentry "destroy 2; build 2"
 
alias dispenser "destroy 0; build 0"
 
alias entrance "destroy 1; build 1"
 
alias exit "destroy 3; build 3"
 
bind f1 sentry
 
bind f2 dispenser
 
bind f3 entrance
 
bind f4 exit
 
</pre>
 
 
 
In this example, buildings are bound to the F1-F4 keys so that they do not interfere with weapon selection keys. When activated, the script will instantly and irreversibly destroy an existing building of the listed type, while pulling up the [[Engineer]]'s blueprints of the destroyed building's same type, ready to deploy. This script will still function if only one or two building types are used (in case you only want to map Sentry quickbuilding to a single key).
 
 
 
===Medic autocall===
 
The player can control the Medic's autocall threshold through keybinds. The command is:
 
 
 
'''hud_medicautocallersthreshold <percentage>
 
 
 
The percentage is the percent health below which the autocall is triggered; 0 will show nothing, while 300 will show all nearby allies (since 300% is the maximum possible health).
 
 
 
This command can be used to make the popular "Medic Radar" script:
 
This set of aliases and commands will temporarily boost the [[Medic]]'s autocall threshold to 300% (which covers everyone, even a [[Spy]] who just [[overheal]]ed with a [[Conniver's Kunai]]) for as long as they hold a key down, allowing the player to see where all of their teammates are by their [[Medic]] autocall speech bubbles in the event they find themselves alone.
 
 
 
  '''alias "autocall_default" "hud_medicautocallersthreshold "75""<br>
 
  '''alias "autocall_all" "hud_medicautocallersthreshold "300""<br>
 
  '''alias "+radar" "autocall_all"<br>
 
  '''alias "-radar" "autocall_default"<br>
 
  '''bind mouse3 "+radar"<br>
 
 
 
The default autocall value, or the autocall threshold when this command is not in use, can be adjusted to any desired number (in the example it is listed as 75% health) and the keybind to activate it can be changed as well (the example is bound to MOUSE3).
 
  
 
==Noteworthy scripts==  
 
==Noteworthy scripts==  
Line 502: Line 350:
 
===Patched scripts===
 
===Patched scripts===
 
====Pistol scripts====
 
====Pistol scripts====
Originally, the [[Pistol]] could be fired almost as fast as the human hand could press a key. Realizing this, some people created scripts that made the Pistol fire as rapidly as possible as long as you held down the fire button. This not only allowed the [[Scout]] and [[Engineer]] to fire faster than most people could manage, but it was easier to aim because you weren't mashing any keys.
+
Originally, the [[Pistol]] could be fired almost as fast as the human hand could press a key. Scripts were created to simulate this rapid pressing by holding down a single key.
 
 
Valve eventually leveled the playing field. They patched the Pistol to have a lower max firing rate, which was reached by default whenever a player held down the attack key. The Pistol scripts were no longer necessary.
 
 
 
====Targe turn scripts====
 
Originally, the keyboard commands to turn your viewpoint left and right were not treated the same as the mouse commands. The [[Chargin' Targe]] was the first weapon to create a restriction on how quickly you could turn your viewpoint, therefore Valve put a limit on mouse turn-speed, yet forgot to apply the same restriction to the keyboard command that resulted in the same action.
 
  
Players made scripts that rebound keys whenever a player charged, allowing them to turn at full speed. The most sophisticated examples temporarily rebound the mouse x-axis inputs to the keyboard turn commands, then unbound them when the player attacked at the end of the charge.
+
{{Patch name|8|13|2009}}: The Pistol now fires at a fixed rate, not based on the speed at which you press the firing button.
 +
====Chargin' Targe turn scripts====
 +
Originally, the keyboard commands to turn your viewpoint left and right were not treated the same as the mouse commands. The [[Chargin' Targe]] was the first weapon to create a restriction on how quickly you could turn your viewpoint, therefore Valve put a limit on mouse turn-speed, yet forgot to apply the same restriction to the keyboard command that resulted in the same action. Scripts were created to rebind the turning controls when a player charged, circumventing this restriction.
  
Valve eventually capped the keyboard turn commands as they did with the mouse commands, thus conferring no advantage to individuals who used the script.
+
{{Patch name|6|23|2011}}: Fixed an exploit with the Chargin' Targe that allowed greater turning control than intended.
  
However, it is still possible to turn easily while using a gamepad's analog sticks.
+
However, there is still no cap on turn speed when using a gamepad's analog sticks.
  
 
====Air crouching scripts====
 
====Air crouching scripts====
 
Originally, you could crouch as many times as you liked in a single jump. By binding a script to crouch and uncrouch as rapidly as possible, you could exploit the engine and make it difficult to properly register shots on jumping targets.
 
Originally, you could crouch as many times as you liked in a single jump. By binding a script to crouch and uncrouch as rapidly as possible, you could exploit the engine and make it difficult to properly register shots on jumping targets.
  
Valve patched it so you could only crouch twice in a single jump.
+
{{Patch name|3|6|2009}}: You can now duck twice in the air.
  
 
====Gloves of Running Urgently Scripts====
 
====Gloves of Running Urgently Scripts====
Originally, while using the [[Gloves of Running Urgently]], the player constantly lost 6 health per second. However, jumping preserved the speed bonus granted by this weapon while the player was still in the air. Because of this, by jumping with this weapon, and then immediately switching to another weapon, health loss could been minimized with very little negative impact on speed. While a player could manually jump and continually switch weapons, using a script greatly simplifies this technique.
+
The [[Gloves of Running Urgently]] used to drain 6 health per second while active. However, jumping preserved the speed bonus granted by this weapon and did not require the weapon to be active. Simple scripting allowed for the player to quickly switch to the gloves, jump, and then switch away.
  
However, after [[June 27, 2012 Patch]], while using Gloves of Running Urgently, the player doesn't lose 6 health per second, but is marked for death for a short period.
+
{{Patch name|6|27|2012}}: Replaced the damage over time of the Gloves of Running Urgently with a time-delayed [[mini-crit]] de-buff.
  
 
===Current Scripts===
 
===Current Scripts===
Line 534: Line 379:
 
While a human can repeat this feat, it is difficult. Some players made scripts which could reliably execute the commands in the right order at the right speed allowing them to make a Sentry jump while carrying their Sentry every time.
 
While a human can repeat this feat, it is difficult. Some players made scripts which could reliably execute the commands in the right order at the right speed allowing them to make a Sentry jump while carrying their Sentry every time.
  
The new [[Engineer]] primary, the [[Rescue Ranger]], allows Engineers to pick up their Sentry Guns while not next to them. This means that Engineers can pack up their Sentry Guns mid-air, meaning that they no longer need to use this script (provided they have the Rescue Ranger equipped).
+
Note: The [[Rescue Ranger]] can circumvent this necessity, as it can pick up buildings at range for 130 metal.
  
 
====Gunslinger Scripts====
 
====Gunslinger Scripts====
Line 540: Line 385:
  
 
====Sensitivity and Control scripts====
 
====Sensitivity and Control scripts====
Some players prefer different mouse sensitivities and control schemes for some classes. (For example, changing from the Demoman, which doesn't require fine aiming, to the Sniper, which encourages low sensitivity for precise aiming so that a hand twitching inadvertently won't ruin a player's aim too much) These scripts alter control schemes and mouse settings on a per class, or even per weapon, basis.
+
Some players prefer different mouse sensitivities and control schemes for some classes. (For example, changing from the Medic, which doesn't require fine aiming, to the Sniper, which encourages low sensitivity for precise aiming so that a hand twitching inadvertently won't ruin a player's aim too much) These scripts alter control schemes and mouse settings on a per class, or even per weapon, basis.
  
 
====Charge Dash Scripts====
 
====Charge Dash Scripts====
Line 546: Line 391:
  
 
====Quickscope Scripts====
 
====Quickscope Scripts====
Many players find it difficult to scope in and fire straight after to get a quick headshot. There are scripts that will zoom in and fire just by clicking one mouse button. It may be harder to aim for some players because it is required that the player aim outside of the scope, though if this is mastered, a player can become much more effective at quickscoping.
+
Many players find it difficult to scope in and fire straight after to get a quick headshot. There are scripts that will zoom in and fire just by clicking one mouse button. This does require players to aim outside of the scope, though.
  
 
====Rocket Jump Scripts====
 
====Rocket Jump Scripts====
In order to Rocket Jump to a maximum height or distance, it is required that the player jumps, crouches, and fires their rocket at roughly the same time. Some players seem to find this difficult, and so use a simple script to perform this action at the press of a button.
+
In order to Rocket Jump to a maximum height or distance, it is required that the player jumps, crouches, and fires their rocket at roughly the same time. This can be easily scripted to occur with the press of a button.
  
 
==See also==
 
==See also==
 
* [[List of useful console commands]]
 
* [[List of useful console commands]]
* [[Customizing#tf.5Ccfg.5Cconfig default.cfg|Customizing - config_default.cfg]]: The default key-binds within TF2.
+
* [[Customizing#tf.5Ccfg.5Cconfig default.cfg|Default keybinds in TF2]]
  
 
==External links==
 
==External links==
*[http://forums.steampowered.com/forums/showthread.php?t=709568 Steam Users' Forums - TF2 Scripting Tutorial]. This covers the basics of scripting, using numerous useful, approachable examples.
+
*[http://www.gamebanana.com/scripts/games/297 Hundreds of scripting examples on Gamebanana]
*[http://warriornation.net/Forum/showthread.php?t=568008 TF2 scripting tutorial - Warrior Nation Network]. This is a much more advanced article, which requires pre-requisite knowledge of the basic scripting syntax.
 
*[http://www.gamebanana.com/scripts/games/297 Gamebanana.com - TF2 scripts]. Hundreds of scripting examples for TF2.
 
  
 
[[Category:Customization]]
 
[[Category:Customization]]

Revision as of 00:43, 13 May 2013

Scripting is the use of configuration files (.cfg) to create new keybinds and aliases automating complex behaviors and console command sequences. Scripting is built into Team Fortress 2 and is not banned by VAC (Valve Anti Cheat). Uses of scripting vary from simply binding a key to a command to self-referential loops and nested aliases that redefine one another. Any functionality that can be created with scripting can also be accomplished without, however scripting will allow these functionalities to be used even in fast-paced battle.

Dedicated Scripting Files

Team Fortress 2 automatically reads several game files and executes any scripts within them. Here is the list of those files:

  • config.cfg - This is the default configuration file which is edited to reflect any in-game changes to keybinds or video settings. It is safe to edit this file, but it will change to reflect any modified keybinds on startup. This config will run every time the game starts up, before any other config.
    • config_default.cfg - This contains a basic set of keybinds, and will be executed as a backup if config.cfg is not present.
  • autoexec.cfg - This is the default config file for executing custom keybinds and aliases. This config will run every time the game starts up, after config.cfg.
  • Scout.cfg, Soldier.cfg, Pyro.cfg, etc. - Each class has a config file which automatically runs whenever you switch to that class. Note that any settings set in one classes config file will be retained when switching classes unless explicitly rebound.

Scripting Commands

The following is a list of commands which have no use apart from scripting; they do not influence gameplay directly.

Bind

The simplest command is the bind command. It will cause a certain key to execute a certain action, whether that action is a setting, a command, or a script.

bind [KEY] [COMMAND]
Quotes can be optionally placed around the key or the command.

bind [KEY] "[COMMAND 1]; [COMMAND 2]; [COMMAND 3]"
Quotes can be optionally placed around the key, but must be present around the commands.


Commands come in two forms:
bind "e" "Voicemenu 0 0"
This bind will make the player call for a medic when they press E.

bind "w" "+forward"
This bind will make the player move forward while they have W held down.

Toggle

This command allows a setting to be toggled between two or more values.

toggle "sv_cheats 0 1"

Bindtoggle

This works identically to toggle, but binds it to a key.

bindtoggle o "sv_cheats 0 1"

Incrementvar

This allows for variables to be increased or decreased repeatedly by a set amount.

bind MWHEELUP "incrementvar fov_desired 75 90 1"
bind MWHEELDOWN "incrementvar fov_desired 75 90 -1"

This will cause the field of view to increase when scrolling up, and to decrease when scrolling down.
Note: Incrementvar will cause the value to wrap around if it gets too large or too small. In this example, once the field of view hits 90, it will drop down to 75, and vice-versa.

Alias

An alias allows multiple commands to be referenced by a single command. This is effectively shorthand, and it is most useful when a series of commands need to be called multiple times. Note: Alias names cannot contain spaces. They may contain underscores, numbers, and symbols. Alias names are case-sensitive.

alias Call_For_Medic "Voicemenu 0 0"
bind "e" "Call_For_Medic"

This script functions the same with a simple bind, meaning that when the player presses E, they will call for a medic.

Exec

This command will execute another file. This means that complex scripts can be stored in other files, so as not to clutter up more general files.

exec autoexec.cfg
This script will execute the player's autoexec script.

Echo

This command will cause text to be printed to console. This is very useful for debugging.

echo Scripting is; echo very useful.
This will print out Scripting isvery useful. Spaces are only parsed if they are between words, or if the echoed text is between quotes, as in the next example.

echo " Scripting is very useful. "
The extra spaces will be printed out, since the sentence is denoted by quotation marks.

Note: It is not possible to print out the " or ; characters, as their meaning will be misinterpreted.

Wait

This command will make the game wait a given number of frames before executing the next command.
Note: The amount of real time this corresponds to depends on the server's tickrate.
Warning: Wait commands are disabled on certain servers. This will cause certain scripts to fail, and may (in semi-rare cases) cause the game to crash.

echo Why did the chicken cross the road?; wait 66; echo To get to the other side!"
This script will wait 66 frames (1 second on most servers) before printing the punchline.

List of key names

Hover over a key to see its scripting name.

ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12

` 1 2 3 4 5 6 7 8 9 0 - = Delete

Tab ⇆ Q W E R T Y U I O P [ ] \

⇪ Caps A S D F G H J K L ; '   ↵  

⇧ Shift Z X C V B N M , . / ⇧ Shift

Ctrl Alt       Spacebar       ≣ Menu Ctrl

PrtScn ScrLk Pause

Insert Home PgUp

Delete End PgDn


       

   

Num / * -
7 8 9 +
4 5 6
1 2 3
    0     .
Mouse Button Name of Keybind
Scroll Up MWHEELUP
Scroll Down MWHEELDOWN
Left Click MOUSE1
Right Click MOUSE2
Wheel Click MOUSE3
Left Button Click (forward) MOUSE4
Right Button Click (back) MOUSE5

Useful commands

Main article: List of TF2 console commands and variables

Disguising

The disguise command takes two arguments, the first being the class and the second being the team.

Class
1. Scout
2. Sniper
3. Soldier
4. Demoman
5. Medic
6. Heavy
7. Pyro
8. Spy
9. Engineer
Team
1. BLU team
2. RED team
-1. Opposite team
-2. Same team

Thus, disguise 5 1 would disguise as a BLU Medic and disguise 7 -2 would disguise as a friendly Pyro. Note: disguise 8 -2 (Friendly spy) will cause the player to un-disguise.

Buildings

The build command takes two arguments, the first being the building and the second being the building type.
build 0 0 will build a dispenser (Engineer only)
build 1 0 will build a teleporter entrance (Engineer only)
build 1 1 will build a teleporter exit (Engineer only)
build 2 0 will build a sentry (Engineer only)
build 3 0 will build a sapper (Spy only)

Similarly, the destroy command will destroy buildings.
destroy 0 0 will destroy a dispenser (Engineer only)
destroy 1 0 will destroy a teleporter entrance (Engineer only)
destroy 1 1 will destroy a teleporter exit (Engineer only)
destroy 2 0 will destroy a sentry (Engineer only)
Note: Sappers cannot be destroyed.

Voice Menu

The voicemenu command takes two arguments, the menu number and the command number.

  • 0 (voice_menu_0)
    0: MEDIC!
    1: Thanks!
    2: Go! Go! Go!
    3: Move Up!
    4: Go Left
    5: Go Right
    6: Yes
    7: No
  • 1 (voice_menu_1)
    0: Incoming
    1: Spy!
    2: Sentry Ahead!
    3: Teleporter Here
    4: Dispenser Here
    5: Sentry Here
    6: Activate Charge!
    7: MEDIC: ÜberCharge Ready
  • 2 (voice_menu_2)
    0: Help!
    1: Battle Cry
    2: Cheers
    3: Jeers
    4: Positive
    5: Negative
    6: Nice Shot
    7: Good Job

Note: These numbers are one less than as they appear in-game.

Assorted

  • clear will clear the console of any information.
  • fov_desired (75-90) will set your field of view.
  • lastdisguise will cause the player to re-disguise as their last disguise. (Spy only)
  • load_itempreset [0, 1, 2, 3] will load a particular loadout preset [A, B, C, D].
  • say "message" will say a message to public chat.
  • say_team "message" will say a message to your team.
  • +taunt will cause the player to taunt.
  • +use_action_slot_item will cause the player to use their action slot item.
  • volume (0-1) will change the in-game volume.

Advanced Scripting Techniques

Toggles

It is possible to bind a key to toggle a command which would otherwise be a press and hold command.

bind w toggle
alias toggle "enable"
alias enable "alias toggle disable; +forward"
alias disable "alias toggle enable; -forward"

This script will cause a press of W to keep the player moving forward until W is pressed again.

Key combinations

It is possible to create a script where pressing one button while another is held down will change the action of the first button.

bind e call
alias call Call_For_Medic
alias Call_For_Medic "Voicemenu 0 0"
alias Call_For_Ubercharge "Voicemenu 1 6"

At this point, the script will mean that every time E is pressed, the player will call for a Medic. It also has an unused alias to call for an Ubercharge.
bind shift +toggleState
alias +toggleState "alias call Call_For_Ubercharge"
alias -toggleState "alias call Call_For_Medic

Now, pressing ⇧ Shift will redirect call to ask for an ubercharge. Releasing ⇧ Shift will make call point back at a medic call.
When ⇧ Shift+E is pressed, the player will call for an Ubercharge, rather than for a Medic.

Wait-testing

Since the wait command is integral to some scripts, it may be necessary to test to see if a server has disabled the command.

alias waitTester "alias waitTest waitPositive; wait; waitTest"
alias wait "alias waitTest waitNegative"
alias waitPositive "echo Wait is enabled on this server.; exec waitPositive.cfg"
alias waitNegative "echo Wait is DISABLED on this server!; exec waitNegative.cfg"
waitTester

This script relies on the fact that if the wait command is disabled on a server, the alias named wait can be defined by the user. Thus, the script creates an alias named waitTest which by default points to waitPositive, but if wait is not allowed (and can thus be defined by the user), will be redirected to waitNegative.

Loops

Warning: Loops which run without a wait command will cause the TF2 client to hang. It is highly suggested to run a script only after a wait testing script.
It is generally considered bad form to have one alias point to itself, as this loop cannot be broken out of and the reset. Therefore, looping scripts tend to include two parts to the loop: The part that waits, and the part that loops.

alias loop "+taunt; wait 132; redirect"
alias redirect loop
bind g "redirect"
bind o "alias redirect break"
alias break "alias redirect loop"

This script will start looping once G is pressed. It will then taunt every 132 frames (2 seconds on most servers). Pressing O would cause the next iteration of the loop to break out. The break alias will then reset the loop, so that next time it is called it will loop again.

Noteworthy scripts

There are several notable scripts that have affected gameplay. Some of these are patched out, while others remain functional.

Patched scripts

Pistol scripts

Originally, the Pistol could be fired almost as fast as the human hand could press a key. Scripts were created to simulate this rapid pressing by holding down a single key.

August 13, 2009 Patch: The Pistol now fires at a fixed rate, not based on the speed at which you press the firing button.

Chargin' Targe turn scripts

Originally, the keyboard commands to turn your viewpoint left and right were not treated the same as the mouse commands. The Chargin' Targe was the first weapon to create a restriction on how quickly you could turn your viewpoint, therefore Valve put a limit on mouse turn-speed, yet forgot to apply the same restriction to the keyboard command that resulted in the same action. Scripts were created to rebind the turning controls when a player charged, circumventing this restriction.

June 23, 2011 Patch: Fixed an exploit with the Chargin' Targe that allowed greater turning control than intended.

However, there is still no cap on turn speed when using a gamepad's analog sticks.

Air crouching scripts

Originally, you could crouch as many times as you liked in a single jump. By binding a script to crouch and uncrouch as rapidly as possible, you could exploit the engine and make it difficult to properly register shots on jumping targets.

March 6, 2009 Patch: You can now duck twice in the air.

Gloves of Running Urgently Scripts

The Gloves of Running Urgently used to drain 6 health per second while active. However, jumping preserved the speed bonus granted by this weapon and did not require the weapon to be active. Simple scripting allowed for the player to quickly switch to the gloves, jump, and then switch away.

June 27, 2012 Patch: Replaced the damage over time of the Gloves of Running Urgently with a time-delayed mini-crit de-buff.

Current Scripts

Weapon Hiding Scripts

There are a large number of scripts which toggle the weapon display option depending on which weapon slot is selected for a class. Players often make their guns invisible to clear up the screen, but make items like melee weapons, PDAs, watches, and so forth visible because these models indicate important information. For example, the Spy relies heavily on his visible model to determine when he is cloaked, when his cloak is disturbed, and when the Dead Ringer activates. Other classes use the melee animations to judge when their attacks will hit.

Sentry Jumping Scripts

Since the Engineer Update, Engineers have been able to pack up and carry their Sentry Guns. Simultaneously introduced in the update, the Wrangler allows Engineers to Sentry jump with their Sentry rockets. With extremely fast inputs, it was discovered that a player could Sentry jump and successfully pack up their Sentry before they were launched away.

While a human can repeat this feat, it is difficult. Some players made scripts which could reliably execute the commands in the right order at the right speed allowing them to make a Sentry jump while carrying their Sentry every time.

Note: The Rescue Ranger can circumvent this necessity, as it can pick up buildings at range for 130 metal.

Gunslinger Scripts

Since it can be troublesome to destroy then rebuild a Combat Mini-Sentry in the heat of battle through the PDA, some players have scripted the destruction and rebuilding of their Combat Mini-Sentry with the click of one or two mouse buttons. Such a script is especially useful when using the Frontier Justice, as the player gains practically instant access to revenge crits when needed.

Sensitivity and Control scripts

Some players prefer different mouse sensitivities and control schemes for some classes. (For example, changing from the Medic, which doesn't require fine aiming, to the Sniper, which encourages low sensitivity for precise aiming so that a hand twitching inadvertently won't ruin a player's aim too much) These scripts alter control schemes and mouse settings on a per class, or even per weapon, basis.

Charge Dash Scripts

Since timing a charge and jump can be difficult, some players may use a quick script that binds the two actions to a button so that the charge dash will cover the maximum amount of distance possible. The player is still required to swing their melee weapon normally to end the charge though.

Quickscope Scripts

Many players find it difficult to scope in and fire straight after to get a quick headshot. There are scripts that will zoom in and fire just by clicking one mouse button. This does require players to aim outside of the scope, though.

Rocket Jump Scripts

In order to Rocket Jump to a maximum height or distance, it is required that the player jumps, crouches, and fires their rocket at roughly the same time. This can be easily scripted to occur with the press of a button.

See also

External links