Esc to clear, Enter to open the best match, click an export to open it in its page
Inventory

Stores

A store is anything that holds items: pockets, a stash, a car's boot, a shop, a bag's panel. One address names any store, and the same server calls read, fill, empty and move between them, open on a screen or not.

How stores work

Each kind of store says how it's read, written and saved; WHIP does the checks, stacking, saving and screen updates for all. A move between any two kinds is a single step, never half done. Ground items aren't a store: they have their own exports.

A kind may declare beforeMove, which can refuse before anything changes, and afterMove, run once the move commits. Panels build on them; RegisterStoreKind declares your own.

A hook that errors refuses the move. An error in beforeMove never counts as a yes; the error is logged in your resource's console.

Addresses#

A store is named by { kind, id, sub, slot }. Leave slot out when the call can choose one (or, for OpenStore, has no use for one).

KindAddressWhat it is
player{ kind = 'player', id = source, sub = 'player' }Pockets; sub = 'accessory' is the strip. sub defaults to 'player'
container{ kind = 'container', id = containerId }A world stash, loaded on demand
vehicle{ kind = 'vehicle', id = vehicleId, sub = 'trunk' }'trunk', 'glovebox' or 'key' (ignition). id may be a vehicle reference ({ plate = 'ABC 123' }). Loaded on demand
panel{ kind = 'panel', id = panelId }A panel open now (owner = source to name whose)
your own{ kind = 'mykind', id = ..., sub = ... }Registered with RegisterStoreKind

shop and basket exist only while a player has one open, so they have no server-side address.

Moving

StoreMove(fromAddr, toAddr, opts)SERVERWAITS#

Moves a stack between stores, or within one, as a player's drag does: hooks asked, checked, saved, viewers updated. Use it instead of a remove-then-add pair, which can fail halfway and lose the item.

ParamTypeDescription
fromAddrtableThe source address, with its slot
toAddrtableThe destination; without a slot it goes wherever it fits
optstable?amount (0 or omitted: the whole slot), mode ('move', 'one' or 'split'), reason for the log
Returns: true, or false, reason
local ok, err = exports.whip_core:StoreMove(
    { kind = 'container', id = 12, slot = 3 },
    { kind = 'player', id = source, sub = 'player', slot = 1 }, { amount = 2 })
It's on the record. Each character it touched gets a "moved" row naming your resource (and reason), and whip_core:item:added / item:removed fire for players whose pockets changed.

Reading

StoreRead(addr)SERVERWAITS#

What's in any store, as a copy keyed by slot number; a slot in the address is ignored. A stash or boot is loaded if needed. A panel exists only while open; an open, empty one has items = {}.

Returns: { kind, id, sub, label, slots, maxWeight, weight, items = { [slot] = { item, amount, metadata } } }, or false, reason: 'No such container', 'Vehicle not found', 'that panel is not open'…
local stash = exports.whip_core:StoreRead({ kind = 'container', id = 12 })
if not stash then return end
for slot, it in pairs(stash.items) do print(slot, it.item, it.amount) end
StoreCount(addr, item)SERVERWAITS#

How many of one item a store holds.

