Adding More Health

Discussion in 'Plugin Development' started by thegarfish, Jul 30, 2014.

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

    thegarfish

    Hello! Currently I am storing a single player in an arraylist and I need to add extra health to just him. I have tried multiple times to add health to the player (500 hearts, 1000 health) and nothing seems to be working.

    I have tried...
    Code:java
    1. player.setHealth(500);
    2. player.setHealth(500.0);
    3. player.setMaxHealth(500);
    4. player.setHealth(20);


    All of these had no effect on the player.

    Code:java
    1. } else if(teamBlue.contains(playerName)) {
    2. player.sendMessage(KillTheKing.messagePrefix + "§9You have joined the §lBLUE §r§9team.");
    3. player.setDisplayName("§9[BLUE] " + player.getName() + "§f");
    4. player.setPlayerListName("§9" + player.getName());
    5. if(King.blueKing.isEmpty()) {
    6. King.blueKing.add(player.getDisplayName());
    7. Bukkit.broadcastMessage(KillTheKing.messagePrefix + King.blueKing.toString() + " §9has been named the BLUE king!");
    8. }
    9. if(King.blueKing.contains(playerName)) {
    10. player.setHealth(20);
    11. }
     
  2. Offline

    AoH_Ruthless

    thegarfish
    1. Have you attempt to debug your code? Are you sure you are properly adding the player to team blue?
    2. For your first part of setting the health, that's just going to set the player's health to 20 with a max health of 500; kind of useless.
     
  3. Offline

    Esophose

    thegarfish
    In 1.7 a potion effect was added that does exactly what you want. The effect is called Absorbtion. Note in the code below, replace (AMMOUNT) with the amount of hearts you wish to add.

    Code:java
    1.  
    2. int heartsToAdd = ((AMMOUNT) / 2) - 1;
    3. p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORBTION, 9999 * 20, heartsToAdd));
    4.  

    That may not be 100% correct as I didn't check, you should get the idea though :)
     
Thread Status:
Not open for further replies.

Share This Page