How to execute a command block once taking hits?

How to execute a command block once taking hits? - Domino blocks in a row and human hand trying to take one of it

So, I am doing a little Minecraft adventure map and the number one thing I keep getting stuck on is how to execute a command block once a zombie hits you three times. Thanks! :D



Best Answer

It's possible, but not 100% reliable. You want to repeatedly testfor a Zombie in less then 1 block from a Player (hitting distance) 3x:

/execute @e[type=Zombie] ~ ~ ~ testfor @a[r=1]

Or the other way around: /execute @a ~ ~ ~ testfor @e[type=Zombie, r=1]

1) Put one of these commands into a Command block with a Comparator facing out of it.

2) Then, use a Redstone impulse lengthener as shown below to lengthen the signal to like 10 seconds.

3) Add a Piston that allows a clock to repeatedly trigger a Command block.

4) This Command blog should have the same command as above.

5) Repeat this one time more and you got it done.

6) Add a fourth CMD block at the end with you own command.

Redstone signal lengthener:

SUPER REDSTONE!
(Instead of "door" use "Next Command block")




Pictures about "How to execute a command block once taking hits?"

How to execute a command block once taking hits? - Man taking one of the domino blocks from a side view
How to execute a command block once taking hits? - Man taking one of the domino blocks and focusing on it
How to execute a command block once taking hits? - Man sitting and taking one of the domino blocks



Quick Answer about "How to execute a command block once taking hits?"

  • Put one of these commands into a Command block with a Comparator facing out of it.
  • Then, use a Redstone impulse lengthener as shown below to lengthen the signal to like 10 seconds.
  • Add a Piston that allows a clock to repeatedly trigger a Command block.


  • How do you activate a command block once?

    To make your command block run multiple commands, you will need to summon FallingSand or falling_block (depending on your version of Minecraft) with command blocks and redstone blocks for each command. The command blocks will be stacked one on top of the other and contain the individual command.



    Minecraft Execute Command [1.19] Tutorial




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

    Images: Ron Lach, Ron Lach, Ron Lach, Ron Lach