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

Solved How do I get the Item that's being transacted between Inventories

Discussion in 'Development' started by CortexPE, May 5, 2017.

  1. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    How can I get the Item that's being transacted between Inventories
    I need to check if the player takes the right Item from Another Inventory.

    This doesn't seem to work:
    PHP:
    $transactions $ev->getTransaction()->getTransactions();
            foreach(
    $transactions as $transaction){
                
    $inv $transaction->getInventory();
                if(
    $inv instanceof PlayerInventory){
                    foreach(
    $inv->getViewers() as $assumed) {
                        if (
    $assumed instanceof Player) {
                            
    //getTargetItem() just produces an ERROR.
                            
    $this->getServer()->getLogger()->info($inv->getTargetItem()->getId());
                        }
                    }
                }
            }
    Nor:
    PHP:
    $item $ev->getTransaction()->getInventories()->getItem(); // Of Course getItem() needs an index. I already know that, But I still tested it.
    $this->getServer()->getLogger()->info("ID: " $item->getId());
    Help is ALWAYS Appreciated. :)

    Note: I already added
    PHP:
    use pocketmine\inventory\PlayerInventory;
     
    Last edited by a moderator: May 5, 2017
  2. Lowkey

    Lowkey Slime

    Messages:
    94
    what is your error?
     
  3. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Code:
    CRITICAL> "Could not pass event 'pocketmine\event\inventory\InventoryTransactionEvent' to 'GUICombiner v1.0.0': Call to undefined method pocketmine\inventory\PlayerInventory::getTargetItem() on CortexPE\TridentNetwork\GUICombiner
    CRITICAL> Error: "Call to undefined method pocketmine\inventory\PlayerInventory::getTargetItem()" (EXCEPTION) in "/plugins/GUICombiner_v1.0.0/src/CortexPE/TridentNetwork/GUICombiner" at line 135
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    The error is pretty self explanatory. You used PlayerInventory->getTargetItem(), which doesn't exist. This function does, though. :p
     
    Lowkey likes this.
  5. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
  6. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
    Oh wait... It did!
    Just fixed it myself...

    SOLVED!
     
    jasonwynn10 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.