找回密码
 点一下
查看: 7901|回复: 8

[原創]SC2 editor 新手觸發(trigger) 教程

[复制链接]
发表于 2010-9-22 21:11:19 | 显示全部楼层 |阅读模式
SC2 editor 新手觸發(trigger) 教程 by Wakeman

這篇教程是希望讓一些從來沒有學過編程的同學也能看得明白, 所以連一些很基礎的如 variable 的種類, if-then-else 的用法之類也解釋了, 希望高手們不要見笑, 同時也幫忙指出錯漏.

1) 基礎
2) 觸發結構
3) 常用 event
4) 常用 condition
5) 常用 action
6) event 和 action 的參數 (parameter)
7) 一些常見錯誤
8) 實例
9) 其他


1) 基礎

觸發是制作自定義地圖(custom map) 差不多必要的原素. 如何把一個普通的對戰地圖(melee map) 或只有地形的地圖變成一個塔防,DotA, 角色扮演(RPG), 第一身射擊(FPS), 或其他五花八門的地圖, 多數都要用到 trigger. trigger 的原理,跟一般的編程語言有很多相同的地方, 所以如果本身有 visual basic, visual c 之類的基礎, 再參考一下其他地圖的trigger, 一般很快可以學會. 就算本來沒有這方面的經驗, 但 Blizzard 給的 trigger editor 也很容易上手,看完這個教程太概可以開始嘗試造自己的地圖吧!

一開始, 先按 F6 或看圖1 (A) 打開 trigger editor.

trigger (B):就是 trigger 程序的單位. 每個 trigger 程序基本上是獨立運作, 例如一個刷兵的 trigger 和一個計算分數的trigger 可以同時進行. trigger 也有同一個 trigger 可以同一時間運行多次的特性, 例如同一個刷兵的 trigger如果由兩個不同的玩家觸發, 電腦便會自動安排兩個該 trigger 的副本各自運行.

variable (C):變量/變數, 是用來保存一些資料以便之後運算用的. SC2 跟 WC3 的 trigger editor 其中一個最大分別是 SC2有了global variable 和 local variable 之分. 兩者的分別是每個 global variable在地圖裡只有一個版本, 而且可以供任何 trigger 使用; 相反local variable 在它的 trigger每次被觸發時就會被產生一個新的版本(但不影響之前的版本), 而且它只能在該 trigger 內有效.
常用的 variable 有:integer (整數), real (實數, 即容許有小數位), unit (地圖中的單位, 可以是一般單位或建築物), unitgroup (單位組, 可以包含零個至到很多個的單位), point (地圖上的位置) 等等.
除了基本的 variable,variable 也可以被造成 array (陣列). 例如你造了一個 myunit 的 unit 類 variable, 然後選了array 再設定大小為 3, 那實際上就有了 myunit (0), myunit (1), myunit (2), myunit (3)這四個 variable 了!

comment (D): 注解, 可以隨便打入一些文字, 純粹是給地圖作者或是其他打開地圖的人看的. 對實際地圖運作沒有影響, 但當你的地圖愈造愈大時在重要的地方加上注解可方便自己的工作.

folder (E): 文件夾, 讓你可以把同類的 trigger 或 variable 放在一起. 對實際地圖運作沒有影響, 但當你的地圖有數十個以至百多個 trigger 時, 用這個分類會方便很多!

*要新加以上的各種, 只要按滑鼠右鍵, 選 New (F), 再選伙想要的.


2) 觸發結構

每個觸發主要分三部份: event, condition 和 action.

event (G): 就是引發起這個 trigger 運行的條件. 可以同時有多個 event, 只要其中一個 event 成立, trigger 便會被引發.

condition (H):上面event 所能判斷的條件有限, 所以有時候便要用到 condition 了. 如果 condition 的位置不是空白,那trigger 被 event 觸發了後, 還要通過 condition 的條件才會真正的被執行. 例如如果 event 是 unitdies, 那地圖上所有的單位死了 trigger 都會被執行. 但如果在下面加了 condition: Owner of(Triggering unit)) == 1, 那麼只有玩家1 的單位死了時trigger 才會被執行.
另外, 如果一個 trigger 中有多於一個 condition, 則必須所有 condition 都成立trigger 才會被執行.

