Elite Script 條件
條件(Conditions)讓腳本編寫者能夠根據特定條件,使腳本與/或動作不執行。
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Conditions:
isAlive: true
conditionType: BLOCKING
Target:
targetType: SELF
Actions:
- action: PLACE_BLOCK
Target:
targetType: DIRECT_TARGET
duration: 20
material: DIRT
offset: 0,3,0
Conditions:
locationIsAir: true
conditionType: BLOCKING
Target:
targetType: ACTION_TARGET
Cooldowns:
local: 60
global: 20
在此範例中,Example 腳本只會在精英仍存活時執行,並且只有在精英所在位置上方 3 格的方塊為空氣方塊時,才會在該處放置一個泥土方塊。個別動作可以擁有各自的條件。
Target
條件使用 Targets 系統來指定哪個實體或位置會受到條件約束。這代表你可以將條件關聯到首領、玩家,或任何其他你能指定的目標。
條件類型
| Key | Details | Values |
|---|---|---|
conditionType | 設定條件的類型 | BLOCKING / FILTERING |
條件分為兩種類型:BLOCKING(阻擋)與 FILTERING(篩選)。BLOCKING 條件會讓腳本或動作停止執行。FILTERING 條件會讓動作跳過不符合條件的目標。也就是說,如果你只想以非空氣的方塊為目標,你會需要 FILTERING 條件;但如果你想在玩家死亡時停止某個動作,你會需要 BLOCKING 條件。
動作之外的條件永遠是 BLOCKING。動作之內的條件則可以是 BLOCKING 或 FILTERING。
注意:如果目標是 SELF(首領)且條件檢查為 isAlive,該檢查永遠是 BLOCKING! 即使把它放在 FILTERING 條件裡,這個特定部分仍會以 BLOCKING 的方式運作。
動作之內的條件預設為 FILTERING。
條件區塊放置
你可以用兩種方式放置或巢狀條件區塊:
-
置於個別動作之下 – 條件只會套用在某個特定動作上。若符合條件,動作便執行;否則就不執行。
-
置於整個腳本之下 – 條件會套用到腳本內的所有動作。若不符合條件,則所有動作都不會執行。
以下範例示範如何為個別動作與整個腳本巢狀放置條件區塊。
置於個別動作之下:
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: MESSAGE
Target:
targetType: NEARBY_PLAYERS
range: 10
sValue: "&2Hello World!"
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
locationIsAir: true
Target:
targetType: SELF
offset: "0,3,0"
檢查首領站立位置上方 2 格的位置是否為空氣,如果是,則在怪物被攻擊時執行 SET_WEATHER 動作;否則就阻擋 SET_WEATHER 動作。但由於沒有對 MESSAGE 動作套用任何條件,首領被攻擊時永遠都會執行 MESSAGE 動作。
置於整個腳本之下:
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: MESSAGE
Target:
targetType: NEARBY_PLAYERS
range: 10
sValue: "&2Hello World!"
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
locationIsAir: true
Target:
targetType: SELF
offset: "0,3,0"
如果首領站立位置上方 2 格的方塊為空氣,則在怪物被攻擊時允許所有腳本執行;否則就阻擋整個腳本執行,包括 SET_WEATHER 與 MESSAGE 動作。
runIfConditionIs
| Key | Details | Values |
|---|---|---|
runIfConditionIs | 設定條件為 true 或 false 時,是否允許動作執行。 | true / false |
你可以在條件名稱前後加上 runIf 前綴與 Is 後綴來反轉一個條件。
舉例來說,以 isAlive 條件為例。一般情況下,寫成:
isAlive: true
代表動作只會在首領存活時執行。
但如果你在同一個條件中也寫上:
runIfAliveIs: false
那麼條件就會被反轉——此時動作只會在首領死亡時才執行。
這種結構讓你能在執行動作之前,控制條件應該通過還是失敗。
範例:
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
isAlive: true
runIfAliveIs: false
Target:
targetType: SELF
此腳本現在只會在首領死亡時將天氣設為雷暴。
基於位置的條件
locationIsAir
將條件設定為目標所在位置是否為空氣。
| Key | Details | Values |
|---|---|---|
locationIsAir | 設定用來檢查該位置是否為空氣方塊(或相反)。 | Boolean |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
locationIsAir: true
Target:
targetType: SELF
offset: "0,3,0"
檢查首領站立位置上方 2 格的位置是否為空氣,如果是,則在怪物被攻擊時不阻擋天氣腳本執行;否則就阻擋該動作。
isOnFloor
檢查該位置是否位於地面上。這代表該位置的方塊不是固體,但其下方的方塊是固體。
| Key | Details | Values |
|---|---|---|
isOnFloor | 設定用來檢查該位置是否為地面位置(或相反)。 | Boolean |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
isOnFloor: true
Target:
targetType: SELF
檢查首領是否站在固體方塊上,如果是,則執行腳本;否則就阻擋腳本執行。
isStandingOnMaterial
檢查目標下方的位置是否為符合的材質類型。
| Key | Details | Values |
|---|---|---|
isStandingOnMaterial | 設定要檢查的材質類型。 | Material |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
isStandingOnMaterial: BIRCH_WOOD
Target:
targetType: SELF
只有當首領站在 BIRCH_WOOD 方塊上時才會執行,否則腳本將被阻擋執行。
基於實體的條件
isAlive
將條件設定為條件的目標實體是否存活。
| Key | Details | Values |
|---|---|---|
isAlive | 設定用來檢查該實體是否存活(或死亡)。 | Boolean |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
isAlive: true
Target:
targetType: SELF
只有當首領目前存活時才會執行,否則腳本將被阻擋。
hasTags
檢查目標實體是否擁有特定標籤。腳本編寫者可以透過動作來指派與移除任意標籤,並將它們用作後續行為的條件。標籤就只是一些字串(文字),你可以將它們指派給首領。
| Key | Details | Values |
|---|---|---|
hasTags | 設定用來檢查該實體是否擁有一組標籤。 | String List |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
hasTags:
- isCool
- hasANiceBeard
Target:
targetType: SELF
只有當首領同時擁有「isCool」與「hasANiceBeard」標籤時才會執行,否則腳本將被阻擋。
doesNotHaveTags
與 hasTags 相同,但檢查的是首領沒有這些值。
| Key | Details | Values |
|---|---|---|
doesNotHaveTags | 設定用來檢查該實體是否沒有一組標籤。 | String List |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
doesNotHaveTags:
- isStinky
- isSus
Target:
targetType: SELF
只有當首領沒有「isStinky」與「isSus」標籤時才會執行,否則腳本將被阻擋。
其他條件
randomChance
賦予條件一個隨機成立的機率。
| Key | Details | Values |
|---|---|---|
randomChance | 條件成立的機率。 | 介於 0.0 與 1.0 之間的數字 |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
randomChance: 0.1
Target: # Not required
targetType: SELF # Not required
這會讓腳本有 10% 的機率執行,否則腳本將被阻擋。
請注意,這個條件比較特殊,因為它不需要目標。
使用標籤篩選 NEARBY
若要根據特定標籤篩選 NEARBY_MOBS 或 NEARBY_PLAYERS,請使用 ACTION_TARGET 作為條件的目標(前提是該條件套用在動作上,而非腳本本身)。這能確保腳本準確地只篩選出帶有指定標籤的怪物/玩家。
範例
eliteScript:
Example:
Actions:
- action: SET_MOB_AI
Target:
targetType: NEARBY_MOBS
range: 40
bValue: false
Conditions:
conditionType: FILTERING
hasTags:
- TurnOff
Target:
targetType: ACTION_TARGET
這個腳本會尋找附近任何帶有 TurnOff 標籤的怪物,如果牠們擁有該標籤,便會關閉牠們的 AI。
targetCountLowerThan 與 targetCountGreaterThan
建立一個條件,只有在指定的目標數量低於或高於所定義的值時,才允許動作執行。
| Key | Details | Values |
|---|---|---|
targetCountLowerThan | 只有在目標數量低於指定數字時才執行該動作。 | 介於 0 與 999 之間的數字 |
| Key | Details | Values |
|---|---|---|
targetCountGreaterThan | 只有在目標數量高於指定數字時才執行該動作。 | 介於 0 與 999 之間的數字 |
範例
eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
targetCountGreaterThan: 2
Target: #required
targetType: NEARBY_MOBS #required
range: 15
只有當 15 格半徑內有超過 2 隻怪物時,腳本才會執行。
請注意,這個條件確實需要目標。