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 indexoptional. 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 instancenut.item.deleteByID (id)
nut.item.deleteByID
Deletes an item from the database by its ID.
Parameters:
number id The item ID to deletenut.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 loadClient
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 identifierVector 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 providednut.item.get (identifier)
nut.item.get
Retrieves an item definition table
Parameters:
string identifier Unique ID of the itemReturns:
table Item definition tableUsage:
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 filestring 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 checkReturns:
bool Whether object is an itemUsage:
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 itemstring 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 definitionnut.item.loadFromDir (directory)
nut.item.loadFromDir
Loads all items from a directory
Parameters:
string directory Directory to scan for item filesUsage:
nut.item.new (uniqueID, id)
nut.item.new
Creates a new item instance
Parameters:
string uniqueID Item definition IDnumber id Unique instance ID
Returns:
table New item instanceUsage:
Tables
ItemDef
ItemDef
Item Definition Structure
Fields:
string uniqueID Unique identifierstring 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 IDtable data Custom data storage
Inventory inventory Current inventory reference