action (I): 通過了 condition, 這裡才是 trigger 的主體! 在這裡的 action 會由第一個開始一步一步的運行, 例如創造單位, 轉換視角, 顯示文字等等, 直至每一行運行完畢或 trigger 被提早關閉為止.

先來一個簡單的例子:
Events

        Timer - Every 5.0 seconds of Game Time

    Local Variables

    Conditions

    Actions

        UI - Display "Hello!" for (All players) to Subtitle area


測試地圖, 地圖就會每五秒顯示一個 Hello!

現在試試 condition:
先按 unit editor, 給玩家1 加一個 SCV. 再給玩家2 加幾個 marine. 回到剛才的 trigger 加多一個 condition:
        
(SCV [28.22, 29.12] is alive) == true
           (SCV [28.22, 29.12] 就是新加的 SCV.)

試試地圖, 一開始時會有 Hello! 出現. 叫你的 SCV 跑去 marine 面前自殺, SCV 死了就沒有 Hello! 了, 因為 (SCV001is alive) 已經不成立, trigger 不會被運行.


3) 常用 event

以下是一些常用的 event (其他比較少用的可以自己以後試試看). 注意可以在 Find (J) 的空格裡輸入英文找你想要的:

map initialization: 地圖起始時觸發. 一般是用來設定一些起始的設定, 如玩家視線, 玩家同盟關係之類. 也可以由此顯示一些開場白.
time elapsed: 當遊戲起始了一些時間後觸發. 例如想在遊戲開始五秒後顯示計分板可以用這個.
periodicevent: 每 x 秒就運行這個 trigger 一次. 例如 DotA 每 30 秒刷一次兵就可以用這個.注意計時是由遊戲開始立即開始計的, 所以如果想在確定所有玩家都準備好才開始刷兵, 必須先關掉 trigger (滑鼠右擊 trigger,除去initially on 一項), 然後再用其他 trigger 在合適的時候開啟這個 trigger.
timer expires: timer 是可以在 trigger 中產生的倒數計時器. timer 倒數完了 timer expires 就會被觸發.

unit acquires target: 單位獲得目標(一般是指敵人).
unit become idle: 單位完成所有指令或本身沒有指令而進入閒置.
unit dies: 單位死亡.
unit enters/leaves point: 單位進入或離開一點.
unit enters/leaves range of unit: 單位進入或離開某個指定單位的距離.
unit enter/leaves region: 單位進入一個區域.
unit is attacked: 單位受到攻擊.
unit property changes: 單位的生命值, 能量等等的數據改變了.
unit starts attacking: 跟 unit is attacked 相反, 單位開始攻擊.
unit takes damage: 單位受到任何傷害.
unit uses ability: 單位使用了技能.

player property changed: 當玩家的一些數據, 例如晶礦量改變時觸發.
player leaves game: 玩家離開了遊戲. 在多人地圖中可以讓你知道有玩家離開, 從而做出相對的動作.

chat message: 玩家輸入了一些文字後會觸發. 一般遊戲中已經很少用, 但可以用來做一些"作弊碼 (cheat code)" 方便自己測試時用.

*另外, event 是可以完全留空的. 如此這個 trigger 不會自動執行, 必須由其他 trigger 用 run trigger 呼叫才會執行.


4) 常用 condition

comparison: 判定一個陳述句是否成立(true). 大部份情況下你都要先選這一項, 再詳細選擇真正要判定的條件. 在下面會再列一些例子.
and: 在 and 以下的所有 comparison 必須是 true, 那 and 才會是 true.
or: 在 or 以下的其中一個 comparison 是 true, 那 or 已經會是 true.
within bounds: 判定一個integer variable / real variable 是否在指定的範圍內.

