Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[New API] Armor

Comments in 'Plugin Development' started by swagboy47, Jun 27, 2014.

  1. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    how do you set an armor for a player in the new API?
  2. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    The last 4 slots of the inventory of a player is the armor.
    getItem($index) and setItem($index, $item) in the inventory would work, but in order to get the index you will need to get the total slots of the normal inventory first. This can be done with getSize() and add 0-3 to it, but pocketmine has a function build in that does this for you: getArmorItem($index) and setArmorItem($index, $item). The index in these functions can be 0-3. Index 0 is the slot of the boots, 1 is the slot of the legging, 2 is the slot of the chestplate and 3 is the slot of the helmet.
    But if you don't want to remember these indexes, you can use the following functions:
    getBoots()/setBoots($item)
    getLeggings()/setLeggings($item)
    getChestplate()/setChestplate($item)
    getHelmet()/setHelmet($item)

    For example if I want to give a player full diamond armor you can use this code:
    Code:
    $player = $this->getServer()->getPlayer("Steve");
    $player->inventory->setBoots(new Item(313, 0, 1));
    $player->inventory->setLeggings(new Item(312, 0, 1));
    $player->inventory->setChestplate(new Item(311, 0, 1));
    $player->inventory->setHelmet(new Item(310, 0, 1));
  3. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I think it is actually
    PHP:
    $player $this->getServer()->getPlayer("Steve");
    $player->getInventory()->setHelmet(Item::get(item id));
    $player->getInventory()->setChestplate(Item::get(item id));
    $player->getInventory()->setLeggings(Item::get(item id));
    $player->getInventory()->setBoots(Item::get(item id));
    $player->getInventory()->sendArmorContents($player);

    //OR

    $items = array(Item::get(id of helmet),Item::get(id of chestplate),Item::get(id of leggings),Item::get(id of boots));
    $player $this->getServer()->getPlayer("Steve");
    $player->getInventory()->setArmorContents($items);
    $player->getInventoey()->sendArmorContents($player);
    PEMapModder likes this.
  4. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Oops... yes you need to send the armor after you set it.
    Thanks for notifying me on that ;)
  5. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    And also is getInventory() not inventory :D
  6. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    I'm not sure, but I think the variable $inventory is public, so you can use it directly

    Edit
    Sorry you're right, $inventory is protected so you can only get it with getInventory()
  7. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    I think I'll better go learn the new api well enough before posting anything again -_-
    iJoshuaHD, Tuff, PEMapModder and 2 others like this.
  8. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    thanks guys
  9. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    from looking at the new api. i found it more fun then the old one :D
  10. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Same!
  11. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    And it's just nostalgic))) you are like learning everything again :D
  12. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    Yeah, it makes complex plugins far easier. Especially because you don't need all the code on one file.
    Killman2 likes this.
  13. Darunia18
    Offline

    Darunia18 Staff Member Sectional Moderator

    Joined:
    Aug 23, 2013
    Posts:
    755
    Plugins:
    2
    Minecraft User:
    Darunia18
    The new API is a lot of fun :p There's lots of stuff to learn, and the docs are really helpful in plugin making. I usually don't answer things because I'm not too familiar with it yet, and don't want to embarrass myself, but I learn a lot from reading peoples' responses as well.
    Killman2 likes this.
  14. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    He rewrote AdminArmor in the new API. Do NOT let him publish it.
  15. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    i well not . if i well i would ask you first
  16. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    and by the way i did't update it i was planning the code in my head but i wrote nothing at all
    LDX likes this.
  17. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Are you still afraid of people who want to help you on github?
    Tuff and Darunia18 like this.
  18. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    Yes. :D
  19. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    if you want i can update it and give it to you to post it :) . sounds good?
  20. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    No thanks, I guess I'll put it on Github and you can do some, but don't do it all.

Share This Page

Advertisement