Solved Player Head

Discussion in 'Development' started by Amon28, May 23, 2017.

  1. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    I don't get it :(
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I can't really explain it any simpler. You used item::get(), try Item::get with an uppercase I in place of it.
     
  3. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
  4. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    I changed item::get() to Item::get() still doesn't give me the item
     
  5. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Try
    PHP:
    $head Item::get(39701);
     
  6. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    $player->getInventory()->sendContents($player->getInventory()); add that after you give the player the head. Sometimes custom named items or items with custom metas don't show in the inventory.
     
  7. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    It doesn't give me the head after I killed the player
    And it didn't send me the message too.
    PHP:
    public function onDeath(PlayerDeathEvent $ev){
         
    $player $ev->getPlayer();
         
    $cause $player->getLastDamageCause();
      
        if(
    $cause instanceof EntityDamageByEntityEvent){
         
    $damager $cause->getDamager();
         
    $inv $damager->getInventory();
         
    $head Item::get(397,0,1);
         
    $name $damager->getName();
         
    $head->setCustomName("$name's Head");
         
    $inv->addItem($head);
         
    $damager->getInventory()->sendContents($damager->getInventory());
         
    $damager->sendMessage("you got $name's Head");
      }
    }
     
  8. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    I think the $damager is not registering as a player
    I've tried
    PHP:
    $p $damager->getPlayer();
    But no luck
     
  9. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Umm tr add if damager is instance of player
    PHP:
    public function onDeath(PlayerDeathEvent $ev){

         
    $player $ev->getPlayer();
         
    $cause $player->getLastDamageCause();
     
        if(
    $cause instanceof EntityDamageByEntityEvent){
         
    $damager $cause->getDamager();
        if(
    $damager instanceof Player){
         
    $inv $damager->getInventory();
         
    $head Item::get(397,0,1);
         
    $name $damager->getName();
         
    $head->setCustomName("$name's Head");
         
    $inv->addItem($head);
         
    $damager->getInventory()->sendContents($damager->getInventory());
         
    $damager->sendMessage("you got $name's Head");
      }
    }
    }
     
  10. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Did you import the events?
     
  11. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Did you even register your listener?
     
  12. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    This is my overall code
    Still doesn't give me the head
    PHP:
    use pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\entity\Entity;

    class 
    Main extends PluginBase implements Listener{
       
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
        }
       
        public function 
    onDeath(PlayerDeathEvent $ev){

         
    $player $ev->getPlayer();
         
    $cause $player->getLastDamageCause();
     
        if(
    $cause instanceof EntityDamageByEntityEvent){
         
    $damager $cause->getDamager();
        if(
    $damager instanceof Player){
         
    $inv $damager->getInventory();
         
    $head Item::get(397,0,1);
         
    $name $damager->getName();
         
    $head->setCustomName("$name's Head");
         
    $inv->addItem($head);
         
    $damager->getInventory()->sendContents($damager->getInventory());
         
    $damager->sendMessage("you got $name's Head");
      }
    }
    }
        public function 
    onDisable(){
         
    $this->getLogger()->Info("Offline");
        }
    }
     
  13. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    You didn't add the use EntityDamageEntityEvent :facepalm:
     
  14. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    I forgot the classes.......EntityDamageEntityEvent and Inventory
     
  15. KelvinCyaX

    KelvinCyaX Silverfish

    Messages:
    18
    GitHub:
    CyanKelv
    Also from your code.. it looks like youre giving the killer's head back to the killer..
    and yea add EntityDamageByEntityEvent class.
     
  16. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    Ye I've fix that it gives the head now but how can I get the Steve head instead of skeleton head
    Do I just need to do 937:3?
     
  17. KelvinCyaX

    KelvinCyaX Silverfish

    Messages:
    18
    GitHub:
    CyanKelv
    yes Item::get(397:3:1);
     
  18. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    It gave me an error
    syntax error, unexpected ':', expecting ',' or ')
     
  19. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Item::get(397, 3, 1);
     
    corytortoise likes this.
  20. Amon28

    Amon28 Slime

    Messages:
    76
    GitHub:
    amon28
    Isn't the 2nd one the damage of the item
    And it gave me an error
     

Share This Page

  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.