comparison 詳解:
先選了comparison, 會看到三個基本參數(K): value 1, operator, value 2. comparison 就是用 operator 的方法比較 value 1 和 value 2. 先點 value 1, 便會看到很多選擇. 先選好你要比較的 source (L)是 function (函數), preset (一些內定的數值), 還是你自己定下的 variable. value 1 選好後,operator 會因應 value 1 的類型有一些選擇: == (等於), != (不等於), < (小於), <=(小於或等於), > (大於), >= (大於或等於). 最後埴上 value 2. value 2 除了可以是function, preset 和 variable 外, 還可以是 value (就是一個固定的數字, 單位之類) 和 customscript.

以下是一些常用的 comparison function:
triggering player,triggering unit, triggering region 等等: 就是引發 event 的玩家, 單位, 區域等等.例如event 是 unit dies, triggering unit 就是死了的單位, triggering player就是擁有該單位的玩家.
alliance aspect: 比較兩個玩家的同盟關係.
arithmetic (integer) / arithmetic (real): 加減乘除.
controller of player: 判斷某玩家是電腦, 人, 空置, 還是中立.
damage effect / damage player / damage unit: 造成傷害的效果, 玩家或單位.
distance between points: 兩點間的距離.
experience level of unit: 單位的等級.
killing player / killing unit: 回應 unit dies event 中殺死 triggering unit 的玩家/單位.
number of players in player group: 一個玩家組中玩家的數目.
number of units in unit group: 一個單位組中單位的數目.
owner of unit: 某個單位的操控者是誰.
player property: 某個玩家的晶礦量之類的數值.
random integer: 一個隨機數. 如果你想某個 trigger 只在一個隨機的機率下才會運作, 可以用這個.
unit count for player: 玩家的總單位數目.
unit in region: 單位在區域內.
unit in unit group: 單位在某個單位組內.
unit is alive: 單位是生存的.
unit property: 單位的生命值, 能量等等的數值.
unit type attribute check: 判定單位是不是建築物, 輕甲, 重甲等等.
unit type classification check: 判定單位是不是英雄, 工人等等.


5) 常用 action

action 比較多, 所以我用我自己的習慣分了類:

地圖起始時常用:
set game speed: 設定遊戲速度.
set minimum game speed: 設定遊戲最低速度.
lock game speed: 鎖定遊戲速度.
modify player property: 更改玩家的晶礦量等等的資料.
set alliance: 設定某兩個玩家為同盟 / 敵對關係.
set alliance for player group: 設定一個玩家組內的所有玩家為同盟 / 敵對關係.
create revealer: 給玩家一個沒有時限的可見區域. 例如給玩家1 看到整個地圖: Visibility - Create a visibility revealer for player 1 within (Entire map)
reveal area: 在一定時間內給玩家一個可見區域.

地圖完結:
end game for player: 指定玩家遊戲完結, 可以是 victory, defeat 或 tie (平手).

鏡頭:
applycamera object: 設定某玩家的鏡頭為一指定鏡頭. 一般的電影鏡頭移動都是用了多個不同的鏡頭加上這個 action 造出來的.如果選了don't include target, 鏡頭只會採用x, y 座標以外的其他特性. 這個是想令玩家改變鏡頭角度,距離等等但不影響當前的目標時會有用. 另外, 可以用default game camera 來重設某玩家的鏡頭為對戰的預設鏡頭.
pan camera: 將玩家的鏡頭移到指定的地方, 但不影響其他鏡頭特性.
lock camera input: 鎖定玩家鏡頭, 令玩家不能控制鏡頭. 如果用了這個指令, 一定要記得在其他地方設定電腦控制玩家鏡頭的方法.
make camera look at and follow unit: 把鏡頭移到目標單位並跟隨單位移動. 一般會配合 lock camera input 用, 否則玩家只要拉一拉滑鼠, 鏡頭就會停止跟隨單位移動.

電影:
cinematic mode: 開啟/關閉電影模式. 電影模式一般就是過場動畫, 片頭片尾等玩家只能看畫面, 不能做其他東西的時間.
global cinemtic setting: 一般開始 cinematic mode 時同時加上這個來固定遊戲速度和隨機數的生成, 關閉 cinematic mode 時也要記得同時關掉.
fade in/out: fade out 令畫面慢慢變黑(或者是其他你想要的顏色); fade in 令畫面慢慢由全黑變回正常.

