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

Solved Help with editing a plugin

Discussion in 'Development' started by Nader Jafari, Mar 14, 2018.

  1. Nader Jafari

    Nader Jafari Silverfish

    Messages:
    16
    Hi, I am amateur in PMMP API can anyone help me with this:
    I am editing Kill Money plugin for my server I have a problem with it
    Kill Money only count kill by PvP but I need it for PvP and Projectiles like Snowball together
    I know l should use DeathEvent but I don't know which event help me with find that event and use it
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event) : void{
        
    $victim $event->getPlayer();
        if(
    $victim->getLastDamageCause() instanceof EntityDamageByChildEntityEvent){
          if(
    $victim->getLastDamageCause()->getDamager() instanceof Player){
              
    $killer $victim->getLastDamageCause()->getDamager()->getName();
              
    $cmd "rankpoints" $killer "5";
              
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd);
            }
          }
        }
     
    Last edited: Mar 14, 2018
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PlayerDeathEvent is called only when a player dies, so you are using the right event.
    Player->getLastDamageCause() will return the last EntityDamageEvent instance that Player took damage from.

    EntityDamageByEntityEvent inherits EntityDamageEvent and EntityDamageByChildEntityEvent inherits EntityDamageByEntityEvent.
    But EntityDamageByChildEntityEvent is called only when a projectile hits an entity and the shooter of the projectile is still online.

    To make it simple, you can check whether Player->getLastDamageCause() is an instance of EntityDamageByEntityEvent and the cause's getDamager() is a Player.

    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event) : void{
        
    $player $event->getPlayer();
        
    $cause $player->getLastDamageCause();
        if(
    $cause instanceof EntityDamageByEntityEvent){
            
    $damager $cause->getDamager();
            if(
    $damager instanceof Player){
                
    $killer $damager->getName();
                
    $cmd "rankpoints {$killer} 5";
                
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd);
            }
        }
    }
     
    Last edited: Mar 15, 2018
    Nader Jafari likes this.
  3. Nader Jafari

    Nader Jafari Silverfish

    Messages:
    16
    Thank you so much Muqsit. you and your plugins are the best.
     
    Muqsit likes 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.