How do I set off a chain of command blocks if a players health goes to a certain health. (Java, 1.17)

How do I set off a chain of command blocks if a players health goes to a certain health. (Java, 1.17) - Spice Bottles on Shelf

I want a chain of command blocks to go off if a player or entities health drops to a certain number. When I try it, it doesn't set off the command blocks, or it doesn't even set off at all.



Best Answer

Setup:

  • scoreboard objectives add Health dummy
  • Tag the entity you want to track. In this answer, the tag myEntity will be used.
  • You should also know how much health your entity has. Use /data get entity @e[tag=myEntity] Health

Command blocks:

Repeating, Unconditional:

execute as @e[tag=myEntity] store result score @s Health run data get entity @s Health

Chain, Unconditional, Always Active:

execute if score @e[tag=myEntity,tag=!health_reached,limit=1] Health matches 20..40

Chain, Conditional, Always Active:

tag @e[tag=myEntity] add health_reached

Chain, Unconditional, Always Active:

say myEntity has between 20 and 40 Health

Your command blocks should look like this: A command block chain, including repeating, chain-unconditional, and chain-conditional command blocks.

You can add more Chain, Unconditional, Always Active blocks to the end of the chain to have more things happen when myEntity reaches 20-40 Health.




Pictures about "How do I set off a chain of command blocks if a players health goes to a certain health. (Java, 1.17)"

How do I set off a chain of command blocks if a players health goes to a certain health. (Java, 1.17) - Composition of multicolored hearts on pink surface
How do I set off a chain of command blocks if a players health goes to a certain health. (Java, 1.17) - Gym Tools
How do I set off a chain of command blocks if a players health goes to a certain health. (Java, 1.17) - Exercise Tools On Gray Surface



How do you set a health player in Minecraft?

To set the health of a player, set that player's sethealth scoreboard to what health you want that player to have, then run the function editor:set_health as the player you want to edit health and you are done.

How do you check the health of an entity in Minecraft?

Using the execute store result score command, we can store the Health of an entity onto a scoreboard. To do so, we will use a dummy scoreboard. If you use /scoreboard objectives setdisplay sidebar , you can view your Health on the sidebar.

What does chain do on a command block?

A chain command block executes every time when triggered. A repeating command block executes every game tick as long as it is activated.



How do Conditional Command Blocks work in Minecraft 1.15? [Tutorial]




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Pixabay, Karolina Grabowska, Mikhail Nilov, Mikhail Nilov