Returns: number, or false, reason
Check it before you compare it. An unreachable store returns false, not 0 (unlike GetItemCount's 0, reason), so StoreCount(addr, 'x') >= 5 throws. Write if n and n >= 5 then.
GetItemAt(addr)SERVERWAITS#

What's in one slot of any store, as a copy. Empty is nil and a wrong address false, so if not item then covers both.

ParamTypeDescription
addrtableAn address with a slot
Returns: { item, amount, metadata }, nil, or false, reason (no such store, a slot past the end)
local item = exports.whip_core:GetItemAt(addr)   -- the item a use handler was given: still there?
if not item or item.item ~= 'alcohol' then return end

Creating and destroying

StoreGive(addr, item, amount, metadata, reason)SERVERWAITS#

Creates an item in any store. With a slot, into exactly that slot (onto the same item if it stacks) or refused; without, wherever it fits, across slots if needed, all or nothing. For a player's reward use AddItem, which drops at their feet instead of refusing.

ParamTypeDescription
addrtableAn address; slot optional
itemstringA registered item
amountnumber?A whole number, 1 or more (default 1)
metadatatable?Left out, a default generator (a gun's serial) fills each slot
reasonstring|table?For the log, or { reason = '...' }
Returns: the (first) slot it landed in, or false, reason
exports.whip_core:StoreGive({ kind = 'vehicle', id = vanId, sub = 'trunk' }, 'delivery_package', 20, false, 'delivery shift')
StoreTake(addr, amount, opts)SERVERWAITS#

Destroys items in any store: materials used up, evidence confiscated. With a slot, from that slot (amount nil: the whole stack); without, from wherever opts.item is. All or nothing.

ParamTypeDescription
addrtableAn address, with or without a slot
amountnumber?How many
optstable|string?{ item = 'drink', metadata = { quality = 'fresh' }, reason = 'used' }. item is required without a slot. Optional metadata is a recursive partial match: extra keys are allowed, supplied values must match. Both filters apply with a slot too. A string is the reason for the log
Returns: { item, amount, metadata } taken (metadata only from one slot), or false, reason ('Empty slot', 'Not enough items'…)
local taken, err = exports.whip_core:StoreTake({ kind = 'container', id = 12 }, 5, { item = 'drink' })
Taking isn't moving. What you take is gone; to put it elsewhere, use StoreMove.

Metadata

SetItemMetadata(addr, metadata, opts)SERVERWAITS#

Changes the metadata of the item at an address. Only the keys you pass change. It's saved and shown to whoever has the store open. The item's uid (its activity log identity) survives even replace, unless you pass uid = false.

ParamTypeDescription
addrtableAn address with a slot
metadatatable|nilThe keys to change. nil only with replace (clears all) or remove; a bare nil is refused
optstable?replace = true: the table becomes the whole metadata. remove = { 'key', ... }. quiet = true (pockets only): don't resend their inventory, for a value that changes many times a second (a round count)
Returns: true once changed (even if the save is retried), or false, reason ('Empty slot', a wrong address, unsaveable metadata)
exports.whip_core:SetItemMetadata({ kind = 'container', id = 12, slot = 3 }, { evidence = true }, { remove = { 'label' } })
Plain data, and players can read it. Anything json.encode can't write is refused (false, 'metadata cannot be saved: ...'). Metadata goes whole to whoever sees the item, so keep secrets (a safe's code) server-side and store an id.

Finding one item

FindItemByUid(uid)SERVER#

Where one item is, by the uid every logged item has in its metadata: its address with a slot, or { kind = 'ground', id }.

Returns: table|nil
local at = exports.whip_core:FindItemByUid(uid)
if at and at.kind == 'player' then exports.whip_core:NotifyPlayer(at.id, 'The police want a word', 'warning') end
It searches what's loaded: online players, stashes, boots and panels in memory, and the ground. Not a stash untouched since the restart, nor inside a bag.
FindItemByMetadata(key, value)SERVER#

Where the first item whose metadata key holds value is, searching the same places as FindItemByUid: FindItemByMetadata('serial', 'AB12CD34EF56') runs a gun's serial.

Returns: an address or nil

Opening a store for a player

GetOpenStores(source)SERVER#

Every store the player has open, as addresses in a stable order. Their pockets are never listed; a shop is { kind = 'shop' }. A panel comes with its label, which is how you learn the id of one an item opened: { kind = 'panel', id = 'wallet_...', owner = source, label = 'Wallet' }.

Returns: table[], empty when nothing is open
OpenStore(source, addr, opts)SERVERWAITS#

Puts a stash, a boot or your own store kind on a player's screen, with the checks of a player's own open (access, distance, lock) unless opts skips them. Players share one stash; the loser of a race is told the slot is empty. Refused: pockets (OpenPlayerInventory), panels (OpenPanel), a glovebox or ignition, and a player with a screen already open.

ParamTypeDescription
sourcenumberServer player ID
addrtable{ kind = 'container', id }, { kind = 'vehicle', id, sub = 'trunk' } or { kind = 'mykind', id, sub }
optstable?skipDistance (a stash; a boot always needs it), skipAccess (a stash's lock and owner, a boot's lock), coords + range (your kind: stay within, default 3 m), readOnly (your kind: every move refused)
Returns: true, or false, reason
local ok, reason = exports.whip_core:OpenStore(source, { kind = 'container', id = containerId }, { skipAccess = true })
if not ok then exports.whip_core:NotifyPlayer(source, reason, 'error') end
Close what you open. The player stays a viewer, whose drags count, until CloseStore. Inside a SecureEvent handler that errors, WHIP releases the view; elsewhere, you must.
CloseStore(source, addr)SERVERWAITS#

Takes a store away from a player, wherever they stand, even after they've disconnected. Other viewers keep it. A stash or boot is saved, and unloaded if nobody else uses it. A panel closes with ClosePanel.

ParamTypeDescription
sourcenumberServer player ID
addrtableThe address you opened it with
Returns: true, or false, 'That is not open'