Item
Item Class.
Represents an instance of an item in NutScript, including persistence, networking, inventory management, and interaction logic.
Methods
Item:removeFromInventory (preserveItem)
Item:removeFromInventory
Removes the item from the inventory it is in and then itself
Parameters:
boolean preserveItemoptional. default
: false
Whether to keep the item in memory/database
Returns:
promise Promise that resolves when the item is removedItem:delete ()
Item:delete
Deletes the item from memory and database.
Returns:
promise Resolves when the item is deletedItem:remove ()
Item:remove
Permanently deletes this item instance and from the inventory it is in.
Returns:
promise Resolves when the item is fully removedItem:getEntity ()
Item:getEntity
Returns the entity representing this item, if one exists.
Returns:
entity or nil The entity representing the itemItem:spawn (position, angles)
Item:spawn
Spawn an item entity based off the item table.
Parameters:
vararg position A Vector position or a player to derive drop position fromAngle
angles
optional
Orientation of the item
Returns:
entity The spawned entityItem:transfer (newInventory, bBypass)
Item:transfer
Transfers the item to a different inventory.
Parameters:
Inventory newInventory The target inventoryboolean
bBypass
optional. default
: false
Whether to bypass access rules
Returns:
bool True if transfer succeeded or was queuedItem:onInstanced (id)
Item:onInstanced
Called when an instance of this item has been created.
Parameters:
integer id The item IDItem:onSync (recipient)
Item:onSync
Called when data for this item should be replicated to the recipient.
Parameters:
Client recipient The player to sync toItem:onRestored (inventory)
Item:onRestored
Called when this item has been loaded from the database.
Parameters:
Inventory inventoryoptional
The inventory the item belongs to
Item:sync (recipient)
Item:sync
Syncs this item’s data to a recipient.
Parameters:
Client recipientoptional
The recipient to send data to (nil = broadcast to all clients)
Item:setData (key, value, receivers, noSave, noCheckEntity)
Item:setData
Sets data on this item and optionally syncs it.
Parameters:
string key The data keyvararg value The data value
Client
receivers
optional
Receiver(s) to send update to
boolean
noSave
optional. default
: false
Whether to skip saving to database
boolean
noCheckEntity
optional. default
: false
Whether to skip syncing with entity
Item:addQuantity (quantity, receivers, noCheckEntity)
Item:addQuantity
Adds quantity to the item.
Parameters:
integer quantity The amount to addClient
receivers
optional
Receiver(s) to notify
boolean
noCheckEntity
optional. default
: false
Whether to skip syncing with entity
Item:setQuantity (quantity, receivers, noCheckEntity)
Item:setQuantity
Sets the quantity of the item.
Parameters:
integer quantity The new quantity valueClient
receivers
optional
Receiver(s) to notify
boolean
noCheckEntity
optional. default
: false
Whether to skip syncing with entity
Item:interact (action, client, entity, data)
Item:interact
Performs an interaction on the item (e.g., use, drop). Handles all logic and hooks associated with the action.
Parameters:
string action The action nameClient client The player performing the action
Entity
entity
optional
The associated entity if any
table
data
optional
Optional data/context
Returns:
bool Whether the interaction succeededItem:getQuantity ()
Item:getQuantity
Gets the quantity of the item.
If item ID is 0, returns maxQuantity
instead.
Returns:
int The quantityItem:getName ()
Item:getName
Gets the item's display name. Localized on client.
Returns:
string Name of the itemItem:getDesc ()
Item:getDesc
Gets the item's description. Localized on client.
Returns:
string Description of the itemItem:getPrice ()
Item:getPrice
Gets the item's price. Used in, for example, vendors.
May be calculated dynamically using calcPrice
.
Returns:
number Price valueSee also:
Item:calcPrice (price)
Item:calcPrice
Dynamically calculate the price of the item.
Parameters:
number price The Item's default priceReturns:
number Calculated priceSee also:
Item:call (method, client, entity, ...)
Item:call
Calls a method on the item with client/entity context.
Parameters:
string method Name of the method to callClient
client
optional
The client context
Entity
entity
optional
The entity context
vararg ... Arguments to pass to the method
Item:getOwner ()
Item:getOwner
Gets the player who owns this item. Scans known inventories and recipients.
Returns:
client The ownerOr
nil If item has no ownerItem:getData (key, default)
Item:getData
Gets stored data from the item.
If key is true
, returns the entire data table.
Parameters:
vararg key Data key (string) or true to return allvararg
default
optional
Default value if key not found
Returns:
any Stored value or defaultItem:hook (name, func)
Item:hook
Attaches a hook function to this item.
Parameters:
string name Hook namefunction func Hook function
Item:postHook (name, func)
Item:postHook
Attaches a post-execution hook to this item.
Parameters:
string name Hook namefunction func Hook function
Item:onRegistered ()
Item:onRegistered
Called after NutScript has stored this item into the list of valid items.
Metamethods
Item:__eq (other)
Item:__eq
Checks if this item is equal to another item.
Parameters:
item other The other itemReturns:
bool Whether the two items have the same IDItem:__tostring ()
Item:__tostring
Converts the item to a string representation.