Skip to content

Doors ​

server

Map doors with a lock state on the server. Single doors, double doors and gates with up to 8 parts.

lua
-- server
exports.np_prophandler:registerDoor({
  id = 'np_police:front',
  doors = {  -- or model + coords for a single door; up to 8 parts (double doors, gates)
    { model = 'v_ilev_ph_door01', coords = vector3(434.7, -980.6, 30.8) },
    { model = 'v_ilev_ph_door002', coords = vector3(434.7, -983.2, 30.8) },
  },
  locked = true,
  jobs = { police = 0 },
  interact = true,   -- or { label = 'Toggle', icon = 'door-closed', key = 'E', distance = 2.0 }
  distance = 2.0,
})

-- keys, lockpicks, a job check: your resource decides
exports.np_prophandler:setDoorLocked('np_police:front', false)

AddEventHandler('np_prophandler:doorChanged', function(id, locked, playerSource)
  -- playerSource is 0 when the change came from setDoorLocked
end)

A full door system on top

np_doors is built on these doors: it registers each of its doors as npd_<id> (no interact) and only changes them through setDoorLocked, and adds access rules, keys, keycards, keypads, biometrics, schedules, a manager and breaches through np_minigames. Use np_doors when you want door locks for a whole server; register doors here when your resource only needs a few of its own.

How it works ​

  • The lock state lives on the server and goes to every client on the sync channel.
  • A client adds the door to the game's door system (AddDoorToSystem, DoorSystemSetDoorState) while the player is within the door's spawnDistance (default 50 m) and removes it beyond spawnDistance + doors.margin (10 m).
  • A change of a door the client has applied fires the local event np_prophandler:doorState with (id, locked).
  • The lock state is binary. There is no hold-open, automatic rate or double-door swing setting.

Double doors and gates ​

A door with several parts (doors = { ... }, up to definition.maxDoorParts, 8) is one door: one id, one lock state, one prompt. Register a double door or a gate made of several pieces as one door, not one door per part. Every part joins the door system under its own hash. The prompt sits at the centre of all parts, and the server measures the toggle distance to that centre. More parts than maxDoorParts are refused with 'invalid_doors'.

Locking and unlocking ​

setDoorLocked(id, locked) may be called by any server resource, not only the owner. Authorization stays with the caller: check keys, lockpicks or jobs before you call it.

The interact toggle ​

With interact, players near the door get a prompt (Unlock while locked, Lock while unlocked, unless you set a label). It is shown only to players who match jobs / gangs / hours. A door's interact takes no event: it always sends the built-in toggle request, np_prophandler:doorToggleRequest.

The server re-checks every request before it toggles:

Check Refused when
Cooldown The same player asked within server.doors.toggleCooldownMs (750 ms)
Door Unknown, disabled or without interact
Routing bucket The door has a routingBucket and the player is in another one
Distance The player is farther than the interact distance + server.doors.distanceTolerance (1.5 m)
Jobs / gangs The door has conditions and the player matches neither (read through the framework bridge)

hours is not re-checked on the server: it has no in-game clock. A door with interact and no jobs / gangs can be toggled by anyone near it.

Picking the lock (np_minigames) ​

With interact.minigame (see Interaction → Minigames) the toggle request plays the game on the server (exports.np_minigames:Play) before the lock changes, with maxMove (minigames.maxMove) around the door. After the game the server checks the door, the distance and the jobs / gangs again, and changes nothing if the door was already moved to that state. By default only unlocking needs the game (lock = true: locking too); with others = true members of jobs / gangs toggle freely and everyone else gets Pick lock. Every game raises the server event np_prophandler:doorMinigame. Without np_minigames: no game, and nobody outside jobs / gangs can pick a door.

lua
exports.np_prophandler:registerDoor({
  id = 'np_police:back', model = 'v_ilev_ph_door002', coords = vector3(...), locked = true, jobs = { police = 0 },
  interact = { minigame = { game = 'lockpick', item = { name = 'lockpick', remove = 'fail', chance = 0.35 }, others = true } },
})

A client resource can send the same request with requestDoorToggle(id). It goes through the same checks.

Hiding the prompt per player ​

A door keeps one built-in toggle, with no option list. A client predicate can hide its prompt, for example while the player has no key:

lua
-- client
exports.np_prophandler:setDoorCanInteract('np_police:front', function(id, locked, data)
  return hasKey
end)
exports.np_prophandler:setDoorCanInteract('np_police:front', nil) -- remove

It only decides what is shown. The server's checks above stay the same. See Client predicates.

Fields ​

Field Default Notes
id required Letters, digits and . _ : -, up to 64 characters
model + coords A single door. Not together with doors
doors 1 to 8 parts (definition.maxDoorParts), each { model, coords }. One door: locking applies to every part
locked true Initial state
distance 2.0 Interact distance, 0.5 to 10. interact.distance wins when both are set
spawnDistance 50.0 5 to 300. The door is in the door system within this
interact none true, or a table with label, icon (default door-closed), key, distance. No event
jobs, gangs, hours none See Conditions
routingBucket all buckets
enabled true A disabled door is not added to the door system
data none Small table, same limits as for props

Door models are map objects, so they are not checked against allowedModels.

Ownership ​

  • Registering an id that exists returns false, 'id_in_use'. Remove the door first.
  • Only the owner can remove a door ('not_owner'). Doors are removed when the owning resource stops.
  • At most server.doors.maxDoors (1024) doors.