巨集

From Team Fortress Wiki
< Scripting
Revision as of 14:23, 13 January 2015 by B1113d (talk | contribs) (蹲跳巨集)
Jump to: navigation, search

巨集又稱為腳本,是使用配置文件來把控制台的指令碼綁定到鍵位或把數個指令綁定成一個新的別名

巨集所涵蓋的範圍可以從綁定鍵位到使用別名來自動重複指令。甚至可以使用巨集來創建千變萬化的行為。

巨集的文件

絕地要塞2會自動讀取以下幾個遊戲文件來實行巨集:

  • config.cfg - 這是默認的配置文件,當你在選項裏面做出更改時,便會將設定儲存在此文件。編輯此文件沒有風險,但在啟動遊戲時會影響到修改過的按鍵配置。每次啟動遊戲時會在其他設置讀取之前優先讀取。
    • config_default.cfg - 這份文件包含了一組基本的按鍵配置,如果 config.cfg 不存在時就會被執行作為備份。
  • autoexec.cfg - 這是儲存玩家設定的配置文件,你可以把巨集或指令儲存在此文件。當config.cfg和autoexec.cfg都有相同的指令時,遊戲會以autoexec.cfg為准
  • <class>.cfg - 每個兵種都有一個配置文件,你可以將綁定鍵位的指令儲存在這些文件。當你選擇了相應的兵種後,相應文件的指令便會執行。需要注意的是,若在文件中使用了開關類型的指令時作用會被保留,直到執行反向指令為止。

編輯巨集文件

若在 Windows 系統,巨集文件能在下列資料夾找到:
<Steam Folder>/SteamApps/common/team fortress 2/tf/cfg
若在 Mac 系統,巨集文件能在下列資料夾找到:
~/Library/Application Support/Steam/SteamApps/common/team fortress 2/tf/cfg
若在 Linux 系統,巨集文件能在下列資料夾找到:
~/.local/share/Steam/SteamApps/common/Team\ Fortress\ 2/tf/cfg
Since the SteamPipe update, code can also be placed in .../team fortress 2/tf/custom/yourfoldernamehere/cfg

語法

The following is a list of commands which have no use apart from scripting; they do not influence gameplay directly. 這是一個語法的規則:

  • 無論是綁定或別名,你都要按照以下格式來編寫:
命令 <argument1> <argument2>
  • 目前有三種命令可供選擇:
  • bind - 用於將指令綁定到鍵位
  • alias - 可以將多個指令綁定成別名來一次性執行
  • exec - 可以讓客戶端加載其他配置文件
  • <argument1> 可以是鍵位的名稱或創建別名的名稱
  • <argument2> 可以是被綁定的指令或別名的指令
  • 要一次執行多條指令,你必須將所以指令用引號括住,例如:
alias "spraynpray" "+attack; wait 500; -attack"
bind "mouse3" "spraynpray"
  • 按mouse3後,開始執行別名spraynpray,然後別名spraynpray會讓你的武器進行攻擊,接著等待500幀,最後停止射擊。

綁定(bind)

最簡單的語法是 bind 指令,能夠影響按鍵執行的動作,該動作可以是個設定、指令或腳本。

bind [KEY] [COMMAND]
可以加上雙引號在按鍵名稱或指令的左右。

bind [KEY] "[COMMAND 1]; [COMMAND 2]; [COMMAND 3]"
可以加上雙引號在按鍵名,但一定要用雙引號包住多項指令。


綁定有兩種形式:
bind "e" "Voicemenu 0 0"
此綁定是當玩家按下E鍵後會觸發『Medic!』的語音指令。

bind "w" "+forward"
此綁定是當玩家按住不放 W 鍵後能夠讓玩家前進。

切換(Toggle)

這項巨集可以設置兩個或兩個以上值的指令進行切換。 toggle "sv_cheats 0 1"

綁定切換(Bindtoggle)

功能和 toggle 相同,只是綁定到一個按鍵上。 bindtoggle o "sv_cheats 0 1"

遞增值(Incrementvar)

可以設置一個數值以反覆執行增加或減少值。

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

此範例能讓玩家向上滾動滑鼠滾輪時增加視野,向下滾動則減少。
註: Incrementvar 指令如果讓數值超出或變得過小時會重複循環。在此範例中,如果視野超過 90 則會下降到 75 ,反之亦然。

別名(Alias)

Alias 可以將多項指令以一個名稱代替,成為一個有效用的簡寫名稱。當一系列的指令需要被重複執行時會非常有用。
註: Alias 名稱不能包含空格。可以包含下底線、數字或符號。 Alias 會區分大小寫。

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

