Scale player health

Discussion in 'Plugin Development' started by bennie3211, Apr 7, 2016.

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

    bennie3211

    Hello,

    I've a question about setting the player hearths. I'm trying to set the player hearts to a specific value, normally you have 10 hearts (20 half hearts) but I wan't to set it to 3 for example. Now when I try to accomplish this with:

    Code:
    p.setHealthScale(a.getDefLives() * 2.0);
                p.setHealth(3.0);
    But I find it strange that when you set the health of a player to 3.0 it will fill all hearts instead of setting the health to the same value as the health scale. If I use higher numbers I get a error in the console saying it should be in range from 0.0 tot 3.0. 'a.getDefLives()' returns a integer that represents the number of full hearths the player get.

    Can someone explain me what I should do to get it working like I want? No spoonfeed please but explain me what is wrong and what I need to check/edit to get it working.

    Thnx
     
  2. Offline

    WolfMage1

    use setMaxHealth (if I understand this correctly)
     
  3. Offline

    ShowbizLocket61

    @bennie3211
    setMaxHealth will set the maximum health( not hearts ) of the entity.
    Code:
    displayedHealth = getHealth() / getMaxHealth() * getHealthScale()
    The number you put in healthscale would be the health you want displayed at full
     
  4. Offline

    WolfMage1

    I figured he'd use setHealth after setMaxHealth :p
     
  5. Offline

    ShowbizLocket61

    @WolfMage1 @bennie3211
    Of course, if you want the player to only have 3 hearts (I dunno why, you'll get 1-hit KO'd by a mob) you'll have to set the max health and current health. If you just want to change the display, and keep the player's 10 hearts, you'll use healthScale only. If you want to do both..... set all three.
     
  6. Offline

    bennie3211

    I'm making a minigame (plugin) where the hearts represents the lives the player has. I have seen it once before on another server and it looks like this:
    [​IMG]

    But I can't get it working for different values. Each arena can have a different game mode, so the player can have 1, 2, 3 ... 10 or infinite lives (then it will limit the hearts to 10). So I need to make it so that when a arena has 2 lives, it will display 2 hearts, if a arena has 8 lives it will show 8 hearts etc etc. Limiting the lives to 10 is not a problem, but I can't get it working so it will display the correct number of hearts without giving an error.

    Edit: The error is when I set the health parameters that it has to be between 0.0 and 3.0?

    Can someone help me with this?
     
    Last edited: Apr 8, 2016
  7. Offline

    ShowbizLocket61

    @bennie3211
    When you set the health, it obviously has to be between 0 and the max health.
    When the arena has 3 lives, do you want the player to have 10 hearts and show 3, or have 3 hearts and show 3?
     
  8. Offline

    mcdorli

    Player#setMaxHealth(float amount)
     
  9. Offline

    bennie3211

    show 3 hearts and have 3 hearts, the player can't get damage, but if he enters a certain region it will be reduced with one.

    But if i set the maxHealth to 6, why can't i set the healt to 6 too? If I set the maxHealth to 8 and I set the health to 3 it will show 4 hearts... If i put a higher number then 3.0 it will give an error that it should be between 0.0 and 3.0
     
  10. Offline

    mcdorli

    Remive the scaling
     
  11. Offline

    ShowbizLocket61

    @mcdorli
    Scaling has nothing to do with the actual health, just the displayed health

    @bennie3211
    1. Set max health to 6
    2. Set health to 6
    3. Set scale to 6
     
    bennie3211 likes this.
Thread Status:
Not open for further replies.

Share This Page