> For the complete documentation index, see [llms.txt](https://mango-5m.gitbook.io/mango5m-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mango-5m.gitbook.io/mango5m-docs/resources/mango-prison/configuration/doors-and-lockdowns.md).

# Doors & Lockdowns

ox\_doorlock integration, lockdown scopes, return-to-cells and auto-expiry.

## Gates that stand open

`Config.Doors.holdOpenWhenUnlocked` (on by default) makes cell gates **physically swing open and stay open** while unlocked, and shut when locked — instead of sitting closed-but-openable.

This is ox\_doorlock's own per-door `holdOpen` flag. Mango Corrections switches it on for every cell gate and solitary gate at boot, writing through ox\_doorlock's `editDoor` export — so **the setting persists in ox\_doorlock's database**, not in this resource. Set it to `false` to switch it back off, or `nil` to leave whatever each door already has alone.

## ox\_doorlock by name

`config/doors.lua` references doors by their **ox\_doorlock name**, never by id — ids differ per install, names don't. At boot the resource resolves names to ids and prints a single warning listing any names it can't find:

```
[mango_prison] doorlock: mapped 179 door name(s)
```

The file ships pre-filled for the Bolingbroke Interior MLO door pack — **179 doors** across every scope:

| Scope        | Doors  | What it covers                                                                                                                                            |
| ------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cells`      | 18     | The six cell gates in each housing block (7, 6, 5)                                                                                                        |
| `blocks`     | 3 each | Wing entrances for blocks 7, 6 and 5                                                                                                                      |
| `yard`       | 12     | Gym, classroom, church and garden                                                                                                                         |
| `medical`    | 12     | Both medical wings (block 8A)                                                                                                                             |
| `visitation` | 19     | The visitation wing (block 8A)                                                                                                                            |
| `solitary`   | 7      | The solitary cell gates in block 9B — **always locked**                                                                                                   |
| `prison`     | 102    | Perimeter gates, booking, mess, the solitary *wing* doors, death row, workshops, offices, garage, the escape route, and the entrances of the unused wings |

Each cell gate is the door nearest that cell's spawn point in `config/locations.lua` — so `cell:7-3` locks the cell that inmate 7-3 actually stands in. The same is true of solitary: the four gates in `Config.Locations.solitary` are the first four names in the `solitary` group.

## When cell doors are locked

Cells are **open by default**. Mango Prison seals a cell gate only while one of these is true, and opens it again the moment they all clear:

1. A lockdown covers it — `prison`, `block:<id>` or `cell:<id>`
2. A **riot alert** is live (`Config.Lockdown.riotLocksCells`)
3. The live timetable slot is flagged `lockCells` — Lights Out and the 22:00 slot by default, sealing 90 seconds after the slot starts. See [Timetable](/mango5m-docs/resources/mango-prison/configuration/timetable.md)
4. An officer locked that specific cell from the terminal

Wing entrances stay open throughout unless a lockdown covers them (`Config.Doors.entrancesUnlockedByDefault`). Set `Config.Doors.cellsUnlockedByDefault = false` for an old-school prison where cells are shut unless someone opens them.

{% hint style="info" %}
An officer pressing **UNLOCK** on a cell during a `lockCells` slot really opens it — the override outlives the schedule until the next slot begins, or until an emergency (lockdown or riot) takes over. **LOCK** seals a cell until an officer opens it again.
{% endhint %}

### Solitary is the exception

The gates in `Config.Doors.solitary` are **always locked**. They are not opened by normal operation, by a timetable slot, or by lifting a lockdown — an inmate in the hole stays there until their solitary time expires and the server teleports them back to their own cell. Set `Config.Doors.solitaryAlwaysLocked = false` if you want them to behave like ordinary cells.

{% hint style="info" %}
**Different MLO or door pack?** Turn on `Config.DoorInspector`, walk the facility and aim at each door. A beam shows what you're pointing at, and the door's **id**, **ox\_doorlock name** and **model** appear on it — colour-coded by whether `config/doors.lua` already references that name.

Press **ENTER** to copy the model and coordinates to your clipboard, ready to paste:

```lua
-- Bolingbroke Visitation 1-5  (ox_doorlock id 94)
model = 'v_ilev_ph_gendoor006', coords = vec3(1781.2748, 2574.3428, 45.9949), heading = 0.0000
```

It works on **unregistered** props too, so you can pull the model and position of a door ox\_doorlock doesn't know about yet. Every copy is printed to the F8 console as well, so a session's worth of doors stays scrolled back.
{% endhint %}

{% hint style="info" %}
No ox\_doorlock? Set `Config.Doors.missingBehaviour = 'warn'` (default) and lockdowns become announcement-only instead of erroring.
{% endhint %}

## Who can open a door

Access is ox\_doorlock's business, not Mango Prison's — the resource only locks and unlocks doors, it never decides who may pass. The recommended setup gives every prison door two ways in:

```json
"groups": {"doc": 0}, "items": ["prison_key"]
```

* **`doc` grade 0+** — every corrections officer, no keys needed
* **`prison_key`** — an item that opens any door. Because it is listed as a plain string it is **not consumed**, so it works as a real key: issue it to staff, or let inmates steal one and open their own route out

See [Installation](/mango5m-docs/resources/mango-prison/getting-started/installation.md) for the one-line SQL that applies this to every door at once, and the item definition.

{% hint style="warning" %}
`doc` opening *every* door includes the perimeter gates — which is what lets the intake bus drive itself in. If you want the outer gates restricted to senior grades, raise the grade on those specific rows (`"groups":{"doc":3}`).
{% endhint %}

## Lockdown scopes

From the terminal, exports or events:

| Scope                    | Locks                                                  |
| ------------------------ | ------------------------------------------------------ |
| `cell:A3`                | One cell gate                                          |
| `block:A`                | Every cell in the block + its entrances                |
| `yard`                   | The yard buildings (gym, classroom, church, garden)    |
| `medical` / `visitation` | Those wings                                            |
| `prison`                 | Everything above + main gates and all remaining blocks |

Active lockdowns are mirrored to `GlobalState.mango_prison_lockdowns`, persist across restarts, and are logged to the audit log with who started them.

## Lockdown behaviour

```lua
Config.Lockdown = {
    returnToCells  = true,   -- prison/block lockdowns teleport affected
                             -- prisoners into their cells and lock the gates;
                             -- gates unlock when the lockdown lifts
    autoEndMinutes = 5,      -- lockdowns lift themselves (0 = manual only)

    riotLocksCells     = true,  -- a riot alert seals every cell gate
    riotAutoEndMinutes = 10,    -- the alert clears itself (0 = manual only)
}
```

* Prisoners in visitation, medical or solitary are not yanked out.
* Auto-end timers **survive restarts** — a lockdown that expired while the server was down is cleaned up at boot; an unexpired one is re-armed with its remaining time.
* Ending a broad lockdown re-applies any narrower ones still active, so cancelling a prison lockdown can never accidentally unlock a separately locked cell.

## Riot alerts

**RIOT ALERT** on the terminal's emergency screen does more than sound the alarm and call dispatch: it seals every cell gate until an officer presses **CANCEL RIOT** (or `riotAutoEndMinutes` elapses). Unlike a lockdown it does **not** teleport anyone — inmates already out of their cells stay where they are, they just can't get back in or shut themselves away.

The riot state persists across restarts and is mirrored to `GlobalState.mango_prison_riot`, so other resources can react to it.

```lua
exports.mango_prison:SetRiot(true)          -- or false to stand it down
exports.mango_prison:IsRiotActive()
```

## Automatic lockdowns

A completed escape triggers a full prison lockdown when `Config.Escape.autoLockdown = true`, alongside the PA alarm and the police dispatch call.
