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

How do I get last damager?

Discussion in 'Development' started by MasApip, Mar 19, 2020.

  1. MasApip

    MasApip Spider

    Messages:
    8
    GitHub:
    MasApip
    How do I get last damager? so I want to make a death message dropped on the void by the damager, how do I get people who dropped enemies on the void.
     
  2. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    Try:
    PHP:
     public function onEntityDamage(EntityDamageEvent $ev){
     
    $p $ev->getEntity();
      
    $kill $p->getLastDamage();
    }
     
  3. MasApip

    MasApip Spider

    Messages:
    8
    GitHub:
    MasApip
    if the player is dropped to void, so how do I send a message, $player has thrown to the void by $killer? if the player is not in void the message will be changed to $player has been killed by $killer. How do I differentiate between players dropped and killed

    PHP:
    case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
     if(
    $player->getY() < 5){
          
    $message $player->getName()." has thrown to the void by ".$killer->getDisplayName();
          return;
     }
     
    $message $player->getName()." was killed by".$killer->getName();
    break;
    i was tried it but not work
     
    Last edited: Mar 19, 2020
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    $damager ($killer) can be get from EntityDamageByEntity event... You can check if last damage ($event->getLastDamageCause() is this class using 'instanceof')

    PHP:
    $lastDmg $event->getLastDamageCause();
    if(
    $lastDmg instanceof EntityDamageByEntityEvent) {
       
    $damager $lastDmg->getDamager();
       
    //code - player was thrown into the void by some entity
       
    if($damager instanceof Player) {
          
    // player was thrown into the void by player
       
    }
       else {
          
    // player was thrown into the void by some entity, not with player (in pmmp almost impossible)
       
    }
    }
    else {
       
    // player jumped into the void
    }
    Also you can check void damage if you are checking entity damage...

    PHP:
    case EntityDamageEvent::CAUSE_ENTITY_ATTACK// wrong, just remove the switch
     
    Clik, IvanCraft623 and brokiem like this.
  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.