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

Edit max health value for entity

Comments in 'Plugin Development' started by IcePL, May 29, 2016.

  1. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Hi.
    How i'm can get Entity in CommandSender??
    e.g in EntityDamageEvent: $entity = $event->getEntity();
    Last edited: May 29, 2016
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    if($sender instanceof Entity)
    Muqsit and applqpak like this.
  3. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    It not work.
    I need to add more health to entity.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Then why is your post about getting the Entity? Elaborate further.
    applqpak likes this.
  5. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    but I know how to add life but i need code to get the entity.
    e.g to get player i use: $sender->getPlayer();
    But i need to get the zombie entity
  6. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    You are the most confusing person I've ever met.
    minebuilder0110 likes this.
  7. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    if($sender instanceof Player){
    $sender->setMaxHealth(/*health*/);
    }
    Is the entity you want supposed to be a player?
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    He wants to get a entity by some identifier, you can use entity name, like 'Zombie' but that's not unique.
    PHP:
    $eName "zombie";
    foreach(
    $this->getServer()->getLoadedLevels() as $level){
         foreach(
    $level->getEntities() as $en){
               if(
    strtolower($en->getName()) === $eName$en->setHealth($en->getMaxHealth());
         }
    }
    deficiency of php knowledge is your only problem.
    Muqsit and applqpak like this.
  9. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    If its another entity, yes you could do that. But I do not lack knowledge in PHP, while everyday I learn something new about PHP, there will always be something you can learn.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Sorry, last sentence wasn't aimed at you.
    applqpak likes this.
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I think he wants to check if a zombie is sending a command.
    PHP:
    if($sender instanceof Zombie)
    Muqsit and applqpak like this.
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    @IcePL What exactly you want?
    applqpak likes this.
  13. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    My bad, I thought it was aimed at me. Well how would a Zombie run a command? I mean if they did something you could dispatch a command, but I don't think it would label them as running the command.
    applqpak likes this.
  14. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Yes they can. You can set a zombie as the command sender.
    PHP:
    $server->dispatchCommand($zombieObject$commandString);
    applqpak likes this.
  15. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    "$sender->getPlayer()" is useless in this case.
    PHP:
    if($sender instanceof Player){
           
    $sender->sendMessage('Hey, you are a player, and we do not need do $sender->getPlayer() because you are already one!');
    }
    elseif(
    $sender instanceof Zombie){
         
    $sender->sendMessage("OMG! A zombie!!");
    }
    ImagicalGamer likes this.

Share This Page

Advertisement