Removing Inventory Items

Started by TDBFW1, Tue 17/07/2018 20:11:46

Previous topic - Next topic

TDBFW1

I don't know if I'm missing something, but is there an easy way to remove all inventory items at once, without checking for it first?

Cassiebsg

yes and no

You need a while loop (or something similar)
something like: check how many inventory items the player has, then subtract 1 (with LoseInventoryItem) until the player has 0.
There are those who believe that life here began out there...

Crimson Wizard

#2
Quote from: Cassiebsg on Tue 17/07/2018 20:23:42
You need a while loop (or something similar)
something like: check how many inventory items the player has, then subtract 1 (with LoseInventoryItem) until the player has 0.

It's faster with InventoryQuantity:
Code: ags

// This removes literally all items from player's inventory
for (int i = 1; i < Game.InventoryItemCount + 1; i++) // inventory IDs begin with 1
    player.InventoryQuantity[i] = 0;
// This removes only particular items
player.InventoryQuantity[iMyItem.ID] = 0;
UpdateInventory(); // You must call this to force update on-screen inventory window

EDIT: fixed script.

TDBFW1

Thanks. It's funny, I just assumed there would be a simple function to reset the inventory.

TDBFW1

This doesn't really work for me, either in room_Load or room_AfterFadeIn. Either way, it brings up the same error message: Character.InventoryQuantity: invalid inventory index 0.

Crimson Wizard

Right, the inventory IDs begin with 1, so
Code: ags

    for (int i = 1; i < Game.InventoryItemCount + 1; i++)
        player.InventoryQuantity[i] = 0;

TDBFW1

Thanks, I accidentally typed in 0, instead of 1

Crimson Wizard

Quote from: TDBFW1 on Wed 18/07/2018 14:51:44
Thanks, I accidentally typed in 0, instead of 1

I also typed 0 myself at first. :)
Also, it was InventoryItemCount not ItemCount. Don't remember this by heart.

SMF spam blocked by CleanTalk