Inventory
Scripting with the Inventory class.
The Inventory
class serves as the settings and functionality for the player's inventory. All fields listed in the Inventory tab of the Inventool editor window are public and can be changed at runtime.
NOTE: Runtime edits of the inventory are not saved automatically. This would need to be done manually.
When making edits to the inventory, relevant parts of the Inventool Window may need to be refreshed.
Accessing the Inventory
You can access the player's inventory with Inventool.Inventory
.
Fields & Properties
navigation
The inventory navigation type.
Inventory.Navigation
public
isInfinite
If the inventory is infinite.
bool
public
enableEquipment
If the inventory's character equipment section should be enabled.
bool
public
enableCraftingTab
If the inventory's crafting tab should be enabled.
bool
public
enableEnchantingTab
If the inventory's enchanting tab should be enabled.
bool
public
enableKeyItemsTab
If the inventory's key item tab should be enabled. If this is enabled, key items will have their own section in the inventory window and will not contribute to weight.
bool
public
useWeights
If the inventory should use weights.
bool
public
totalItemWeight
The current weight of all items. This is the cached value since the last time RecalculateTotalWeight
was used.
float
public
maxWeight
The max number of item weight the inventory can hold.
float
public
disallowNewItemsIfMaxWeight
If the player should not be able to obtain new items if the weight has reached the max value.
bool
public
showSubtypeInKeyItemsTab
If the details in the key items tab should display subtype names.
bool
public
allowItemDropping
If item dropping should be allowed.
bool
public
showSubtypes
If item subtypes should be displayed in the inventory filter list.
bool
public
deleteItemsOnDrop
If the item should be deleted on drop.
bool
public
currentPage
The current page number.
int
public
maxPages
The max number of pages. This is only relevant if the navigation type is set to pagination and the inventory is not infinite.
int
public
minPageSize
The minimum size of the page. This is only relevant if navigation is set to scrolling and the inventory is infinite.
Vector2Int
public
pageSize
The size of each page. This is only relevant if navigation is not set to scrolling and the inventory is not infinite.
Vector2Int
public
enchantingSlotLeftIcon
The icon of the left enchanting slot.
Sprite
public
enchantingSlotRightIcon
The icon of the right enchanting slot.
Sprite
public
enchantingSlotLeftIconTint
The color tint of the left enchanting slot.
Color
public
enchantingSlotRightIconTint
The color tint of the right enchanting slot.
Color
public
noFilterIcon
The icon of the no filter button.
Sprite
public
noFilterIconColorTint
The color tint of the no filter icon.
Color
public
itemStacks
A list of all items stacks in the inventory. Use SetItems
, AddItems
, or RemoveItems
to change the list instead of editing the list itself.
List<ItemStack>
public
keyItems
A list of key items separated from the main item stack list. This is only relevant if enableKeyItems
is set to true.
List<ItemStack>
public
currencies
A list of player currencies that can be managed.
Currency
public
itemSlots
A list of all item slots.
ItemSlot[]
public
orderMode
The order mode of the items.
Inventory.OrderMode
public
activeItemTypeFilter
The active item type filter.
ItemType
public
MaxWeightExceeded
If the total item weight is greater than the max weight.
bool
public
PageSlotCount
The number of total slots per page.
int
public
TotalSlotCount
The number of total slots, combining all slots in all pages.
int
public
Items
Setting Items
You can set items with the SetItems
method. This will remove all previous items in the inventory.
Adding Items
With the AddItems
method, you can add a single or a list of item stacks to the inventory.
Remove Items
With the RemoveItems
method, you can remove a single or a list of item stacks from the inventory.
Getting Items
You can get the full list of items with the itemStacks
and keyItems
fields.
Get All Items in a Specific Page
Get All Items in the Current Page
Checking If An Item Can Fit
You can check if an item will fit in the inventory with the HasSpaceForItem
method.
Checking Items
You can use the Contains
method to check and see if the player has an instance of an item in their inventory. You can use an Item
object, the item ID, or the item name to perform this check.
Using Items
Items in the inventory can be used with the UseItem
method. Used items are removed from the inventory.
Pick Up Items
Pick up methods simply remove an Item Drop from the game world and add an instance of an Item Stack to the player's inventory.
PickUpAllItemsInRange
method picks up all items that the player is in range of in the game world.
To pick up a single item, use PickUpItem
.
Drop Items
To drop a specific item (remove it from the inventory), use the DropItem
method. This may create an instance of an Item Drop in the game world.
Currencies
In the examples below, cost
is a Currency. You can access the full list of currencies with the Inventool.Inventory.currencies
field.
Spending
A currency can be spent with the TrySpend
method. This method returns a bool
. False will be returned if the player doesn't have enough of the specific currency. Otherwise, it will return true.
Earning
You can add an amount to a player's currency with the TryEarn
method. While this method returns a bool
, it should always return true unless the specific currency type does not exist in the inventory.
Sufficient Funds Checking
You can check if the player has enough of a particular currency with the HasEnoughCurrency
method and providing a cost parameter.
Resetting
You can reset all currencies to their starting values with the ResetCurrencies
method.
Weights
Weights are only relevant if the useWeights
field is set to true.
Max Weight
You can get and set the max weight with the maxWeight
field.
Total Item Weight
To get the total weight of all items in the inventory, use RecalculateTotalWeight
.
Checking If An Item Will Exceed the Weight
Sometimes it may be necessary to check if an item will cause the max weight to be exceeded. You can use the ItemWillExceedWeightLimit
method for this purpose.
Pages & Organization
Inventory items are organized in grid-based pages. Whether your inventory 1 page or 100, the logic is the same.
Reorganization
You can reorganize the inventory with the Reorganize
method.
If you'd only like to regroup item stacks, use the Regroup
method.
Filters
Inventory items can be filtered with Item Type. Items that don't match the filter will not be returned when using the GetAllItemsInPage
or GetAllItemsInCurrentPage
methods. If the ItemType
is a parent, items with the parent type or any of it's child types will not be filtered out.
Set the Item Filter
Remove Item Filter
Page Sizes
Setting the Size
You can set the page size by editing the minPageSize
or pageSize
fields. When these are changed, the inventory may need to be reorganized.
Recalculating the Size
Pages sizes may need to be recalculated when the inventory is infinite, navigation is set to scrolling, and new items are added. Call the RecalculatePageSize
method for this purpose. This will update the pageSize
field automatically.
Pagination
Current Page
The current page number is stored in the currentPage
field.
You can flip to the next page with the NextPage
method.
Similarly, you can flip to the previous page with PreviousPage
method.
Alternatively, you can set the current page (page numbers start at 0).
Recalculate Required Pages
The maxPages
field is an integer that stores the max number of pages that the inventory has. The pages can be limited or unlimited (this can be set from the Inventory). In the case they are unlimited, the maxPages
field may need to be recalculated at times. You can call RecalculateRequiredPages
for this purpose.
Minimum Required Pages
You can get the minimum required pages to fit all items with the MinimumRequiredPages
method.
Last updated