跟單位有關:
createunits with default facing / create units with point facing / createunits facing angle / create units facing point: 給玩家創造 x 個單位. 4 個actions 的分別只是設定單位面向的方法.
issue order / issue order to unit group: 給一個單位或一組單位下命令.
set unit property: 設定單位的生命值, 能量之類的數值.
set unit state: 設定單位的"可動", "可被選"之類的特性.
make unit invulnerable: 令單位無敵或取消單位的無敵.
make unit uncommandable: 令單位可以或不可以被玩家控制.
change owner: 把單位的控制權交給指定玩家.
kill unit: 把單位殺死. 單位會有死亡動畫, 有屍體, 會觸發 unit dies 的 event.
remove unit: 直接把單位移離遊戲. 不會有死亡動畫, 不會有屍體, 不會觸發 unit dies 的 event. (完全消失了不留痕跡...)
move unit instantly: 立即把單位移到指定的地方.
pause/unpause unit / pause/unpause all units: pause 令一個單位/所有單位立即停止所有活動, 也不能接受新的命令; unpause 就令單位/所有單位回復正常.
show/hide unit: 顯示/隱藏一個單位. 注意 hide 了的單位不會動, 但如果有敵人在近處單位仍會進行攻擊! (有可能是 bug, 但也說不定有它的用意.) 所以用 hide unit 時一般同時 pause unit.
select unit / select unit group: 給玩家選取一個或一組單位, 就像玩家自己在遊戲中用滑鼠點了一個或幾個單位一樣. 用deselect 取消指定的單位的選取.
clear unit selection: 取消所有該玩家選取了的單位.

跟單位組有關:
add unit to unit group / add unit group to unit group: 把一個單位或一組單位加到一個 unit group 類的 variable.
removeunit from unit group / remove unit group from unit group remove allunits from unit group: 把一個單位, 一組, 或所有單位從一個 unit group 類的 variable 中移除.
pick each unit in unit group: 逐一選取一組單位中的所有單位, 並為選取了的單位逐一執行一些指令.
例如:
UnitGroup - Pick each unit in (Any units in (Entire map) owned by player 2matching Excluded: Missile, Dead, Hidden, with at most Any Amount) anddo (Actions)

Actions

Unit - Set (Picked unit) Life (Percent) to 100.0

Unit - Set (Picked unit) Energy (Percent) to 100.0

Unit - Order (Picked unit) to ( Attack targeting Barracks [37.50, 34.50]) (Replace Existing Orders)


就會把所有玩家2 的單位的生命值和能量值立即回滿, 然後攻擊 Barracks [37.50, 34.50].

文字:
text message: 在指定的地方顯示一段文字.
clear text message: 清除所有文字.
show cinematic text / show text crawl: 跟text message 一樣作用, 只是出來的效果不同.
hide cinematic text / hide text crawl: 清除以上的文字.
send transmission: 給玩家一段由指定單位發出有頭像顯示的文字 (即是由該單位向玩家發言).

模型和音效:
create actor / create actor at point: 創造一個 actor, 這個 actor 可以有 model / sound, 但只是視覺/音效上存在, 不是真正的 unit. 一般是用來做 trigger 的特效用.
create model at point: 創造一個 model. 這個 model 只是視覺上存在, 不是真正的 unit. 一般是用來做 trigger 的特效用.
animplay: 指示一個 model 做一個特定的動畫. 這個 model 可以是某個 unit 的 actor, 也可以是上面用 createactor 製造出來沒有指定 unit 的 actor. 而 play 的必須是該 model 本來有的動畫, 如 attack,stand, dead 之類. 個別 model 有甚麼不同動畫可以用 previewer 看.
create effect at point / create effect on unit: 在指定的地點或單位上創造一個效果(effect), 並可指定效果來自那個玩家/單位.
play sound / play sound on unit / play sound at point: (在指定的單位/ 位置)播放一段音效.
stop sound: 停止一段音效.

