3

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)

5

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
    
  • thankyou! This helped me a lot Skylinerw. I will be sure to include you in my map. – Segosaurus Jan 21 '16 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 '16 at 11:41
  • @Segosauras If this answers your question, you should click the green "accept answer" checkmark. – rustphoenix Jan 22 '16 at 1:01
-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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.