外观
动作与脚本流程
Action 是机关触发以后真正发生的事情。一个触发器可以执行多个动作,例如开门、播放声音、生成怪物,再向玩家提示任务目标。动作写在触发器的 actions 列表中,type 决定动作种类。
📷 效果展示
🗝️ 制作一扇消耗钥匙的机关门
先在物品库中创建 遗迹钥匙,再建立两个点位:工作台机关 用来点击,石门 对应需要清除的方块。打开模板的 triggers 目录,新建 钥匙门.yml:
yaml
钥匙门:
enabled: true
event: block_click
target: 'point:工作台机关'
scope: INSTANCE
once: true
conditions:
- type: item
item: 遗迹钥匙
amount: 1
actions:
- type: take_item
item: 遗迹钥匙
amount: 1
- type: break_block
target: 'point:石门'
drop: false
- type: message
text: '&a石门已开启!'没有钥匙时条件不通过,不执行后面的动作。成功时扣除一把钥匙、清除门的方块并提示玩家。INSTANCE 配合 once: true 让整个遗迹实例共享一次开启机会。
如果想让门在打开后 5 秒关闭,将下面的动作添加到同一个 actions 列表末尾;同时把 once 改为 false,并为触发器设置 cooldown-ticks: 100。
yaml
- type: delay
ticks: 100
actions:
- type: set_block
target: 'point:石门'
material: STONE
data: 0delay 延迟的是自己的子动作,而不是让服务器线程休眠。20 Tick 约等于 1 秒。
位置写法
| 写法 | 作用 |
|---|---|
player | 当前触发玩家所在位置 |
point:石门 | 模板中名为石门的点位 |
block:5,1,6 | 模板相对方块坐标 |
relative:5,1,6 | 相对坐标的兼容写法 |
region:核心房间 | 区域中心,数量统计条件可用整个区域 |
last_safe | 最近安全位置 |
支持 offset 的动作可在目标基础上偏移 [x, y, z];它跟随遗迹旋转和镜像。下面各段是独立的动作示例,选择需要的条目加入自己的 actions,不需要整页复制。
消息、声音与粒子
用来给玩家反馈机关状态。消息支持颜色代码;{player}、{instance}、{template} 是内置动态文本。
message
text 是仅发给触发玩家的聊天文字。
yaml
actions:
- type: message
text: '&a全部 Condition 都通过以后,才会看到这条消息。'broadcast
text 会广播给全服玩家。
yaml
actions:
- type: broadcast
text: '&6{player} 触发了一个遗迹机关。'actionbar
text 显示在快捷栏上方。
yaml
actions:
- type: actionbar
text: '&e这是 ActionBar'title
title / subtitle 分别为主副标题;fade-in、stay、fade-out 是淡入、停留、淡出时长,单位 Tick。
yaml
actions:
- type: title
title: '&6主标题'
subtitle: '&7副标题'
fade-in: 10
stay: 40
fade-out: 10command
command 填不带 / 的命令;默认由控制台执行。
yaml
actions:
- type: command
command: say {player} 触发机关sound
sound 为 Bukkit 声音名称;volume 控制音量,pitch 控制音调,1 为正常音调。
yaml
actions:
- type: sound
sound: ENTITY_EXPERIENCE_ORB_PICKUP
volume: '1'
pitch: '1'particle
particle 为粒子名称,count 为数量;center 决定点位是否居中;offset-x/y/z 为三轴扩散,extra 为粒子的额外参数。
yaml
actions:
- type: particle
target: point:工作台机关
particle: END_ROD
count: 10
center: true
offset-x: '0.3'
offset-y: '0.3'
offset-z: '0.3'
extra: '0'物品、传送与方块
物品 ID 来自 Extension 物品库,坐标使用前面的写法。
give_item
item 物品 ID,amount 数量;背包放不下时 overflow: DROP 掉在地上,IGNORE 不放入多余物品。
yaml
actions:
- type: give_item
item: 遗迹金币袋
amount: 1
overflow: DROPtake_item
从背包扣除 amount 个指定物品;可先用 item 条件检查数量。
yaml
actions:
- type: take_item
item: 遗迹钥匙
amount: 1drop_item
将 amount 个物品生成在 target 加 offset 的位置,不直接放进背包。
yaml
actions:
- type: drop_item
item: 遗迹金币袋
amount: 1
target: point:工作台机关
offset:
- 0
- 1
- 0teleport
把玩家传送到 target。
yaml
actions:
- type: teleport
target: point:入口地面velocity
x、y、z 是三轴速度分量;示例只改变竖直速度,让玩家向上弹起。
yaml
actions:
- type: velocity
x: '0'
y: '0.5'
z: '0'set_block
material 是方块材质,data 是旧版数据值;现代版本可用 block-data 指定完整方块状态。
yaml
actions:
- type: set_block
target: point:工作台机关
material: STONE
data: 0break_block
drop: false 直接清除方块,true 允许正常破坏掉落。
yaml
actions:
- type: break_block
target: point:工作台机关
drop: falsespawn_entity
entity 为 Bukkit 实体类型,count 为生成数量。
yaml
actions:
- type: spawn_entity
target: point:工作台机关
offset:
- 0
- 2
- 0
entity: ZOMBIE
count: 1spawn_mythicmob
id 为 MythicMobs 怪物内部 ID,level 为生成等级。GUI 可从 MM 生物列表选择。
yaml
actions:
- type: spawn_mythicmob
target: block:7,1,3
id: ExampleBoss
level: 1变量与流程控制
变量可以保存机关次数和挑战进度。作用域使用 PLAYER、PARTY、INSTANCE、GLOBAL;同一个变量名在不同作用域不共享。
set_variable
key 为变量名,value 为要写入的值。
yaml
actions:
- type: set_variable
scope: INSTANCE
key: example_value
value: '1'add_variable
对指定数字变量加上 value,例如累加击杀数。
yaml
actions:
- type: add_variable
scope: INSTANCE
key: example_value
value: '2'remove_variable
删除指定作用域下的 key。
yaml
actions:
- type: remove_variable
scope: INSTANCE
key: example_valuedelay
等待 ticks 后执行子 actions。
yaml
actions:
- type: delay
ticks: 20
actions:
- type: message
text: '&7这条消息延迟约 1 秒执行。'random
以 chance(0~1)概率执行子 actions;0.5 表示 50%。
yaml
actions:
- type: random
chance: 0.5
actions:
- type: message
text: '&d你命中了 50% 随机 Action。'repeat
重复执行子 actions,count 为次数,内部最多 1000 次。
yaml
actions:
- type: repeat
count: 3
actions:
- type: particle
target: point:工作台机关
particle: END_ROD
count: 2if
计算 expression,成立执行 then 列表,否则执行 else。
yaml
actions:
- type: if
expression: player.health > 10
then:
- type: message
text: '&a你的生命值大于 10。'
else:
- type: message
text: '&c你的生命值不大于 10。'wait_condition
每隔 interval-ticks 检查 expression;成立执行 actions;等待超过 timeout-ticks 后执行 on-timeout。
yaml
actions:
- type: wait_condition
expression: instance.example_value >= 3
interval-ticks: 10
timeout-ticks: 200
actions:
- type: message
text: '&a等待条件已经满足。'
on-timeout:
- type: message
text: '&c等待超时。'阶段、恢复与动态全息
恢复规则的详细取值见 区域保护与恢复。
start_stage
flow 为阶段流程 ID,stage 为目标阶段。
yaml
actions:
- type: start_stage
flow: main
stage: finishedfinish_stage
结束指定 flow。
yaml
actions:
- type: finish_stage
flow: mainset_block_policy
修改遗迹的 break、place、break-drops 与 restore 规则。
yaml
actions:
- type: set_block_policy
break: ALLOW
place: ALLOW
break-drops: NO_DROP
restore: falseset_restore_policy
修改自动补全规则;point 非空时优先修改点位,否则使用 region,两者为空作用于整个遗迹。
yaml
actions:
- type: set_restore_policy
region: 核心房间
point: ''
mode: DELAY_BLOCK
delay-ticks: 100
wait-player-clear: true
verify: false
retry-ticks: 10
max-wait-ticks: 600restore_ruin
按指定恢复模式恢复结构,INHERIT 继承模板设置。
yaml
actions:
- type: restore_ruin
mode: INHERITrestore_region
按指定模式恢复 region 对应区域。
yaml
actions:
- type: restore_region
region: 核心房间
mode: INHERITreset_ruin
重置实例,恢复结束后重新进入 ACTIVE,并重置阶段流程。
yaml
actions:
- type: reset_ruin
mode: INHERITcancel_pending_restore
取消指定区域的补全任务;clear-delta 控制是否同时删除变化记录。
yaml
actions:
- type: cancel_pending_restore
region: 核心房间
clear-delta: falsedisable_restoration
关闭恢复,clear-pending: true 同时取消等待中的恢复并清理记录。
yaml
actions:
- type: disable_restoration
clear-pending: trueenable_restoration
重新开启恢复。
yaml
actions:
- type: enable_restorationhologram_create
id 为动态全息 ID;provider 为全息实现选择;target 和 offset-x/y/z 控制位置,lines 为逐行文本。
yaml
actions:
- type: hologram_create
id: 临时提示
provider: INHERIT
target: block:5,1,6
offset-x: 0.5
offset-y: 1.8
offset-z: 0.5
lines:
- '&e这里是一个动态全息'
- '&7遗迹实例:{instance}'hologram_remove
删除与 id 对应的动态全息。
yaml
actions:
- type: hologram_remove
id: 临时提示地牢流程与多分支
set_point_state
给点位记录一个状态字符串,供 point_state 条件判断。它不是改变方块材质的动作。下面将 Boss 核心标记为已解锁:
yaml
actions:
- type: set_point_state
point: Boss核心
state: UNLOCKEDnext_floor
用于无限地牢的下一层入口。message 只在切换成功后发送,可省略。
yaml
actions:
- type: next_floor
message: '&b正在为队伍切换到下一层……'complete_dungeon / fail_dungeon
前者结束当前地牢并判定成功;后者判定失败,reason 可以写失败原因。二者应放在不同的触发器中。
yaml
actions:
- type: complete_dungeonyaml
actions:
- type: fail_dungeon
reason: 挑战时间耗尽revive_player
复活指定地牢玩家。player 省略时使用触发玩家名称。
yaml
actions:
- type: revive_playerswitch
将 expression 的结果转换为字符串,再从 cases 中寻找同名分支。没有同名分支时执行 default(若定义);每个分支都是动作列表。例如根据一个布尔表达式选择消息:
yaml
actions:
- type: switch
expression: '1 > 0'
cases:
'true':
- type: message
text: '&a条件成立!'
default:
- type: message
text: '&c条件不成立。'