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

What's wrong?

Discussion in 'Development' started by NickteeChunky, Jul 27, 2019.

  1. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    No errors, just won't work. I want it to announce how many pots the player has left on killing event.

    PHP:
    <?php
    namespace HMR;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\command\ConsoleCommandSender;

    class 
    Main extends PluginBase implements Listener{
        

        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->getLogger()->info(TextFormat::BLUE "HealthMessageReturn Enabled!");
        }

        public function 
    onDeath(PlayerDeathEvent $event) {
      
            
    $cause $event->getEntity()->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent) {
                
    $player $event->getEntity();
                
    $killer $event->getEntity()->getLastDamageCause()->getDamager();
                if(
    $killer instanceof $player){
                  
    $item $killer->getInventory()->getContents();
                  
    $itemId $item->getId();
                  if (
    $itemId === "438:22") {
                    
    $count $item->getCount();
                    
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), "sm * §4".$player->getName()." §r§chas been annihilated by the one and only§4 ".$killer->getName()."§4[❤ ".$killer->getHealth()." HP - ".$count." Pots]§r§c.");
                  }
                }
              }
            }
        }

    }
     
  2. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    The function getInventory()->getContents() returns an array, not an item.
     
    wolfdale likes this.
  3. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    Okay, could you please give an example?
     
  4. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    I'm sure you can find an example without any help... Just loop through the array and count how many items have the ID.
     
    OnTheVerge likes this.
  5. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    Okay, thank you for your help.
     
  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.