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.
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).
| Kind | Address | What 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
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.
| Param | Type | Description |
|---|---|---|
| fromAddr | table | The source address, with its slot |
| toAddr | table | The destination; without a slot it goes wherever it fits |
| opts | table? | amount (0 or omitted: the whole slot), mode ('move', 'one' or 'split'), reason for the log |
true, or false, reasonlocal ok, err = exports.whip_core:StoreMove(
{ kind = 'container', id = 12, slot = 3 },
{ kind = 'player', id = source, sub = 'player', slot = 1 }, { amount = 2 })
reason), and whip_core:item:added / item:removed fire for players whose pockets changed.Reading
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 = {}.
{ 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
How many of one item a store holds.
number, or false, reasonfalse, not 0 (unlike GetItemCount's 0, reason), so StoreCount(addr, 'x') >= 5 throws. Write if n and n >= 5 then.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.
| Param | Type | Description |
|---|---|---|
| addr | table | An address with a slot |
{ 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
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.
| Param | Type | Description |
|---|---|---|
| addr | table | An address; slot optional |
| item | string | A registered item |
| amount | number? | A whole number, 1 or more (default 1) |
| metadata | table? | Left out, a default generator (a gun's serial) fills each slot |
| reason | string|table? | For the log, or { reason = '...' } |
false, reasonexports.whip_core:StoreGive({ kind = 'vehicle', id = vanId, sub = 'trunk' }, 'delivery_package', 20, false, 'delivery shift')
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.
| Param | Type | Description |
|---|---|---|
| addr | table | An address, with or without a slot |
| amount | number? | How many |
| opts | table|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 |
{ 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' })
StoreMove.Metadata
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.
| Param | Type | Description |
|---|---|---|
| addr | table | An address with a slot |
| metadata | table|nil | The keys to change. nil only with replace (clears all) or remove; a bare nil is refused |
| opts | table? | 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) |
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' } })
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
Where one item is, by the uid every logged item has in its metadata: its address with a slot, or { kind = 'ground', id }.
table|nillocal 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
Where the first item whose metadata key holds value is, searching the same places as FindItemByUid: FindItemByMetadata('serial', 'AB12CD34EF56') runs a gun's serial.
nilOpening a store for a player
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' }.
table[], empty when nothing is openPuts 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.
| Param | Type | Description |
|---|---|---|
| source | number | Server player ID |
| addr | table | { kind = 'container', id }, { kind = 'vehicle', id, sub = 'trunk' } or { kind = 'mykind', id, sub } |
| opts | table? | 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) |
true, or false, reasonlocal 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
CloseStore. Inside a SecureEvent handler that errors, WHIP releases the view; elsewhere, you must.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.
| Param | Type | Description |
|---|---|---|
| source | number | Server player ID |
| addr | table | The address you opened it with |
true, or false, 'That is not open'