Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved How does setHealth($amount) work?

Comments in 'Plugin Development' started by haimann951, Sep 23, 2015.

  1. haimann951
    Offline

    haimann951 New Member

    Joined:
    Mar 15, 2015
    Posts:
    18
    Minecraft User:
    haimann951
    I need to use setHealth() in my Plugin. I´m using $player->setHealth(20); 20, because the Player has 20 half hearts. But when the setHealth method gets called, it removes 2 hearts from the player instead of adding them. How do I need to use this method?

    Thanks
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    don't use pocketmine 1.6 if you want get it to work
  3. haimann951
    Offline

    haimann951 New Member

    Joined:
    Mar 15, 2015
    Posts:
    18
    Minecraft User:
    haimann951
    Thanks, works fine on 1.5!
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but you can try setHealth(-20) :D
  5. haimann951
    Offline

    haimann951 New Member

    Joined:
    Mar 15, 2015
    Posts:
    18
    Minecraft User:
    haimann951
    I already tried that. Has the same effect. I could try to use setMaxHealth() or wait some time until it gets fixed. I'll report it as a bug.
  6. haimann951
    Offline

    haimann951 New Member

    Joined:
    Mar 15, 2015
    Posts:
    18
    Minecraft User:
    haimann951
  7. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    $event->getPlayer()->setHealth(0)
    This is you want to kill the person

    Let's say your making like a badword plugin
    PHP:
    public function onChat(PlayerChatEvent $event) {
      
    $msg $event->getMessage();
      
    $fuckword "fuck"// Your fucked lol

      
    if(strpos($msg$fuckword) !==false) {
      
    $event->getPlayer()->sendMessage("DONT EVER SAY THAT AGAIN YOU DIE NOW");
      
    $event->getPlayer()->setHealth(0);
    // That's the part you use setHealth()
    }
    }
    Last edited: Sep 23, 2015
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    if(strolower($msg, $fuckword) ???
    Thats not how you use strtolower.
    I think you meant stripos($msg, $fuckword)
  9. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    if (strpos ($msg,$fuckword)){
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    stripos() Is better because it is not case sensitive.
  11. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    OMG SORRY LOL I MEAN TO DO STRPOS LOL!! IM GONNA EDIT THAT REAL QUICK oh sorry for caps
    Hotshot_9930 likes this.
  12. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Then why don't just
    PHP:
    $player_object->kill();
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    He wanted to show him how to use setHealth?
  14. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    setHealth() is broken in 1.6.
    jojoe77777 likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use stripos() !== false

    And you should use attack(), otherwise it will cause other issues e.g. no EntityDamageEvent fired (hence no update in getLastDamageCause, hence breaks some other plugins e.g. plugins that announce who killed who).

Share This Page

Advertisement