How to check if armor inventory slot is not empty

Discussion in 'Development' started by WhoAreMe, May 17, 2020.

  1. WhoAreMe

    WhoAreMe Spider Jockey

    Messages:
    35
    As title suggests, i wanna know of armor inv slot is not empty.
    I tried this code
    if($sender->getArmorInventory()->getHelmet() !== null)
    But no luck
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    708
    GitHub:
    xXNiceYT
    PHP:
    use pocketmine\item\Helmet;

    if(
    $sender->getArmorInventory()->getHelmet() instanceof Helmet){
    }
     
  3. wolfdale

    wolfdale Zombie Pigman

    Messages:
    435
    There is no such class...
    A simple way is to do
    PHP:
    if(!$sender->getArmorInventory()->getHelmet()->isNull())
     
    WhoAreMe likes this.
  4. NTT

    NTT Zombie

    Messages:
    201
    GitHub:
    NTT1906
    If I was you, I would
    PHP:
    if(!is_null($player->getArmorInventory()->getHelmet())){
    }
     
  5. WhoAreMe

    WhoAreMe Spider Jockey

    Messages:
    35
    Now i got another problem. How can i transfer armor inventory item to player inventory if that item already exist in armor inventory.
    I hope anyone won't hard time understanding this lol
     
  6. WhoAreMe

    WhoAreMe Spider Jockey

    Messages:
    35
    Ex. A player has helmet with custom name in inventory. If i do getArmorInventory->setHelmet it will override that item in inventory.What i want to do is transfer it to player inventory.
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    435
    Simple
    PHP:
    $player->getInventory()->addItem($player->getArmorInventory()->getHelmet());
    //set helmet
     
    WhoAreMe likes this.

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.