Solved Adding Extra Hearts to Player

Discussion in 'Plugin Development' started by plisov, Jun 27, 2017.

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

    plisov

    When a player gets hit I want to add a few extra hearts to the player however it doesnt seem to work.

    I made sure that the item has the lore specified however it doesnt add the hearts.
     
    Last edited: Jun 28, 2017
  2. Offline

    mehboss

    Have you tried debugging to see if those if statements are being met?
     
  3. Offline

    plisov

    Hmmmm. It seems to be working now however everytime I hit a player it adds hearts to the player. How would I make it add once? What I'm trying to do is make it so that if the player has the piece of armor on, it will add 1 heart and when they remove the armor piece it removes that 1 heart.
     
  4. Offline

    mehboss

    You can do it with seperate events, this would be more challenging. Or, you can use a lib ;)
    <Edit by Moderator: Redacted not allowed paid resource url>
     
    Last edited by a moderator: Feb 10, 2021
  5. Offline

    plisov

     
    Last edited by a moderator: Feb 10, 2021
  6. Offline

    Zombie_Striker

    @plisov
    Why are you against using libraries. Why re-invent the wheel? They are there to make features like this easier.
     
    mehboss likes this.
  7. Offline

    plisov

    Alright, I've tried using the LIB and it semi works. When I put the armor on it adds the hearts but when I remove the armor, it doesnt remove the hearts. Also I've noticed that if you put the armor on quickly, it doesnt register some of the hearts that need to be added. Meaning it doesnt add some of the hearts it should.
     
    Last edited: Jun 28, 2017
  8. Offline

    Zombie_Striker

    @plisov
    The issue is that you are using relative calculating, meaning you are only adding or subtractring based on what changed, which is why you can glitch it by clicking quickly (if you do it fast enough, you can do it within the same tick, meaning comparing this tick to the last tick will show that nothing changed).

    Instead, what you need to do is get the base maximum health (which is 20) and add onto it depending on the amount of armor pieces and reinforced levels.
     
  9. Offline

    plisov

    You mean something like this?


    Wasn't I getting the Maximum base Health and adding the hearts before?
     
    Last edited: Jun 28, 2017
  10. Offline

    Zombie_Striker

    @plisov
    No, that looks like exactly the same code as you posted before. What you need to do is, every time the event is called, create a new int call 'health' that will be equal to 20. After that, check if the player has boots that are reinforced. If so, increase health by some amount (1 for heartful1 , 2 for heartful2, ect.) Then, after the boots, move to leggings, to chestpltes, and then to the helmet, doing the same checks for each one of them. Once you're done, set the max health equal to 'health'
     
  11. Offline

    plisov

    Oh alright. I've done like you said but I have a feeling I'm still doing it wrong.
     
    Last edited: Jun 28, 2017
  12. Offline

    mehboss

    Have you tried it?
     
  13. Offline

    plisov

    Yeh. Doesn't add hearts it seems
     
  14. Offline

    mehboss

    1. Remove all the lore checks

    2. Move all the helmet checks (+1) to one section and make them else statements after the first helmet check.
    3. Move all the chestplate checks (+1) to one section and make them else statements after the first chestplate check.
    4. Move all the leggings checks (+1) to one section and make them else statements after the first legging check.
    5. Move all the boots checks (+1) to one section and make them else statements after the first boots check.

    Do the same for the (-1) negatives.

    *remove duplicated message please*

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

    plisov

    I've done like you said however it doesn't work. I noted that when I put on Heartful 1 Armor and then remove everything, when I remove the boots after I remove all the armor, it removes 3 hearts. 2 problems. It only removes it when all the armor is on and when it's taken off last, and 2 it should be removing only 1 heart as it is not Heartful 3. Here is what I have currently.
     
    Last edited: Jun 28, 2017
  16. Offline

    mehboss

    When removing the hearts, you need to make a health variable for the removing section that will be getMaxHealth because they will no longer have 20 hearts, they will have more with the armor pieces.
     
  17. Offline

    plisov

    So you mean like so?
     
    Last edited: Jun 28, 2017
  18. Offline

    mehboss

    This should be removeHealth = player.getMaxHealth();

    Also, for removing the armor..
    You should only get the armor piece that was removed using #getOldarmorpiece

    Should be all set after that. ;)
     
  19. Offline

    plisov

    I've done exactly like you said but no luck :p. I put the armor on, it doesn't add extra hearts but when I remove the armor, it removes 2 heart for every armor piece instead of 1 heart. When I tried putting an armor piece on with Heartful 3 it didn't remove any hearts.
     
    Last edited: Jun 28, 2017
  20. Offline

    mehboss

    That should be an else statement.
     
  21. Offline

    plisov

    Sadly that didn't change anything. Still seems to do the same thing.

    Any ideas @timtower @Zombie_Striker

    EDIT: I've changed the player.getInventory() things in the top section to event.getNewArmorPiece() and now it adds hearts however for only one piece. I put one piece on, it adds 2 hearts (should only add 1 as its Reinforced 1). It should add 1 heart for every piece of armor. And then when I remove the armor, it remove 2 hearts for each armor piece. When I put on an armor piece, it jumps back to 10 hearts and adds 2 for only one armor piece.


    @mehboss I've also noticed that since you told me to change the bottom part to event.getOlrArmorPiece() I now have 4 sections of code that are exactly the same. Should I remove the 3 that are unneeded?

    I've fixed it thanks ;)
     
    Last edited: Jun 28, 2017
Thread Status:
Not open for further replies.

Share This Page