Skip to content

nut.item

Item Module.

Core system for managing in-game items, their definitions, and instances.

Functions

nut.item.instance (index, uniqueID, itemData, x, y, callback)
nut.item.instance

Creates a new item instance in the database.

Parameters:

number index optional. default: nil Inventory ID (nil for none)

string uniqueID The item's unique identifier

table itemData optional. default: {} Additional item data

number x optional X position in inventory

number y optional Y position in inventory

function callback optional Function to call when item is created

Returns:

promise Returns a promise that resolves with the item instance

nut.item.deleteByID (id)
nut.item.deleteByID

Deletes an item from the database by its ID.

Parameters:

number id The item ID to delete

nut.item.loadItemByID (itemIndex, recipientFilter)
nut.item.loadItemByID

Loads an item from the database by its ID.

Parameters:

vararg itemIndex If number, single item ID. Otherwise if table, a table of IDs to load

Client recipientFilter optional Player filter for network messages

nut.item.spawn (uniqueID, position, callback, angles, data)
nut.item.spawn

Instances and spawns a given item type.

Parameters:

string uniqueID The item's unique identifier

Vector position Where to spawn the item

function callback optional Function to call when spawned (receives item, entity)

Angle angles optional Spawn angles

table data optional. default: {} Additional item data

Returns:

promise A promise when no callback is provided

nut.item.get (identifier)
nut.item.get

Retrieves an item definition table

Parameters:

string identifier Unique ID of the item

Returns:

table Item definition table

Usage:

    local itemDef = nut.item.get("medkit")
    

nut.item.load (path, baseID, isBaseItem)
nut.item.load

Internal

This is used internally - although you're able to use it you probably shouldn't.

Loads an item definition from file

Parameters:

string path Path to the item file

string baseID Base item ID to inherit from

boolean isBaseItem Whether this is a base item definition

nut.item.isItem (object)
nut.item.isItem

Checks if an object is a valid item instance

Parameters:

vararg object Object to check

Returns:

bool Whether object is an item

Usage:

    if nut.item.isItem(entity) then print("Is item") end
    

nut.item.register (uniqueID, baseID, isBaseItem, path, luaGenerated)
nut.item.register

Internal

This is used internally - although you're able to use it you probably shouldn't.

Registers a new item definition

Parameters:

string uniqueID Unique ID for the item

string baseID Base item ID to inherit from

boolean isBaseItem Whether this is a base item

string path Path to the item definition file

boolean luaGenerated Whether item is generated dynamically

Returns:

table Registered item definition

nut.item.loadFromDir (directory)
nut.item.loadFromDir

Loads all items from a directory

Parameters:

string directory Directory to scan for item files

Usage:

    nut.item.loadFromDir("nutscript/items")
    

nut.item.new (uniqueID, id)
nut.item.new

Creates a new item instance

Parameters:

string uniqueID Item definition ID

number id Unique instance ID

Returns:

table New item instance

Usage:

    local medkit = nut.item.new("medkit", 123)
    

Tables

ItemDef
ItemDef

Item Definition Structure

Fields:

string uniqueID Unique identifier

string name Display name

string desc Description text

string model World model path

integer width Inventory width

integer height Inventory height

string category Organizational category

table hooks Table of event hooks

table functions Table of interaction functions

ItemInstance
ItemInstance

Item Instance Structure

Fields:

integer id Unique instance ID

table data Custom data storage

Inventory inventory Current inventory reference