Page 1 of 1

Clear Players Inventory

Posted: Tue Jan 10, 2017 6:13 am
by xdlewisdx
Just wondering if there is a way of clearing a players inventory like

player.Inventory.clearInventory

or something like that?

Re: Clear Players Inventory

Posted: Thu Jan 12, 2017 4:25 am
by sharkbound
xdlewisdx wrote:Just wondering if there is a way of clearing a players inventory like

player.Inventory.clearInventory

or something like that?

Here is the main way of doing it:

Code: Select all

            UnturnedPlayer player = (UnturnedPlayer)caller;

            // Loops over each of the player's inventory pages
            for (byte page = 0; page < 8; page++)
            {
                // gets the item count for the current inventory page its looking in
                var items = player.Inventory.getItemCount(page);

                // loop over all items in current inventory page
                for (byte index = 0; index < items; index++)
                {
                    // remove the item
                    player.Inventory.removeItem(page, 0);
                }
            }