此巨集是一個簡單的綁定,功能是當玩家按下 E 後會觸發『Medic!』語音指令。

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

此巨集可以讓玩家斜向移動,按下 Z 玩家會往左後方斜著走。

警告:下列寫法不會有作用
bind "z" "+moveleft; +back"
雖然按 Z 可以讓玩家往左邊及後方移動,但遊戲引擎不會反轉 +back 指令,導致放開 Z 後玩家不會停止向後移動。

執行(Exec)

此指令可以執行其他的文件檔。意味著複雜的巨集可以存在其他文件檔裡,以免弄亂一般的文件。

exec autoexec.cfg
此巨集將會讀取 autoexec.cfg 文件內的巨集。

回應(Echo)

此指令會將文字顯示到控制台上,對於偵錯非常有用。

echo Scripting is; echo very useful.
如果將分號(;)加在文字之間則會顯示 Scripting isvery useful. 。 或將文字用雙引號包住,如下例

echo " Scripting is very useful. "
則會將多餘的空格顯示出來,因為它包含在雙引號內。

註: 雙引號是無法顯示的符號,因為它的用途會被曲解。

等待(Wait)

此指令可使遊戲等待所設定的 FPS 數值後才執行下一個指令。
註: 這項指令對應的實際時間取決於伺服器的處理速率。
警告: Wait 指令在部分伺服器禁用。這會導致某些巨集失效,並且(在極少數的情況下)讓遊戲當機。請看 Wait Testing 避免這種情況發生。

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

絕地要塞2的鍵盤名稱

滑鼠移上按鍵即可看到按鍵名稱。

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

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

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

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

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

Ctrl Alt       Spacebar       ≣ Menu Ctrl

PrtScn ScrLk Pause

Insert Home PgUp

Delete End PgDn


       

   

Num / * -
7 8 9 +
4 5 6
1 2 3
    0     .
滑鼠按鍵 按鍵名稱
滾輪上滑 MWHEELUP
滾輪下滑 MWHEELDOWN
左鍵 MOUSE1
右鍵 MOUSE2
點擊滾輪 MOUSE3
左側鍵(下一頁) MOUSE4
右側鍵(上一頁) MOUSE5

實用的指令

主條目: TF2 指令及值數列表(英)

Spy快速偽裝

這些巨集可以讓玩家按下一個鍵後即偽裝而不用開啟偽裝菜單

偽裝命令使用以下語法:

disguise <class_number> <team_number>

<class_number>是代表兵種的編號;<team_number>是代表團隊的編號

偽裝編號參數

  • 1 <class_number>
    1: 偵察兵
    2: 狙擊手
    3: 火箭兵
    4: 爆破兵
    5: 醫護兵
    6: 重裝兵
    7: 火焰兵
    8: 間諜
    9: 工程師
  • 2 <team_number>
    1: 藍隊
    2: 紅隊
    -1: 敵隊
    -2: 同隊

Engineer快速建造

類似Spy的快速偽裝,這可以讓Engineer不必開啟建造菜單即能建造。

建築指令使用以下語法

build <building_number>
destroy <building number>

<building_number>是建築的編號

建築編號參數

  • Number: Building/Destroying
    0: 補給器
    1: 傳送裝置入口
    2: 步哨防禦槍/迷你戰鬥步哨
    3: 傳送裝置出口

以下是快速建造巨集的例子:

 alias sentry "destroy 2; build 2"
alias Dispenser "destroy 0; build 0"
alias entrance "destroy 1; build 1"
alias exit "destroy 3; build 3"
bind f1 sentry
bind f2 dispenser
bind f3 entrance
bind f4 exit

這巨集會在建造前先破壞要建造的建築,使玩家建造前無需開啟破壞菜單。

語音指令

語音指令可以讓你在遊戲內發出特定的語音。

語音指令使用以下語法

voicemenu <menu_number> <phrase_number>

<menu_number>是編號1到3的語音菜單編號,<phrase_number>則是語音菜單1到7的語音編號

語音相關編號

  • 0 <phrase_number>
    0: 醫生!
    1: 謝謝!
    2: 前進! 前進! 前進!
    3: 往前!
    4: 往左走
    5: 往右走
    6: 好
    7: 不
  • 1 <phrase_number>
    0: 敵人來襲
    1: Spy!
    2: 前方有步哨!
    3: 這裡需要傳送裝置
    4: 這裡需要補給器
    5: 這裡需要步哨
    6: 啟動 ÜberCharge!
    7: (只有Medic可以使用)ÜberCharge 就緒
  • 2 <phrase_number>
    0: 幫我!
    1: 戰鬥咆哮
    2: 乾杯
    3: 嘲弄
    4: 收到
    5: 不行
    6: 打得好
    7: 幹得好


