如题 版本1.14
本帖最后由 (=°ω°)丿 于 2020-4-17 12:46 编辑
对所有实体均有效,不仅仅只是玩家。
代码:
- # 初始化
- ## 血量记分板
- scoreboard objectives add health dummy
- ## 备用记分板
- scoreboard objectives add health2 dummy
代码:
- # 高频
- ## 获取血量
- execute as @e store result score @s health run data get entity @s Health
- ## 如果血量不相等
- execute as @e unless score @s health2 = @s health run function health:if
代码:
- # 函数 health:if
- ## 如果血量减少
- execute if score @s health < @s health2 run say 我受伤了
- ## 更新数据
- scoreboard players operation @s health2 = @s health
对所有实体均有效,不仅仅只是玩家。
这边建议使用execute或者记分板指令哦
本帖最后由 brooke_zb 于 2020-4-5 09:53 编辑
用计分板,minecraft.custom:minecraft.damage_taken准则能够检测玩家受到的伤害,大于0即受到攻击,检测+后续指令后分数清零即可
创建计分板
复制代码检测+后续复制代码清空分数复制代码
用计分板,minecraft.custom:minecraft.damage_taken准则能够检测玩家受到的伤害,大于0即受到攻击,检测+后续指令后分数清零即可
创建计分板
- scoreboard objectives add damage minecraft.custom:minecraft.damage_taken
- execute if score @s damage matches 0.. run 后续指令
- scoreboard players reset <span id="kM0.1352018499512304">@s damage</span>
检测@a[nbt={HurtTime:9s}]
相比上面的方法能耗最高但是最简单
相比上面的方法能耗最高但是最简单