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

Panels API

Server exports for panels. How panels and their hooks work is in Panels.

Opening and closing

OpenPanel(source, config)SERVER#

Opens a panel for a player, with their inventory beside it. The server keeps its contents, checks every player move against its rules and calls its hooks.

ParamTypeDescription
sourcenumberServer player ID
configtableThe fields below
Config fieldTypeRequiredDescription
idstring|numberYesAddress { kind = 'panel', id = id }. Opened again for the same player, nothing happens. Ids are shared, so prefix yours ('myres:bench_' .. src): one another resource has open returns false, 'Panel id "…" is already open by …'
labelstringNoHeader text (default 'Panel')
slotsnumberNoDefault 10, at most 5 per row
itemstableNo{ [slot] = { item, amount, metadata } }, used only when the panel isn't already open
maxWeightnumberNokg (nil = unlimited)
allowedItemstableNo{ 'food', 'drink' } or { food = true } (nil = any)
readOnlybooleanNoThe player can look; every move is refused, rearranging included
onValidatefunctionNo(ctx) → ok, reason, before a player's move; false or an error refuses
onChangefunctionNo(ctx), after a player's move landed
onClosefunctionNo(ctx), once the last viewer has left: { panel, source, items }. Give one to keep the contents. Without one (or if it errors), each player gets back what they put in and didn't take out, at their feet if their pockets are full (unless dropping is off). The rest goes, logged as lost. A readOnly panel without one gives nothing back
Returns: true, or false, reason
Contents live in memory until you take them. WHIP saves the player's side of a move, not the panel's, so a crash before onChange or onClose hands them to you loses them. To survive a crash, save in onChange, or use a store kind with persist.
ClosePanel(source, panelId?)SERVERWAITS#

Closes a panel for one player. If they were its last viewer, onClose runs and the panel is gone.

ParamTypeDescription
sourcenumberServer player ID
panelIdstring|number?Leave it out to close every panel they have open
Returns: true, or false, 'No such panel open'
A panel's id. A RegisterPanelItem panel's id is made up by WHIP, in an internal format. GetOpenStores(source) lists each open panel as { kind = 'panel', id, owner, label }, ready for StoreRead.

Items that hold items

RegisterPanelItem(itemKey, config)SERVER#

Makes an item open a panel from its context action, like a wallet or toolbox. It registers the action and a metadata generator (adding the empty-slots default only when the item has none), and folds the contents into the item's metadata as they change. The custom hooks are in Panels.

ParamTypeDescription
itemKeystringRegistered, with a defaultAction unless the config names an action
configtableThe fields below
Config fieldTypeRequiredDescription
slotsnumberNoDefault 3
labelstring | functionNoHeader text, or (host) → string (a magazine's round count)
storageKeystringNoMetadata key for the items (default 'slots')
allowedItemstableNo{ 'cash', 'id_card' } or { cash = true }, fixed at registration
allowedFlagstringNoAlso every item whose definition has this field set to true, read each time it opens (the wallet's 'wallet': RegisterItem('mybank_card', { ..., wallet = true })). Plain slot array only (no read/write). Every count and take of what a player carries looks inside it for those items (HasItem, GetItemCount, RemoveItem, FindItem, FindAllItems, an item requirement, the item events)
actionstringNoDefault the item's defaultAction; several items may share one
canOpenfunctionNo(host) → ok, reason, before read; fails closed
readfunctionNo(host) → items. Default metadata[storageKey]
onValidatefunctionNo(ctx) → ok, reason: OpenPanel's ctx, plus host
writefunctionNo(host, items) → metadata, no side effects: it's also run on a copy to check each move. Default metadata[storageKey]
onChangefunctionNo(ctx), after the move landed; never speculative
Returns: true, or false, reason, changing nothing, when the item isn't registered or has no action, another resource has a panel for it, or another resource holds the action.
Not taken here: maxWeight, readOnly, or a per-item maxPerSlot in allowedItems (only keys count, in OpenPanel too). They're ignored silently; enforce caps and read-only views in onValidate.