Doors API
Server and client exports for doors. New to doors? Read Doors first. A server export that takes a door also takes { key = 'office' } for one your resource declared (add set = '…' with more than one set); a key reaches only your own doors.
Declaring and saving
Declares your resource's doors, instead of a door script that fights WHIP's locks. The list is your whole set, keyed: a new key makes its door or adopts the one on that spot; a known key follows the list; a key that left the list is released (deleted if the list made it, put back if adopted).
| Field | Type | Description |
|---|---|---|
| key | string | Required. Letters, digits, _ - . :, at most 60 |
| model | string | number | Required. A name, or a hash (signed or not) |
| coords | vector3 | vector4 | table | Required. A vector4's w is the heading (or x, y, z, heading) |
| label, folder | string? | What the Doors page shows. The label defaults to the key |
| requirements | table? | Who may open it. Left out: anyone |
| autolock, autolockDelay | boolean?, number? | Lock again this many seconds (default 10) after any unlock. A picked lock stays open |
| link | string? | The key of the other half of a double door |
| opts | table? | id (the set, default 'doors'), label (the Doors page's name for the set), prune (default true; false keeps dropped doors) |
{ doors = { [key] = doorId }, failed = { [key] = why }, released = n }, or false, reasonWhip.register(function()
local res, why = exports.whip_core:EnsureDoors({
{ key = 'lobby_l', model = 'v_ilev_ph_gendoor004', coords = vector4(-868.84, -1275.53, 5.10, 110.0), link = 'lobby_r' },
{ key = 'lobby_r', model = 'v_ilev_ph_gendoor004', coords = vector4(-867.60, -1273.20, 5.10, 110.0) },
{ key = 'office', model = 'v_ilev_ph_gendoor', coords = vector3(-870.1, -1280.4, 5.1),
requirements = { jobs = { 'realestate' }, onDuty = true }, autolock = true },
}, { label = 'Pink Lady' })
if not res then print('doors: ' .. why) return end
for key, reason in pairs(res.failed) do print('door ' .. key .. ': ' .. reason) end
end)
label and folder (a Doors page rename lasts until your next start). Requirements, auto-lock, the link and the door's existence belong to the list, and the other exports refuse them. One bad entry and nothing changes; a door that can't be placed goes in failed. Declared doors stay when your resource stops.EnsureDoors for one door, never releasing any. It's kept in its own set, 'door:<key>' (or opts.id), so an EnsureDoors call neither prunes nor undoes it. data takes an entry's fields without key and link: declare a pair with EnsureDoors.
door, or false, reasonSaves a door, always locked, and leaves it to admins. Waits up to 60 s for whip_core to finish starting.
| Param | Type | Description |
|---|---|---|
| data | table | { label, folder, model, x, y, z, heading, requirements, metadata } |
false, reason, plus the id of a door already within half a metreLocking and access
Locks or unlocks a door and its linked door, and tells the players near it.
| Param | Type | Description |
|---|---|---|
| doorId | number|table | Door id, or { key = … } |
| locked | boolean | true locks |
true, or false, reasonWhether a door is locked.
| Param | Type | Description |
|---|---|---|
| doorId | number|table | Door id, or { key = … } for a door you declared |
boolean, or nil for no such doorWhether this player may open this door, by its any-of requirements, and if not, the reason they're shown.
| Param | Type | Description |
|---|---|---|
| source | number | Player server id |
| doorId | number|table | Door id, or { key = … } |
true, or false, reason ('Requires job: police (on duty)', 'Door not found')require (not requirements) takes it when it names one rule and refuses it when it names more. A field it doesn't read is reported in the server console.Finding doors
A door's full data.
| Param | Type | Description |
|---|---|---|
| doorId | number|table | Door id, or { key = … } for a door you declared |
table|nilEvery door on the server (a client only knows the doors it streamed in).
table[]Every saved door within a range of a point.
| Param | Type | Description |
|---|---|---|
| x, y, z / coords | number / vector3 | Centre |
| range | number | Metres (default 25) |
table[]A saved door near a point, when you know where it is but not its id.
| Param | Type | Description |
|---|---|---|
| x, y, z | number | World position |
| range | number? | Metres (default 1). The first door found wins, not the nearest: keep it small |
table|nilChanging doors
Changes label, folder, locked (linked door too), requirements, autolock, autolockDelay, linkedDoorId and metadata (not its managedBy). Other fields are refused: position and model are fixed. Every door starts locked when the server starts.
| Param | Type | Description |
|---|---|---|
| doorId | number|table | Door id, or { key = … } for a door you declared |
| updates | table | Fields to change. Clear requirements with {}, not nil |
| manager | table? | For a door you manage: its set, { id = 'doors' } (or your opts.id, or 'door:<key>') |
true, or false, reason ('Door not found', someone else's managed door, bad fields)Deletes a saved door.
| Param | Type | Description |
|---|---|---|
| doorId | number|table | Door id, or { key = … } for a door you declared |
| manager | table? | As for UpdateDoor |
true, or false, reasonLinks two doors so they lock together, unlinking each one's old partner.
| Param | Type | Description |
|---|---|---|
| doorId1 | number | First door id |
| doorId2 | number | Second door id |
| manager | table? | As for UpdateDoor |
true, or false, reasonUnlinks both halves of a pair; true if it wasn't linked. linkedDoorId = nil in UpdateDoor can't do this (a nil is no key in Lua).
| Param | Type | Description |
|---|---|---|
| doorId | number|table | Either door of the pair (id, or { key = … }) |
| manager | table? | As for UpdateDoor |
true, or false, reasonManaged and held doors#
A managed door belongs to one resource, as the doors you declare with EnsureDoors do: the Doors page and other resources can't change its requirements, link or auto-lock. A held door is yours only while a job runs.
A declared door sits in a set: 'doors' for EnsureDoors with no opts.id, your opts.id otherwise, and 'door:<key>' for one from EnsureDoor. That set is the manager that UpdateDoor, DeleteDoor, LinkDoors and UnlinkDoors take: { id = 'doors' }. To give a door back, declare its set without it; for one from EnsureDoor, EnsureDoors({}, { id = 'door:<key>' }). It is deleted if it was made for you and restored if you adopted it.
The doors your resource manages, to reconcile against when it starts.
| Param | Type | Description |
|---|---|---|
| id | any? | A manager id, or nil for all |
table[]Holds the door within half a metre of a spot (a heist's vault), making a temporary unsaved door for everyone if there's none. While held, nobody may press it until you say who and it never relocks itself; both leaves of a pair are held. When the hold ends (ReleaseDoor, ReleaseTag, or your resource stopping) it returns to its old lock. A property's door, another resource's managed door and an already held door are refused.
| Param | Type | Description |
|---|---|---|
| data | table | { model, x, y, z, heading?, label? }, as the Door Editor reads them |
| opts | table? | { tag?, requirements? }: tag releases it with your run; requirements is who may press it (nobody if left out) |
doorId, how ('held', 'made', 'already'), or false, reason. Also SetHeldDoorAccess(doorId, requirements) (nil = nobody, {} = anyone), ReleaseDoor(doorId) and GetDoorHold(doorId) → { owner, tag, doorId, made } or nil.local vault = exports.whip_core:HoldDoor({ model = vaultModel, x = pos.x, y = pos.y, z = pos.z }, { tag = 'heist:' .. jobId })
exports.whip_core:SetDoorLocked(vault, false)
exports.whip_core:SetHeldDoorAccess(vault, { charIds = crewCharIds })
Client#
The client knows only the doors it has streamed in, as of its last visit: ask the server for anything that matters.
Whether a door is locked, from the client's cache. A far door catches up as it comes back into range.
| Param | Type | Description |
|---|---|---|
| doorId | number | Door id |
boolean, or nil for a door the client doesn't knowEvery saved door within a range of the player, or of a point.
| Param | Type | Description |
|---|---|---|
| coords / x, y, z | vector3? / number? | Left out, the player's position |
| range | number | Metres (default 25) |
table[]Every door the client has streamed in, not every door: the server's GetDoors has those.
table[]A door's full data, from the client cache: by id, or the saved door a world entity is (by model and position).
| Param | Type | Description |
|---|---|---|
| ref | number|table | A door id, or { entity = } |
table|nillocal door = exports.whip_core:GetDoor({ entity = entity })