3

My question is as simple as it sounds; is there a way to check if a mob (and perhaps of a custom named mob) has x amount of health left. Example: Im making a skeleton boss, and when he hits half health, I want him to summon some "skeleton warriors" to assist him in battle. Any ideas?

2

You can do something like this.

/testfor @e[x,y,z,r,type=Skeleton] {Health:10s}

If you want the name in it do this. (Correct me if I'm wrong.)

/testfor @e[x,y,z,r,type=Skeleton,name=Jimmy] {Health:10s}

How To Check A Mobs Health

  • 2
    Awesome. Sorry, but do what does the "s" stand for in {Health:10s}? Half hearts? Whole hearts? – SMILIECHICKEN Jan 10 '16 at 1:08
  • 1
    It is whole health (as in, 0-10 hearts). I'm assuming if you wanted health you could use 0.5 – Bagel Jan 10 '16 at 1:24
  • 2
    @SMILIECHICKEN The "s" is a tag-type declaration for NBT data. It causes a whole number between -32768 and 32767 to have the short datatype. There's handful of declarations: byte:1b, byte:true, byte:false, short:1s, integer:1, long:1l, float:1.0f, double:1.0, double:1.0d, IntArray:[1,2,3], List:[], Compound:{}, string:none of the previous declarations string:"quotes, allowing commas as values". "true/false" are byte values of 1 and 0 respectively. – Skylinerw Jan 10 '16 at 8:46
  • 1
    @SMILIECHICKEN You can find a list of all NBT datatypes here, noting that there is no declaration available for ByteArray. This means you cannot create or detect a byte array using commands and would need a third-party editor to create one. – Skylinerw Jan 10 '16 at 8:46
1

Yes you can test for a mob with a specific amount of health and a custom name.


For example:

/testfor @e[x,y,z,r,type=Creeper,name=George] {Health:10s}

would test for a creeper within a radius of the target coordinates named George with 10 health. This should be placed on a loop to continually test the parameters.

Also, note that the {Health:10s} tag is separate from the entity tags. That is because health can only be stored in an NBT tag for mobs. As an added note, health can only be tested for exact values, not ranges.

(Source)

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.