程序運算:
set variable: 設定一個 variable 的值.
modify variable (integer) / modify variable (real): 對一個 integer variable 或 real variable 進行數學運算.
wait: 等待 x 秒, 然後繼續下一步. 注意這個等待只對於 wait 所在的 trigger 以後的 action 有影響, 不會影響到其他的trigger.
wait for condition: 一樣是等待, 不過會等到指定的 condition 為 true 時才會繼續下一步.

if then else: 非常有用的邏輯動作. 假如 if 之後的 condition 為 true, 就會做 then 之後的動作; 否則則會做 else 之後的動作.
例如:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
General - If (Conditions) then do (Actions) else do (Actions)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;If

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(Triggering player) == 1

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Then

Unit - Create 1 Marine for player (Triggering player) at (Center of(Entire map)) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Else

Unit - Create 1 Zergling for player (Triggering player) at (Center of(Entire map)) using default facing (No Options)


假如觸發的玩家是玩家1, 那就給他生一個 marine, 否則就給他生一個 zergling.

switch: 如果 if then else 的 condition 有兩個以上的可能性, 有些人會以多個 if then else 來完成. 另一個方法是用switch.
例如:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
General - Switch (Actions) depending on (Triggering player)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Cases

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - If (1)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

Unit - Create 1 Marine for player (Triggering player) at (Center of(Entire map)) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - If (2)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

Unit - Create 1 Zergling for player (Triggering player) at (Center of(Entire map)) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Default

Unit - Create 1 Zealot for player (Triggering player) at (Center of(Entire map)) using default facing (No Options)


假如觸發的玩家是玩家1, 那就給他生一個 marine; 假如是玩家2, 那就給他生一個 zergling; 如果兩者都不是, 就給他生一個 zealot.

for each integer / for each real: 重複一些 action, 並且在每次重複時增加指定的 integer variable / real variable 的值, 直到該 variable 大於另一個值.
例如:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
General - For each integer i from 1 to 3 with increment 1, do (Actions)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Create i Marine for player 1 at (Center of (Entire map)) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - Wait 1.0 Game Time seconds


如此第一次生一個 marine, 然後等一秒, 再生兩個 marine, 然後又等一秒, 再生三個 marine, 再等一秒, 才繼續餘下的 action.

while: 只要 condition 保持是 true 就一直運行一些 action, 直至 condition 變為 false.
例如:
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
General - While (Conditions) are true, do (Actions)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(Barracks [37.50, 34.50] is alive) == true

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Create 1 Marine for player 1 at (Position of Barracks [37.50, 34.50]) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - Wait 3.0 Game Time seconds


只要 Barracks [37.50, 34.50] 一直生存, 每三秒就會在它的位置創造一個 marine. 如果 Barracks [37.50, 34.50] 死了, 就會停止生 marine 并繼續餘下的 action.

和觸發相關的:
runtrigger: 運行一個指定的 trigger (可以是該 action 本身的 trigger). run trigger 下面的action 仍然會繼續運行(除非你選了 wait until it finishes). 留意可選擇 check condition 還是ignore condition (不理會該 trigger 的 condition 成立與否都會運行該 trigger).
stop trigger: 停止所有指定的執行中的 trigger. 上面提過一個 trigger 是可以有多個版本同時運行的. 這個指令就會殺掉所有版本.
turntrigger on/off: 關掉所有指定的 trigger. 跟 stop trigger 不同, turn trigger off只會防止該trigger 的 event 被觸發(直到重新被 turn trigger on 為止), 但不會理會已經在運行的trigger. 相反, stop trigger 只是停止在運行中的 trigger, 但該 trigger 仍可以在以後被觸發.


6) event 和 action 的參數 (parameter)

新加一個 event 或 action, 很多時都要自己改參數. 例如 Timer - Every 5.0 seconds of GameTime, 點一下 5.0 就可以把 5 改到你想要的時間. 又例如 create units with default facing,會先給你 Unit - Create 1 Unit for player 1 at Point using default facing(No Options). 你需要點 unit 選你想要創造的單位, 再點 point 選你要它出來的地方.你也可以改變創造單位的數目和擁有的玩家.

