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

Solved Switching Items in players inventory

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

  1. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    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:
    245
    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));
     
  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.