Item
Item management system for the Lilia framework.
Overview
isRotated()
Purpose
Reports whether the item is stored in a rotated state.
When Called
Use when calculating grid dimensions or rendering the item icon.
Returns
boolean True if the item is rotated.
Example Usage
if item:isRotated() then swapDims() end
getWidth()
Purpose
Returns the item's width considering rotation and defaults.
When Called
Use when placing the item into a grid inventory.
Returns
number Width in grid cells.
Example Usage
local w = item:getWidth()
getHeight()
Purpose
Returns the item's height considering rotation and defaults.
When Called
Use when calculating how much vertical space an item needs.
Returns
number Height in grid cells.
Example Usage
local h = item:getHeight()
getQuantity()
Purpose
Returns the current stack quantity for this item.
When Called
Use when showing stack counts or validating transfers.
Returns
number Quantity within the stack.
Example Usage
local count = item:getQuantity()
tostring()
Purpose
Builds a readable string identifier for the item.
When Called
Use for logging, debugging, or console output.
Returns
string Formatted identifier including uniqueID and item id.
Example Usage
print(item:tostring())
getID()
Purpose
Retrieves the numeric identifier for this item instance.
When Called
Use when persisting, networking, or comparing items.
Returns
number Unique item ID.
Example Usage
local id = item:getID()
getModel()
Purpose
Returns the model path assigned to this item.
When Called
Use when spawning an entity or rendering the item icon.
Returns
string Model file path.
Example Usage
local mdl = item:getModel()
getSkin()
Purpose
Returns the skin index assigned to this item.
When Called
Use when spawning the entity or applying cosmetics.
Returns
number|nil Skin index or nil when not set.
Example Usage
local skin = item:getSkin()
getBodygroups()
Purpose
Provides the bodygroup configuration for the item model.
When Called
Use when spawning or rendering to ensure correct bodygroups.
Returns
table Key-value pairs of bodygroup indexes to values.
Example Usage
local groups = item:getBodygroups()
getPrice()
Purpose
Calculates the current sale price for the item.
When Called
Use when selling, buying, or displaying item cost.
Returns
number Price value, possibly adjusted by calcPrice.
Example Usage
local cost = item:getPrice()
call(method, client, entity)
Purpose
Invokes an item method while temporarily setting context.
When Called
Use when you need to call an item function with player/entity context.
Parameters
string method Name of the item method to invoke.
Player client optional Player to treat as the caller.
Entity entity optional Entity representing the item.
Returns
any Return values from the invoked method.
Example Usage
item:call("onUse", ply, ent)
getOwner()
Purpose
Attempts to find the player that currently owns this item.
When Called
Use when routing notifications or networking to the item owner.
Returns
Player|nil Owning player if found.
Example Usage
local owner = item:getOwner()
getData(key, default)
Purpose
Reads a stored data value from the item or its entity.
When Called
Use for custom item metadata such as durability or rotation.
Parameters
Returns
any Stored value or default.
Example Usage
local durability = item:getData("durability", 100)
getAllData()
Purpose
Returns a merged table of all item data, including entity netvars.
When Called
Use when syncing the entire data payload to clients.
Returns
table Combined data table.
Example Usage
local data = item:getAllData()
print(detail)
Purpose
Prints a concise or detailed identifier for the item.
When Called
Use during debugging or admin commands.
Parameters
boolean detail Include owner and grid info when true.
Example Usage
item:print(true)
getName()
Purpose
Returns the display name of the item.
When Called
Use for UI labels, tooltips, and logs.
Returns
string Item name.
Example Usage
local name = item:getName()
getDesc()
Purpose
Returns the description text for the item.
When Called
Use in tooltips or inventory details.
Returns
string Item description.
Example Usage
local desc = item:getDesc()
removeFromInventory(preserveItem)
Purpose
Removes the item from its current inventory instance.
When Called
Use when dropping, deleting, or transferring the item out.
Parameters
boolean preserveItem When true, keeps the instance for later use.
Returns
Promise Deferred resolution for removal completion.
Example Usage
item:removeFromInventory():next(function() end)
delete()
Purpose
Deletes the item record from storage after destroying it in-game.
When Called
Use when an item should be permanently removed.
Returns
Promise Resolves after the database delete and callbacks run.
Example Usage
item:delete()
remove()
Purpose
Removes the world entity, inventory reference, and database entry.
When Called
Use when the item is consumed or otherwise removed entirely.
Returns
Promise Resolves once removal and deletion complete.
Example Usage
item:remove()
getEntity()
Purpose
Finds the world entity representing this item instance.
When Called
Use when needing the spawned entity from the item data.
Returns
Entity|nil Spawned item entity if present.
Example Usage
local ent = item:getEntity()
spawn(position, angles)
Purpose
Spawns a world entity for this item at the given position and angle.
When Called
Use when dropping an item into the world.
Parameters
Vector|table|Entity position Where to spawn, or the player dropping the item.
Angle|Vector|table angles optional Orientation for the spawned entity.
Returns
Entity|nil Spawned entity on success.
Example Usage
local ent = item:spawn(ply, Angle(0, 0, 0))
transfer(newInventory, bBypass)
Purpose
Moves the item into another inventory if access rules allow.
When Called
Use when transferring items between containers or players.
Parameters
Returns
boolean True if the transfer was initiated.
Example Usage
item:transfer(otherInv)
onSync(recipient)
Purpose
Hook called after the item data is synchronized to clients.
When Called
Triggered by sync calls; override for custom behavior.
Parameters
Player recipient optional The player who received the sync, or nil for broadcast.
Example Usage
function ITEM:onSync(ply) end
onSync(recipient)
Purpose
Hook called after the item data is synchronized to clients.
When Called
Triggered by sync calls; override for custom behavior.
Parameters
Player recipient optional The player who received the sync, or nil for broadcast.
Example Usage
function ITEM:onSync(ply) end
sync(recipient)
Purpose
Sends this item instance to a recipient or all clients for syncing.
When Called
Use after creating or updating an item instance.
Parameters
Player recipient optional Specific player to sync; broadcasts when nil.
Example Usage
item:sync(ply)
setData(key, value, receivers, noSave, noCheckEntity)
Purpose
Sets a custom data value on the item, networking and saving as needed.
When Called
Use when updating item metadata that clients or persistence require.
Parameters
string key Data key to set.
any value Value to store.
Player|table receivers optional Targets to send the update to; defaults to owner.
boolean noSave Skip database write when true.
boolean noCheckEntity Skip updating the world entity netvar when true.
Example Usage
item:setData("durability", 80, item:getOwner())
addQuantity(quantity, receivers, noCheckEntity)
Purpose
Increases the item quantity by the given amount.
When Called
Use for stacking items or consuming partial quantities.
Parameters
number quantity Amount to add (can be negative).
Player|table receivers optional Targets to notify; defaults to owner.
boolean noCheckEntity Skip updating the entity netvar when true.
Example Usage
item:addQuantity(-1, ply)
setQuantity(quantity, receivers, noCheckEntity)
Purpose
Sets the item quantity, updating entities, clients, and storage.
When Called
Use after splitting stacks or consuming items.
Parameters
number quantity New stack amount.
Player|table receivers optional Targets to notify; defaults to owner.
boolean noCheckEntity Skip updating the world entity netvar when true.
Example Usage
item:setQuantity(5, ply)
interact(action, client, entity, data)
Purpose
Handles an item interaction action, running hooks and callbacks.
When Called
Use when a player selects an action from an item's context menu.
Parameters
string action Action identifier from the item's functions table.
Player client Player performing the action.
Entity entity optional World entity representing the item, if any.
any data Additional data for multi-option actions.
Returns
boolean True if the action was processed; false otherwise.
Example Usage
item:interact("use", ply, ent)
getCategory()
Purpose
Returns the item's localized category label.
When Called
Use when grouping or displaying items by category.
Returns
string Localized category name, or "misc" if undefined.
Example Usage
local category = item:getCategory()