如果你想因應觸發的玩家或單位來創造新單位, 可以用 triggeringplayer, triggering unit 等等, 變成: Unit - Create 1 (Unit type of(Triggering unit)) for player (Triggering player) at Point usingdefault facing (No Options)

另外, 大部份有 integer / real parameter 的地方都可以用到以下的數學運算:
arithmetic(integer) / arithmetic (real): 給 integer variable / real variable進行加減乘除的運算. 留意這個 action 還有其他的數學有關的 action 都可以在一個 action 中重複使用, 拼成一些複雜的算式.

例如:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Variable - Set x = (((a + b) * h) / 2)

power/ square root / sine / cosine / tangent / arcsine / arccosine /arctangent from value / arctangent from deltas: 都是數學運算, 不用解釋吧!

還有一樣要注意的是有時在參數裡沒有你想要的選擇, 那第一是先想想你想要的參數類型對不對. 例如你想文字顯示玩家的晶礦量, 但 UI -Display Message for (All players) to Subtitle area 點 message你不會立即找到晶礦量的選擇. 因為 message 是 text, 晶礦量是 integer. 你必須要用 convert integerto text, 再在 text(0) 點一下 0, 找到 player property. 完成是這樣: UI - Display(Text((Player (Triggering player) Minerals))) for (All players) toSubtitle area


7) 一些常見錯誤

a)習慣了用 triggering unit, last created unit 後, 會發現這些參數很多地方都用得着. 但要小心不可以把一個trigger 內的這些參數直接用在其他 trigger 上. 如有必要, 要用 set variable 把 triggering unit的值給了一個 global variable, 然後在其他的 trigger 上讀取那個 global variable.

b) 另外, 這些參數不能維持長時間, 如果 trigger 中有 wait, 例如:
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Any Unit dies

Actions

Unit - Create 1 (Unit type of (Triggering unit)) for player (Triggeringplayer) at (Center of (Entire map)) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - Wait 2.0 Game Time seconds

Unit - Create 1 (Unit type of (Triggering unit)) for player (Triggeringplayer) at (Center of (Entire map)) using default facing (No Options)


那只有第一個 create unit 會被執行. 第二個 create unit 就會出錯誤. 正確的方法是把有用的參數用 local variable 保留:
&#160;&#160;&#160;&#160;
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Any Unit dies

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;TypeofUnitDied = No Game Link <Game Link - Unit>

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;OwningPlayer = 0 <Integer>

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

Unit - Create 1 (Unit type of (Triggering unit)) for player (Triggeringplayer) at (Center of (Entire map)) using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Variable - Set OwningPlayer = (Triggering player)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Variable - Set TypeofUnitDied = (Unit type of (Triggering unit))

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - Wait 2.0 Game Time seconds

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Create 1 TypeofUnitDied for player OwningPlayer at (Center of (Entire map)) using default facing (No Options)


c)有時用了 triggering unit, last created unit 但沒效果, 或出錯誤, 可能是因為 event本身不會產生這些參數 (例如 event: Timer - Every 5.0 seconds of Game Time).也有可能是用錯了參數, 例如 event: Unit - Any Unit is attacked, 被攻擊者是 triggeringunit, 攻擊者是 attaking unit, 一不小心就會弄錯.

d)有些 trigger 沒用的時候記得用 Trigger - Turn (trigger) Off 關掉. 例如 RPG 地圖 KO了一個頭目後, 就應該把跟那個頭目有關的 trigger 關掉, 否則以後不小心觸發了那些 trigger 就不知會產生甚麼問題.就算沒問題也有可能令電腦做多了不必要的運作.

e) 上面提過,有時找不到你想要的參數, 可能是因為類型不對, 如 integer vs real, unit vs unit type, unit vsunit group. 這些情況用 conversion 或其他 function 一般最終可以找到你想要的.


8) 實例


現在給幾個實例, 同時列出我用的方法, 當然也有其他的方法做.

