此翻译需要更新。您可以通过以从“Scripting”(查看来源)里的内容编辑来协助改善它。参见帮助:语言翻译(英语)。
此页面正在被翻译成简体中文。如果您能熟练地运用简体中文,请在讨论页上留言或与为此页面贡献的作者讨论(通过浏览页面历史)。
“
这玩意还不是全自动的,孩子! 点击试听
— 工程师在使用他的步哨跳脚本后说
”
脚本编写是通过利用配置文件(configuration files,文件扩展名.cfg) 对按键绑定进行改动与新增,将一系列复杂的行为以及控制台指令统筹到一个指定的别名下的行为。与作弊不同,脚本实质是在利用《军团要塞2》这款游戏的内置功能,并不会被Valve反作弊系统侦测到。脚本的利用十分广泛,小到将一条指令绑定到一个按键上,大到一条涉及自我指涉循环与互相嵌套重定义的指定别名的指令。如果一项功能能够靠脚本的创建来实现,那么它必然也能在无脚本参与的情况下完成,而脚本的意义就在于在紧张的实战中能够更为便捷地实现这些功能。
备注:如果一个绑定指令没有生效,用引号括起来写入可能有效。例如:bind "r" "voicemenu 2 6"。
目录
1 标准配置
2 配置文件路径
3 脚本指令
3.1 绑定(Bind)
3.2 切换(Toggle)
3.2.1 绑定切换(Bindtoggle)
3.3 增量变量(Incrementvar)
3.4 别名(Alias)
3.5 执行(Exec)
3.6 回显(Echo)
3.7 等待(Wait)
4 Class-specific CFG Files
4.1 VPK files and config files
5 启动项
5.1 设置启动项
5.2 窗口选项
5.2.1 分辨率
5.2.2 刷新率
5.2.3 窗口化
5.2.4 无边框窗口化
5.2.5 全屏
5.3 外接设备支持
5.3.1 禁用摇杆输入
5.3.2 禁用Steam控制器输入
5.4 软件支持
5.4.1 禁用SourceTV
5.5 网络选项
5.5.1 启用假IP
5.6 引擎选项
5.6.1 禁用开屏动画
5.6.2 Change Beam Particle Limit
5.6.3 Precache Font Rendering
5.6.4 Disable Texture Streaming
5.7 DirectX Version (Windows exclusive)
5.8 Vulkan (Windows exclusive)
5.9 Execute Other Scripts on Startup
6 按键名称
7 实用指令
7.1 伪装
7.2 建造
7.3 快捷语音
7.4 Eureka Teleport
7.5 其他
8 Advanced Scripting Techniques
8.1 切换指令
8.2 组合键
8.3 Wait-testing
8.4 循环
8.5 按序执行
8.6 重复
8.7 选择项
8.8 随机项
8.9 定时器
8.10 Basic Conditionals
9 Commenting
10 Noteworthy scripts
10.1 Patched scripts
10.1.1 Pistol scripts
10.1.2 Chargin' Targe turn scripts
10.1.3 Air crouching scripts
10.1.4 Idling Scripts
10.2 Current Scripts
10.2.1 Weapon Viewmodel Hiding Scripts
10.2.2 Weapon Zoom Scripts
10.2.3 Building Scripts
10.2.4 Eureka Effect Scripts
10.2.5 Sentry Jumping Scripts
10.2.6 Gunslinger Scripts
10.2.7 Sensitivity and Control scripts
10.2.8 Charge Dash Scripts
10.2.9 Quickscope Scripts
10.2.10 Rocket Jump Scripts
10.2.11 Auto-Disguise Scripts
10.2.12 ÜberCharge Broadcasting Scripts
10.2.13 Medic Radar
10.2.14 Kill-Bind Scripts
10.2.15 Null-Cancelling Movement Scripts
10.2.16 Chat Bind Scripts
10.2.17 Voice Toggle
11 注意
12 参见
13 外部链接
标准配置
《军团要塞2》自带一些配置文件,或者由游戏自动创建:
config.cfg包含您在游戏中的设置,如图像画面设定、按键绑定、击中音效等。
config_default.cfg是《军团要塞2》的默认配置,其在玩家没有相应config.cfg文件及初次启动游戏时应用。
配置文件路径
Windows:
在SteamPipe更新后,配置文件同样可存储在.../SteamApps/common/Team Fortress 2/tf/custom/yourfoldernamehere/cfg
脚本指令
以下是除了脚本编写外没有实际用处的的命令列表; 它们不会直接影响实际游玩。
绑定(Bind)
最简单的命令是绑定命令。它会使得按下某个键便能执行一项动作,无论该动作是设置,命令还是脚本。
bind [KEY] [COMMAND]
可以选择在按键和/或命令的两边加上引号。 但是,当值和命令之间有空格时,命令必须带有引号,以便控制台可以将其解释为一个命令。 示例:bind mouse1 "say texthere"(将某一段文本绑定到鼠标左键上),由于两个短语之间存在距离,"say texthere"两端需要加上引号。
bind [KEY] "[COMMAND 1];[COMMAND 2];[COMMAND 3]"
在按键部分两端添加引号不是必须的,但是在命令的两端则必须加上,因为如果引号不存在,控制台将无法解释连续的命令。
注意: 下面这条指令
say "Example Text" 是正确的, 但是下面这条
bind
绑定有两种形式:
bind e "voicemenu 0 0"
这项绑定将允许玩家通过按下E键来呼叫医生。
bind w +forward
这项绑定将允许玩家通过按住W键来往前走动。
切换(Toggle)
这项指令将允许一项设置在两个或更多个值之间进行切换。
toggle sv_cheats 0 1
绑定切换(Bindtoggle)
功能和绑定相同,只是绑定到一个按键上。
bindtoggle o sv_cheats 0 1
注意:若无预设值,绑定和绑定切换会使用默认值0与1。
增量变量(Incrementvar)
允许变量以预设值多次地增加或减少。
bind MWHEELUP "incrementvar fov_desired 75 90 1"
bind MWHEELDOWN "incrementvar fov_desired 75 90 -1"
上面这组指令可使滚轮上滚时抬升视场角,在滚轮下滚时降低视场角。
注意: 值增加到上限或是减少到下限时,该值都会出现回绕。 在上面这组示例中,一旦视场角超出最大值90,它将降到最小值75,反之亦然。
别名(Alias)
将多个指令指定到一个别名下可以只用一个指令就将它们全部统筹起来。当一系列指令需要被反复使用时,别名指定是最为有用的高效速记法。
注意: 别名名称不能包含空格,但可包含下划线,数字和符号。别名名称区分大小写。
alias Call_For_Medic "Voicemenu 0 0"
bind "e" "Call_For_Medic"
上面这项脚本示例与单纯地将呼叫医生的指令绑定在E键上的效果相同。
注意: 在别名前添加+号(正向指令)并按下相应绑定键执行后,其后的-号别名(负向指令)会随后被执行。 下例:
alias "+Diagonal" "+moveleft; +back"
alias "-Diagonal" "-moveleft; -back"
bind "z" "+Diagonal"
在上面的脚本中,+Diagonal别名指定给了其后的+moveleft与+back,分别表示(按下相应绑定键后)向左移动和向后移动;而下一行的-Diagonal别名则指定给了-moveleft与-back,分别表示(松开相应绑定键后)停止向左移动和停止向后移动。那么这样一来,按下 Z 键就会使得玩家以对角线方向向左后方移动。
而要注意的是,下面的写法就是一个错误的示例。
bind "z" "+moveleft; +back"
虽然说用上面这条脚本按下Z键还是有朝左后方移动的效果的,但是这样一来系统将无法执行-号别名,也就是说一旦按下Z键,玩家将一直向左后方移动,无法在松开按键时停下来。
执行(Exec)
使用该指令可以指定执行某一特定的配置文件。这意味着一个特殊而复杂的脚本可以专门写在一个通用配置文件之外的新配置文件里,从而在安装和编辑方面免除干扰其他脚本的麻烦。
exec autoexec.cfg
上面这个脚本就是在指定执行autoexec.cfg文件。
回显(Echo)
回显指令的作用是用“Echo 信息内容”的格式来输出提示信息。如下例:
echo Scripting is; echo very useful
输出结果就是 Scripting is (脚本)和 very useful (很有用),这一句话的两部分将以分立的两行输出并显示出来。单词之间的空格和双引号内的空格都将被回显, 如下例:
echo " Scripting is very useful. "
在Scripting is very useful.这句话的后面跟了3个空格字符,它们也会被显示出来。
注意: 双引号无法被系统识别为文本的一部分,因此无法显示。但是单引号可以。
等待(Wait)
等待指令可被用来阻塞当前进程的执行,直至指定的子进程执行结束后,才继续执行。使用等待指令可以在脚本在多进程执行模式下,起到一些特殊控制的作用。等待指令可以被赋予特定时间来决定等待的持续时长,而赋予的进程号代表的是刻(tick),因此,实际等待时间与服务器的刷新率(tickrate)有关。如果wait后面不带任何的进程号,那么等待指令会阻塞当前进程的执行,直至当前进程的所有子进程都执行结束后,才继续执行。
警告: 等待指令在部分服务器被禁用。这会导致某些脚本失效,并且(在极少数的情况下)让游戏崩溃。
echo Why did the chicken cross the road?;wait 66;echo To get to the other side!
上面这条脚本会把Why did the chicken cross the road?(为什么小鸡们在过马路?)这句话回显完毕后,先等待66刻,再显示它的答句To get to the other side!(为了到另一边去!)
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 can be used to change how TF2 runs, both in terms of performance and functionality. Please see Command Line Options (英语) ,源于 Valve 开发者社区 (英语) for a comprehensive list of launch options.
设置启动项
如何设置启动项的示意图(如红框所示)
在Steam库中鼠标右键游戏标题,并选择属性。
Next to the General column, click the box below Launch Options.
Enter the launch options you wish to apply (be sure to separate each code with a space).
Close the game's Properties window and launch the game.
窗口选项
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.
分辨率
Launch Option: -w # -h #
Description: Forces the game resolution width and height in pixels.
刷新率
Launch Option: -freq #
Description: Forces the game refresh rate in Hz.
窗口化
Launch Option: -windowed
Description: Launches the game in 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.
全屏
Launch Option: -fullscreen
Description: Forces the game to be in fullscreen mode.
外接设备支持
禁用摇杆输入
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.
禁用Steam控制器输入
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.
软件支持
禁用SourceTV
Launch Option: -nohltv
Description: Disables SourceTV support, improving memory usage. Don't use this if you host SourceTV on your client.
网络选项
启用假IP
Launch Option: -enablefakeip
Description: Uses a reserved IP address rather than your own and an anonymous server ID when local server hosting. If sv_lan is set to 0 it allows other players to join your server.
引擎选项
禁用开屏动画
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.
Note: A config named autoexec.cfg is automatically executed on startup.
按键名称
将光标移动到下图的按键上并悬浮以查看按键的脚本名称。按键名称为非事件敏感型。
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
.
鼠标键
绑定名称
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
实用指令
主条目: List of TF2 console commands and variables
伪装
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.
建造
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]
快捷语音
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
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
其他
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 causes the player to re-disguise as their last disguise. (Spy only)
lastdisguise (random) causes the player to disguise as a random enemy class, excluding Scout or Spy. (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
切换指令
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.
组合键
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.
循环
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.
按序执行
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.
重复
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".
toggle, incrementvar, and multvar can often be used in place of aliases when a console variable is being changed.
选择项
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 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 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.
2009年8月13日补丁: 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.
2011年6月23日补丁: 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.
2009年3月6日补丁: 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.
Script:
bindtoggle [KEY] "r_drawviewmodel"
Weapon Zoom Scripts
By changing your field of view, 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. Below is an example of a script which toggles the field of view:
alias +zoom "fov_desired 20"
alias -zoom "fov_desired 90"
bind shift "+zoom"
Building Scripts
A quick and easy way to build and destroy Engineer buildings with a single press of a button, removing the hassle of having to press multiple buttons, especially in the heat of the moment.
Script:
bind [KEY] "destroy 2 0; build 2 0" // Sentry Gun
bind [KEY] "destroy 0 0; build 0 0" // Dispenser
bind [KEY] "destroy 1 0; build 1 0" // Teleporter Entrance
bind [KEY] "destroy 1 1; build 1 1" // Teleporter Exit
Eureka Effect Scripts
Allows the player to use the Eureka Effect's teleportation witout having to go through the menu.
Script:
alias "tele_home" "slot3; eureka_teleport 0" // for teleporting to spawn
alias "tele_exit" "slot3; eureka_teleport 1" // for teleporting to the Teleporter Exit
bind [KEY] "tele_home"
bind [KEY] "tele_exit"
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.
Script:
alias "+alertandPop" "+attack2; say_team ÜBERED; spec_prev"
alias "-alertandPop" "-attack2"
bind [KEY] "+alertandPop"
You may change "UBERED" to any message that you desire
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
主条目: Suicide
In certain circumstances, such as when cornered by a Medic wielding the Übersaw, 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.
Script:
alias +mfwd "-back;+forward;alias checkfwd +forward;
alias +mback "-forward;+back;alias checkback +back;
alias +mleft "-moveright;+moveleft;alias checkleft +moveleft;
alias +mright "-moveleft;+moveright;alias checkright +moveright;
alias -mfwd "-forward;checkback;alias checkfwd none"
alias -mback "-back;checkfwd;alias checkback none"
alias -mleft "-moveleft;checkright;alias checkleft none"
alias -mright "-moveright;checkleft;alias checkright none"
alias checkfwd none
alias checkback none
alias checkleft none
alias checkright none
alias none ""
bind w "+mfwd"
bind s "+mback"
bind a "+mleft"
bind d "+mright"
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.
Script:
bind [KEY] "say Howdy! this is all chat"
bind [KEY] "say_team Howdy! this is team chat"
bind [KEY] "say_party Howdy! this is party chat"
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"
注意
每个脚本的大小只允许在1MiB(1048576字节)内,但可在某个脚本的末端通过 exec(运行)另一个脚本来避开这个限制。
参见
有用的控制台指令列表
List of TF2 console commands and variables (英语) ,源于 Valve 开发者社区 (英语)
Command Line Options (英语) ,源于 Valve 开发者社区 (英语)
VScript (英语) ,源于 Valve 开发者社区 (英语)
作弊
外部链接
TF2 脚本教程。
TF2 scripting tutorial - Warrior Nation Network。
FPSBanana.com - TF2 脚本。
cfg.tf - TF2脚本专用网站