PlayerJoinEvent

Discussion in 'Development' started by Daniel23, Oct 15, 2017.

Thread Status:
Not open for further replies.
  1. Daniel23

    Daniel23 Witch

    Messages:
    65
    GitHub:
    daniel23
    When a player join it doesnt give the player an item even on respawn event
    PHP:
        public function onPlayerJoin(PlayerJoinEvent $e)
        {
            
    $player $e->getPlayer()->getInventory();
            
    $player->clearAll();
            
    $player->setItem(0Item::get(Item::COMPASS01)->setCustomName("�6Server Selector"));
            
    $player->setItem(1Item::get(Item::CLOCK01)->setCustomName("�2Kit Map"));
        }
     
  2. SkySeven

    SkySeven Baby Zombie

    Messages:
    142
    GitHub:
    SkySevenMC
    At PlayerJoinEvent you can't teleport Player or give item, I don't no why...
     
    Daniel23 likes this.
  3. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Umm I'm pretty sure it is not setItem().
    Try this
    PHP:
    Public function onJoin(PlayerJoinEvent $ev){
      
    $ev $ev->getPlayer()->getInventory;
      
    $ev->addItem(Item::get(Item::COMPASS));
    //etc...
    }
     
  4. Daniel23

    Daniel23 Witch

    Messages:
    65
    GitHub:
    daniel23
    I used setItem to put Item on a particular spot
     
  5. Daniel23

    Daniel23 Witch

    Messages:
    65
    GitHub:
    daniel23
    Is there anything wrong here. Nothing seems to work
    PHP:
    <?php

    namespace HUB;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase implements Listener{
        
        public function 
    onTap(PlayerInteractEvent $e)
        {
            if (
    $e->getAction() == PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
                
    $player $e->getPlayer();
                switch (
    $e->getItem()->getId()) {
                    case 
    Item::COMPASS:
                        
    $this->getServer()->dispatchCommand($player"cui testsimple");
                        break;
                    case 
    Item::CLOCK:
                        
    $this->getServer()->dispatchCommand($player"cui testsimple");
                        break;
                }
            }
        }

        public function 
    onPlayerJoin(PlayerJoinEvent $e) {
            
    $ev $e->getPlayer()->getInventory;
            
    $ev->clearAll();
            
    $ev->addItem(Item::get(Item::COMPASS01)->setCustomName("Server Selector"));
            
    $ev->addItem(Item::get(Item::CLOCK01)->setCustomName("Kit Map"));
        }
          
        public function 
    onPlayerRespawn(PlayerRespawnEvent $e) {
            
    $ev $e->getPlayer()->getInventory;
            
    $ev->clearAll();
            
    $ev->addItem(Item::get(Item::COMPASS01)->setCustomName("Server Selector"));
            
    $ev->addItem(Item::get(Item::CLOCK01)->setCustomName("Kit Map"));
        }
    }
     
  6. DayKoala

    DayKoala Silverfish

    Messages:
    22
    GitHub:
    daykoala
    Hm...

    PHP:
    public function onJoin(PlayerJoinEvent $event){
           
    $player $event->getPlayer();
           if(
    $player == null){
              return;
           }
           
    $inventory $player->getInventory();
           
    $inventory->setItem(/*Slot*//*Item*/);
           
    $player->sendMessage("Hello!");
    }
     
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    681
    gerInventory is not variable, it's function
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    681
     
Thread Status:
Not open for further replies.

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.