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

Solved setArmor?

Discussion in 'Development' started by kazuya, Jun 11, 2017.

  1. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    I want players to get a full diamond armor when they join

    PHP:
    public function onJoin(PlayerJoinEvent $event){

        
    $player $event->getPlayer();
        
    $name $event->getPlayer()->getName();

        
    $player->sendMessage($this->getConfig()->get("join-message"));
        
    $player->setArmor(Item::get(Item::DIAMOND_CHESTPLATE));
      }
     
  2. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    use
    PHP:
     $player->getInventory()->setChestplate(Item::get(Item::DIAMOND_CHESTPLATE)); 
     
    kazuya likes this.
  3. DayKoala

    DayKoala Silverfish

    Messages:
    22
    GitHub:
    daykoala
    And
    PHP:
    $player->getInventory()->sendArmorContents();
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
  5. mal0ne_23

    mal0ne_23 Spider Jockey

    Messages:
    30
    GitHub:
    mal0ne-23
    PHP:
    $player->getInventory()->setHelmet(Item::get(Item::DIAMOND_HELMET)); 
    $player->getInventory()->setChestplate(Item::get(Item::DIAMOND_CHESTPLATE));
    $player->getInventory()->setLeggings(Item::get(Item::DIAMOND_LEGGINGS)); 
    $player->getInventory()->setBoots(Item::get(Item::DIAMOND_BOOTS)); 
     
    Teamblocket likes this.
  6. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\inventory\PlayerInventory::sendArmorContents()" (EXCEPTION) in "plugins/LobbyCore/src/Superomarking/LobbyCore/Main" at line 396
     
  7. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    public function __construct(Living $holder){
    $this->holder = $holder;
    parent::__construct();
    }

    public function getHolder() : Living{
    return $this->holder;
    }

    public function getName() : string{
    return "Armor";
    }

    public function getDefaultSize() : int{
    return 4;
    }

    public function getHelmet() : Item{
    return $this->getItem(self::SLOT_HEAD);
    }

    public function getChestplate() : Item{
    return $this->getItem(self::SLOT_CHEST);
    }

    public function getLeggings() : Item{
    return $this->getItem(self::SLOT_LEGS);
    }

    public function getBoots() : Item{
    return $this->getItem(self::SLOT_FEET);
    }

    public function setHelmet(Item $helmet) : bool{
    return $this->setItem(self::SLOT_HEAD, $helmet);
    }

    public function setChestplate(Item $chestplate) : bool{
    return $this->setItem(self::SLOT_CHEST, $chestplate);
    }

    public function setLeggings(Item $leggings) : bool{
    return $this->setItem(self::SLOT_LEGS, $leggings);
    }

    public function setBoots(Item $boots) : bool{
    return $this->setItem(self::SLOT_FEET, $boots);
    }

    public function sendSlot(int $index, $target) : void{
    if($target instanceof Player){
    $target = [$target];
    }

    $pk = new MobArmorEquipmentPacket();
    $pk->entityRuntimeId = $this->getHolder()->getId();
    $pk->head = $this->getHelmet();
    $pk->chest = $this->getChestplate();
    $pk->legs = $this->getLeggings();
    $pk->feet = $this->getBoots();
    $pk->encode();

    foreach($target as $player){
    if($player === $this->getHolder()){
    /** @var Player $player */

    $pk2 = new InventorySlotPacket();
    $pk2->windowId = $player->getWindowId($this);
    $pk2->inventorySlot = $index;
    $pk2->item = ItemStackWrapper::legacy($this->getItem($index));
    $player->dataPacket($pk2);
    }else{
    $player->dataPacket($pk);
    }
    }
    }

    public function sendContents($target) : void{
    if($target instanceof Player){
    $target = [$target];
    }

    $pk = new MobArmorEquipmentPacket();
    $pk->entityRuntimeId = $this->getHolder()->getId();
    $pk->head = $this->getHelmet();
    $pk->chest = $this->getChestplate();
    $pk->legs = $this->getLeggings();
    $pk->feet = $this->getBoots();
    $pk->encode();

    foreach($target as $player){
    if($player === $this->getHolder()){
    $pk2 = new InventoryContentPacket();
    $pk2->windowId = $player->getWindowId($this);
    $pk2->items = array_map([ItemStackWrapper::class, 'legacy'], $this->getContents(true));
    $player->dataPacket($pk2);
    }else{
    $player->dataPacket($pk);
    }
    }
    }

    /**
    * @return Player[]
    */
    public function getViewers() : array{
    return array_merge(parent::getViewers(), $this->holder->getViewers());
    }
    }
    this is in the pocketmine armor inventory
     
  8. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    The sendArmorContents() doesn't even exist. Do more research before giving a wrong answer?

    The inventory and armor slots' been separated a while ago. An alternative would be
    PHP:
    $player->getArmorInventory()->setContents($items);
    Edit: Noticed that the thread was from 3 years ago. Honestly, @Superomarking. Make a new thread instead of bumping old threads by bringing up an outdated code. It causes confusions(at least for me)
     
    Primus likes this.
  9. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking

    thanks
     
  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.