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

Nothing executed

Discussion in 'Development' started by JarguarLoveMC, Jan 4, 2019.

  1. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    I'm trying to make it so if player wear diamond chestplate and died it will send "L" as a message to the killer but nothing happened

    public function onDeath(PlayerDeathEvent $event){

    if($event->getEntity()->getLastDamageCause() instanceof EntityDamageByEntityEvent){
    $killer = $event->getEntity()->getLastDamageCause()->getDamager();
    $dead = $event->getEntity();

    if($killer instanceof Player && $dead instanceof Player){

    if($dead->getArmorInventory()->getChestplate());
    $killer->sendMessage(TF::BOLD . TF::DARK_AQUA . "+L");
    }
    }
    }

    i think i'm missing something?
     
  2. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    PHP:
    if($dead->getArmorInventory()->getChestplate()->getId() == Item::DIAMOND_CHESTPLATE) {
     
    $killer->sendMessage(TF::BOLD TF::DARK_AQUA "+L");

    }
     
    wolfdale likes this.
  3. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    that?
     
  4. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    yea because your last if statement doesnt return a boolean
     
  5. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    First, did you register events?
    Then did you use \pocketmine\event\entity\EntityDamageByEntityEvent and \pocketmine\Player?
     
  6. JarguarLoveMC

    JarguarLoveMC Spider Jockey

    Messages:
    49
    yes i did
     
  7. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    PHP:
    public function onDeath(PlayerDeathEvent $event) {
      
    $player $event->getPlayer();
      
    $lastDamageCause $player->getLastDamageCause();
      if(
    $lastDamageCause instanceof EntityDamageByEntityEvent) {
        
    $killer $lastDamageCause->getDamager();
        if(
    $killer instanceof Player) {
          if(
    $player->getArmorInventory()->getChestplate()->getId() == Item::DIAMOND_CHESTPLATE) {
            
    $killer->sendMessage("+L");

          }

        }

      }

    }
     
    JarguarLoveMC likes this.
  8. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    Its true. You can try.
     
  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.