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

Full INV

Discussion in 'Development' started by BaoNam99, Jun 21, 2019.

  1. BaoNam99

    BaoNam99 Spider Jockey

    Messages:
    30
    I want to create a plugin which send the mess "FULL" when player's inv is full. But nothing happen

    Code:
        //AutoSell
        public function isInventoryFull($player){
            $inv = $player->getInventory();
            if($event->getPlayer()->getInventory()->firstEmpty() === -1) {
                $player->sendMessage("FULLFULLFULLFULLFULLFULLFULLFULLFULL");
                return true;
            }
        }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    $event isnt even defined, are you sure you even called the function?
     
  3. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    $event must be $player and function must return true
     
  4. BaoNam99

    BaoNam99 Spider Jockey

    Messages:
    30
    is it right?
    Code:
        public function isInventoryFull($event){
            $player = $event->getPlayer();
            if($player->getInventory()->firstEmpty() === -1) {
                $player->sendMessage("FULLFULLFULLFULLFULLFULLFULL");
                return true;
            }
        }
     
  5. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    Yes
     
  6. BaoNam99

    BaoNam99 Spider Jockey

    Messages:
    30
    It's still not working
     
  7. BaoNam99

    BaoNam99 Spider Jockey

    Messages:
    30
    do i need use pocketmine\... or anything else ?
     
  8. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    Yes u need to import it but i dont know what package
     
  9. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    If you know how to use events (if not tell me I'll explain), look here https://github.com/pmmp/PocketMine-MP/tree/stable/src/pocketmine/event what you need is an inventory event to check when the inventory is updated, https://github.com/pmmp/PocketMine-...event/inventory/InventoryTransactionEvent.php
    this should do, now you're going to listen to that event, and when called check if inventory is full.
    If inventory is full send the message.
    Tips :
    To get the player in this event it's $event->getTransaction()->getSource();
    To get the inventory you get the player inventory;
    Use an ide to have automatic imports; ( right now it's pocketmine\event\inventory\InventoryTransactionEvent );
     
    jasonwynn10 likes this.
  10. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    PHP:
    if (!$p->getInventory()->canAddItem(Item::get(ItemIds::AIR))){
                
    $ev->setCancelled();
                
    $p->sendTip("FULLFULLFULLFULLFULLFULLFULLFULLFULL");
            }
    Don't over think it!
     
  11. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    What you just did is useless it'll never get called lol if you can't item it just doesn't send it, plus where do you call that fuction
     
    KielKing likes this.
  12. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    onBreakEvent -.-
     
  13. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    no lol if you do that it'll call only after the player picked up an item.
     
    KielKing likes this.
  14. Dafa

    Dafa Creeper

    Messages:
    3
    GitHub:
    dapwestwood
    How do i make block break event?
     
  15. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    public function onBreak(BlockBreakEvent $ev){
    //CODE HERE
    }:
     
  16. Dafa

    Dafa Creeper

    Messages:
    3
    GitHub:
    dapwestwood
     
  17. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    PHP:
    /**
    * @param InventoryPickupItemEvent $ev
    * @priority HIGHEST
    * @ignoreCancelled TRUE
    */
    public function onInventoryPickupItem(InventoryPickupItemEvent $ev): void{
        
    $inv $ev->getInventory();
        if(
    $inv instanceof PlayerInventory){
            
    $player $inv->getHolder();
            if(!
    $inv->canAddItem($ev->getItem()->getItem())){
                
    $player->sendTip("WEE WOO WEE WOO");
                
    $ev->setCancelled();
            }
        }
    }
     
    Mr174 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.