RegisterItem
Last updated on
Adds an item to the catalogue while the server runs, on the server and every client.
local res = exports.opx_infinity:RegisterItem(name, definition)Scope write · await it — answers at once.
Parameters
-
name:
string— letters, digits,_ - ., up to 48 characters -
definition:
table— every field optional- label?:
string— your text, or a locale key; up to 160 characters - description?:
string - weight?:
integer— grams, 0–1 000 000 000; default the inventory'sDEFAULT_ITEM_WEIGHT - stack?:
boolean— defaulttrue - drop?:
boolean— defaulttrue;falserefuses a drop on the server - category?:
string— word characters; neverweaponorammo - image?:
string— an image file name of the inventory page - model?:
string— a curatedOpen77.propsalias for a pile on the ground, never a.meshpath - use?:
table— makes it usable:{ consume?, close?, status?, animation? = { name, variant?, durationMs? } }- status?:
{ [need] = amount }— at most 8 needs, each name up to 32 characters (bad_definition:use.statuspast that): every client walks it inside the one resume that received it
- status?:
- label?:
-
Validated whole by the catalogue's own
Catalog.Register, which every client runs on the same table; the first wrong field refuses it (bad_definition:<field>,bad_definition:field:<name>for a field the catalogue does not know). -
Sent to every client at once, four items per event, and to a client that joins later when it says hello.
-
A name config or another resource already holds is
item_taken. Your own name may be registered again, which replaces it. -
At most
SERVER.EXPORTS.ITEMS.MAX_PER_CALLERitems per resource (64):item_cap. -
Not persisted, and not removed when your resource stops (stacks of it are in bags): register your items again on every start.
-
To decide what using it does, add
RegisterUsableItem.
Returns
table— the item asGetItemanswers it
Errors
bad_name,item_taken,item_cap,bad_definition:<field>,export.badArgument,export.callerDenied
AddEventHandler('onResourceStart', function(name)
if name ~= GetCurrentResourceName() then return end
local res = exports.opx_infinity:RegisterItem('burger', {
label = 'Burger', weight = 250, category = 'food',
use = { consume = 1, status = { hunger = 25 } },
})
if not res.ok then print('burger refused: ' .. res.error) end
end)