本帖最后由 Minecraft.Wnxi 于 2022-7-28 10:47 编辑 
想在名为King的僵尸死后(被杀死)触发tittle和tp指令
解决了:设自定义掉落物,然后清除,后接连锁
解决了:设自定义掉落物,然后清除,后接连锁
条件子命令
条件子命令if和unless用于限制命令只有在指定的条件下执行。if为如果......就,而unless为除非......否则。 除此之外两者都有相同的参数结构。
比如
- execute unless entity 实体 run 指令
是1.13+版本吗?如果是的话,就循环execute unless @e[name=King] run 你要触发的指令,即检测不到名为King的实体就执行后续指令
 本帖最后由 尸先peng 于 2022-7-27 21:13 编辑 
 execute unless entity @a[type=zombie,name=king] run title...
 execute unless entity @a[type=zombie,name=king] run title...
 execute unless entity @a[type=zombie,name=king] run tp...
execute unless entity @a[type=zombie,name=king] run tp...
检测不到目标就执行加粗字体的指令
(这个是1.13+的指令,之后记得说一下游戏版本)
 execute unless entity @a[type=zombie,name=king] run tp...
execute unless entity @a[type=zombie,name=king] run tp...检测不到目标就执行加粗字体的指令
(这个是1.13+的指令,之后记得说一下游戏版本)
 本帖最后由 Muggle2077 于 2022-7-27 22:58 编辑 
由上一个提问可知,名为 King 的僵尸,拥有 boss 标签。
I
先建立一个记分板。
复制代码
再高频检测 boss 是否死亡。
复制代码
解释:
函数 foo:bar
复制代码
II
先写一个进度 foo:aaa,来检测玩家杀死 BOSS。
复制代码
再写一个函数 foo:bbb,来执行命令。
复制代码
III
让 BOSS 使用特定的死亡战利品表,使其在死亡后掉落带有特定 NBT 的物品,然后检测该物品即可。
使用此方法甚至可以知道 BOSS 死亡的具体位置,代码略。
由上一个提问可知,名为 King 的僵尸,拥有 boss 标签。
I
先建立一个记分板。
- scoreboard objectives add foo dummy
再高频检测 boss 是否死亡。
- execute unless entity @e[type=zombie,tag=boss] unless score #killed foo matches 1 run function foo:bar
解释:
- unless entity @e[type=zombie,tag=boss] 表示实体 @e[type=zombie,tag=boss] 不存在。
- unless score #killed foo matches 1 表示名叫 #killed 的玩家 foo 记分板的分数不是 1。
- run function foo:bar 表示运行函数 foo:bar。
- 在函数 foo:bar 中将分数设置为 1,以防止该函数被再次运行。即防止 BOSS 死亡后一直 tp 玩家,一直向玩家显示标题。
 
函数 foo:bar
- scoreboard players set #killed foo 1
 
- tp @a 2 3 3
 
- title @a title "BOSS已经被成功击杀!"
II
先写一个进度 foo:aaa,来检测玩家杀死 BOSS。
- {
 
-   "rewards": {
 
-     "function": "foo:bbb"
 
-   },
 
-   "criteria": {
 
-     "player_killed_king": {
 
-       "trigger": "minecraft:player_killed_entity",
 
-       "conditions": {
 
-         "entity": {
 
-           "nbt": "{Tags:['boss']}"
 
-         }
 
-       }
 
-     }
 
-   }
 
- }
再写一个函数 foo:bbb,来执行命令。
- tp @a 2 3 3
 
- title @a title "BOSS已经被成功击杀!"
III
让 BOSS 使用特定的死亡战利品表,使其在死亡后掉落带有特定 NBT 的物品,然后检测该物品即可。
使用此方法甚至可以知道 BOSS 死亡的具体位置,代码略。
建议用 /tag 标明一下需要触发此指令的玩家
版本:1.13+ (此前与 /tag 同样功能的指令是 /scoreboard players tag,但我可能不会用,所以不提)
例:指定玩家周围 50格内 不存在僵尸,且僵尸由玩家击杀时玩家获胜
注:黄色 为 只要触发一次,紫色 为 循环 保持开启,绿色 为 连锁 条件制约 保持开启,且需要和前一个按图示要求连续摆放(注意方向)
 execute as @a at @s if entity @e[type=minecraft:zombie, distance=..50, name="king"] run tag @s add KS
execute as @a at @s if entity @e[type=minecraft:zombie, distance=..50, name="king"] run tag @s add KS execute as @a[tag=KS] run scoreboard player set @s kingslayed 0
execute as @a[tag=KS] run scoreboard player set @s kingslayed 0 execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run title "Congradulated!"
execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run title "Congradulated!" execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run tp @s 0 0 0
execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run tp @s 0 0 0 execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run scoreboard player set @s kingslayed 0
execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run scoreboard player set @s kingslayed 0 execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run tag @s remove KS
execute as @a[tag=KS,score={kingslayed=1..}] at @s unless entity @a[type=zombie, distance=..50,  name="king"] run tag @s remove KS可能的问题:如果某个玩家挑战僵尸"king",但打死了一只普通的僵尸就 run 了,这种按上面的规则是算挑战成功的((
(本人指令小白,如果还有其他问题希望大佬多多指教,谢谢!)