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

Help Me !! PLS For Item

Discussion in 'Plugin Help' started by WoolChannel3295, Feb 16, 2020.

  1. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    Suppose in the player's pocket there are rocks, wood, sand that I want to check how many stones there should be
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
            /** @var Player $player */
            
    $cobble 0;
            foreach (
    $player->getInventory()->getContents() as $item) {
                if(
    $item->getId() === Item::COBBLESTONE) {
                    
    $cobble += $item->getCount();
                }
            }
     
    HimbeersaftLP likes this.
  3. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    Ok,

    but when it has about 128 stones, it sends outMessage, it will output about 2 lines 1 line 64 1 line 128. is there any way to accumulate it?
    :(
     
  4. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    suppose in the player's pocket there are 2 stone stacks that when sending Message it sends two lines: line 1 is 64 stones line 2 is 128 stones. Is there a way to sendMessage 1 line?
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    The code @GamakCZ sent does exactly what you want. The combined count of all cobblestone blocks is stored in the $cobble variable.

    See, this would only send one message:
    PHP:
            /** @var Player $player */
            
    $cobble 0;
            foreach (
    $player->getInventory()->getContents() as $item) {
                if(
    $item->getId() === Item::COBBLESTONE) {
                    
    $cobble += $item->getCount();
                }
            }
            
    $player->sendMessage("You have $cobble cobblestones in your inventory");
     
    WoolChannel3295 and GamakCZ like this.
  6. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    Oh thks very much ☺
     
    HimbeersaftLP 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.