a) 地圖開始時給所有玩家全地圖視野, 把鏡頭指到你希望的起始鏡頭及顯示歡迎字眼.

&#160;&#160;&#160;&#160;
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Game - Map initialization

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

Player Group - Pick each player in (All players) and do (Actions) (下面的visibility 和 camera 兩個 action 都只能用於一個玩家, 所以要先用這句選取了所有玩家.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Visibility - Create a visibility revealer for player (Picked player) within (Entire map)

Camera - Apply Camera 001 for player (Picked player) over 0.0 secondswith Existing Velocity% initial velocity, 0% deceleration, and IncludeTarget (這裡 camera 001 是一個在 camera palette 板面加了的鏡頭.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;UI - Display "Welcome to this demo! Please choose..." for (All players) to Subtitle area


b) 簡單的英雄選擇: 玩家點選一個英雄, 然後在指定的地方給玩家創造一個選了的英雄.

&#160;&#160;&#160;&#160;
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit Selection - Any Unit is Selected by player 1

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Trigger - Turn (Current trigger) Off&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (非常重要, 否則玩家就可以選 n 次了!)

Unit - Create 1 (Unit type of (Triggering unit)) for player 1 at Point001 using default facing (No Options) (point 001 是預先在 point palette 加了的point.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit Selection - Deselect all units for player 1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(要先取消玩家剛才的選取, 否則下一步便不能自動替玩家選取新的英雄.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit Selection - Select (Last created unit) for player 1

Camera - Apply (Default game camera) for player 1 over 2.0 seconds withExisting Velocity% initial velocity, 10% deceleration, and Don'tInclude Target (把鏡頭改回正常.)

Camera - Pan the camera for player 1 to Point 001 over 2.0 seconds withExisting Velocity% initial velocity, 10% deceleration, and Do Not usesmart panning (把鏡頭移到新英雄那裡.)


用這個方法要給每個玩家一個獨立的 trigger.

&#160;&#160;&#160;&#160;
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit Selection - Any Unit is Selected by player 2

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Trigger - Turn (Current trigger) Off

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Create 1 (Unit type of (Triggering unit)) for player 2 at Point 002 using default facing (No Options)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit Selection - Deselect all units for player 2

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit Selection - Select (Last created unit) for player 2

Camera - Apply (Default game camera) for player 2 over 2.0 seconds withExisting Velocity% initial velocity, 10% deceleration, and Don'tInclude Target

Camera - Pan the camera for player 2 to Point 002 over 2.0 seconds withExisting Velocity% initial velocity, 10% deceleration, and Do Not usesmart panning


當然還有很多更加華麗的選擇英雄的方法, 大家可以慢慢研究.

c) 在地圖開始及以後每10 秒就在指定的地方刷兵, 並指示它們攻擊目的地.

&#160;&#160;&#160;&#160;
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Game - Map initialization&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (地圖開始)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Timer - Every 10.0 seconds of Game Time&#160;&#160;&#160;&#160; (每10 秒)

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

Unit - Create 5 Zealot for player 1 at Point 001 using default facing(No Options) (給玩家1 刷5 個 zealot 放在 point 001)

Unit - Order all units in (Last created units) to ( Attack targeting(Position of Gateway [22.50, 32.50])) (Replace Existing Orders) (命令剛才刷的zealot 向玩家 2 的 gateway 的位置攻擊.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Create 5 Zealot for player 2 at Point 002 using default facing (No Options)

Unit - Order all units in (Last created units) to ( Attack targeting(Position of Gateway [40.50, 32.50])) (Replace Existing Orders)


d) 誰的 gateway 被炸爆了就輸!

給每一隊各造一個 trigger 比較簡單些:

&#160;&#160;&#160;&#160;
Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Gateway [22.50, 32.50] dies

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Game - End game in Victory for player 1 (Show dialogs, Show score screen)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Game - End game in Defeat for player 2 (Show dialogs, Show score screen)


&#160;&#160;&#160;&#160;Events

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Unit - Gateway [40.50, 32.50] dies

&#160;&#160;&#160;&#160;Local Variables

&#160;&#160;&#160;&#160;Conditions

&#160;&#160;&#160;&#160;Actions

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Game - End game in Victory for player 2 (Show dialogs, Show score screen)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Game - End game in Defeat for player 1 (Show dialogs, Show score screen)


把a) 至 d) 加起來基本上已是一個簡陋的 DotA 了! 當然, 要做一個真正見得人的地圖還要花很多功夫去畫地形, 造新技能, 造道具,刷更多的兵種, 造積分表等等. 不過對 trigger 有了基本的概念後其他的就慢慢加上去, 就可以造出很複雜的地圖!

