Skip to content

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 preserveItem optional. default: false Whether to keep the item in memory/database

Returns:

promise Promise that resolves when the item is removed

Item:delete ()
Item:delete

Deletes the item from memory and database.

Returns:

promise Resolves when the item is deleted

Item:remove ()
Item:remove

Permanently deletes this item instance and from the inventory it is in.

Returns:

promise Resolves when the item is fully removed

Item:destroy ()
Item:destroy

Deletes the in-memory data for this item

Item:onDisposed ()
Item:onDisposed

Called when the item data has been cleaned up from memory.

Item:getEntity ()
Item:getEntity

Returns the entity representing this item, if one exists.

Returns:

entity or nil The entity representing the item

Item: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 from

Angle angles optional Orientation of the item

Returns:

entity The spawned entity

Item:transfer (newInventory, bBypass)
Item:transfer

Transfers the item to a different inventory.

Parameters:

Inventory newInventory The target inventory

boolean bBypass optional. default: false Whether to bypass access rules

Returns:

bool True if transfer succeeded or was queued

Item:onInstanced (id)
Item:onInstanced

Called when an instance of this item has been created.

Parameters:

integer id The item ID

Item:onSync (recipient)
Item:onSync

Called when data for this item should be replicated to the recipient.

Parameters:

Client recipient The player to sync to

Item:onRemoved ()
Item:onRemoved

Called when this item has been deleted permanently.

Item:onRestored (inventory)
Item:onRestored

Called when this item has been loaded from the database.

Parameters:

Inventory inventory optional The inventory the item belongs to

Item:sync (recipient)
Item:sync

Syncs this item’s data to a recipient.

Parameters:

Client recipient optional 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 key

vararg 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 add

Client 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 value

Client 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 name

Client 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 succeeded

Item:getQuantity ()
Item:getQuantity

Gets the quantity of the item. If item ID is 0, returns maxQuantity instead.

Returns:

int The quantity

Item:getID ()
Item:getID

Gets the unique item ID.

Returns:

int Item ID

Item:getName ()
Item:getName

Gets the item's display name. Localized on client.

Returns:

string Name of the item

Item:getDesc ()
Item:getDesc

Gets the item's description. Localized on client.

Returns:

string Description of the item

Item:getModel ()
Item:getModel

Gets the item's model path.

Returns:

string Model path

Item:getSkin ()
Item:getSkin

Gets the item's skin index.

Returns:

int Skin index

Item:getPrice ()
Item:getPrice

Gets the item's price. Used in, for example, vendors. May be calculated dynamically using calcPrice.

Returns:

number Price value

See also:

Item:calcPrice (price)
Item:calcPrice

Dynamically calculate the price of the item.

Parameters:

number price The Item's default price

Returns:

number Calculated price

See 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 call

Client 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 owner

Or

nil If item has no owner

Item: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 all

vararg default optional Default value if key not found

Returns:

any Stored value or default

Item:hook (name, func)
Item:hook

Attaches a hook function to this item.

Parameters:

string name Hook name

function func Hook function

Item:postHook (name, func)
Item:postHook

Attaches a post-execution hook to this item.

Parameters:

string name Hook name

function 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 item

Returns:

bool Whether the two items have the same ID

Item:__tostring ()
Item:__tostring

Converts the item to a string representation.

Returns:

string The item as string identifier