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

Entity ID on EntityDamageByEntityEvent

Comments in 'Plugin Development' started by JackboyPlay, Aug 7, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hi, is it possible to do an action on EntityDamageByEntityEvent if I hit an entity with a specified entityID like:
    If I hit an entity with the ID 10 [Chicken] I'll get a message "Wow you hitted a chicken"
  2. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Make sure to use EntityDamageEvent and then get if the event is an instance of an EntityDamageByEntityEvent.

    $entity = $event->getEntity();
    if($entity instanceof Chicken){
    /*code here */
    }
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    I mean ID nor other things...
  4. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    You can get their ID by doing Chicken::NETWORK_ID. I believe that returns the ID.
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    IDK thats the reason because I ask
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Exists something like $entity->getId() ?
  7. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Nope. I don't believe it exists as of now, although I could be wrong.
  8. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    I think there is an $entity->getId(); checking again.
  9. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  10. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    $entity->getId() is the entity ID, which is unique for every instance of entity in one server runtime, and reset per server restart (probably even changes when their chunks is reloaded). This thread asks for the entity type ID, not the entity ID.
    According to somewhere in PocketMine source code, you can use $entity::NETWORK_ID for the type ID.
    Primus likes this.
  11. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    If($entity::NETWORK_ID == 10) ?
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Further citation:
    Survingo likes this.
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
  14. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Also is ->getId() and ::Network_ID right?
  15. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    There are three possible things you're wanting to find/know as far as I can tell from reading this thread. The most probable answer I think would be one where you are able to get the name of an entity as a string, not the EID.

    Get an entities name (string):
    PHP:
    // Getting an entities name regardless of it's type/EID
    $entity->getName();
    I'll post the other answers in case you or someone else wants to know them.

    Get an entities type/EID (int):
    PHP:
    // Get the EID of any entity
    $entity::NETWORK_ID;
    Get an entities unique identifier:
    PHP:
    // Get the unique identifier of an entity
    $entity->getId();
    These are the three answers I could see you seeking, if the answer you're searching for isn't here please explain in more detail what you are wanting to know.
    JackboyPlay likes this.
  17. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    You're half right, if you wanted to send to damager/attacker a message telling them the name of the mob they'd hit you would simply do:
    PHP:
    public function onDamage(pocketmine\event\entity\EntityDamageEvent $event) {
      
    $victim $event->getEntity();
      
    $cause $victim->getCause();
      if(
    $cause instance of pocketmine\event\entity\EntityDamageByEntityEvent) {
        
    $damager $event->getDamager();
        
    $damager->sendMessage("You dealt " $event->getFinalDamage() / " hearts of damage to " $victim->getName());
      }
    }
    Within a registered event listener class of course.
    JackboyPlay likes this.

Share This Page

Advertisement