Registering items
Define item properties and connect usable items to server exports.
Resource start order
Register all items inside the inventory resource. If another resource registers an item after the inventory loads, the item may not be added and may be deleted from an inventory.
Item definition
labelstringDisplay name of the item.
tradablebooleanControls whether the item can be traded.
deletablebooleanControls whether the item can be deleted.
stackablebooleanAllows multiple items to share a stack.
descriptionstringItem description.
weightnumberWeight of one item.
categorystringCategory assigned to the item.
defaultMetaInventoryItemMetaDataDefault metadata assigned to new items.
usablebooleanControls whether the item can be used.
droppedModelstringWorld model used when the item is dropped.
weaponHashnumber | stringAssociated weapon hash.
allowedAttachmentsstring[]Attachments supported by the item.
generateSerialbooleanEnables serial number generation.
server?{ export?: string; onUseDeleteAmount?: number }Server export and removal amount used when the item is activated.
Register an item
Basic item
Register money as a stackable, tradable currency item.
ScriptShared.Items:Add("money", {
stackable = true,
deletable = true,
tradable = true,
label = "Money",
weight = 0.0,
category = "Currency"
})
Register item use behavior
Set server.export to the export that should run when the item is used. Create that export in the named resource.
Usable item
Register gold as a usable item connected to a server export.
ScriptShared.Items:Add("gold", {
stackable = true,
deletable = true,
tradable = true,
label = "Gold",
weight = 1.5,
usable = true,
category = "Raw material",
server = {
export = "resource_name.any_function_name",
onUseDeleteAmount = 1
}
})
Item use export
Handle the item in the resource specified by server.export.
exports("any_function_name", function(source, item)
print(source)
print(json.encode(item, { indent = true }))
end)