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

RegisterStoreKind(kindId, kindDef)SERVER#

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.

FunctionSignaturePurpose
resolve(key) → handle|nilRequired. Instance key to something to operate on. nil means "cannot proceed", never "empty"
instanceId(key, handle) → stringRequired. This store's stable identity, starting with your kind's name and a colon ('my_safe:3') or OpenStore refuses it
unitKey(key, handle) → stringWhat persists together. Default instanceId, right for almost every kind
slots / maxWeight(handle) → numberRequired. Capacity
get(handle, slot) → slotData|nilRequired. { item, amount, metadata }
set / clear(handle, slot, …)Required. Write and empty a slot
authorize(src, addr) → booleanLets players drag in a kind that decides "has it open" itself. Not needed while it's open with OpenStore
allows(handle, itemKey, metadata) → booleanItem 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[]|nilnil 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