config/items.lua and by resources at runtime. Inventories that hold them come from the inventory module.
Config
config/items.lua
Item names are lowercase letters, digits and underscores. The file replaces the default items entirely.
Register
metadata:
UgSchemaRule | function
Checked on every write of the item’s metadata. A schema rule, or a function
fun(metadata): ok, message?.- Invalid definitions raise, with the same messages as config errors.
- When
config/items.luadefines the same name, the config wins: its fields stay, and only yourmetadatarule is added. A warning is logged. - A name registered by another resource raises.
- Items registered by a resource are removed when it stops.
Metadata rules
Every item’s metadata MUST be bounded data, rule or not: booleans, finite numbers, strings up to 512 characters, at most 128 entries, 6 levels deep. Vectors are not allowed, since metadata is saved as JSON.nilmetadata is always allowed. An empty table counts asnil.- Stacks only merge when their metadata is equal.
- A rejected write returns
invalid_args. The reason goes to the server log in debug mode.
RegisterUse
Inventory.Use, which runs every check before your handler.
fun(source, item): boolean?
required
Gets the player and a copy of the slot:
{ slot, name, count, metadata }. Return false to refuse: nothing is consumed.integer
default:"0"
Units removed from the slot after a successful use. 0 to 1,000.
integer
default:"0"
Milliseconds between uses of this item, per player.
boolean
default:"true"
Refuses downed and dead players.
Get / GetAll / Exists / IsUsable
table
Client
GlobalState['ug-core:Items'], without metadata rules. Use them for labels and weights in a UI.
Events
Hooks
It allows or cancels. A cancelled use returns
no_permission and consumes nothing.