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
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.
| Param | Type | Description |
|---|---|---|
| source | number | Server player ID |
| config | table | The fields below |
| Config field | Type | Required | Description |
|---|---|---|---|
| id | string|number | Yes | Address { 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 …' |
| label | string | No | Header text (default 'Panel') |
| slots | number | No | Default 10, at most 5 per row |
| items | table | No | { [slot] = { item, amount, metadata } }, used only when the panel isn't already open |
| maxWeight | number | No | kg (nil = unlimited) |
| allowedItems | table | No | { 'food', 'drink' } or { food = true } (nil = any) |
| readOnly | boolean | No | The player can look; every move is refused, rearranging included |
| onValidate | function | No | (ctx) → ok, reason, before a player's move; false or an error refuses |
| onChange | function | No | (ctx), after a player's move landed |
| onClose | function | No | (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, reasonContents 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.Closes a panel for one player. If they were its last viewer, onClose runs and the panel is gone.
| Param | Type | Description |
|---|---|---|
| source | number | Server player ID |
| panelId | string|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
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.
| Param | Type | Description |
|---|---|---|
| itemKey | string | Registered, with a defaultAction unless the config names an action |
| config | table | The fields below |
| Config field | Type | Required | Description |
|---|---|---|---|
| slots | number | No | Default 3 |
| label | string | function | No | Header text, or (host) → string (a magazine's round count) |
| storageKey | string | No | Metadata key for the items (default 'slots') |
| allowedItems | table | No | { 'cash', 'id_card' } or { cash = true }, fixed at registration |
| allowedFlag | string | No | Also 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) |
| action | string | No | Default the item's defaultAction; several items may share one |
| canOpen | function | No | (host) → ok, reason, before read; fails closed |
| read | function | No | (host) → items. Default metadata[storageKey] |
| onValidate | function | No | (ctx) → ok, reason: OpenPanel's ctx, plus host |
| write | function | No | (host, items) → metadata, no side effects: it's also run on a copy to check each move. Default metadata[storageKey] |
| onChange | function | No | (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.