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

Transactions

Discussion in 'Development' started by Teamblocket, Apr 9, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    hey , how can i do Inventory Transactions , i want the player to hit a clock in a chest inventory and get a chain armor piece.
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    InventoryTransactionEvent
     
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    yes ik, but what else do i have todo?
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Transactions can be a bit confusing. You can listen for InventoryTransactionEvent, then do event->getTransaction()->getTransactions(), because the event is confusing like that. You can foreach the transactions, then get the inventory, the target item, etc. You will learn more by looking in the source or by reading the API docs. I also may be wrong on this, so feel free to check me.
     
    jasonwynn10 likes this.
  5. Aviv

    Aviv Baby Zombie

    Messages:
    156
    There was a plugin named ChestShop made by @Muqsit , he showed a really good way to do InventoryTransactionEvent
    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 CustomChestInventory){
            foreach(
    $inv->getViewers() as $assumed){
              if(
    $assumed instanceof Player){
                
    $player $assumed;
                
    $chestinv $inv;
                
    $action $transaction;
                break 
    2;
              }
            }
          }
        }
        
    /*
        * $player => Player interacting with the GUI.
        * $chestinv => The chest's inventory.
        * $action => BaseTransaction|Transaction|SimpleTransactionGroup
        */
      
    if($chestinv === null) return;
      
    // code
      
    }
     
    Muqsit likes this.
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    am kinda confused on what todo on code ,
    PHP:
    if($player->getInventory()->getTargetItem() === ITEM::CLOCK){
    \\?
     
  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.