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

setItem()

Discussion in 'Development' started by Zuruki, Apr 14, 2017.

  1. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    will this code work? I'm trying to give the 'MainItems' on PlayerJoinEvent.
    PHP:
      public function MainItems(Player $player){
            
    $player->getInventory()->clearAll();
            
    $player->getInventory()->setItem(0Item::get(345)->setCustomName(C::BOLD.C::GREEN."Teleporter"));
            
    $player->getInventory()->setItem(2Item::get(339)->setCustomName(C::BOLD.C::GOLD."Info"));
            
    $player->getInventory()->setItem(6Item::get(280)->setCustomName("§eHide §aPlayers"));
        
    $player->getPlayer()->setHealth(20);
                
    $player->getPlayer()->setFood(20);

        }

    now event
    PHP:
        public function onJoin(PlayerJoinEvent $event){         //OnJoin
            
    $player $event->getPlayer();
            
    $name $player->getName();
            
    $ds $this->getServer()->getDefaultLevel()->getSafeSpawn();
            
    $player->setGamemode(0);
            
    $player->teleport($ds);
            
    $event->setJoinMessage("");
            
    $this->MainItems($player);
            
    $player->setGamemode(0);
            }
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Why not test the code yourself?
     
  3. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    I did, it seem not to work
     
  4. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Any errors?
     
  6. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    I fixed it
     
  7. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    thankyou for offering to help me , however
     
    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.