e) 加送一個做出隨機效果的方法.

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
General - Switch (Actions) depending on (Random integer between 1 and 5)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(實際的數字可以自己改.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Cases

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - If (1)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

Unit - Create 1 Marine for player 1 at Point 001 using default facing(No Options) (5 份 1 的機會生一個 marine.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;General - If (2)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Actions

Unit - Create 1 Zergling for player 1 at Point 001 using default facing(No Options) (5 份 1 的機會生一個 zergling.)

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Default

Unit - Create 1 Zealot for player 1 at Point 001 using default facing(No Options) (如果上面沒有一個中就生一個 zealot, 即有 5 份 3 的機會.)


如果除最後一項外其他每一項的機會率也是不同, 那就要用到 if-then-else. 不過原理大至相同.


9) 總結

由於這個教程是給新手看的, 所以有很多 event, condition 和 action 都省略了. 大家如果都掌握了上面介紹的各種event, condition 和 action, 可以自己看看其他沒有介紹的, 包括 dialog, leaderboard,objective, text tag, timer, cargo unit, inventory 等等.最好是打開官方的戰役地圖或其他高手的地圖看看別人是怎寫的.

希望大家覺得這個教程有用. 如有錯漏希望各位指出. 當然還有是轉載的話就請寫明作者是GA 的 Wakeman!


triggertutorial1.jpg
triggertutorial2.jpg
triggertutorial3.jpg

demo.SC2Map

10 KB, 下载次数: 26

SimpleExample.SC2Map

15 KB, 下载次数: 29

评分

参与人数 1威望 +4 收起 理由
Renee + 4 幸苦幸苦~~

查看全部评分

 楼主| 发表于 2010-9-22 21:16:07 | 显示全部楼层
其他相關的帖子:

[新手向演示教程]一个资源采集排行榜的演示地图 <= 頭目寫的很詳細的排行榜(leaderboard)教程



附:

Text Message (UI - Display (Text) for (All players) to XXX area) 的位置:

Screenshot2010-10-09 20_50_40.jpg
回复

使用道具 举报

发表于 2010-9-22 22:09:00 | 显示全部楼层
表扬。
回复

使用道具 举报

发表于 2010-9-22 22:59:05 | 显示全部楼层
辛苦
回复

使用道具 举报

发表于 2010-9-22 23:17:48 | 显示全部楼层
感谢 对触发真的不了解
回复

使用道具 举报

 楼主| 发表于 2010-9-23 11:58:42 | 显示全部楼层
花了一天半寫的, 都是些很基本的東西, 希望對觸發方面的新手有用. 至於進一步的教程或演示, 就由其他高手有空寫寫吧!
回复

使用道具 举报

发表于 2010-9-23 13:21:31 | 显示全部楼层
等你補完後…我再補上剩下的>3<(我雖為菜鳥…但也懂一點毛皮的=3=)
回复

使用道具 举报

 楼主| 发表于 2010-9-23 19:42:56 | 显示全部楼层

回 6楼(wilson98k) 的帖子

頭目之前寫了有關 leaderboard 的教程, 其他的你都可以寫寫! 我暫時還是不要再班門弄斧了.  :P
回复

使用道具 举报

发表于 2010-9-23 21:19:13 | 显示全部楼层
比起官方的action,我更喜歡寫新的action…一大排的action擠在一起令我頭腦發暈…|暫時我寫了transmission和objective,之後準備寫進階產兵…之類的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-5-6 20:56 , Processed in 0.212739 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表