Solved Applying Health Boost every second

Discussion in 'Plugin Development' started by _loco_, Mar 22, 2016.

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

    _loco_

    I want to apply health boost to a player every second. But when I do this:

    Code:
    player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 30, 0));
    This works for all other potion effects, and it gives the extra hearts of health boost, but every second when the effect is reapplied, all your extra health disappears and comes back, so you lose all your extra health.

    I even tried:

    Code:
    player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 30, 0), true);
    (to force the effect on the player every second) But the problem still exists.

    EDIT: This only triggers every second that the player matches a certain condition (say, wearing a chestplate) so I can't just give the effect forever.
     
    Last edited: Mar 23, 2016
  2. Offline

    mine-care

    Err can you describe what you are trying to do?
    Are you trying to aply the same potion effect every second? Are you trying to boost the hearts of a player every second?
     
  3. Offline

    _loco_

    @mine-care Yes, I'm trying to apply health boost every second. Each time the health boost is reapplied, its as if it was removed and added instantly, so the player loses all of their extra hearts.
     
  4. Offline

    Lightspeed

    @_loco_ Are you just trying to make it so players never run out of the potion effect yet keeping to extra/lost hearts?
     
  5. Offline

    _loco_

    @Lightspeed Yes. I want the players to get health boost every second but keep all the extra health they got between seconds. Since I think some people don't understand, here's an explanation.
    1. First, the player's health is 20.
    2. Then, the player gets health boost I. The health is now 20, but max health is 24.
    3. The player regenerates some health to fill the new health. The health is now 21, and max health is 24.
    4. 1 second passes.
    5. The 1-second-duration health boost effect wears off, so the player loses their extra hearts. The health is now 20, and max health is 20.
    6. The health boost is instantly reapplied, but it's too late, because health is already 20. The health is now 20, but max health is back up to 24.
    7. Process is repeated every second.
     
  6. Offline

    Lightspeed

    @_loco_ Why don't you just set the players max health to 24?
    Then reset it back when finished?

    Code:
    player.setMaxHealth(24);
    
    player.resetMaxHealth(); //Yes this is a method
     
  7. Offline

    Sir_Cam

    @_loco_ Looks like you are over-complicating a quite simple task. That would be an immense pain to do it the way you are describing. Instead, i agree with what @Lightspeed said. just change the player's MaxHealth to the desired number: in this case 24. If i understand your post, that is all you were trying to accomplish, so problem solved?
     
  8. Offline

    _loco_

    @Lightspeed @Sir_Cam Okay, I'll try that method, but it will be hard because the player needs to match certain requirements to get the health boost (which are checked every second)
     
Thread Status:
Not open for further replies.

Share This Page