跳至主要内容

Elite Script 條件

條件允許腳本編寫者根據特定條件使腳本和/或動作執行。

範例
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 系統來指定哪個實體或位置會受到條件的影響。這意味著你可以將條件關聯到首領、玩家或任何你可以指定的目標。


Condition Type

詳情
conditionType設定條件的類型BLOCKING / FILTERING

有兩種類型的條件:BLOCKINGFILTERINGBLOCKING 條件會使腳本或動作停止執行。FILTERING 條件會使動作跳過不符合條件的目標。這意味著如果你只想指定非空氣的方塊,你會需要 FILTERING 條件,但如果你想在玩家死亡時停止動作,你會需要 BLOCKING 條件。

動作之外的條件始終是 BLOCKING。動作內部的條件可以是 BLOCKINGFILTERING

注意:如果目標是 SELF(首領)且條件檢查是 isAlive,則該檢查始終是 BLOCKING! 這可以放在 FILTERING 條件內,但這個特定部分仍然會表現為 BLOCKING

動作內部的條件預設設定為 FILTERING


Condition Block Placement

你可以用兩種方式放置或嵌套條件區塊:

  1. 在個別動作下 – 條件只會應用於特定動作。如果條件符合,動作會執行;否則不會執行。

  2. 在整個腳本下 – 條件會應用於腳本內的所有動作。如果條件不符合,所有動作都不會執行。

以下是範例,展示如何為個別動作和整個腳本嵌套條件區塊。

在個別動作下:

範例
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 動作,因為沒有條件應用於它。

在整個腳本下:

範例
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"

如果首領所站位置上方兩格的方塊是空氣,則在生物被攻擊時允許所有腳本執行。否則,阻止整個腳本執行,包括 SET_WEATHER 和 MESSAGE 動作。


runIfConditionIs

詳情
runIfConditionIs設定條件為真或假時是否允許動作執行。true / false

你可以通過在條件名稱前使用 runIf 前綴和 Is 後綴來反轉條件。

例如,以 isAlive 條件為例。通常,寫下: isAlive: true 意味著動作只有在首領存活時才會執行。

但如果你也寫下: runIfIsAliveIs: false 在同一個條件中,則條件會反轉 — 現在動作只有在首領死亡時才會執行。

這種結構允許你控制在執行動作之前條件應該通過還是失敗。

範例:

eliteScript:
Example:
Events:
- EliteMobDamagedByPlayerEvent
Actions:
- action: SET_WEATHER
Target:
targetType: SELF
weather: THUNDER
duration: 120
Conditions:
conditionType: BLOCKING
isAlive: true
runIfIsAliveIs: false
Target:
targetType: SELF

這個腳本現在只有在首領死亡時才會將天氣設定為雷暴。


基於位置的條件

locationIsAir

設定條件為目標位置是否為空氣。

詳情
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

檢查位置是否在地板上。這意味著該位置的方塊不是固體,但其下方的方塊是固體。

詳情
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

檢查目標下方的位置是否為匹配的材質類型。

詳情
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

設定條件為條件目標實體是否存活。

詳情
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

檢查目標實體是否有特定標籤。腳本編寫者可以通過動作指定和取消指定任何標籤,並將它們用作後續行為的條件。標籤只是你可以指定給首領的字串(單詞)。

詳情
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 相同,但檢查首領是否沒有這些值。

詳情
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

使條件有隨機機率為有效。

詳情
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_MOBSNEARBY_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

創建一個條件,只有當指定的目標數量低於或大於定義的值時才允許動作執行。

詳情
targetCountLowerThan只有當目標數量低於指定數字時才執行動作。介於 0 和 999 之間的數字
詳情
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 個生物時,腳本才會執行。

注意,這個條件確實需要目標。