Inventory
Characters carry items in pockets, and everything they carry has weight. Your resource gives, takes and checks items with four calls; this page also covers weight, metadata and saving.
Pockets
| Slots | Max weight | For | |
|---|---|---|---|
player | 30 | 80 kg, the strip included | The main inventory. It takes anything, and items go here first |
accessory | 5 | 10 kg of the 80 | The strip beside it. Each slot takes one kind of item |
Sizes come from Config.ContainerSlots and Config.MaxWeight. Config.AccessoryStrip = false removes the strip (keys then go in the ignition by hand), and what a character had in it moves into player at login. Read the list with GetPockets() rather than typing it out.
| Strip slot | Takes |
|---|---|
| 1 Phone | Phones while whip_phone runs; it looks here for one first. Without whip_phone, anything |
| 2 Money | cash or a wallet |
| 3 to 5 Key | Any ignition key (RegisterIgnitionKey) |
The server holds each slot to its rule on a drag, a StoreMove and an AddItem, and tells a player why ("Only Cash or Wallet can go there"). A reward too big for the main inventory only spills into a slot that takes it. What a slot held before its rule changed stays until it's moved. Reshape a slot with RegisterAccessorySlot.
A vehicle_key in the strip goes into the ignition by itself when its holder takes the driver's seat of the car it fits, and comes back when they leave the seat, so three Key slots carry three cars' keys. Keys in player never move by themselves.
The four calls
| Export | Does |
|---|---|
AddItem | Puts an item on the player, wherever it fits |
RemoveItem | Takes an item from wherever it is |
HasItem | Do they have at least this many, anywhere on them? |
GetItemCount | How many they carry in total |
if not exports.whip_core:HasItem(source, 'lockpick') then return false, 'You need a lockpick' end
exports.whip_core:RemoveItem(source, 'lockpick', 1, false, { reason = 'snapped' })To act on one slot, name it with an address and use the store calls. You rarely build one: a use handler and FindItem hand you the address of their item.
When an inventory is full#
| Operation | Means | When it won't fit |
|---|---|---|
| Give | The item enters the world: a reward, a purchase, a refund, an admin spawn | Dropped at the player's feet. Failing would destroy it |
| Move | The item already exists: a pickup, a stash transfer, a drag, a trade | Left where it is. A copy at their feet would duplicate it |
AddItem is a give: it returns 'inventory' or 'ground', and both count as given.
Weight is nested#
An item's weight is what it weighs empty. Its contents are added on top, at every level, with nothing for you to declare.
duffle_bag 1.5 kg (empty)
└─ wallet 0.2 kg (empty)
└─ 5,000 cash @ 0.0001 kg = 0.5 kg
The bag weighs 2.2 kg, and every container above it agrees.- Filling a bag makes its carrier heavier, and a tooltip's weight includes the contents.
- Bags inside bags count 4 levels deep at most.
- A
readhook that throws falls back to the item's base weight rather than failing the move. - An item with no definition weighs 0 (see Panels).
Metadata
An item can carry any JSON metadata: a key's plate, a jerry can's fuel, a wallet's contents. It's saved with the item and travels with it everywhere.
exports.whip_core:AddItem(source, 'id_card', 1, { name = 'John Smith', number = 'A-10294' })
local found = exports.whip_core:FindItem(source, 'jerry_can') -- { item, amount, metadata, addr }
if found then exports.whip_core:SetItemMetadata(found.addr, { fuel = 50 }) end -- changes fuel onlyFor starting metadata on every new item of yours (a radio's frequency, a gun's serial), register a generator with RegisterItemDefaultMetadata.
Saving#
Inventories save write-behind: a change is in memory at once and written within about a second (Config.FlushInterval). Only changed rows are written (none on the first save after a load), and both halves of a move share one transaction.
So a true from a change means "owed to disk", not "on disk": a hard crash can lose up to one flush interval. Data that can't afford that belongs on a store kind that writes through. See also Save System.
Durability is per store kind. Player inventories, containers and vehicle storage defer. Ground items and shop stock write through, and the bank writes immediately with whatever the running action has saved, so an ATM's cash and its bank write are one transaction. A move that touches any write-through store commits immediately.