Skip to content

nut.inventory

Inventory System.

Base framework for creating and managing different inventory implementations.

Functions

nut.inventory.newType (typeID, invTypeStruct)
sh_nut.inventory.newType

Performs type checking for new inventory types then stores them into nut.inventory.types if there are no errors.

Parameters:

string typeID Unique identifier for the inventory type

table invTypeStruct Inventory type definition table

Raises:

Error if type validation fails or typeID exists

Usage:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    nut.inventory.newType("storage", {
        __index = table,
        add = function(self, item) ... end,
        remove = function(self, item) ... end,
        sync = function(self, client) ... end,
        typeID = "storage",
        className = "StorageInventory",
        config = {size = 10}
    })
    

nut.inventory.new (typeID)
sh_nut.inventory.new

Creates an instance of an inventory class whose type is the given type ID.

Parameters:

string typeID Type identifier to instantiate

Returns:

table New inventory instance

Raises:

Error if typeID doesn't exist

Usage:

    local inventory = nut.inventory.new("storage")
    

nut.inventory.show (inventory, parent)
cl_nut.inventory.show

Displays an inventory UI panel (client-only)

Parameters:

table inventory Inventory to display

Panel parent optional Parent panel for the UI

Returns:

panel Created inventory panel

See also:

nut.inventory.loadByID (id, noCache)
sh_nut.inventory.loadByID

Loads an inventory by its ID

Parameters:

number id Inventory ID to load

boolean noCache optional. default: false Whether to bypass cache

Returns:

promise Promise resolving to inventory instance

nut.inventory.loadFromDefaultStorage (id, noCache)
sh_nut.inventory.loadFromDefaultStorage

Loads inventory from default storage

Parameters:

number id Inventory ID to load

boolean noCache optional. default: false Whether to bypass cache

Returns:

promise Promise resolving to inventory instance

nut.inventory.instance (typeID, initialData)
sh_nut.inventory.instance

Creates a new inventory instance

Parameters:

string typeID Inventory type identifier

table initialData optional Initial inventory data

Returns:

promise Promise resolving to new inventory instance

nut.inventory.loadAllFromCharID (charID)
sh_nut.inventory.loadAllFromCharID

Loads all inventories for a character

Parameters:

integer charID Character ID to load for

Returns:

promise Promise resolving to table of inventories

nut.inventory.deleteByID (id)
sh_nut.inventory.deleteByID

Deletes an inventory by ID

Parameters:

integer id Inventory ID to delete

nut.inventory.cleanUpForCharacter (character)
sh_nut.inventory.cleanUpForCharacter

Cleans up inventories for a character

Parameters:

table character Character to clean up for

Tables

InventoryTypeDef
sh_InventoryTypeDef

Inventory Type Definition Structure

Fields:

vararg __index Metatable reference (must be "table")

function add Function to add items (server-only, required)

function remove Function to remove items (server-only, required)

function sync Function to sync inventory (server-only, required)

string typeID Unique string identifier (required)

string className Class name for metatable (required)

table config Configuration table (optional)

InventoryInstance
sh_InventoryInstance

Inventory Instance Structure

Fields:

vararg config Type-specific configuration

integer id Unique numeric identifier

table items Table containing inventory items