1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Health

Discussion in 'Development' started by JarguarLoveMC, Dec 20, 2018.

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    How to check if player has health below 5?

    How to check if player has health equal to 5?
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    below 5
    PHP:
    $player->getHealth() < 5
    equal to 5
    PHP:
    $player->getHealth() == 5
     
    JarguarLoveMC likes this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    If by "equal to 5" you mean 2.5 heart icons, then you need to do a little rounding...
    PHP:
    $displayed_health = (int) ceil($player->getHealth());
    return 
    $displayed_health === 5;
    What's wrong with $player->getHealth() == 5?
    Health points are stored as float. The player could have 4.99 or 4.75 health points yet it would show up as 2.5 hearts to the player.
     
    Kyd likes this.
  4. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    HealthBar plugin on GitHub or YouTube.
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    He didn't ask for HealthBar plugin
     
    Primus likes this.
  6. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    PHP:
                       $player $event->getPlayer();
                       if (
    $player->getHealth() == 5) {
                            
    //do stuff
                        
    }

                        if (
    $player->getHealth() < 5) {
                            
    //do stuff
                        
    }
     
    SpekledFrog4T4 and JarguarLoveMC like this.
  7. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    But he can use the code in HeathBar plugin.
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    but he didn't ask how to make health bar
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.