Custom mob health

Discussion in 'Plugin Development' started by chris8787878787, Aug 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    chris8787878787

    i was wondering if it's possible to give a mob custom health? Meaning instead of the average amount of health they have I could set it to something else. .setHealth() doesn't work in this way it seems, after a few attempts. So is it possible or will I have to do some kind of illusion
     
  2. Try something like increasing the damage done to it, if the ways you tried since now didn't work.
    For example:
    Pig has 20 hearts and you hit it with a sword giving 5 damage to it.
    If you want the pig to only have 10 hearts instead, multiply the damage done to it with 20/10 (=2).
     
  3. Offline

    chris8787878787

    @Ahmet094 Would this be in EntityDamageEntity event? And instead of multiplying the damage would dividing it to lower the damage work? I would really appreciate an example.
     
  4. Online

    timtower Administrator Administrator Moderator

    Moved to plugin development
     
  5. Code:
        int pig_original_health = 30;
        int pig_new_health = 20;
        @EventHandler
        public void modifiedDamage(EntityDamageByEntityEvent e){ 
            if(e.getEntityType() == EntityType.PIG){
                e.setDamage(e.getDamage()*(pig_original_health/pig_new_health));
            }
        }
    Just an example. Neither effective nor perfect.
     
  6. Offline

    au2001

    @Ahmet094 The original health would have to be 10 for pigs though.

    @chris8787878787 And why would .setHealth not work? Did you use .setMaxHealth too?
     
  7.  
  8. Offline

    chris8787878787

    @au2001 Yes. I think .setHealth just confuses the code into thinking I want to set its health to a number within its normal max health, nothing more.
     
  9. Offline

    au2001

    @chris8787878787 Use:
    Damageable.setMaxHealth(Math.min(health, Damageable.getMaxHealth()));
    and then:
    Damageable.setHealth(health);
     
  10. Offline

    chris8787878787

    @au2001 Still doesn't work :/ Does that normally work for you? It still gives me that same error: "Health must be between 0 and 20.0"

    @au2001 Ah, nevermind, solved it. Thanks though.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  11. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page