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

Inventory menu

Discussion in 'Development' started by #A6543, Feb 8, 2017.

  1. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    So you want to change the item that the player selected from the chest?
     
  2. #A6543

    #A6543 Zombie

    Messages:
    267
    So u know BedWars? I want to create something like the shop in BedWars
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try
    PHP:
    public function onTransaction(InventoryTransactionEvent $event){
      
    $transactions $event->getTransaction()->getTransactions();
      
    $player null;
      
    $chestinv null;
      
    $action null;
      foreach(
    $transactions as $transaction){
       if((
    $inv $transaction->getInventory()) instanceof ChestInventory){
        foreach(
    $inv->getViewers() as $assumed)
         if(
    $assumed instanceof Player) {
          
    $player $assumed;
          
    $chestinv $inv;
          
    $action $transaction;
          break;
         }
       }
      }
      if(
    $chestinv === null) return;
      
    $event->setCancelled();
      
    $item $action->getTargetItem();

      if(
    $item->getName() == "Site 1") {
        
    $chestinv->clearAll();
        
    //Slot: $action->getSlot();
        //Site 1
      
    }
    }
     
  4. #A6543

    #A6543 Zombie

    Messages:
    267
    This does exactly the same lol. It only works, if I put the item from the chest to the players inv and back
     
  5. Aviv

    Aviv Baby Zombie

    Messages:
    156
    yeah same (im using pmmp)
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Isn't it what it should be doing? It's working great, then. No errors in code.
     
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    I want to tap a item to change the inventory. But need to tap it and in the same moment tap it again in the players inventory. And that's not what I want
     
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    How can i stop the player from adding back the item inside the chest?
     
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    @Muqsit Wouldn't this work for an Interactive Chest Tile?
    What i mean:
    1) Players are able to purchase stuffs but can't add stuffs inside the Chest.
    2) Players are able to click on a stuffs and check the price..

    I've checked you GitHub here at: https://github.com/Muqsit/ChestShop - Very cool but i need to know the way and how to make a plugin w/o actually copying..

    My Loader - I agree this was copied from others for learning purposes:

    PHP:
    <?php

    /* Essentials */
    use pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\TextFormat as TF;

    use 
    pocketmine\tile\Tile;
    use 
    pocketmine\tile\Chest;
    use 
    pocketmine\inventory\ChestInventory;

    /* Events */
    use pocketmine\event\inventory\InventoryTransactionEvent;

    class 
    Loader extends PluginBase implements Listener {
       
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       
        public function 
    onChest(InventoryTransactionEvent $e) {
           
            
    $trans $e->getTransaction()->getTransactions();
           
                foreach(
    $trans as $t) {
                   
                    
    $inv $t->getInventory();
                       
                        if(
    $inv instanceof ChestInventory) {
                           
                            foreach(
    $inv->getViewers() as $assumed) {
                               
                                if(
    $assumed instanceof Player) {
                                   
                                    
    $p $assumed;
                                    
    $cinv $inv;
                                    
    $action $t;
                                    break;  
                                }
                               
                            }
       
                        }
                       
                        if(
    $inv == null) return;
                        
    $e->setCancelled();
                        
    $item $action->getTargetItem();
                           
                            if(
    $item->getName() === "Test") {
                               
                                
    $sender->sendMessage("Whats this");
                               
                            }

                }
             
        }

        public function 
    sendChest(Player $p) {
           
            
    $nbt = new CompoundTag(' ', [
                    new 
    ListTag('Items', []),
                    new 
    StringTag('id'Tile::CHEST),
            new 
    IntTag('ChestShop'1),
            new 
    IntTag('x'floor($player->x)),
            new 
    IntTag('y'floor($player->y) - 4),
            new 
    IntTag('z'floor($player->z))
                   
            ]);
            
    $tile Tile::createTile("Chest"$player->getLevel()->getChunk($player->getX() >> 4$player->getZ() >> 4), $nbt);
            
    $p->addWindow($tile->getInventory());
           
        }
       
        public function 
    onDisable() {
            
    parent::onDisable();
        }
       
    }
    I might miss some "use" statements :D but i'm aware of it..

    My GitHub - Just want to show the progress and for me w/o getting lost:
    https://github.com/RTGDaCoder/Test-ChestTransaction
     
  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.