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

PlayerDamageEvent.

Discussion in 'Facepalm' started by DanielYTK, Feb 8, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    No PlayerDamageEvent como posso obter o jogador que deu o dano eo jogador que levou o dano?
     
  2. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Inglish message:

    In PlayerDamageEvent how can I get the player that gave the damage, and the player that took the damage?
     
  3. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    There is no PlayerDamageEvent. There is, however, EntityDamageEvent, and EntityDamageByEntityEvent, which can be used as you describe. After you have checked if the event is an instance of EntityDamageByEntityEvent, you can use $event->getDamager() and $event->getEntity() to find the desired information. The Damager is the Entity that gave the damage, and the Entity is the Entity that took the damage. Keep in mind that you will also need to check if the Entity and the Damager are both Players, if you only want to listen for the event that one Player damages another. For more info, or to fact check me(I may very well be wrong), check out the source file here.
     
    wolfdale likes this.
  4. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    you need to check if the EntityDamageEvent is an Instanceof EntityDamageByEntityEvent
     
  5. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    PHP:
    public function onDamage(pocketmine\event\entity\EntityDamageEvent $event) {
        if(
    $event instanceof pocketmine\event\entity\EntityDamageByEntityEvent) {
            
    $victim $event->getEntity();
            if(
    $victim instanceof pocketmine\Player) {
                
    $attacker $event->getDamager();
                
    // Do stuff here
            
    }
        }
    }
    Please refrain from using other languages on this forum; this in an English forum, not an international one.

    Why bother spamming the thread with information that is easily readily accessible within said thread?
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Anyone else notice that English is spelled with an 'I' ? lol

    Also, this topic has been discussed many times. This needs to be moved to the facepalm section.
     
    HimbeersaftLP likes this.
  7. Bluplayz

    Bluplayz Spider Jockey

    Messages:
    43
    GitHub:
    bluplayz
    all bad questions should be answered, why? Because the people get no answer at other sites lol we should help all who want to learn something ^^ its my opinion xD
     
  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.