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

How to check player item ammount

Discussion in 'Development' started by AmalCraft, Jul 22, 2021.

  1. AmalCraft

    AmalCraft Creeper

    Messages:
    5
    Hello there, i am making rpg server that use emerald as its currency but i have no idea how to check ammount of emeralds in player inventory so i can make scorehud addons. Pls help
     
  2. xLeakDev Enzo

    xLeakDev Enzo Spider Jockey

    Messages:
    38
    GitHub:
    nya-enzo
    PHP:
    /** @var pocketmine\Player $player*/
    $count 0;
    foreach(
    $player->getInventory()->getContents() as $item)
    {
          if(
    $item->getId() === Item::EMERALD)
                 
    $count += $item->getCount()
    }

    $player->sendMessage("§aYou have §l{$count} §r§aEmeralds !");
    To make the thing show in scoreboard, in your addon instead of sending a message you could set your value to the $count variable
     
  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.