OPX//77
CreatorsServer exports

RegisterUsableItem

Last updated on

Makes one of your exports decide what using an item does.

local res = exports.opx_infinity:RegisterUsableItem(item, export)

Scope write · await it — answers at once.

Parameters

  • item: string — an item the catalogue carries

  • export: string — an export of your resource (letters, digits, _, up to 64)

  • When a player uses the item, the inventory holds the slot and calls exports.<you>:<export>(source, info) with info = { name, slot, count, metadata, label, citizenId }.

  • Your export answers { ok = true, consume = <n>? } to let the use go ahead (consume overrides the item's own, 0 keeps the stack), or { ok = false, error = '<code>' } to refuse it. It may yield (the database, a check); it must answer inside the inventory's handler deadline, or the use is refused and nothing is consumed.

  • An item another owner (a module, or another resource) already handles is export.usableTaken.

Answer fast, and stay idempotent

The inventory waits USE_HANDLER_MS (5 s) for your answer. A handler slower than that is refused (handler_timeout) and nothing is consumed — but your export keeps running, so an effect it already applied (money paid, a need filled, a door opened) stays applied while the item stays in the bag. Answer quickly, apply your effect last, and make it safe to run twice: the player can use the item again.

  • Removed when your resource stops (not on a restart that is already running again: see When your resource stops). Give the item a use table in its definition if you want the inventory screen to offer Use.

Returns

  • true

Errors

  • unknown_item, export.usableTaken, export.badArgument, export.callerDenied
Example
-- server.lua of my_food
exports('UseBurger', function(source, info)
  -- check on the server, then decide
  return { ok = true, consume = 1 }
end)

exports.opx_infinity:RegisterUsableItem('burger', 'UseBurger')

On this page

No Headings