Solved Switching Items in players inventory

Discussion in 'Development' started by Mr174, Jun 13, 2019.

  1. Mr174

    Mr174 Witch

    Messages:
    62
    GitHub:
    Mr174
    Does anyone have a basic analogy on how to switch players items in there inventory?
    (The item in hand with a random one in the inventory)
    Everything I have been trying is duping the items.
     
    Last edited: Jun 13, 2019
  2. KielKing

    KielKing Zombie

    Messages:
    243
    GitHub:
    kielking
    PHP:
    /** @var Player $player */
    $inv $player->getInventory();

    $rand mt_rand(0$inv->getSize());
    $item1 $inv->getItem($rand);
    $item2 $inv->getItemInHand();

    $inv->setItem($rand$item2);
    $inv->setItemInHand($item1));
     

Share This Page

  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.