Change Max Health

Discussion in 'Spigot Plugin Development' started by DireLegendDev, Jun 8, 2015.

  1. I am trying to make armor that for every piece of it they have on get 1/2 a heart extra. Is there any easy way besides testing every combination of armor possible to set their max health? Any help appreciated!

    Thanks!
     
  2. I don't want to have to test every situation Example: Helmet, Chestplate = 1 heart extra health
    Example: Boots, Helmet = 1 extra heart
    Example: Boots, Chestplate, Helmet = 1.5 extra hearts

    Any easier way to do this without using a 24 if statements that are pretty glitchy?
     
  3. Step 1: learn java
    What about:
    Code (Text):

    number = 0
    if (helmet)
    number += 2
    if (chestplate)
    number += 2
    ...
     
     
  4. ? I know java pretty well, just wondering if anyone has a good method to do so. I have to test for combinations of 1 piece of armor, 2 pieces of armor, and 3 pieces of armor..
     
  5. Would it be possible to create a method that adds max health?
     
  6. There is a set max health method but I have never used it.
     
  7. It is a little hard to explain but if I use setmaxhealth I will have to test all the combinations of armor the player could have on and set the max health accordingly.
     
  8. Oh so you want to add health not set health. I don't think there is a method for that.
     
  9. Have you seen anything like a method addMaxHealth? Or do you know how to create that method? I am very lost :(
     
  10. Nope there is definitely no method for it. Is it possible to getMaxHealt() + 1.5 etc?
     
  11. Do you mean by adding extra heart rows? If so, i believe the method is "setHealthScale()"
     
  12. I will pay $5 if someone will give me the code for a method called addMaxHealth(#) that adds the amount of health the player's health (in an extra row of hearts, not healing the player)
     
  13. Could probably do this but I am at school at the moment :(
     
  14. Ok what about adding potion effects while a player has armor on and removing them if they don't? What event would I use?
     
  15. Check my plugin health levels, like that?
     
  16. I think there may be an armor change event. I could definitely be wrong though.
     
  17. You can set the maxhealth and give the health..

    Example:
    Code (Text):

    //Set max
    p.setMaxHealth(40.0);

    //Set health
    p.setHealth(40.0);
     
     
  18. Not really what I want :( I have to set the max health based on the number of pieces of armor the player has on. So I need a method like addMaxHealth that will add the specified number of health to their maximum health.
     
  19. Is there a way to test the number of pieces of armor a player has on?
     
  20. Try this:
    Code (Text):

            public void addMaxHealth(Player p, double health) {
            Damageable dm = p;
            dm.setMaxHealth(dm.getMaxHealth() + health);
           
            //If you want to heal it instantly
           
            dm.setHealth(dm.getMaxHealth());
        }
    }
     
    Then you have the armor you give addMaxHealth(player p, double health);
     
    • Winner Winner x 2