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

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

PocketSlotsMax weightFor
player3080 kg, the strip includedThe main inventory. It takes anything, and items go here first
accessory510 kg of the 80The 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 slotTakes
1 PhonePhones while whip_phone runs; it looks here for one first. Without whip_phone, anything
2 Moneycash or a wallet
3 to 5 KeyAny 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.

More room is an item, not a pocket. A duffle bag holds 25 slots, and players find, drop, steal and lose it like anything else. See RegisterPanelItem.

The four calls

ExportDoes
AddItemPuts an item on the player, wherever it fits
RemoveItemTakes an item from wherever it is
HasItemDo they have at least this many, anywhere on them?
GetItemCountHow 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#

OperationMeansWhen it won't fit
GiveThe item enters the world: a reward, a purchase, a refund, an admin spawnDropped at the player's feet. Failing would destroy it
MoveThe item already exists: a pickup, a stash transfer, a drag, a tradeLeft 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.

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 only

For 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.