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

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

EnsureDoors(list, opts)SERVERWAITS#

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

FieldTypeDescription
keystringRequired. Letters, digits, _ - . :, at most 60
modelstring | numberRequired. A name, or a hash (signed or not)
coordsvector3 | vector4 | tableRequired. A vector4's w is the heading (or x, y, z, heading)
label, folderstring?What the Doors page shows. The label defaults to the key
requirementstable?Who may open it. Left out: anyone
autolock, autolockDelayboolean?, number?Lock again this many seconds (default 10) after any unlock. A picked lock stays open
linkstring?The key of the other half of a double door
optstable?id (the set, default 'doors'), label (the Doors page's name for the set), prune (default true; false keeps dropped doors)
Returns: { doors = { [key] = doorId }, failed = { [key] = why }, released = n }, or false, reason
Whip.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)
The list wins. By key you can lock, read, and change 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.
EnsureDoor(key, data, opts)SERVERWAITS#

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.

Returns: door, or false, reason
CreateDoor(data)SERVERWAITS#

Saves a door, always locked, and leaves it to admins. Waits up to 60 s for whip_core to finish starting.

ParamTypeDescription
datatable{ label, folder, model, x, y, z, heading, requirements, metadata }
Returns: the door, or false, reason, plus the id of a door already within half a metre

Locking and access

SetDoorLocked(doorId, locked)SERVER#

Locks or unlocks a door and its linked door, and tells the players near it.

ParamTypeDescription
doorIdnumber|tableDoor id, or { key = … }
lockedbooleantrue locks
Returns: true, or false, reason
IsDoorLocked(doorId)SERVER#

Whether a door is locked.

ParamTypeDescription
doorIdnumber|tableDoor id, or { key = … } for a door you declared
Returns: boolean, or nil for no such door
CanUseDoor(source, doorId)SERVER#

Whether this player may open this door, by its any-of requirements, and if not, the reason they're shown.

ParamTypeDescription
sourcenumberPlayer server id
doorIdnumber|tableDoor id, or { key = … }
Returns: true, or false, reason ('Requires job: police (on duty)', 'Door not found')
A door or stash given 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

GetDoor(doorId)SERVER#

A door's full data.

ParamTypeDescription
doorIdnumber|tableDoor id, or { key = … } for a door you declared
Returns: table|nil
GetDoors()SERVER#

Every door on the server (a client only knows the doors it streamed in).

Returns: table[]
GetDoorsNearby(x, y, z, range) · GetDoorsNearby(coords, range)SERVER#

Every saved door within a range of a point.

ParamTypeDescription
x, y, z / coordsnumber / vector3Centre
rangenumberMetres (default 25)
Returns: table[]
GetDoorByPosition(x, y, z, range)SERVER#

A saved door near a point, when you know where it is but not its id.

ParamTypeDescription
x, y, znumberWorld position
rangenumber?Metres (default 1). The first door found wins, not the nearest: keep it small
Returns: table|nil

Changing doors

UpdateDoor(doorId, updates, manager)SERVERWAITS#

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.

ParamTypeDescription
doorIdnumber|tableDoor id, or { key = … } for a door you declared
updatestableFields to change. Clear requirements with {}, not nil
managertable?For a door you manage: its set, { id = 'doors' } (or your opts.id, or 'door:<key>')
Returns: true, or false, reason ('Door not found', someone else's managed door, bad fields)
DeleteDoor(doorId, manager)SERVERWAITS#

Deletes a saved door.

ParamTypeDescription
doorIdnumber|tableDoor id, or { key = … } for a door you declared
managertable?As for UpdateDoor
Returns: true, or false, reason
LinkDoors(doorId1, doorId2, manager?)SERVERWAITS#

Links two doors so they lock together, unlinking each one's old partner.

ParamTypeDescription
doorId1numberFirst door id
doorId2numberSecond door id
managertable?As for UpdateDoor
Returns: true, or false, reason
UnlinkDoors(doorId, manager?)SERVERWAITS#

Unlinks 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).

ParamTypeDescription
doorIdnumber|tableEither door of the pair (id, or { key = … })
managertable?As for UpdateDoor
Returns: true, or false, reason

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

GetManagedDoors(id)SERVER#

The doors your resource manages, to reconcile against when it starts.

ParamTypeDescription
idany?A manager id, or nil for all
Returns: table[]
HoldDoor(data, opts)SERVERWAITS#

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.

ParamTypeDescription
datatable{ model, x, y, z, heading?, label? }, as the Door Editor reads them
optstable?{ tag?, requirements? }: tag releases it with your run; requirements is who may press it (nobody if left out)
Returns: 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.

IsDoorLocked(doorId)CLIENT#

Whether a door is locked, from the client's cache. A far door catches up as it comes back into range.

ParamTypeDescription
doorIdnumberDoor id
Returns: boolean, or nil for a door the client doesn't know
GetDoorsNearby(range) · GetDoorsNearby(coords, range) · GetDoorsNearby(x, y, z, range)CLIENT#

Every saved door within a range of the player, or of a point.

ParamTypeDescription
coords / x, y, zvector3? / number?Left out, the player's position
rangenumberMetres (default 25)
Returns: table[]
GetLoadedDoors()CLIENT#

Every door the client has streamed in, not every door: the server's GetDoors has those.

Returns: table[]
GetDoor(ref)CLIENT#

A door's full data, from the client cache: by id, or the saved door a world entity is (by model and position).

ParamTypeDescription
refnumber|tableA door id, or { entity = }
Returns: table|nil
local door = exports.whip_core:GetDoor({ entity = entity })