雜項

  • clear 清除控制台的所有訊息。
  • alias 列出所有目前定義的別名。
  • fov_desired (75-90) 設置視野距離。
  • viewmodel_fov 設置武器模型的視野,默認範圍為 54~70 之間。
  • r_drawviewmodel (0/1) 顯示(1) 或隱藏(0) 武器模型。
  • lastdisguise 使玩家偽裝成上一次偽裝的職業。 (間諜專用)
  • load_itempreset [0, 1, 2, 3] 更換自訂的 [A, B, C, D] 裝備欄位。
  • say "message" 發送公開的聊天訊息。
  • say_team "message" 發送隊伍聊天訊息。
  • +taunt 玩家會進行嘲諷動作。
  • +use_action_slot_item 玩家會使用動作欄位所裝備的物品。
  • volume (0-1) 改變遊戲中的音量。

高級巨集技巧

Toggles

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

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

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

Key combinations

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

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

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

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

Wait-testing

由於 wait 指令是一些巨集不可缺少的部分,利用此指令查看伺服器是否能使用等待指令。

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

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

Loops

Warning: Loops which run without a wait command will cause the TF2 client to hang. It is highly suggested to run a 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; +right; wait 33; redirect"
alias redirect loop

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 (1second on most servers). Pressing G would cause the next iteration of the loop to stop, also stopping the firing.


Medic Radar

這些巨集可以讓Medic只要按住一個按鍵,就將自動呼救的上限提升至150%(醫護兵能超量治療的生命上限),讓他可以看到附近所有隊友的位置。

 alias "autocall_default" "hud_medicautocallersthreshold "75""
alias "autocall_all" "hud_medicautocallersthreshold "150""
alias "+radar" "autocall_all"
alias "-radar" "autocall_default"
bind mouse3 "+radar"

預設的自動呼救值(也就是沒有使用這個巨集時的自動呼救值)可以調整為任何你想要的值(在這個例子中是75%),啟動巨集的按鈕也可以改為任意按鍵(在這個例子中是mouse3)。

值得注意的巨集

有些巨集會破壞遊戲的環境和平衡。

已被修正的巨集

手槍連射巨集

原先遊戲裏的手槍只能單發射擊,後來有人編寫了手槍連射巨集,讓玩家一直按下鍵位即可連續發射手槍。後來Valve為了確保遊戲公平性,讓玩家即使不使用巨集也可以連續發射手槍。

Targe Turn Scripts

用鍵盤改變視角與用滑鼠改變視角,是不同的兩個動作。衝擊刺盾是第一個限制改變視角速度的武器,而Valve雖然對使用該武器時,滑鼠改變視角的速度做出限制,卻忘了對鍵盤指令做出相同限制。有玩家利用這個特性,寫了重新改變輸出的巨集,讓他們可以用正常的速度改變視角。最複雜的例子中,玩家在衝刺時,滑鼠的x軸指令被改變為相同結果的鍵盤指令,在衝刺結束後再將這個改變還原。

Valve之後對鍵盤指令做出相同限制,因此這個巨集再也沒有作用了。然而,還是可以寫出一個巨集,讓玩家在衝刺時有超高滑鼠靈敏度,在攻擊時恢復正常。It is also possible to turn easily while using a gamepad's analog sticks.

蹲跳巨集

原先跳到空中時,蹲下的次數是沒有限制的。因此你可以在空中執行一個不斷超高速蹲下站起的巨集,讓遊戲沒辦法正常判斷子彈是否擊中你。Valve修正為在空中只能蹲下兩次。

Gloves of Running Urgently Scripts

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

2012年6月27日更新: Replaced the damage over time of the Gloves of Running Urgently with a time-delayed mini-crit de-buff.

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.

目前的巨集

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.

Sentry Jumping Scripts

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

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

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

Gunslinger Scripts

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

靈敏度和控制巨集

對於一些對於喜歡不同的靈敏度和控制的巨集(例如,改變偵察兵,這就需要高靈敏度去快速轉動和操作,對於狙擊手,鼓勵使用低靈敏度精確瞄準這樣一隻手無意抽搐的時候不會偏離你的目標太大). These scripts alter their control schemes and mouse settings on a per class or even per weapon basis.

Charge Dash Scripts

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

Quickscope Scripts

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

Rocket Jump Scripts

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

Kill-bind Scripts

In certain circumstances is it beneficial for a class to be able to kill themselves. Although mostly only relevant in competitive play, there are occasional uses in public servers.

參見

外部鏈接