Health methods aren't working

Discussion in 'Plugin Development' started by Pitazzo, Oct 11, 2014.

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

    Pitazzo

    Hi guys,
    I'm experimenting some problems when I use some health methods like setMaxHealth() or setHealthScale(); they just dont't do anything. Here's the code that I'm testing:

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label,
    2. String[] args) {
    3. if (sender instanceof Player) {
    4. Player player = (Player) sender;
    5. if (cmd.getName().equalsIgnoreCase("test")) {
    6. player.sendMessage(ChatColor.BLUE+"Comando de prueba ejecutado");
    7. // Desmayo.setPostDesmayo(player.getName());
    8. player.setMaxHealth(30.0D);
    9. player.setHealthScale(60.0D);
    10. System.out.println("Max health: "+player.getMaxHealth());
    11. System.out.println("Health: "+player.getHealth());
    12. System.out.println("Scaled health: "+player.getHealthScale());
    13. return true;
    14. }
    15. }
    16.  
    17. return false;
    18. }


    Output:
    Code:java
    1. 2014-10-11 14:50:15 [INFO] Pitazzo issued server command: /test
    2. 2014-10-11 14:50:15 [INFO] Max health: 30.0
    3. 2014-10-11 14:50:15 [INFO] Health: 20.0
    4. 2014-10-11 14:50:15 [INFO] Scaled health: 60.0
    5.  


    So, in theory, it works, but I still have only 10 hearts. By the way, I'm using the last recommended build, 1.6.4 R2.0

    Thanks in advance
     
  2. Pitazzo Try setting the health after you've changed the max & the scale
     
  3. Offline

    Watto

    I don't really understand your problem, could you elaborate please?
    What are you trying to achieve because i don't see anything wrong with your code..
     
  4. Offline

    Pitazzo


    I've already tried it but it didn't work, in the output I had 30 points of life, and in fact I've them because I hurt myself and my health bar was still full, but at any time I didn't have 15 hearts.


    I'm trying to see more than 10 hearts in my health bar, 20 for example. I got it ages ago, but it doesn't longer work.

    Any idea...?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  5. Offline

    LeonTG77

    Use:
    Code:java
    1. Damageable dEntity = (Damageable) player;

    then use:
    Code:java
    1. dEntity.getHealth()
    2. dEntity.getMaxHealth()
     
  6. Offline

    Code0

    Setting a health level above 20 will not change anything. Also, setHealthScaled will simply scale all health-related events. So you might have 20 hearts, but a zombie will, instead of doing 1 heart, do 2 hearts of damage. Pitazzo
     
  7. LeonTG77 That's not the problem, and your solution isn't the solution that should be used for the problem you're thinking of.
     
  8. Offline

    Code0

    You can always use the additional hearts potion effect (forgot the name). Pitazzo
     
  9. Code0 Well depends which - health boost and absorption both work for different things.
     
    Code0 likes this.
  10. Offline

    Code0

    I'd use the health boost (which adds "empty" hearts) and heal him. After adding the effect, maxHealth will automatically get raised and you can pass an integer over 20. AdamQpzm
     
    AdamQpzm likes this.
  11. Offline

    Pitazzo

    Code0
    Since 1.6.4 is possible to have more than 10 hearts, but in any case I should be able to scale my health, and I can't do it. LeonTG77
    As they said, that isn't the problem, already tried that, but thanks anyway.
    AdamQpzm
     
Thread Status:
Not open for further replies.

Share This Page