OPX//77
opx_infinitydoorlock

Server

Last updated on

The doorlock contract on the server — ox_doorlock's exports, read and write doors.

local doorlock = OPX.Api.Get('doorlock')

From server code inside opx_infinity. Other resources use the door exports. ref is a door id, or the key a seeded (config:) or carried-over (legacy:) door was filed under. by is free text written to the audit line; default 'contract'. No answer ever carries a door's code. Errors are doorlock.<code> (see codes).

The door record

What Get, GetFromName and All answer:

  • id: integer
  • name: string
  • state: 0 | 1 — live state, 1 locked
  • coords: { x, y, z }
  • bucket: integer
  • groups?: { [name] = grade }
  • items?: { { name, metadata?, remove? } }
  • characters?: string[]
  • maxDistance: number

Get

ox's getDoor.

doorlock.Get(ref)

Parameters

  • ref: integer | string

Returns

GetFromName

ox's getDoorFromName: the lowest id with that name.

doorlock.GetFromName(name)

Parameters

  • name: string

Returns

All

ox's getAllDoors, sorted by id.

doorlock.All()

Returns

SetState

ox's setDoorState. The caller has decided: the door's own rules are not checked. Yields on the networked backend.

doorlock.SetState(ref, state, by)

Parameters

  • ref: integer | string
  • state: 0 | 1 | boolean — 1 or true locks
  • by?: string

Returns

  • Result — the state; errors doorlock.unknownDoor, doorlock.badState
Example
CreateThread(function()
  local res = doorlock.SetState('ncpd_front', 0, 'raid event')
  if not res.ok then print(res.error) end
end)

SetLocked

The first version's boolean form of SetState.

doorlock.SetLocked(ref, locked, by)

Parameters

  • ref: integer | string
  • locked: boolean
  • by?: string

Returns

  • Result — locked; errors doorlock.unknownDoor, doorlock.badState

Create

ox's createDoor. Validated like a panel save, without the staff position check. Yields.

doorlock.Create(data, by)

Parameters

  • data: table — a door in ox's shape
  • by?: string

Returns

  • Result — the new id; errors doorlock.error.<code>: bad_door, the other bad_* field codes, unknown_group, unknown_item, door_taken, too_many_doors, not_loaded, save_failed. Every one has a sentence in the catalogue.
Example
CreateThread(function()
  local res = doorlock.Create({ name = 'Back room', native = '0x00000000ABCDEF01',
    coords = { x = 10.0, y = 20.0, z = 3.0 }, groups = { police = 1 } })
  if res.ok then print('door #' .. res.value) end
end)

Edit

ox's editDoor: the fields given replace the door's, '' clears one, a type that differs from the stored one is refused (doorlock.error.bad_field, the field in detail). A new native replaces a double door, and doors a single one. Yields.

doorlock.Edit(ref, data, by)

Parameters

  • ref: integer | string
  • data: table
  • by?: string

Returns

  • Result — the id; errors as Create, plus doorlock.unknownDoor

Remove

ox's removeDoor. A seeded door leaves a tombstone so the next boot does not insert it again. Yields.

doorlock.Remove(ref, by)

Parameters

  • ref: integer | string
  • by?: string

Returns

  • Result — errors doorlock.unknownDoor, doorlock.error.save_failed

IsAuthorised

Whether a player may turn a door by its rules, ignoring where they stand and the code. Yields (reads the bag).

doorlock.IsAuthorised(playerId, ref)

Parameters

  • playerId: number
  • ref: integer | string

Returns

  • Result — { allowed, how, passcode }
    • how: 'staff' | 'acl' | 'character' | 'group' | 'item' | 'passcode', or the refusal code
    • passcode: boolean — the code would still be asked

Mode

The running backend. A plain string, not a Result.

doorlock.Mode()

Returns

  • 'networked' | 'local'

On this page