OnPlayerUseDoor
A player opened, closed, locked or unlocked a door - return false to refuse; for a checked door, before it moves.
open and locked are the door’s state as it is now on the player’s client. Return false to refuse: the record stands,
the player’s door is put back, nobody else hears of it. Otherwise the state becomes the record and every client shows it.
For a door you check first (SetDoorCheck) this is called before the door moves: the player’s game holds the swing and
waits for your answer, open and locked are the state the use would leave the door in, and a refusal keeps it still - no
swing, nothing to put back. Return a text after the false and their chat shows it (return false, "The vault is the guild's.").
The use’s own reports that follow a yes are not asked about again.
side says where the player stood. A level door has a keyhole on one side and a bolt on the other: "inside" is the bolt’s
side - from there the game unbolts a locked door for anyone, key or not - and "outside" is the keyhole’s (or the side that
cannot open the door at all while it is locked). A door without a lock of its own, and a player on an older game, give "".
wasLocked is whether the door was locked when the use began: an opening from inside with wasLocked is someone unbolting it.
To make the bolt’s side ask for the key too, use SetDoorLockSides.
Syntax
Section titled “Syntax”function OnPlayerUseDoor(pid, key, open, locked, side, wasLocked) -- ...end| Parameter | Type | |
|---|---|---|
pid |
number | the player |
key |
string | the door’s level name |
open |
boolean | open now (a checked door - open once the use is done) |
locked |
boolean | locked now (a checked door - locked once the use is done) |
side |
string | "inside" (the bolt’s side), "outside" (the keyhole’s side) or "" (no lock side) |
wasLocked |
boolean | the door was locked when the use began |
Returns
Section titled “Returns”false refuses the change (false, "text" also tells the player that text); anything else accepts it
Example
Section titled “Example”-- the vault opens for the guards alone, and does not even swing for anyone elsefunction OnGameModeInit() SetDoorCheck(VAULT_DOOR)endfunction OnPlayerUseDoor(pid, key, open, locked, side, wasLocked) if key == VAULT_DOOR and GetPlayerData(pid, "role") ~= "guard" then return false, "Locked. The guards have the key." endend
-- a locked house: only the holder of its key unbolts it from inside (nobody lets a stranger in)function OnPlayerUseDoor(pid, key, open, locked, side, wasLocked) if HOUSES[key] and side == "inside" and wasLocked and not FindPlayerItem(pid, HOUSES[key].keyId) then return false, "Only the owner unbolts this door." endendSee also
Section titled “See also”SetDoorCheck · SetDoorLockSides · SetDoorKey · GetDoorState · SetDoorState · GetDoors · the Doors and containers group of the index
