枯若Kuro
如题 版本1.14

(=°ω°)丿
本帖最后由 (=°ω°)丿 于 2020-4-17 12:46 编辑

代码:

  1. # 初始化
  2. ## 血量记分板
  3. scoreboard objectives add health dummy
  4. ## 备用记分板
  5. scoreboard objectives add health2 dummy

代码:

  1. # 高频
  2. ## 获取血量
  3. execute as @e store result score @s health run data get entity @s Health
  4. ## 如果血量不相等
  5. execute as @e unless score @s health2 = @s health run function health:if

代码:

  1. # 函数 health:if
  2. ## 如果血量减少
  3. execute if score @s health < @s health2 run say 我受伤了
  4. ## 更新数据
  5. scoreboard players operation @s health2 = @s health

对所有实体均有效,不仅仅只是玩家。

Kunst
这边建议使用execute或者记分板指令哦

brooke_zb
本帖最后由 brooke_zb 于 2020-4-5 09:53 编辑

用计分板,minecraft.custom:minecraft.damage_taken准则能够检测玩家受到的伤害,大于0即受到攻击,检测+后续指令后分数清零即可
创建计分板
  1. scoreboard objectives add damage minecraft.custom:minecraft.damage_taken
复制代码
检测+后续
  1. execute if score @s damage matches 0.. run 后续指令
复制代码
清空分数
  1. scoreboard players reset <span id="kM0.1352018499512304">@s damage</span>
复制代码


Jokey_钥匙
检测@a[nbt={HurtTime:9s}]
相比上面的方法能耗最高但是最简单

第一页 上一页 下一页 最后一页