Esc to clear, Enter to open the best match, click an export to open it in its page
Inventory
Store kinds
A store is anything items sit in: pockets, a stash, a car boot, a panel. For your own kind you write how it's read, written and saved; weight, stacking, metadata merging, the transaction and client sync come with it.
Do you need one?
A store kind is for storage that persists, authorises itself and behaves like a first-class container. For a slot grid open for one session, OpenPanel is simpler, with no persistence to write; for an item that holds items, use RegisterPanelItem.
Registering a kind
Declares a kind of store: once per kind, never per instance. The name is yours once registered (the registration rule): another resource's kind is refused, and registering yours again swaps the definition quietly.
| Function | Signature | Purpose |
|---|---|---|
resolve | (key) → handle|nil | Required. Instance key to something to operate on. nil means "cannot proceed", never "empty" |
instanceId | (key, handle) → string | Required. This store's stable identity, starting with your kind's name and a colon ('my_safe:3') or OpenStore refuses it |
unitKey | (key, handle) → string | What persists together. Default instanceId, right for almost every kind |
slots / maxWeight | (handle) → number | Required. Capacity |
get | (handle, slot) → slotData|nil | Required. { item, amount, metadata } |
set / clear | (handle, slot, …) | Required. Write and empty a slot |
authorize | (src, addr) → boolean | Lets players drag in a kind that decides "has it open" itself. Not needed while it's open with OpenStore |
allows | (handle, itemKey, metadata) → boolean | Item filter for the whole store |
allowsAt | (handle, slot, itemKey, metadata) → boolean, reason? | Per-slot filter (a tool rack, a magazine slot), checked wherever an item lands |
persist | (handle) → queries[]|nil | nil means "cannot persist right now" |
durability | 'writeThrough' | 'writeBehind' | Default write-through |
beforeMove / afterMove | (handle, ctx) | Veto; side effect after the commit. ctx: direction, slot, otherSlot, item, amount, metadata, swap, other (an address, { kind, id, sub, slot, label }). Destroying: direction = 'out', destroyed = true, no other |
Returns:
boolean ok, string|nil err. Never throws, so a malformed definition can't kill your resource.local lockers = { [3] = { slots = {} } } -- yours, in memory; save it from persist
Whip.register(function()
Whip.core:RegisterStoreKind('my_locker', {
resolve = function(key) return lockers[key.id] and { id = key.id } or nil end,
instanceId = function(key, h) return 'my_locker:' .. h.id end,
slots = function(h) return 20 end,
maxWeight = function(h) return 100.0 end,
get = function(h, slot) return lockers[h.id].slots[slot] end,
set = function(h, slot, item, amount, metadata)
lockers[h.id].slots[slot] = { item = item, amount = amount, metadata = metadata }
return true
end,
clear = function(h, slot) lockers[h.id].slots[slot] = nil; return true end,
})
end)
exports.whip_core:OpenStore(source, { kind = 'my_locker', id = 3 }) -- beside their pockets
A handle carries an id, never a live table. FiveM copies what
resolve returns, so a set on a handle holding your rows writes into a copy: the move succeeds, the item leaves the player and never arrives. Return { id = id } and look your storage up in get, set and clear.Good to know
- Every store call works with it (
StoreRead,StoreGive,StoreMove,GetItemAt,SetItemMetadata...), with{ kind = 'mykind', id, sub }resolved asresolve({ id, sub }). - Players touch it only when you let them: while it's open on their screen with
OpenStore(held toopts.coords/opts.range; never ifreadOnly), or whenauthorizereturns a literaltrue(an error refuses). Your resource can always move items. idandsubcome from the client when a player drags.resolvemust look them up and returnnilfor anything unknown.resolve,get,setandclearmust not yield (noWait, no databaseawait): a refused write is undone with a plainset. Keep storage in memory; save frompersist.- Reserved names:
player,rawInventory,container,vehicle,panel, and client-addressable names such astargetandaccessory. Two resources can't claim one kind; the first wins. Your kinds go when your resource stops.