Containers
A container is a stash in the world: a prop with an E prompt that opens beside the player's inventory. Declare one with EnsureContainer, decide who may open it, and fill or read it with the store calls.
Opening one
The prop appears within 100 m. E opens it in place of the Ground panel when it isn't locked, the player may open it and they stand within 4.5 m. Several players can share it at once.
Who may open it
| Field | Effect |
|---|---|
locked = true | Nobody (an admin can override) |
accessCharId = charId | Only that character |
requirements = { jobs = 'police', onDuty = true } | Anyone meeting any one rule: jobs (with onDuty, on duty there), charIds, items (carrying a keycard), ace, or property (its owner and keyholders, by id or key) |
| none of these | Anyone |
allowedItems = { 'item1', 'item2' } | Only these items go in. A keyed table ({ item1 = true }) works too; nil allows all |
Requirements hold on every move, so going off duty, losing a property's key or the stash being locked stops the looting there. A required item can never go into the container it opens.
Reading and filling
A stash is a store at { kind = 'container', id = containerId }: read it with StoreRead (.items, by slot), fill it with StoreGive and StoreTake, and show it with OpenStore. Nobody needs it open. Closing or disconnecting saves it, and contents are in memory only while it's open, so thousands of containers cost little.
Declaring and creating#
EnsureContainer for a stash your resource always has. CreateContainer makes a new one on every call: in your resource's start, that's a twin with separate contents on every restart.A container declared by key, the same rule as EnsureShop and EnsureZone. The same declaration again changes nothing, so an admin's edits stand; a changed one applies your fields, clears an allowedItems or requirements you dropped, and refuses fewer slots while an item sits above the new count. Another running resource's key is refused.
| Param | Type | Description |
|---|---|---|
| key | string | Letters, digits, _ - . :, at most 100. Prefix it: 'pd:weapon_locker' |
| data | table | { x, y, z, heading?, name?, type?, slots?, maxWeight?, prop?, locked?, allowedItems?, requirements? }. An unread field is reported in the console. Not ownerCharId / accessCharId: use UpdateContainer |
| data.requirements | table? | { jobs?, onDuty?, charIds?, items?, ace?, property? }, any one lets a player in; checked on open and every move |
table with containerId, key and declared (your declaration), or false, reason. While whip_core starts it waits up to 60 s, then returns false, 'whip_core has not finished starting …' (so do EnsureZone, EnsureDoors, EnsureJob).-- Officers on duty only. Without `requirements` anyone could loot it.
Whip.register(function()
Whip.core:EnsureContainer('pd:weapon_locker', {
name = 'Weapon Locker', slots = 30, maxWeight = 200.0,
x = 441.5, y = -982.3, z = 30.7, heading = 90.0,
allowedItems = { gunny_pistol = true, gunny_mag_pistol = true },
requirements = { jobs = 'police', onDuty = true },
})
end)
lockpick is refused. An action's require is taken when it names one rule and refused when it names more: containers, like doors, read rules as any one, actions as all.Creates a container on every call. accessCharId makes it one character's; requirements is as in EnsureContainer (a house stash: { property = 'pinklady_flat' }).
persist = false makes one that's never saved, for a job or a heist, which only your resource can change or delete. It goes when your resource stops or its tag is released (ReleaseTag): screens it's open on close, and what's left is logged as lost. It takes items (starting contents, all or nothing), prop = false (only a prompt) and placed = true with rx/ry (no snap to the ground).
table with containerId, or false, reason (no x/y/z, a key taken, a requirements shape it won't take such as a lockpick rule or an unknown property, an item that can't go in, a run whose tag has ended, a database error)-- The vault's safe: never saved, gone with the job, the money already inside
local safe = exports.whip_core:CreateContainer({
persist = false, tag = 'heist:' .. jobId, name = 'Safe',
x = 255.1, y = 225.4, z = 101.9, prop = false,
items = { { item = 'cash', amount = 5000 } },
requirements = { charIds = crewCharIds }, -- only the crew
})
Finding
What a container is (name, size, position, owner), from cache. What it holds is StoreRead.
| Param | Type | Description |
|---|---|---|
| ref | number|table | A container id, or { key = } (the key it was declared by) |
table|nillocal locker = exports.whip_core:GetContainer({ key = 'pd:weapon_locker' })
Changing and deleting
Changes only the fields in data, saves them and re-sends them to clients. Players who have it open are held to the change on their next move.
| Param | Type | Description |
|---|---|---|
| containerId | number | Container ID |
| data | table | Any of name, type, slots, maxWeight, ownerCharId, accessCharId, locked, x, y, z, heading, prop, allowedItems, requirements, key. Fewer slots are refused while an item sits above the new count |
| data.accessCharId | number? | The only way to change it after creation (a tradeable key, a handover). 0 makes it public; nil leaves it |
| data.requirements | table|false? | As in EnsureContainer; false clears it |
| data.key | string|false? | Gives it a key, so EnsureContainer finds it; false removes it |
true, or false, reason: no such container, a slot above a smaller slots isn't empty, the key is another container's, or the write failed-- Hand a stash to whoever used the key
exports.whip_core:UpdateContainer(containerId, { accessCharId = player.charId, locked = false })
Deletes a container and its inventory. Refused while a shop sells from it.
| Param | Type | Description |
|---|---|---|
| containerId | number | Container ID |
true, or false, reason