Difference between revisions of "Scripting"

From Team Fortress Wiki
Jump to: navigation, search
m (Not favored, as far as I can tell. Code works the same from both places.)
m
 
(248 intermediate revisions by 86 users not shown)
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). 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.
+
{{Quotation|'''The Engineer''' after using his [[sentry jump]] script|This thing ain't on auto-pilot, son!|sound=Engineer wranglekills01.wav}}
 +
'''Scripting''' is the use of configuration files ({{code|.cfg}}) typically used to create new keybinds and aliases, change advanced graphical settings, automating complex behaviors, and creating sequences of [[console]] commands. Unlike [[hacking]], scripting is an intentional feature natively built into ''Team Fortress 2'', and will not trigger a VAC ([[Valve Anti-Cheat]]) ban. The complexity of scripting varies from simply binding an input key to output a command, to self-referential loops and nested aliases that redefine one another. There are many graphical settings that can only be changed through the use of console commands, or scripts that automate the input of said console commands. Outside of specific graphical settings, most other functions that can be performed via scripting may also be achieved without it, but scripting grants the advantage of allowing these functionalities to be instantly executed within the heat of battle.  
  
==Dedicated Scripting Files==
+
== Scripting Commands ==
''Team Fortress 2'' automatically reads several game files and executes any scripts within them. Here is the list of those files:
+
The following is a list of commands which have no use apart from scripting; they do not influence gameplay directly.
  
* 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.
+
=== bind ===
** config_default.cfg - This contains a basic set of keybinds, and will be executed as a backup if config.cfg is not present.
+
{{Main|vdc:bind|l1=bind}}
* 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.
+
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.
* {{botignore|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.
 
  
==Editing Scripting Files==
+
<pre>bind [KEY] [COMMAND]</pre>
If on Windows, scripting files may be found in:<br/>
+
Quotes can be optionally placed around the key and/or the command. However, the commands will need to have quotes when it has spaces in between the values and the command, so that the console can interpret it as one command. An example would be bind mouse1 "say texthere", where quotes are needed around "say texthere" because of the space between the two phrases.
<code><Steam Folder>/SteamApps/common/team fortress 2/tf/cfg</code><br/>
 
If on a Mac, scripting files may be found in:<br/>
 
<code>~/Library/Application Support/Steam/SteamApps/common/team fortress 2/tf/cfg</code><br/>
 
Since the SteamPipe update, code can also be placed in
 
<code>.../SteamApps/common/team fortress 2/tf/custom/yourfoldernamehere/cfg</code>
 
  
==Scripting Commands==
+
<pre>bind [KEY] "[COMMAND 1];[COMMAND 2];[COMMAND 3]"</pre>
The following is a list of commands which have no use apart from scripting; they do not influence gameplay directly.
+
Quotes can be optionally placed around the key, but must be present around the commands, as the console will not interpret consecutive commands if quotes are not present.
===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.
+
''Note:'' The command <code>say "Example Text"</code> is correct, but <code>bind <KEY> "say "Example Text""</code> is not. This is because the quotes are misinterpreted, and quotes inside of quotes are unnecessary due to commands automatically stopping at every semicolon.
  
<code>bind [KEY] [COMMAND]</code><br />
+
When a key is bound to a string starting with a plus, the same command(s) will be executed when the key is released, except the first plus will be replaced with a minus. For example, <code>bind w +forward</code> will make pressing {{key|W}} execute <code>+forward</code> and releasing {{key|W}} execute <code>-forward</code>. Note that this only effects the first command, and other commands will not be negated. See [[#alias|alias]] for more information.
Quotes can be optionally placed around the key or the command.<br />
+
This bind will make the player move forward while they have {{key|W}} held down.
  
<code>bind [KEY] "[COMMAND 1]; [COMMAND 2]; [COMMAND 3]"</code><br />
+
=== toggle ===
Quotes can be optionally placed around the key, but must be present around the commands.
+
This command allows a cvar to be toggled between two or more values. If no values are specified, defaults to toggling between 0 and 1.
  
 +
<pre>toggle tf_bot_quota normal fill match</pre>
  
Commands come in two forms:<br />
+
==== bindToggle ====
<code>bind "e" "Voicemenu 0 0"</code><br />
+
BindToggle may be used to bind a key to toggle a cvar between 0 and 1. It cannot be used for values besides 0 and 1.
This bind will make the player call for a Medic when they press {{key|E}}.
 
  
<code>bind "w" "+forward"</code><br />
+
<pre>bindToggle o sv_cheats</pre>
This bind will make the player move forward while they have {{key|W}} held down.
 
  
===Toggle===
+
=== incrementvar ===
This command allows a setting to be toggled between two or more values.
+
This allows for variables to be increased or decreased repeatedly by a set amount.
  
<code>toggle "sv_cheats 0 1"</code>
+
<pre>bind MWHEELUP "incrementvar fov_desired 75 90 1"
 +
bind MWHEELDOWN "incrementvar fov_desired 75 90 -1"</pre>
 +
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.
  
===Bindtoggle===
+
=== alias ===
This works identically to toggle, but binds it to a key.
+
{{Main|vdc:alias|l1=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. Alias names cannot contain spaces. They may contain underscores, numbers, symbols, and are not case-sensitive (only when being created, when removing an alias it is case-sensitive). Aliases may not overwrite existing commands or variables except those that start with a plus or minus (for example, <code>alias help</code> is disallowed,  but <code>alias +forward</code> is allowed).
  
<code>bindtoggle o "sv_cheats 0 1"</code>
+
After running the command <code>alias foo "echo bar"</code>, typing <code>foo</code> in the console will execute <code>echo bar</code>.
 +
After running the command <code>alias foo</code>, typing <code>foo</code> in the console will no longer do anything. If the alias was created with uppercase letters (such as <code>alias fOO "echo bar"</code>), typing <code>alias foo</code> will not remove the alias, but <code>alias fOO</code> will.
  
===Incrementvar===
+
Aliases may begin with a plus or minus character. This allows them to be used in conjunction with <code>bind</code> to negate several commands when a key is released. For example, this script allows a player to move diagonally with a single key:
This allows for variables to be increased or decreased repeatedly by a set amount.
 
  
<code>bind MWHEELUP "incrementvar fov_desired 75 90 1"<br />
+
<pre>alias +diagonal "+moveleft; +back"
bind MWHEELDOWN "incrementvar fov_desired 75 90 -1"</code><br />
+
alias -diagonal "-moveleft; -back"
This will cause the [[field of view]] to increase when scrolling up, and to decrease when scrolling down.<br />
+
bind z "+diagonal"</pre>
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===
+
Releasing Z will execute <code>-diagonal</code> in this script, whereas simply typing <code>bind "z" "+moveleft; +back"</code> would result in the game never running <code>-back</code> when the player releases the key. This results in the player moving backwards continuously.
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 />
 
  
<code>alias Call_For_Medic "Voicemenu 0 0"<br />
+
=== exec ===
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.
 
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.
  
<code>exec autoexec.cfg</code><br />
+
<code>exec highquality</code>
This script will execute the player's autoexec script.
+
This script will execute the config named {{code|highquality.cfg}} script within the {{code|tf/cfg}} folder.
===Echo===
+
 
This command will cause text to be printed to console. This is very useful for debugging.
+
=== echo ===
 +
This command will cause text to be printed to the console. This is very useful for debugging.
 +
 
 +
<pre>echo Scripting is; echo very useful</pre>
 +
This will print out <code>Scripting is</code> and <code>very useful</code> on ''two separate lines''. This is because a newline is added to the end of any text passed to <code>echo</code>. Spaces are only parsed if they are between words, or if the echoed text is between quotes, as in the next example:
 +
 
 +
<pre>echo " Scripting is very useful.  "</pre>
 +
The extra spaces will be printed out, since the string is delimited by quotation marks.
 +
:''Note:'' It is not possible to print out the " character, as its meaning will be misinterpreted. However, you can print single quotes: that is, the ' character.
 +
:''Note:'' Echo occasionally will misprint strings that are not delimited by quotation marks. As a general rule of thumb, it is better to enclose what you wish to print within quotation marks. It also makes it easier to read for humans.
 +
 
 +
=== wait ===
 +
This command will make the game wait a given number of frames before executing the next command.
 +
:'''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. See [[#Wait-testing|Wait Testing]] for help to protect against this.'''
 +
 
 +
<pre>echo Why did the chicken cross the road?;wait 300;echo To get to the other side!</pre>
 +
This script will wait 300 frames (1 second at the default max FPS) before printing the punchline.
 +
 
 +
== Class-specific CFG Files ==
 +
When switching to a certain class, the game executes the corresponding CFG file (if it exists), named after the given class.
 +
<pre>
 +
scout.cfg
 +
soldier.cfg
 +
pyro.cfg
 +
demoman.cfg
 +
heavyweapons.cfg
 +
engineer.cfg
 +
medic.cfg
 +
sniper.cfg
 +
spy.cfg
 +
</pre>
 +
 
 +
This automation lets the player have different keybinds and game settings for each class.
 +
 
 +
=== VPK files and config files ===
 +
[[vdc:VPK|.vpk]] files take priority over config files located within the {{code|cfg}} folder. Mods using {{code|.vpk}} files may run the risk of negatively interfering with any custom configuration changes, however, some mods provide methods to override the configs from within the .vpk files natively.
 +
 
 +
== Launch Options ==
 +
Launch options can be used to change how TF2 runs, both in terms of performance and functionality. Please see {{vdc|Command Line Options|Command Line Options}} for a comprehensive list of launch options.
 +
 
 +
=== Set Launch Options ===
 +
[[File:Setting Launch Options.png|thumb|none|A visual guide on how to set launch options (indicated by the pink circles).]]
 +
# Right-click on the game title under the '''Library''' in Steam and select '''Properties'''.
 +
# Under the '''General''' tab click the '''Set launch options...''' button.
 +
# Enter the launch options you wish to apply (be sure to separate each code with a space) and click '''OK'''.
 +
# Close the game's '''Properties''' window and launch the game.
 +
 
 +
=== Window Options===
 +
Note that these may incorrectly setup an improper video mode not preferred by the material system, reducing performance. Where possible, you should use the in-game settings instead.
 +
====Resolution====
 +
Launch Option: '''-w # -h #'''
 +
:''Description:'' Forces the game resolution width and height in pixels.
 +
====Refresh Rate====
 +
Launch Option: '''-freq #'''
 +
:''Description:'' Forces the game refresh rate in Hz.
 +
====Windowed Mode====
 +
Launch Option: '''-windowed'''
 +
:''Description:'' Launches the game in windowed mode.
 +
====Borderless Windowed Mode====
 +
Launch Option: '''-noborder'''
 +
:''Description:'' When in windowed mode, remove the window border to allow for borderless fullscreen mode, as opposed to exclusive fullscreen mode.
 +
====Fullscreen Mode====
 +
Launch Option: '''-fullscreen'''
 +
:''Description:'' Forces the game to be in fullscreen mode.
 +
 
 +
===Peripheral Support===
 +
====Disable Joystick Support====
 +
Launch Option: '''-nojoy'''
 +
:''Description:'' Prevents the joystick system from loading, improving start-up time and memory usage. Don't use this if you intend to use a joystick with the game.
 +
====Disable Steam Controller Support====
 +
Launch Option: '''-nosteamcontroller'''
 +
:''Description:'' Prevents the Steam controller system from loading, improving start-up time and memory usage. Don't use this if you intend to use a Steam controller with the game.
 +
 
 +
===Software Support===
 +
====Disable SourceTV====
 +
Launch Option: '''-nohltv'''
 +
:''Description:'' Disables [[SourceTV]] support, improving memory usage. Don't use this if you host SourceTV on your client.
 +
 
 +
===Engine Options===
 +
====Disable Intro Video====
 +
Launch Option: '''-novid'''
 +
:''Description:'' Removes the Valve intro video shown when the game is started, improving loading times.
 +
 
 +
====Change Beam Particle Limit====
 +
Launch Option: '''-particles #'''
 +
:''Description:'' Limits the number of beam particles. Set # to '1' to (a limit of 512) to improve memory usage.
 +
 
 +
====Precache Font Rendering====
 +
Launch Option: '''-precachefontchars'''
 +
:''Description:'' Precaches font rendering for common characters, improving rendering time.
  
<code>echo Scripting is; echo very useful.</code><br />
+
====Disable Texture Streaming====
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.
+
Launch Option: '''-no_texture_stream'''
 +
:''Description:'' Disables using lower quality textures whilst higher quality versions load, instead favoring to always instantly load the higher quality versions. Disabling texture streaming results in a performance boost on systems running GPUs with low VRAM (video memory).
  
<code>echo " Scripting is very useful.   "</code><br />
+
===DirectX Version (Windows exclusive)===
The extra spaces will be printed out, since the sentence is denoted by quotation marks.
+
Launch Option: '''-dxlevel #'''
 +
:''Description:'' Sets the DirectX Version used by the game; accepts many values ranging from 80 to 100. The manual setting of DirectX levels is experimental and is typically altered to support older hardware.  
 +
::'-dxlevel 100' uses DirectX 9. Hardware is automatically detected to determine the system's graphical capabilities.
 +
::'-dxlevel 81' is the most stable version of DirectX for GPUs released prior to 2004. DirectX 8 has a reduced feature set such as a lack of [[War Paint]]s and transparency on models (such as the [[Voodoo-Cursed Soul]]s). Values below 81 will cause even more graphical issues. This should be avoided unless necessary for compatibility reasons.
 +
:Note: After launching the game with the -dxlevel command once, the game should then be closed, and then the launch option removed entirely before launching the game again.
  
Note: It is not possible to print out the " or ; characters, as their meaning will be misinterpreted.
+
===Vulkan (Windows exclusive)===
===Wait===
+
Launch Option: '''-vulkan'''
This command will make the game wait a given number of frames before executing the next command.<br />
+
:''Description:'' Enables [[w:Vulkan|Vulkan]] rather than DirectX. Vulkan is enabled by default on Linux systems.
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.'''
 
  
<code>echo Why did the chicken cross the road?; wait 66; echo To get to the other side!"</code><br />
+
===Execute Other Scripts on Startup===
This script will wait 66 frames (1 second on most servers) before printing the punchline.
+
Launch Option: '''+exec script.cfg'''
 +
:''Description:'' Executes the specified script when the game launches.
 +
{{Note|Note: A config named {{code|autoexec.cfg}} is automatically executed on startup.}}
  
==List of key names==
+
== List of key names ==
Hover over a key to see its scripting name.
+
Hover over a key to see its scripting name. Names are not case-sensitive.
<code>
 
 
{|
 
{|
! width="45%" <!-- Main keyboard -->|
+
! width="45%" <!-- Main Keyboard -->|
! width="4%" <!-- Spacing -->|
+
! width="03%" <!-- Spacing       -->|
! width="20%" <!-- Special keys -->|
+
! width="25%" <!-- Special Keys  -->|
! width="1%" <!-- Spacing -->|
+
! width="01%" <!-- Spacing       -->|
! width="25%" <!-- Keypad 1 -->|
+
! width="25%" <!-- Keypad 1     -->|
! width="5%" <!-- Keypad 2 -->|
+
! width="05%" <!-- Keypad 2     -->|
 
|-
 
|-
 
|
 
|
Line 110: Line 195:
 
{{tooltip|{{key|F12}}|F12}}
 
{{tooltip|{{key|F12}}|F12}}
  
{{tooltip|{{key|`}}|`}}
+
{{tooltip|{{key|` &nbsp;}}|`}}
 
{{tooltip|{{key|1}}|1}}
 
{{tooltip|{{key|1}}|1}}
 
{{tooltip|{{key|2}}|2}}
 
{{tooltip|{{key|2}}|2}}
Line 123: Line 208:
 
{{tooltip|{{key|-}}|-}}
 
{{tooltip|{{key|-}}|-}}
 
{{tooltip|{{key|{{=}}}}|{{=}}}}
 
{{tooltip|{{key|{{=}}}}|{{=}}}}
{{tooltip|{{key|Delete}}|BACKSPACE}}
+
{{tooltip|{{key|← Backspace}}|BACKSPACE}}
  
 
{{tooltip|{{key|TAB}}|TAB}}
 
{{tooltip|{{key|TAB}}|TAB}}
Line 138: Line 223:
 
{{tooltip|{{key|[}}|[}}
 
{{tooltip|{{key|[}}|[}}
 
{{tooltip|{{key|]}}|]}}
 
{{tooltip|{{key|]}}|]}}
{{tooltip|{{key|\}}|\}}
+
{{tooltip|{{key|\ &nbsp; &nbsp; &nbsp;}}|\}}
  
 
{{tooltip|{{key|⇪ Caps}}|CAPSLOCK}}  
 
{{tooltip|{{key|⇪ Caps}}|CAPSLOCK}}  
Line 151: Line 236:
 
{{tooltip|{{key|L}}|L}}
 
{{tooltip|{{key|L}}|L}}
 
{{tooltip|{{key|;}}|SEMICOLON}}
 
{{tooltip|{{key|;}}|SEMICOLON}}
{{tooltip|{{key|'}}|'}}
+
{{tooltip|{{key|' &nbsp;}}|'}}
{{tooltip|{{key|&nbsp; &nbsp; }}|ENTER}}
+
{{tooltip|{{key|Enter ↵}}|ENTER}}
  
{{tooltip|{{key|Shift}}|SHIFT}}
+
{{tooltip|{{key|Shift &nbsp; &nbsp;}}|SHIFT}}
 
{{tooltip|{{key|Z}}|Z}}
 
{{tooltip|{{key|Z}}|Z}}
 
{{tooltip|{{key|X}}|X}}
 
{{tooltip|{{key|X}}|X}}
Line 162: Line 247:
 
{{tooltip|{{key|N}}|N}}
 
{{tooltip|{{key|N}}|N}}
 
{{tooltip|{{key|M}}|M}}
 
{{tooltip|{{key|M}}|M}}
{{tooltip|{{key|,}}|,}}
+
{{tooltip|{{key|, &nbsp;}}|,}}
{{tooltip|{{key|.}}|.}}
+
{{tooltip|{{key|. &nbsp;}}|.}}
{{tooltip|{{key|/}}|/}}
+
{{tooltip|{{key|/ &nbsp;}}|/}}
{{tooltip|{{key|Shift}}|RSHIFT}}
+
{{tooltip|{{key|Shift &nbsp; &nbsp; &nbsp; &nbsp;}}|RSHIFT}}
  
{{tooltip|{{key|Ctrl}}|CTRL}}
+
{{tooltip|{{key|Ctrl &nbsp;}}|CTRL}}
 
{{tooltip|{{key|⊞}}|LWIN}}
 
{{tooltip|{{key|⊞}}|LWIN}}
 
{{tooltip|{{key|Alt}}|ALT}}
 
{{tooltip|{{key|Alt}}|ALT}}
{{tooltip|{{key| &nbsp; &nbsp; &nbsp; Spacebar &nbsp; &nbsp; &nbsp; }}|SPACE}}
+
{{tooltip|{{key|&nbsp; &nbsp; &nbsp; Spacebar &nbsp; &nbsp; &nbsp;}}|SPACE}}
 
{{tooltip|{{key|⊞}}|RWIN}}
 
{{tooltip|{{key|⊞}}|RWIN}}
 +
{{tooltip|{{key|Alt}}|RALT}}
 
{{tooltip|{{key|Menu}}|Cannot be bound}}
 
{{tooltip|{{key|Menu}}|Cannot be bound}}
{{tooltip|{{key|Ctrl}}|RCTRL}}
+
{{tooltip|{{key|Ctrl &nbsp; &nbsp;}}|RCTRL}}
  
 
|<!-- Spacing -->
 
|<!-- Spacing -->
 
|
 
|
 
{{tooltip|{{key|PrtScn}}|Cannot be bound}}
 
{{tooltip|{{key|PrtScn}}|Cannot be bound}}
{{tooltip|{{key|ScrLk}}|SCROLLOCK}}
+
{{tooltip|{{key|ScrLk}}|SCROLLLOCK}}
{{tooltip|{{key|Pause}}|NUMLOCK}}
+
{{tooltip|{{key|Pause}}|PAUSE}}
  
{{tooltip|{{key|Insert}}|INS}}
+
{{tooltip|{{key|Insert &nbsp;}}|INS}}
 
{{tooltip|{{key|Home}}|HOME}}
 
{{tooltip|{{key|Home}}|HOME}}
 
{{tooltip|{{key|PgUp}}|PGUP}}
 
{{tooltip|{{key|PgUp}}|PGUP}}
  
 
{{tooltip|{{key|Delete}}|DEL}}
 
{{tooltip|{{key|Delete}}|DEL}}
{{tooltip|{{key|End}}|END}}
+
{{tooltip|{{key|&nbsp; End &nbsp;}}|END}}
 
{{tooltip|{{key|PgDn}}|PGDN}}
 
{{tooltip|{{key|PgDn}}|PGDN}}
  
  
&nbsp; &nbsp; &nbsp; &nbsp; {{tooltip|{{key|&uarr;}}|UPARROW}}
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{tooltip|{{key|&uarr;}}|UPARROW}}
  
&nbsp; &nbsp; {{tooltip|{{key|&larr;}}|LEFTARROW}}
+
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{tooltip|{{key|&larr;}}|LEFTARROW}}
 
{{tooltip|{{key|&darr;}}|DOWNARROW}}
 
{{tooltip|{{key|&darr;}}|DOWNARROW}}
 
{{tooltip|{{key|&rarr;}}|RIGHTARROW}}
 
{{tooltip|{{key|&rarr;}}|RIGHTARROW}}
Line 227: Line 313:
 
|}
 
|}
  
</code>
+
== Useful commands ==
 
+
{{Main|vdc:List of TF2 console commands and variables|l1=List of TF2 console commands and variables}}
==Useful commands==
 
{{Main|vdc:List_of_TF2_console_commands_and_variables|l1=List of TF2 console commands and variables}}
 
  
 
===Disguising===
 
===Disguising===
Line 252: Line 336:
  
 
Thus, <code>disguise 5 1</code> would disguise as a BLU Medic and <code>disguise 7 -2</code> would disguise as a friendly Pyro.
 
Thus, <code>disguise 5 1</code> would disguise as a BLU Medic and <code>disguise 7 -2</code> would disguise as a friendly Pyro.
Note: <code>disguise 8 -2</code> (Friendly Spy) will cause the player to un-disguise.
+
:''Note:'' <code>disguise 8 -2</code> (Friendly Spy) will cause the player to un-disguise.
 +
:''Note:'' Any collection of characters and/or numbers after the class number that are not 1, 2, -1, or -2 will default the disguise to RED team, regardless of the player's current team. For example, <code>disguise 1 3</code> will disguise the Spy as a RED Scout.
  
===Buildings===
+
=== Buildings ===
The <code>build</code> command takes two arguments, the first being the building and the second being the building type.
+
The <code>build</code> and <code>destroy</code> commands each take two arguments, the first being the building and the second being the building type. The second argument is only required if it is not <code>0</code>, and is currently only used to differentiate between teleporter entrances and exits.
<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>
+
The <code>build</code> command will pull up the blueprint to place a building, with an exception of the Sapper, which is wielded.
<br /><code>build 1 1</code> will build a teleporter exit <small>(Engineer only)</small>
+
:<code>build 0 0</code> will build a [[Dispenser]] <small>(Engineer only)</small>
<br /><code>build 2 0</code> will build a [[Sentry Gun]] <small>(Engineer only)</small>
+
:<code>build 1 0</code> will build a [[teleporter entrance]] <small>(Engineer only)</small>
<br /><code>build 3 0</code> will build a [[Sapper]] <small>(Spy only)</small>
+
:<code>build 1 1</code> will build a [[teleporter exit]] <small>(Engineer only)</small>
 +
:<code>build 2 0</code> will build a [[Sentry Gun]] <small>(Engineer only)</small>
 +
:<code>build 3 0</code> will build a [[Sapper]] <small>(Spy only)</small>
  
 
Similarly, the <code>destroy</code> command will destroy buildings.
 
Similarly, the <code>destroy</code> command will destroy buildings.
<br /><code>destroy 0 0</code> will destroy a [[Dispenser]] <small>(Engineer only)</small>
+
:<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>
+
:<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>
+
:<code>destroy 1 1</code> will destroy a teleporter exit <small>(Engineer only)</small>
<br /><code>destroy 2 0</code> will destroy a [[Sentry Gun]] <small>(Engineer only)</small>
+
:<code>destroy 2 0</code> will destroy a Sentry Gun <small>(Engineer only)</small>
<br />Note: Sappers cannot be destroyed.
+
:''Note:'' Sappers cannot be destroyed.
  
===Voice Menu===
+
It is possible to use the old <code>build</code> commands, which used only one argument.
The <code>voicemenu</code> command takes two arguments, the menu number and the command number.
+
:<code>build 0</code> will build a Dispenser <small>(Engineer only)</small>
*0 (<code>voice_menu_1</code>)
+
:<code>build 1</code> will build a teleporter entrance <small>(Engineer only)</small>
 +
:<code>build 2</code> will build a Sentry Gun <small>(Engineer only)</small>
 +
:<code>build 3</code> will build a teleporter exit <small>(Engineer only)</small>
 +
:<code>build 3</code> will build a Sapper <small>(Spy only) [deprecated]</small>
 +
 
 +
=== Voice Menu ===
 +
The <code>voicemenu</code> command takes two arguments, the menu number and the command number.  
 +
*<code>voicemenu 0</code>
 
*:0: {{botignore|MEDIC!}}
 
*:0: {{botignore|MEDIC!}}
 
*:1: Thanks!
 
*:1: Thanks!
Line 280: Line 374:
 
*:6: Yes
 
*:6: Yes
 
*:7: No
 
*:7: No
*1 (<code>voice_menu_2</code>)
+
*:8: Pass To Me!
 +
*<code>voicemenu 1</code>
 
*:0: Incoming
 
*:0: Incoming
 
*:1: Spy!
 
*:1: Spy!
Line 289: Line 384:
 
*:6: Activate Charge!
 
*:6: Activate Charge!
 
*:7: {{botignore|MEDIC: ÜberCharge Ready}}
 
*:7: {{botignore|MEDIC: ÜberCharge Ready}}
*2 (<code>voice_menu_3</code>)
+
*:8: Pass To Me!
 +
*<code>voicemenu 2</code>
 
*:0: Help!
 
*:0: Help!
 
*:1: Battle Cry
 
*:1: Battle Cry
Line 299: Line 395:
 
*:7: Good Job
 
*:7: Good Job
  
Note: These numbers are one less than as they appear in-game.
+
:''Note'': If you wish to display the voicemenu, rather than fire the <code>voicemenu <num> <num></code> message, the command is <code>voice_menu_<num></code>: where <num> is a number between 1 and 3, and takes no arguments. For instance, to display the first voicemenu, one would run the command <code>voice_menu_1</code>.
  
===Assorted===
+
=== Eureka Teleport ===
 +
The <code>eureka_teleport</code> can teleport an Engineer holding the [[Eureka Effect]] to their spawn or teleporter exit.
 +
*<code>eureka_teleport 0</code> will teleport the player to their spawn
 +
*<code>eureka_teleport 1</code> will teleport the player to their [[teleporter exit]]
 +
 
 +
=== Assorted ===
 
*<code>clear</code> will clear the console of any information.
 
*<code>clear</code> will clear the console of any information.
*<code>fov_desired (75-90)</code> will set your [[field of view]].
+
*<code>alias</code> will list all currently defined aliases.
 +
*<code>fov_desired (20-90)</code> will set the [[field of view]].
 +
*<code>viewmodel_fov </code> will set the FOV for weapon models. It ranges by default from 54 to 70.
 +
*<code>r_drawviewmodel (0/1)</code> will show (1) or hide (0) weapon models.
 
*<code>lastdisguise</code> will cause the player to re-disguise as their last disguise. <small>(Spy only)</small>
 
*<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>load_itempreset (0-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 message</code> will send a message to [[Text chat|public chat]].
*<code>say_team "message"</code> will say a message to your team.
+
*<code>say_team message</code> will send a message to team chat.
*<code>+taunt</code> will cause the player to taunt.
+
*<code>say_party message</code> will send a message to party chat.
 +
*<code>+taunt</code> will open the player's taunt loadout.
 
*<code>+use_action_slot_item</code> will cause the player to use their action slot item.
 
*<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.
 
*<code>volume (0-1)</code> will change the in-game volume.
 +
*<code>taunt_by_name (name)</code> will run a specified taunt, given the exact name of a taunt in the player's current taunt loadout, without opening the taunt menu.
 +
*<code>key_findbinding (string)</code> will list all keys bound to a string containing the given substring (case-sensitive).
 +
*<code>key_listboundkeys</code> will list all keys currently bound and their associated commands.
  
==Advanced Scripting Techniques==
+
== Advanced Scripting Techniques ==
===Toggles===
+
=== Toggles ===
 
It is possible to bind a key to toggle a command which would otherwise be a press and hold command.
 
It is possible to bind a key to toggle a command which would otherwise be a press and hold command.
  
<code>bind w toggle<br />
+
<pre>bind w toggle_movement
alias toggle "enable"<br />
+
alias toggle_movement enable_movement
alias enable "alias toggle disable; +forward"<br />
+
alias enable_movement "alias toggle_movement disable_movement;+forward"
alias disable "alias toggle enable; -forward"</code><br />
+
alias disable_movement "alias toggle_movement enable_movement;-forward"</pre>
 
This script will cause a press of {{key|W}} to keep the player moving forward until {{key|W}} is pressed again.
 
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.
 
  
<code>bind e call<br />
+
=== Key combinations ===
alias call Call_For_Medic<br />
+
It is possible to create a script where holding down a key changes the action of another key. For example, the following script can be used to make {{key|Alt}}+{{key|F4}} exit the game:
alias Call_For_Medic "Voicemenu 0 0"<br />
+
 
alias Call_For_Ubercharge "Voicemenu 1 6"</code><br />
+
<pre>
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 />
+
alias +alt_pressed  bind f4 exit
<code>bind shift +toggleState<br />
+
alias -alt_pressed unbind f4
alias +toggleState "alias call Call_For_Ubercharge"<br />
+
 
alias -toggleState "alias call Call_For_Medic</code><br />
+
bind alt +alt_pressed
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 />
+
</pre>
When {{Key|Shift|E}} is pressed, the player will call for an Ubercharge, rather than for a Medic.
+
Note that pressing Alt will execute <code>+alt_pressed</code>, and releasing it will execute <code>-alt_pressed</code>.
  
===Wait-testing===
+
=== Wait-testing ===
 
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.
 
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.
  
<code>alias waitTester "alias waitTest waitPositive; wait; waitTest"<br />
+
<pre>alias waitTester "alias waitTest waitPositive; wait 0; waitTest"
alias wait "alias waitTest waitNegative"<br />
+
alias wait "alias waitTest waitNegative"
alias waitPositive "echo Wait is enabled on this server.; exec waitPositive.cfg"<br />
+
alias waitPositive "echo Wait is enabled on this server.; exec waitPositive.cfg"
alias waitNegative "echo Wait is DISABLED on this server!; exec waitNegative.cfg"<br />
+
alias waitNegative "echo Wait is DISABLED on this server!; exec waitNegative.cfg"
waitTester</code><br />
+
waitTester</pre>
 
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>.
 
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.
 
  
<code>alias loop "+taunt; wait 132; redirect"<br />
+
=== Loops ===
alias redirect loop<br />
+
:'''Warning: Loops which run without a wait command will cause the TF2 client to hang. It is highly suggested to run a looping script only after a wait testing script.'''
bind g "redirect"<br />
+
It is generally considered bad form to have one alias point to itself, as although the loop can be broken out of, it cannot be reset. Therefore, looping scripts tend to include two parts to the loop: The part that waits, and the part that loops.
bind o "alias redirect break"<br />
+
 
alias break "alias redirect loop"</code><br />
+
<pre>bind g loopKey
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.
+
alias loopKey startLoop
 +
alias startLoop "alias loopKey stopLoop;+attack;alias redirect loop;loop"
 +
alias stopLoop "-attack;alias redirect;alias loopKey startLoop"
 +
alias loop "+left;wait 33;-left;+right;wait 33;-right;redirect"</pre>
 +
 
 +
This script will start looping once {{Key|G}} is pressed. It begins by firing, and then switches the player's view back and forth every 33 frames (half of a second on most servers). Pressing {{Key|G}} would cause the next iteration of the loop to stop, also stopping the firing.
 +
 
 +
=== Sequences ===
 +
<pre>alias +pyrocombo "slot1;+attack;wait 32;slot2"
 +
alias -pyrocombo "-attack;slot1"</pre>
 +
This script will create two aliases, one to start a sequence, and one to end it. The sequence will switch to a Pyro's [[Degreaser]] and fire for 32 ticks, before switching to the [[Panic Attack]] and shooting until the button is no longer held. Sequences can also be made like this:
 +
<br><pre>alias quickscope "slot1;+attack2;wait 32;+attack;wait 16;-attack;-attack2"</pre>
 +
This script will create a sequence alias, that once activated will cause the Sniper to quick-scope his [[Sniper Rifle]]; by executing the long string of commands called a sequence.
 +
Sequences are useful in making scripts, and learning how to make one will help in the long run of scripting.
 +
 
 +
=== Cycles ===
 +
A cycle is toggle script where there are a minimum of 3 possible options, which loop (ex, 1, 2, 3, 1). Example:
 +
<pre>
 +
alias message_1 "say message 1.; bind x message_2"
 +
alias message_2 "say message 2.; bind x message_3"
 +
alias message_3 "say message 3.; bind x message_1"
 +
bind x message_1
 +
</pre>
 +
This script makes it so pressing the {{Key|X}} key will cycle between making you say "message 1", "message 2", and "message 3".
 +
 
 +
 
 +
{{note|<code>[[vdc:toggle|toggle]]</code>, <code>[[vdc:incrementvar|incrementvar]]</code>, and <code>[[vdc:multvar|multvar]]</code> can often be used in place of aliases when a console variable is being changed.}}
 +
 
 +
=== Selection addons ===
 +
A selection script is built onto a cycle to make it more intuitive. Selection scripts allow cycling upwards and downwards, ultimately giving more control for selecting which command(s) to run.
 +
<pre>
 +
alias CondC_UP Cond1
 +
alias CondC_DOWN Cond5
 +
alias ApplyCond ApplyCond33
 +
alias ApplyCond33 "addcond 33"
 +
alias ApplyCond49 "addcond 49"
 +
alias ApplyCond72 "addcond 72"
 +
alias ApplyCond74 "addcond 74"
 +
alias ApplyCond90 "addcond 90"
 +
alias Cond1 "alias CondC_UP Cond2;alias CondC_DOWN Cond5;alias ApplyCond ApplyCond33"
 +
alias Cond2 "alias CondC_UP Cond3;alias CondC_DOWN Cond1;alias ApplyCond ApplyCond49"
 +
alias Cond3 "alias CondC_UP Cond4;alias CondC_DOWN Cond2;alias ApplyCond ApplyCond72"
 +
alias Cond4 "alias CondC_UP Cond5;alias CondC_DOWN Cond3;alias ApplyCond ApplyCond74"
 +
alias Cond5 "alias CondC_UP Cond1;alias CondC_DOWN Cond4;alias ApplyCond ApplyCond90"
 +
</pre>
 +
This gives more control in what conditions to add to the player. This also allows for better freedom of selection and ease of use, as it makes scrolling through options in the cycle possible.
 +
 
 +
=== Randomization ===
 +
Randomization is a strange and niche feature. Randomization is rarely used, as most processes aren't as useful when randomized. However, randomization can be useful for chat binds, such as for trade advertising.
 +
 
 +
'''Note: Due to the nature of TF2's scripting, this section will be considerably long. If you don't already have an understanding of how cycles work, the information presented may not be relevant.'''
 +
<pre>
 +
alias call f1
 +
alias cycle c2
 +
 
 +
alias c1 "alias cycle c2;alias call f1"
 +
alias c2 "alias cycle c3;alias call f2"
 +
alias c3 "alias cycle c4;alias call f3"
 +
alias c4 "alias cycle c5;alias call f4"
 +
alias c5 "alias cycle c1;alias call f5"
 +
 
 +
alias f1 "say 1"
 +
alias f2 "say 2"
 +
alias f3 "say 3"
 +
alias f4 "say 4"
 +
alias f5 "say 5"
 +
 
 +
alias +w "+forward;cycle"
 +
alias -w "-forward;cycle"
 +
alias +a "+moveleft;cycle"
 +
alias -a "-moveleft;cycle"
 +
alias +s "+back;cycle"
 +
alias -s "-back;cycle"
 +
alias +d "+moveright;cycle"
 +
alias -d "-moveright;cycle"
 +
 
 +
bind o call
 +
bind w +w
 +
bind a +a
 +
bind s +s
 +
bind d +d
 +
</pre>
 +
This script is assigning and resigning multiple alias values. When any of the {{key|WASD}} keys are pressed or released, the cycle command is ran, which moves the cycle command to the next value in the cycle and sets the "call" command to a value corresponding to the cycle number. This is based on the player's movement, and only changes values if the player is moving. It is possible to make this randomizer more effective by using other various techniques stated here (ex. Loops), but this example is for demonstration purposes only.
 +
 
 +
=== Timed action ===
 +
Timed or held actions trigger when a button is pressed down for a certain amount of time. Timed actions can be used in situations where a script or command shouldn't be instantly ran the moment a button is pressed (ex. accidentally pressing a disconnect bind).
 +
 
 +
<pre>
 +
alias "+ti_zoom" "alias zoom_con zoomOn; wait 132; zoom_con"
 +
alias "-ti_zoom" "zoomOff; alias zoom_con ; rb_tizoom-M4"
 +
alias "rb_tizoom-M4" "unbind mouse4; wait 132; bind mouse4 +ti_zoom"
 +
alias "zoomOn" "fov_desired 20; r_drawviewmodel 0"
 +
alias "zoomOff" "fov_desired 90; r_drawviewmodel 1"
 +
bind "mouse4" "+ti_zoom"
 +
</pre>
 +
 
 +
Pressing (and immediately releasing) {{key|Mouse 4}} with this script loaded will have no noticeable effect, however holding down {{key|Mouse 4}} for 2 seconds will cause the script to lower the FOV to 20, and hide viewmodels. Letting go of {{key|Mouse 4}} at any point will undo these changes by setting the FOV to 90 and unhiding viewmodels.
 +
 
 +
This works because of the use of + and - aliases. Pressing the key <code>+ti_zoom</code> is bound to will redefine <code>zoom_con</code> to activate the script, and if left pressed for the <code>wait</code> duration will execute the script. However, if the button is released, <code>zoom_con</code> is redefined to do nothing. The key is then "disabled" by being unbound for the same <code>wait</code> duration, and rebound afterwards to restore use of the key.
 +
 
 +
'''Note:''' Rebinding of the key is technically redundant, as the script will not execute the timed action if the button is released. However, if the button is pressed multiple times it is possible to execute the timed action if the confirmation alias (in this case, <code>zoom_con</code> is properly defined as any of the presses would execute it. Unbinding the key for the same duration of the original <code>wait</code> delay ensures that the effect can't be triggered if the button is rapidly pressed.
 +
 
 +
=== Basic Conditionals ===
 +
{{rewrite}}
 +
The basic conditional allows a script to change its behavior without running an entirely new script. By making use of a dummy alias it is possible to change the outcome of an input based on other inputs. Basic conditionals can support potentially infinitely many checks on the state of other commands, however it's unlikely that a script would need more than a few checks per conditional.
 +
 
 +
A very basic example of a conditional may look like:
 +
<pre>
 +
alias "check_test" "alias test success; check1; check2; test"
 +
alias "check1" ""
 +
alias "check2" ""
 +
alias "test" "success"
 +
 
 +
alias "fail_check" "alias test failure"
 +
 
 +
alias "success" "echo SUCCESS!"
 +
alias "failure" "echo FAILURE!"
 +
 
 +
alias "+k_pressed" "alias check1 fail_check"
 +
alias "-k_pressed" "alias check1"
 +
alias "+j_pressed" "alias check2 fail_check"
 +
alias "-j_pressed" "alias check2"
 +
 
 +
bind "l" "check_test"
 +
bind "j" "+j_pressed"
 +
bind "k" "+k_pressed"
 +
</pre>
 +
 
 +
The main function of this script is the <code>check_test</code> alias. When ran, this alias checks the other 2 conditionals, and if the checks succeed it runs the <code>success</code> alias. However, if one of the checks fails, the dummy alias <code>test</code> is pointed to run the <code>failure</code> alias. Simply put, when a check succeeds the checking command doesn't redirect the alias <code>test</code> is pointing to. If a check fails, it redirects the <code>test</code> alias to the alias storing the code to run when the check fails.
 +
 
 +
In this case, pressing the button {{key|L}} without pressing either {{key|J}} or {{key|K}}, the check succeeds and prints <code>SUCCESS!</code> to the console. When pressing and holding either {{key|J}} or {{key|K}} and then pressing {{key|L}}, the check will fail and print <code>FAILURE!</code> to the console.
 +
 
 +
A real world example of basic conditionals:
 +
<pre>
 +
// Change the crosshair color when moving around
 +
 
 +
alias "+w_pressed" "+forward;  alias check_w pressed_w; chc_forward"
 +
alias "+a_pressed" "+moveleft;  alias check_a pressed_a; chc_left"
 +
alias "+s_pressed" "+back;      alias check_s pressed_s; chc_back"
 +
alias "+d_pressed" "+moveright; alias check_d pressed_d; chc_right"
 +
 
 +
alias "-w_pressed" "-forward;  alias check_w; check_none"
 +
alias "-a_pressed" "-moveleft;  alias check_a; check_none"
 +
alias "-s_pressed" "-back;      alias check_s; check_none"
 +
alias "-d_pressed" "-moveright; alias check_d; check_none"
 +
 
 +
alias "check_w"
 +
alias "check_a"
 +
alias "check_s"
 +
alias "check_d"
 +
 
 +
alias "pressed_w" "dchk_fail; chc_forward"
 +
alias "pressed_a" "dchk_fail; chc_left"
 +
alias "pressed_s" "dchk_fail; chc_back"
 +
alias "pressed_d" "dchk_fail; chc_right"
 +
 
 +
alias "check_none" "check_s; check_a; check_d; check_w; dmy_check"
 +
alias "dmy_check" "chc_success"
 +
 
 +
alias "dchk_fail" "alias dmy_check chc_failure"
 +
alias "dchk_reset" "alias dmy_check chc_success"
 +
 
 +
alias "chc_failure" "dchk_reset"
 +
alias "chc_success" "chc_default"
 +
 
 +
alias "chc_default" "color0"
 +
alias "chc_forward" "color1"
 +
alias "chc_left"    "color2"
 +
alias "chc_back"    "color3"
 +
alias "chc_right"  "color4"
 +
 
 +
// Binds
 +
bind "w" "+w_pressed"
 +
bind "a" "+a_pressed"
 +
bind "s" "+s_pressed"
 +
bind "d" "+d_pressed"
 +
 
 +
// Colors
 +
alias "color0" "cl_crosshair_red 0; cl_crosshair_green 255; cl_crosshair_blue 0"        // Default color when not moving
 +
alias "color1" "cl_crosshair_red 0; cl_crosshair_green 0; cl_crosshair_blue 255"        // Color when moving forward
 +
alias "color2" "cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_blue 255"      // Color when moving left
 +
alias "color3" "cl_crosshair_red 128; cl_crosshair_green 212; cl_crosshair_blue 255"    // Color when moving back
 +
alias "color4" "cl_crosshair_red 255; cl_crosshair_green 140; cl_crosshair_blue 25"    // Color when moving right
 +
</pre>
 +
 
 +
This script will change the color of the user's crosshair as they walk around with the {{key|WASD}} keys. An important note this script takes advantage of is that when a check fails it can do several things instead of just changing the dummy command for testing. When a check fails the crosshair will change colors, and also change the dummy command to fail the check. This means when several buttons are released, the crosshair's color will properly change to the most recently pressed key.
 +
 
 +
== Commenting ==
 +
As scripts get longer, the need for well-named aliases grows. However, it is not always sufficient to explain what an alias does simply by its name. Adding a pair of forward slashes (//) will turn the rest of the line into a comment–it will not execute any actions on the text.
 +
 
 +
<pre>voicemenu 1 6 //Activate Charge!</pre>
 +
Since it is not obviously clear what the voice command is, a comment can explain it.
  
==Noteworthy scripts==  
+
== Noteworthy scripts ==  
 
There are several notable scripts that have affected gameplay. Some of these are patched out, while others remain functional.
 
There are several notable scripts that have affected gameplay. Some of these are patched out, while others remain functional.
  
===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. Scripts were created to simulate this rapid pressing by holding down a single key.
 
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.
  
{{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.
+
{{Patch name|8|13|2009}}: The Pistol now fires at a fixed rate, not based on the speed of pressing the fire button.
====Chargin' Targe turn scripts====
+
==== 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.
+
Originally, the keyboard commands to turn 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 a player could turn, 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.
  
 
{{Patch name|6|23|2011}}: Fixed an exploit with the Chargin' Targe that allowed greater turning control than intended.
 
{{Patch name|6|23|2011}}: 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, players could crouch as many times as they liked in a single jump. By binding a script to crouch and uncrouch as rapidly as possible, the engine could be exploited to make it difficult to properly register shots on jumping targets.
  
====Air crouching scripts====
+
{{Patch name|3|6|2009}}: Players can now only duck twice in the air.
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.
 
  
{{Patch name|3|6|2009}}: You can now duck twice in the air.
+
==== Idling Scripts ====
 +
Most servers seek to prevent players idling for [[Item drop system|drops]]. Players can try to outsmart these systems with scripts that simulate basic movement.
  
====Gloves of Running Urgently Scripts====
+
[http://www.teamfortress.com/post.php?id=11105 An Active Solution to an Idle Threat] requires players to accept a pop-up notification in order to continue to get drops.
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.
 
  
{{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 ===
 +
==== Weapon Viewmodel Hiding Scripts ====
 +
There are a large number of scripts which toggle the weapon viewmodel depending on which weapon slot is selected for a class. Players often make their viewmodels 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 viewmodel 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.
  
===Current Scripts===
+
==== Weapon Zoom Scripts ====
====Weapon Hiding Scripts====
+
By changing your [[FOV]], this script creates the visual effect of zooming in with whatever weapon the user is holding. It can usually be toggled between a zoomed and normal (unzoomed) version.
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====
+
==== Sentry Jumping Scripts ====
 
Since the [[Engineer Update]], Engineers have been able to pack up and carry their [[Sentry Gun]]s. 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.
 
Since the [[Engineer Update]], Engineers have been able to pack up and carry their [[Sentry Gun]]s. 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.
 
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 100 [[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 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 high precision headshots, a player may wish to change their mouse sensitivity. 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 button. This does require players to aim outside of the scope, though.
  
Note: The [[Rescue Ranger]] can circumvent this necessity, as it can pick up buildings at range for 130 metal.
+
==== Rocket Jump Scripts ====
 +
In order to [[Jumping#Soldier jumps|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.
  
====Gunslinger Scripts====
+
==== Auto-Disguise 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.
+
For Spies who find manually disguising to be a hassle, this script automatically disguises as a chosen class after the player attacks with any weapon. Auto-disguise can usually be toggled and customized to choose a disguise to use.
  
====Sensitivity and Control scripts====
+
==== ÜberCharge Broadcasting 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.
+
With this script, activating ÜberCharge as [[Medic]] will also write a custom message in team chat to alert your teammates about your activation, in order to encourage your team to push ahead with you. A similar script, upon activation, plays the "ÜberCharge Ready" voice command while writing in team chat that you faked your Über to fool the enemy team.
  
====Charge Dash Scripts====
+
==== Medic Radar ====
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.
+
This script only works for Medic, as it lets you press a button to temporarily set the autocall percentage to a very high number. This makes it so that you can see the locations of nearby teammates.
 +
Script:
 +
<pre>alias "autocall_default" "hud_medicautocallersthreshold 75.730003/Custom Threshold"
 +
alias "autocall_all" "hud_medicautocallersthreshold 150"
 +
alias "+radar" "autocall_all"
 +
alias "-radar" "autocall_default"
 +
bind [KEY] "+radar</pre>
 +
 
 +
==== Kill-Bind Scripts ====
 +
{{main|Suicide}}
 +
In certain circumstances, such as when cornered by a Medic wielding the [[Ubersaw]], it can be beneficial for a class to be able to kill themselves quickly (in this case, to deny the Medic Über) with a key bind (for example, <code>bind k kill</code>). Although mostly only relevant in competitive play, there are occasional uses in public servers, often for comedic effect instead of to benefit gameplay. The killbind can be set to explode you if you use <code>explode</code> instead (for example, <code> bind k explode</code>). There is no difference between these two mechanically.
 +
 
 +
==== Null-Cancelling Movement Scripts ====
 +
In stock TF2, pressing two opposing movement keys at once (such as "A" (+moveleft) and "D" (+moveright)) will cancel all movement and render the player immobile, which can be a fatal mistake during battle. This script makes it so that the direction of the last key pressed will be used instead. For example, pressing "A" will make the player go left, and pressing "D" while still holding "A" will make the player go right instead of stopping.
 +
 
 +
==== Chat Bind Scripts ====
 +
Chat bind scripts are designed to post a pre-written message in the in-game text chat. Typically, users will bind these scripts to a key on their keyboard for easy repetition. These scripts can vary from user-to-user, and can say anything within the text limit, depending on what a player would want to say. Some common binds are used for team co-ordination, such as a bind to tell a team that their Medic has popped an [[ÜberCharge]]. Other common binds are used for banter, such as messages upon kills and/or dominations. Another variation on this is a trade offer bind, where it sends information to the chat about a possible trade offer. This type of script can also be automated to send these offers every couple of minutes.
  
====Quickscope Scripts====
+
==== Voice Toggle ====
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.
+
This script enables you to voice toggle, instead of push-to-talk.  
 +
Script:
 +
<pre>bind [KEY] mic_toggle
 +
alias mic_toggle mic_enable
 +
alias mic_enable "+voicerecord; alias mic_toggle mic_disable"
 +
alias mic_disable "-voicerecord; alias mic_toggle mic_enable"</pre>
  
====Rocket Jump Scripts====
+
== Notes ==
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.
+
* Each config file is limited to one [[w:mebibyte|mebibyte]] (1.04858 megabytes) of information, though this restriction can be circumvented by [[#Exec|exec-ing]] another config file at the end of the first.
  
 
== See also ==
 
== See also ==
 
* [[List of useful console commands]]
 
* [[List of useful console commands]]
* [[Customizing#tf.5Ccfg.5Cconfig default.cfg|Default keybinds in TF2]]
+
* {{vdc|List of TF2 console commands and variables}}
 +
* {{vdc|Command Line Options|Command Line Options}}
 +
* {{vdc|VScript}}
 +
* [[Cheats]]
  
 
== External links ==
 
== External links ==
*[http://www.gamebanana.com/scripts/games/297 Hundreds of scripting examples on Gamebanana]
+
* [https://gamebanana.com/scripts/games/297 Hundreds of scripting examples on Gamebanana]
 +
* [https://cfg.tf cfg.tf, website dedicated to Team Fortress 2 configuration]
  
 
[[Category:Customization]]
 
[[Category:Customization]]

Latest revision as of 22:43, 7 December 2024

This thing ain't on auto-pilot, son!
The Engineer after using his sentry jump script

Scripting is the use of configuration files (.cfg) typically used to create new keybinds and aliases, change advanced graphical settings, automating complex behaviors, and creating sequences of console commands. Unlike hacking, scripting is an intentional feature natively built into Team Fortress 2, and will not trigger a VAC (Valve Anti-Cheat) ban. The complexity of scripting varies from simply binding an input key to output a command, to self-referential loops and nested aliases that redefine one another. There are many graphical settings that can only be changed through the use of console commands, or scripts that automate the input of said console commands. Outside of specific graphical settings, most other functions that can be performed via scripting may also be achieved without it, but scripting grants the advantage of allowing these functionalities to be instantly executed within the heat of battle.

Contents

Scripting Commands

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

bind

Main article: 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 and/or the command. However, the commands will need to have quotes when it has spaces in between the values and the command, so that the console can interpret it as one command. An example would be bind mouse1 "say texthere", where quotes are needed around "say texthere" because of the space between the two phrases.

bind [KEY] "[COMMAND 1];[COMMAND 2];[COMMAND 3]"

Quotes can be optionally placed around the key, but must be present around the commands, as the console will not interpret consecutive commands if quotes are not present.

Note: The command say "Example Text" is correct, but bind <KEY> "say "Example Text"" is not. This is because the quotes are misinterpreted, and quotes inside of quotes are unnecessary due to commands automatically stopping at every semicolon.

When a key is bound to a string starting with a plus, the same command(s) will be executed when the key is released, except the first plus will be replaced with a minus. For example, bind w +forward will make pressing W execute +forward and releasing W execute -forward. Note that this only effects the first command, and other commands will not be negated. See alias for more information. This bind will make the player move forward while they have W held down.

toggle

This command allows a cvar to be toggled between two or more values. If no values are specified, defaults to toggling between 0 and 1.

toggle tf_bot_quota normal fill match

bindToggle

BindToggle may be used to bind a key to toggle a cvar between 0 and 1. It cannot be used for values besides 0 and 1.

bindToggle o sv_cheats

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

Main article: 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. Alias names cannot contain spaces. They may contain underscores, numbers, symbols, and are not case-sensitive (only when being created, when removing an alias it is case-sensitive). Aliases may not overwrite existing commands or variables except those that start with a plus or minus (for example, alias help is disallowed, but alias +forward is allowed).

After running the command alias foo "echo bar", typing foo in the console will execute echo bar. After running the command alias foo, typing foo in the console will no longer do anything. If the alias was created with uppercase letters (such as alias fOO "echo bar"), typing alias foo will not remove the alias, but alias fOO will.

Aliases may begin with a plus or minus character. This allows them to be used in conjunction with bind to negate several commands when a key is released. For example, this script allows a player to move diagonally with a single key:

alias +diagonal "+moveleft; +back"
alias -diagonal "-moveleft; -back"
bind z "+diagonal"

Releasing Z will execute -diagonal in this script, whereas simply typing bind "z" "+moveleft; +back" would result in the game never running -back when the player releases the key. This results in the player moving backwards continuously.

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 highquality This script will execute the config named highquality.cfg script within the tf/cfg folder.

echo

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

echo Scripting is; echo very useful

This will print out Scripting is and very useful on two separate lines. This is because a newline is added to the end of any text passed to echo. 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 string is delimited by quotation marks.

Note: It is not possible to print out the " character, as its meaning will be misinterpreted. However, you can print single quotes: that is, the ' character.
Note: Echo occasionally will misprint strings that are not delimited by quotation marks. As a general rule of thumb, it is better to enclose what you wish to print within quotation marks. It also makes it easier to read for humans.

wait

This command will make the game wait a given number of frames before executing the next command.

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. See Wait Testing for help to protect against this.
echo Why did the chicken cross the road?;wait 300;echo To get to the other side!

This script will wait 300 frames (1 second at the default max FPS) before printing the punchline.

Class-specific CFG Files

When switching to a certain class, the game executes the corresponding CFG file (if it exists), named after the given class.

scout.cfg
soldier.cfg
pyro.cfg
demoman.cfg
heavyweapons.cfg
engineer.cfg
medic.cfg
sniper.cfg
spy.cfg

This automation lets the player have different keybinds and game settings for each class.

VPK files and config files

.vpk files take priority over config files located within the cfg folder. Mods using .vpk files may run the risk of negatively interfering with any custom configuration changes, however, some mods provide methods to override the configs from within the .vpk files natively.

Launch Options

Launch options can be used to change how TF2 runs, both in terms of performance and functionality. Please see Command Line Options on the Valve Developer Community for a comprehensive list of launch options.

Set Launch Options

A visual guide on how to set launch options (indicated by the pink circles).
  1. Right-click on the game title under the Library in Steam and select Properties.
  2. Under the General tab click the Set launch options... button.
  3. Enter the launch options you wish to apply (be sure to separate each code with a space) and click OK.
  4. Close the game's Properties window and launch the game.

Window Options

Note that these may incorrectly setup an improper video mode not preferred by the material system, reducing performance. Where possible, you should use the in-game settings instead.

Resolution

Launch Option: -w # -h #

Description: Forces the game resolution width and height in pixels.

Refresh Rate

Launch Option: -freq #

Description: Forces the game refresh rate in Hz.

Windowed Mode

Launch Option: -windowed

Description: Launches the game in windowed mode.

Borderless Windowed Mode

Launch Option: -noborder

Description: When in windowed mode, remove the window border to allow for borderless fullscreen mode, as opposed to exclusive fullscreen mode.

Fullscreen Mode

Launch Option: -fullscreen

Description: Forces the game to be in fullscreen mode.

Peripheral Support

Disable Joystick Support

Launch Option: -nojoy

Description: Prevents the joystick system from loading, improving start-up time and memory usage. Don't use this if you intend to use a joystick with the game.

Disable Steam Controller Support

Launch Option: -nosteamcontroller

Description: Prevents the Steam controller system from loading, improving start-up time and memory usage. Don't use this if you intend to use a Steam controller with the game.

Software Support

Disable SourceTV

Launch Option: -nohltv

Description: Disables SourceTV support, improving memory usage. Don't use this if you host SourceTV on your client.

Engine Options

Disable Intro Video

Launch Option: -novid

Description: Removes the Valve intro video shown when the game is started, improving loading times.

Change Beam Particle Limit

Launch Option: -particles #

Description: Limits the number of beam particles. Set # to '1' to (a limit of 512) to improve memory usage.

Precache Font Rendering

Launch Option: -precachefontchars

Description: Precaches font rendering for common characters, improving rendering time.

Disable Texture Streaming

Launch Option: -no_texture_stream

Description: Disables using lower quality textures whilst higher quality versions load, instead favoring to always instantly load the higher quality versions. Disabling texture streaming results in a performance boost on systems running GPUs with low VRAM (video memory).

DirectX Version (Windows exclusive)

Launch Option: -dxlevel #

Description: Sets the DirectX Version used by the game; accepts many values ranging from 80 to 100. The manual setting of DirectX levels is experimental and is typically altered to support older hardware.
'-dxlevel 100' uses DirectX 9. Hardware is automatically detected to determine the system's graphical capabilities.
'-dxlevel 81' is the most stable version of DirectX for GPUs released prior to 2004. DirectX 8 has a reduced feature set such as a lack of War Paints and transparency on models (such as the Voodoo-Cursed Souls). Values below 81 will cause even more graphical issues. This should be avoided unless necessary for compatibility reasons.
Note: After launching the game with the -dxlevel command once, the game should then be closed, and then the launch option removed entirely before launching the game again.

Vulkan (Windows exclusive)

Launch Option: -vulkan

Description: Enables Vulkan rather than DirectX. Vulkan is enabled by default on Linux systems.

Execute Other Scripts on Startup

Launch Option: +exec script.cfg

Description: Executes the specified script when the game launches.

Pictogram comment.png Note: A config named autoexec.cfg is automatically executed on startup.

List of key names

Hover over a key to see its scripting name. Names are not case-sensitive.

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

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

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

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

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

Ctrl   Alt       Spacebar       Alt ≣ 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.
Note: Any collection of characters and/or numbers after the class number that are not 1, 2, -1, or -2 will default the disguise to RED team, regardless of the player's current team. For example, disguise 1 3 will disguise the Spy as a RED Scout.

Buildings

The build and destroy commands each take two arguments, the first being the building and the second being the building type. The second argument is only required if it is not 0, and is currently only used to differentiate between teleporter entrances and exits.

The build command will pull up the blueprint to place a building, with an exception of the Sapper, which is wielded.

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 Gun (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 Gun (Engineer only)
Note: Sappers cannot be destroyed.

It is possible to use the old build commands, which used only one argument.

build 0 will build a Dispenser (Engineer only)
build 1 will build a teleporter entrance (Engineer only)
build 2 will build a Sentry Gun (Engineer only)
build 3 will build a teleporter exit (Engineer only)
build 3 will build a Sapper (Spy only) [deprecated]

Voice Menu

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

  • voicemenu 0
    0: MEDIC!
    1: Thanks!
    2: Go! Go! Go!
    3: Move Up!
    4: Go Left
    5: Go Right
    6: Yes
    7: No
    8: Pass To Me!
  • voicemenu 1
    0: Incoming
    1: Spy!
    2: Sentry Ahead!
    3: Teleporter Here
    4: Dispenser Here
    5: Sentry Here
    6: Activate Charge!
    7: MEDIC: ÜberCharge Ready
    8: Pass To Me!
  • voicemenu 2
    0: Help!
    1: Battle Cry
    2: Cheers
    3: Jeers
    4: Positive
    5: Negative
    6: Nice Shot
    7: Good Job
Note: If you wish to display the voicemenu, rather than fire the voicemenu <num> <num> message, the command is voice_menu_<num>: where <num> is a number between 1 and 3, and takes no arguments. For instance, to display the first voicemenu, one would run the command voice_menu_1.

Eureka Teleport

The eureka_teleport can teleport an Engineer holding the Eureka Effect to their spawn or teleporter exit.

  • eureka_teleport 0 will teleport the player to their spawn
  • eureka_teleport 1 will teleport the player to their teleporter exit

Assorted

  • clear will clear the console of any information.
  • alias will list all currently defined aliases.
  • fov_desired (20-90) will set the field of view.
  • viewmodel_fov will set the FOV for weapon models. It ranges by default from 54 to 70.
  • r_drawviewmodel (0/1) will show (1) or hide (0) weapon models.
  • lastdisguise will cause the player to re-disguise as their last disguise. (Spy only)
  • load_itempreset (0-3) will load a particular loadout preset [A, B, C, D].
  • say message will send a message to public chat.
  • say_team message will send a message to team chat.
  • say_party message will send a message to party chat.
  • +taunt will open the player's taunt loadout.
  • +use_action_slot_item will cause the player to use their action slot item.
  • volume (0-1) will change the in-game volume.
  • taunt_by_name (name) will run a specified taunt, given the exact name of a taunt in the player's current taunt loadout, without opening the taunt menu.
  • key_findbinding (string) will list all keys bound to a string containing the given substring (case-sensitive).
  • key_listboundkeys will list all keys currently bound and their associated commands.

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_movement
alias toggle_movement enable_movement
alias enable_movement "alias toggle_movement disable_movement;+forward"
alias disable_movement "alias toggle_movement enable_movement;-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 holding down a key changes the action of another key. For example, the following script can be used to make Alt+F4 exit the game:

alias +alt_pressed   bind f4 exit
alias -alt_pressed unbind f4

bind alt +alt_pressed

Note that pressing Alt will execute +alt_pressed, and releasing it will execute -alt_pressed.

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 0; 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 looping script only after a wait testing script.

It is generally considered bad form to have one alias point to itself, as although the loop can be broken out of, it cannot be reset. Therefore, looping scripts tend to include two parts to the loop: The part that waits, and the part that loops.

bind g loopKey
alias loopKey startLoop
alias startLoop "alias loopKey stopLoop;+attack;alias redirect loop;loop"
alias stopLoop "-attack;alias redirect;alias loopKey startLoop"
alias loop "+left;wait 33;-left;+right;wait 33;-right;redirect"

This script will start looping once G is pressed. It begins by firing, and then switches the player's view back and forth every 33 frames (half of a second on most servers). Pressing G would cause the next iteration of the loop to stop, also stopping the firing.

Sequences

alias +pyrocombo "slot1;+attack;wait 32;slot2"
alias -pyrocombo "-attack;slot1"

This script will create two aliases, one to start a sequence, and one to end it. The sequence will switch to a Pyro's Degreaser and fire for 32 ticks, before switching to the Panic Attack and shooting until the button is no longer held. Sequences can also be made like this:


alias quickscope "slot1;+attack2;wait 32;+attack;wait 16;-attack;-attack2"

This script will create a sequence alias, that once activated will cause the Sniper to quick-scope his Sniper Rifle; by executing the long string of commands called a sequence. Sequences are useful in making scripts, and learning how to make one will help in the long run of scripting.

Cycles

A cycle is toggle script where there are a minimum of 3 possible options, which loop (ex, 1, 2, 3, 1). Example:

alias message_1 "say message 1.; bind x message_2"
alias message_2 "say message 2.; bind x message_3"
alias message_3 "say message 3.; bind x message_1"
bind x message_1

This script makes it so pressing the X key will cycle between making you say "message 1", "message 2", and "message 3".


Pictogram comment.png toggle, incrementvar, and multvar can often be used in place of aliases when a console variable is being changed.

Selection addons

A selection script is built onto a cycle to make it more intuitive. Selection scripts allow cycling upwards and downwards, ultimately giving more control for selecting which command(s) to run.

alias CondC_UP Cond1
alias CondC_DOWN Cond5
alias ApplyCond ApplyCond33
alias ApplyCond33 "addcond 33"
alias ApplyCond49 "addcond 49"
alias ApplyCond72 "addcond 72"
alias ApplyCond74 "addcond 74"
alias ApplyCond90 "addcond 90"
alias Cond1 "alias CondC_UP Cond2;alias CondC_DOWN Cond5;alias ApplyCond ApplyCond33"
alias Cond2 "alias CondC_UP Cond3;alias CondC_DOWN Cond1;alias ApplyCond ApplyCond49"
alias Cond3 "alias CondC_UP Cond4;alias CondC_DOWN Cond2;alias ApplyCond ApplyCond72"
alias Cond4 "alias CondC_UP Cond5;alias CondC_DOWN Cond3;alias ApplyCond ApplyCond74"
alias Cond5 "alias CondC_UP Cond1;alias CondC_DOWN Cond4;alias ApplyCond ApplyCond90"

This gives more control in what conditions to add to the player. This also allows for better freedom of selection and ease of use, as it makes scrolling through options in the cycle possible.

Randomization

Randomization is a strange and niche feature. Randomization is rarely used, as most processes aren't as useful when randomized. However, randomization can be useful for chat binds, such as for trade advertising.

Note: Due to the nature of TF2's scripting, this section will be considerably long. If you don't already have an understanding of how cycles work, the information presented may not be relevant.

alias call f1
alias cycle c2

alias c1 "alias cycle c2;alias call f1"
alias c2 "alias cycle c3;alias call f2"
alias c3 "alias cycle c4;alias call f3"
alias c4 "alias cycle c5;alias call f4"
alias c5 "alias cycle c1;alias call f5"

alias f1 "say 1"
alias f2 "say 2"
alias f3 "say 3"
alias f4 "say 4"
alias f5 "say 5"

alias +w "+forward;cycle"
alias -w "-forward;cycle"
alias +a "+moveleft;cycle"
alias -a "-moveleft;cycle"
alias +s "+back;cycle"
alias -s "-back;cycle"
alias +d "+moveright;cycle"
alias -d "-moveright;cycle"

bind o call
bind w +w
bind a +a
bind s +s
bind d +d

This script is assigning and resigning multiple alias values. When any of the WASD keys are pressed or released, the cycle command is ran, which moves the cycle command to the next value in the cycle and sets the "call" command to a value corresponding to the cycle number. This is based on the player's movement, and only changes values if the player is moving. It is possible to make this randomizer more effective by using other various techniques stated here (ex. Loops), but this example is for demonstration purposes only.

Timed action

Timed or held actions trigger when a button is pressed down for a certain amount of time. Timed actions can be used in situations where a script or command shouldn't be instantly ran the moment a button is pressed (ex. accidentally pressing a disconnect bind).

alias "+ti_zoom" "alias zoom_con zoomOn; wait 132; zoom_con"
alias "-ti_zoom" "zoomOff; alias zoom_con ; rb_tizoom-M4"
alias "rb_tizoom-M4" "unbind mouse4; wait 132; bind mouse4 +ti_zoom"
alias "zoomOn" "fov_desired 20; r_drawviewmodel 0"
alias "zoomOff" "fov_desired 90; r_drawviewmodel 1"
bind "mouse4" "+ti_zoom"

Pressing (and immediately releasing) Mouse 4 with this script loaded will have no noticeable effect, however holding down Mouse 4 for 2 seconds will cause the script to lower the FOV to 20, and hide viewmodels. Letting go of Mouse 4 at any point will undo these changes by setting the FOV to 90 and unhiding viewmodels.

This works because of the use of + and - aliases. Pressing the key +ti_zoom is bound to will redefine zoom_con to activate the script, and if left pressed for the wait duration will execute the script. However, if the button is released, zoom_con is redefined to do nothing. The key is then "disabled" by being unbound for the same wait duration, and rebound afterwards to restore use of the key.

Note: Rebinding of the key is technically redundant, as the script will not execute the timed action if the button is released. However, if the button is pressed multiple times it is possible to execute the timed action if the confirmation alias (in this case, zoom_con is properly defined as any of the presses would execute it. Unbinding the key for the same duration of the original wait delay ensures that the effect can't be triggered if the button is rapidly pressed.

Basic Conditionals

The basic conditional allows a script to change its behavior without running an entirely new script. By making use of a dummy alias it is possible to change the outcome of an input based on other inputs. Basic conditionals can support potentially infinitely many checks on the state of other commands, however it's unlikely that a script would need more than a few checks per conditional.

A very basic example of a conditional may look like:

alias "check_test" "alias test success; check1; check2; test"
alias "check1" ""
alias "check2" ""
alias "test" "success"

alias "fail_check" "alias test failure"

alias "success" "echo SUCCESS!"
alias "failure" "echo FAILURE!"

alias "+k_pressed" "alias check1 fail_check"
alias "-k_pressed" "alias check1"
alias "+j_pressed" "alias check2 fail_check"
alias "-j_pressed" "alias check2"

bind "l" "check_test"
bind "j" "+j_pressed"
bind "k" "+k_pressed"

The main function of this script is the check_test alias. When ran, this alias checks the other 2 conditionals, and if the checks succeed it runs the success alias. However, if one of the checks fails, the dummy alias test is pointed to run the failure alias. Simply put, when a check succeeds the checking command doesn't redirect the alias test is pointing to. If a check fails, it redirects the test alias to the alias storing the code to run when the check fails.

In this case, pressing the button L without pressing either J or K, the check succeeds and prints SUCCESS! to the console. When pressing and holding either J or K and then pressing L, the check will fail and print FAILURE! to the console.

A real world example of basic conditionals:

// Change the crosshair color when moving around

alias "+w_pressed" "+forward;   alias check_w pressed_w; chc_forward"
alias "+a_pressed" "+moveleft;  alias check_a pressed_a; chc_left"
alias "+s_pressed" "+back;      alias check_s pressed_s; chc_back"
alias "+d_pressed" "+moveright; alias check_d pressed_d; chc_right"

alias "-w_pressed" "-forward;   alias check_w; check_none"
alias "-a_pressed" "-moveleft;  alias check_a; check_none"
alias "-s_pressed" "-back;      alias check_s; check_none"
alias "-d_pressed" "-moveright; alias check_d; check_none"

alias "check_w" 
alias "check_a" 
alias "check_s" 
alias "check_d" 

alias "pressed_w" "dchk_fail; chc_forward"
alias "pressed_a" "dchk_fail; chc_left"
alias "pressed_s" "dchk_fail; chc_back"
alias "pressed_d" "dchk_fail; chc_right"

alias "check_none" "check_s; check_a; check_d; check_w; dmy_check"
alias "dmy_check" "chc_success"

alias "dchk_fail" "alias dmy_check chc_failure"
alias "dchk_reset" "alias dmy_check chc_success"

alias "chc_failure" "dchk_reset"
alias "chc_success" "chc_default"

alias "chc_default" "color0"
alias "chc_forward" "color1"
alias "chc_left"    "color2"
alias "chc_back"    "color3"
alias "chc_right"   "color4"

// Binds
bind "w" "+w_pressed"
bind "a" "+a_pressed"
bind "s" "+s_pressed"
bind "d" "+d_pressed"

// Colors
alias "color0" "cl_crosshair_red 0; cl_crosshair_green 255; cl_crosshair_blue 0"        // Default color when not moving
alias "color1" "cl_crosshair_red 0; cl_crosshair_green 0; cl_crosshair_blue 255"        // Color when moving forward
alias "color2" "cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_blue 255"      // Color when moving left
alias "color3" "cl_crosshair_red 128; cl_crosshair_green 212; cl_crosshair_blue 255"    // Color when moving back
alias "color4" "cl_crosshair_red 255; cl_crosshair_green 140; cl_crosshair_blue 25"     // Color when moving right

This script will change the color of the user's crosshair as they walk around with the WASD keys. An important note this script takes advantage of is that when a check fails it can do several things instead of just changing the dummy command for testing. When a check fails the crosshair will change colors, and also change the dummy command to fail the check. This means when several buttons are released, the crosshair's color will properly change to the most recently pressed key.

Commenting

As scripts get longer, the need for well-named aliases grows. However, it is not always sufficient to explain what an alias does simply by its name. Adding a pair of forward slashes (//) will turn the rest of the line into a comment–it will not execute any actions on the text.

voicemenu 1 6 //Activate Charge!

Since it is not obviously clear what the voice command is, a comment can explain it.

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 of pressing the fire button.

Chargin' Targe turn scripts

Originally, the keyboard commands to turn 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 a player could turn, 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.

Air crouching scripts

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

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

Idling Scripts

Most servers seek to prevent players idling for drops. Players can try to outsmart these systems with scripts that simulate basic movement.

An Active Solution to an Idle Threat requires players to accept a pop-up notification in order to continue to get drops.

Current Scripts

Weapon Viewmodel Hiding Scripts

There are a large number of scripts which toggle the weapon viewmodel depending on which weapon slot is selected for a class. Players often make their viewmodels 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 viewmodel 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.

Weapon Zoom Scripts

By changing your FOV, this script creates the visual effect of zooming in with whatever weapon the user is holding. It can usually be toggled between a zoomed and normal (unzoomed) version.

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 100 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 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 high precision headshots, a player may wish to change their mouse sensitivity. 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 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.

Auto-Disguise Scripts

For Spies who find manually disguising to be a hassle, this script automatically disguises as a chosen class after the player attacks with any weapon. Auto-disguise can usually be toggled and customized to choose a disguise to use.

ÜberCharge Broadcasting Scripts

With this script, activating ÜberCharge as Medic will also write a custom message in team chat to alert your teammates about your activation, in order to encourage your team to push ahead with you. A similar script, upon activation, plays the "ÜberCharge Ready" voice command while writing in team chat that you faked your Über to fool the enemy team.

Medic Radar

This script only works for Medic, as it lets you press a button to temporarily set the autocall percentage to a very high number. This makes it so that you can see the locations of nearby teammates. Script:

alias "autocall_default" "hud_medicautocallersthreshold 75.730003/Custom Threshold"
alias "autocall_all" "hud_medicautocallersthreshold 150"
alias "+radar" "autocall_all"
alias "-radar" "autocall_default"
bind [KEY] "+radar

Kill-Bind Scripts

Main article: Suicide

In certain circumstances, such as when cornered by a Medic wielding the Ubersaw, it can be beneficial for a class to be able to kill themselves quickly (in this case, to deny the Medic Über) with a key bind (for example, bind k kill). Although mostly only relevant in competitive play, there are occasional uses in public servers, often for comedic effect instead of to benefit gameplay. The killbind can be set to explode you if you use explode instead (for example, bind k explode). There is no difference between these two mechanically.

Null-Cancelling Movement Scripts

In stock TF2, pressing two opposing movement keys at once (such as "A" (+moveleft) and "D" (+moveright)) will cancel all movement and render the player immobile, which can be a fatal mistake during battle. This script makes it so that the direction of the last key pressed will be used instead. For example, pressing "A" will make the player go left, and pressing "D" while still holding "A" will make the player go right instead of stopping.

Chat Bind Scripts

Chat bind scripts are designed to post a pre-written message in the in-game text chat. Typically, users will bind these scripts to a key on their keyboard for easy repetition. These scripts can vary from user-to-user, and can say anything within the text limit, depending on what a player would want to say. Some common binds are used for team co-ordination, such as a bind to tell a team that their Medic has popped an ÜberCharge. Other common binds are used for banter, such as messages upon kills and/or dominations. Another variation on this is a trade offer bind, where it sends information to the chat about a possible trade offer. This type of script can also be automated to send these offers every couple of minutes.

Voice Toggle

This script enables you to voice toggle, instead of push-to-talk. Script:

bind [KEY] mic_toggle
alias mic_toggle mic_enable
alias mic_enable "+voicerecord; alias mic_toggle mic_disable"
alias mic_disable "-voicerecord; alias mic_toggle mic_enable"

Notes

  • Each config file is limited to one mebibyte (1.04858 megabytes) of information, though this restriction can be circumvented by exec-ing another config file at the end of the first.

See also

External links