4

i am making a boss battle for my minecraft adventure map, and using a mob spawned with commands as the boss. When the mob gets hit, some command blocks will give the player a potion effect, but I can't figure out how to activate the command block when the mob gets hit. I am in the latest snapshot (16w03a). please help me (the person who answers my question will be given credit for it in my map)

1

3 Answers 3

8

Since automated scoreboard statistics (namely stat.damageTaken) only increments for players, you will need to rely on NBT data for non-player entities.

The HurtTime tag will be set to 10 when a mob is struck, decreasing by 1 per tick until it reaches 0 again.

  1. Adding the label for mobs that were struck.

    /scoreboard players tag @e[type=Creeper,tag=!Hurt] add Hurt {HurtTime:10s}
    
  2. Remove the label when the value is 9.

    /scoreboard players tag @e[type=Creeper,tag=Hurt] remove Hurt {HurtTime:9s}
    
  3. Target the mob based on the "Hurt" tag.

    /execute @e[type=Creeper,tag=Hurt] ~ ~ ~ /effect @a minecraft:slowness
    
3
  • thankyou! This helped me a lot Skylinerw. I will be sure to include you in my map.
    – Segosaurus
    Jan 21, 2016 at 5:50
  • I would have suggested using two scoreboard objectives, one that is tied to the health of the mob, the other that stores the last known value, and just do a comparison. This solution is much easier.
    – MBraedley
    Jan 21, 2016 at 11:41
  • 2
    @Segosauras If this answers your question, you should click the green "accept answer" checkmark. Jan 22, 2016 at 1:01
2

1.13 Update

The answer in 1.12 and below still applies. Note that commands were overhauled in 1.13. Please note the following:

  • /scoreboard players tag is now /tag.
  • /testfor is now a branch of /execute, using the (if|unless) parameters.
  • The NBT selector has been moved inside the target selector, using the nbt argument.
  • This answer was written before the entity IDs were changed in 1.11. In this change, we see that ZombieVillager and Creeper are now zombie_villager and creeper.

Here are the old commands that used to work but now don't.

/scoreboard players tag @e[type=Creeper,tag=!Hurt] add Hurt {HurtTime:10s}
/scoreboard players tag @e[type=Creeper,tag=Hurt] remove Hurt {HurtTime:9s}
/execute @e[type=Creeper,tag=Hurt] ~ ~ ~ /effect @a minecraft:slowness

And here are the new 1.13+ commands!

/tag @e[type=creeper,tag=!hurt,nbt={HurtTime:10s}] add hurt
/scoreboard players tag @e[type=creeper,tag=hurt,nbt={HurtTime:9s}] remove hurt
/execute if entity @e[type=creeper,tag=hurt] run say No Hurting Creepers!
-1

You can use this command to test for the creature's health. To make this work properly, several command blocks connected to redstone circuits will be necessary. /testfor @e[type=Zombie] {Health:19s} Of course, Zombie can be replaced with any mob name (first letter capital) You would also have to have a redstone comparator heading out of the command block(s) to the command block with the command you want executed after the creature is hit. You would have to have 19 command block circuits, one for each number from 1-19 to make a fully functional circuit/system. If you don't want this, then just find out how much damage should result from the zombie being hit with the available weapon (remember, your fist is always available)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .