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

contents

Discussion in 'Development' started by Teamblocket, Feb 18, 2018.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Hey, am trying to drop all the player's contents from their Inventory(not ArmorInventory) when they quit the server.
     
  2. MioTaku

    MioTaku Witch

    Messages:
    69
    GitHub:
    uselesswaifu
    Okay.
     
  3. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Use the Player::dropItem() function on each item of the inventory

    PHP:
    foreach($player->getInventory()->getContents() as $item)
    {
        
    $player->dropItem($item);
    }
    Then clear the inventory.

    PHP:
    $player->getInventory()->clearAll();
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    There's a dropContents() method in the inventory class.
     
    CortexPE and OnTheVerge like this.
  5. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Yes I know. But the contents don’t drop when the player quits the server.
     
  6. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Can you post the code?
     
    Thunder33345 likes this.
  7. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    PHP:
        public function onQuit(PlayerQuitEvent $event){
            
            
    /** @var ServerPlayer $player */ // ServerPlayer class is a class I made extending Player class.
            
    $player $event->getPlayer();
            if(
    $player->getUserIndex(User::COMBAT) == true){
                
    $player->getInventory()->dropContents($player->getLevel(), $player);
                
    $player->getArmorInventory()->dropContents($player->getLevel(), $player);

                
    $player->getInventory()->clearAll();
                
    $player->getArmorInventory()->clearAll();
                
    $player->removeUserIndex(User::COMBAT);
            }
        }
     
  8. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
  9. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    We would need more code!
     
  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.