Skip to main content
Server Client Proxied to ug-core. Items are defined by owners in 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

Adds an item from a resource. Same fields as the config, plus 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.lua defines the same name, the config wins: its fields stay, and only your metadata rule 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.
  • nil metadata is always allowed. An empty table counts as nil.
  • 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

Makes an existing item usable. Players use items through 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.
One resource per item. Handlers are removed when their resource stops.

Get / GetAll / Exists / IsUsable

table

Client

Definitions replicate through 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.