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

How can i send a Message to a Player when he kills a Player?

Discussion in 'Development' started by SkyZone, Dec 6, 2016.

  1. SkyZone

    SkyZone Slime

    Messages:
    95
    Now its working fine :D Thanks
     
    Sandertv likes this.
  2. SkyZone

    SkyZone Slime

    Messages:
    95
    And now im getting this error:
    [Server thread/CRITICAL]: pocketmine\utils\PluginException: "pocketmine\event\entity\EntityDamageByEntityEvent does not have a handler list" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 787
    What is this meaning?
     
  3. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You're probably doing this:
    PHP:
    public function onDamage(EntityDamageByEntityEvent $event) { 
      
    //stuff
    }
    but it should be:
    PHP:
    public function onDamage(EntityDamageEvent $event) {
      if(
    $event instanceof EntityDamageByEntityEvent) {
         
    //stuff
      
    }
    }
     
    SkyZone and Primus like this.
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This is because EntityDamageEvent can be used as an event listener argument, but not EntityDamageByEntityEvent. You can identify this by the $handlerList property in the file.
     
    Muqsit, SkyZone, Primus and 1 other person like this.
  5. SkyZone

    SkyZone Slime

    Messages:
    95
    Still getting error:
    [Server thread/CRITICAL]: pocketmine\utils\PluginException: "pocketmine\event\entity\EntityDamageByEntityEvent does not have a handler list" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 787
    Ive no idea why
     
  6. kaliiks

    kaliiks Zombie

    Messages:
    250
    use
    PHP:
    public function onDamage(EntityDamageEvent $event) {
    $damager $event->getDamager();
    $player $event->getPlayer();
     
    $damager->sendMessage("Your message");
      }
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Show your code please!
    This is incorrect. EntityDamageEvent doesn't have a function getDamager(). You should first check if the event is instanceof EntityDamageByEntityEvent.
     
    SOFe likes this.
  8. SkyZone

    SkyZone Slime

    Messages:
    95
    This is my code:
    PHP:
    public function onDeath(EntityDamageByEntityEvent $event){
            if(
    $event instanceof EntityDamageByEntityEvent){
                
    $health $event->getEntity()->getHealth();
                
    $damager $event->getDamager();
                
    $player $event->getPlayer();
                if(
    $damager instanceof \pocketmine\Player){
                    if(
    $health === 0){
                        if(
    $levelofkiller == ""){
                        
    $levelofkiller 1;
                        }
                        if(
    $levelofkilled == ""){
                        
    $levelofkilled 1;
                        }
                    }
                    
    //Ab hier steht, was passiert wenn der Spieler stirbt :D
                    
    $levelofkiller $levelofkiller 1;
                    
    $levelofkilled $levelofkilled 1;
                    if(
    $levelofkilled === -1){
                        
    $levelofkilled 1;
                    }
                
    $this->getServer()->broadcastMessage("The level of killer is $levelofkiller of killed is $levelofkilled");
                }
            }
        }
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    The first check is useless. I can't find you messing with handler list though...
     
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Change the first line to
    PHP:
     public function onDeath(EntityDamageEvent $event) {
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And about this...
    Why?
     
  12. SkyZone

    SkyZone Slime

    Messages:
    95
    Ive changed the code to this
    PHP:
    public function onDamage(EntityDamageEvent $event){
            
    $health $event->getEntity()->getHealth();
            
    $damager $event->getEntity()->getLastDamageCause();
            if(
    $health === 0){
                if(
    $damager instanceof \pocketmine\Player){
                    
    $damager->sendMessage("You are the Damager!!!");
                }
            }
        }
    But event this is not working and i need that the plugin is finished to 90% bug free an 24th.
     
  13. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You should have kept that if statement where you check if the event is instanceof EntityDamageByEntityEvent, if you want to make use of the getDamager() method.
     
  14. SkyZone

    SkyZone Slime

    Messages:
    95
    The Damager is getting no Message :/
    PHP:
    public function onDamage(EntityDamageEvent $event){
            if(
    $event instanceof EntityDamageByEntityEvent){
                
    $health $event->getEntity()->getHealth();
                
    $damager $event->getEntity()->getLastDamageCause();
                if(
    $health === 0){
                    if(
    $damager instanceof \pocketmine\Player){
                        
    $damager->sendMessage("You are the Damager!!!");
                    }
                }
            }
        }
     
  15. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Change the line: $damager = ... to:
    PHP:
     $damager $event->getDamager(); 
    and I'm not sure why you would do the $health === 0, wouldn't you use playerDeathEvent for that?
     
  16. SkyZone

    SkyZone Slime

    Messages:
    95
    I found a solution!
    PHP:
    public function onDeath(PlayerDeathEvent $event){
            
    $ldc $event->getPlayer()->getLastDamageCause()->getEntity();
            if(
    $ldc instanceof \pocketmine\Player){
                
    $damager $ldc->getPlayer()->getNameTag();
                
    $iskilled $event->getPlayer()->getNameTag();
                
    $event->setDeathMessage(TextFormat::RED."$iskilled ".TextFormat::BLUE."wurde von ".TextFormat::GOLD."$damager".TextFormat::BLUE." getötet");
            }
            
        }
    THX A LOT :D
     
    Sandertv likes this.
  17. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why $ldc->getPlayer()... Player->getPlayer() returns the player itself...

    And the $damager should be the dead player according to what you have written.
     
    [deleted] and Sandertv 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.