> For the complete documentation index, see [llms.txt](https://tgiann.gitbook.io/tgiann/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tgiann.gitbook.io/tgiann/scripts/tgiann-doorlock/exports.md). Agents can also search and read this documentation through its [MCP server](https://tgiann.gitbook.io/tgiann/~gitbook/mcp).

# Exports

## Client

### GetClosestDoor

Key of the door the player is currently close enough to use (the door whose prompt is showing). Returns `nil` when no door is in range.

```lua
local key = exports["tgiann-doorlock"]:GetClosestDoor()
```

#### Returns

* `string?` door key, `nil` when no door is in range

***

### UseClosestDoor

Locks or unlocks the closest door exactly like pressing the use key. Access rules, keypad and distance are checked on the server.

```lua
local started = exports["tgiann-doorlock"]:UseClosestDoor()
```

#### Returns

* `boolean` `false` when no door is in range

***

### KnockClosestDoor

Knocks on the closest door like pressing the knock key. Only works on a locked door that allows knocking and while the player is inside the knock distance.

```lua
local started = exports["tgiann-doorlock"]:KnockClosestDoor()
```

#### Returns

* `boolean` `false` when no door is in range

***

### PickClosestDoor

Starts a lockpick attempt on the closest door like pressing the lockpick key. The server checks that the door allows lockpicking and that the player carries a fitting item, then the preparation bar and the minigame run on the client.

```lua
local started = exports["tgiann-doorlock"]:PickClosestDoor()
```

#### Returns

* `boolean` `false` when no door is in range

***

### GetDoorLocked

Current lock state of a door as the client knows it.

```lua
local locked = exports["tgiann-doorlock"]:GetDoorLocked("mrpd_front")
```

#### Parameters

* **key**: `string` door key from the admin panel

#### Returns

* `boolean?` `true` locked, `false` unlocked, `nil` when the door does not exist

## Server

### GetDoor

Serialized copy of a door record (label, door objects, general, interact, access, keypad, lockpick, schedule, sounds). Preset values are already merged in.

```lua
local door = exports["tgiann-doorlock"]:GetDoor("mrpd_front")
```

#### Parameters

* **key**: `string` door key from the admin panel

#### Returns

* `table?` door record, `nil` when the door does not exist

***

### GetAllDoors

Every enabled door keyed by door key.

```lua
local doors = exports["tgiann-doorlock"]:GetAllDoors()
```

#### Returns

* `table<string, table>` door records by key

***

### GetDoorLocked

Current lock state of a door.

```lua
local locked = exports["tgiann-doorlock"]:GetDoorLocked("mrpd_front")
```

#### Parameters

* **key**: `string` door key from the admin panel

#### Returns

* `boolean?` `true` locked, `false` unlocked, `nil` when the door does not exist

***

### SetDoorLocked

Locks or unlocks a door for every player. Cancels a pending auto lock and fires the `tgiann-doorlock:stateChanged` event.

```lua
local changed = exports["tgiann-doorlock"]:SetDoorLocked("mrpd_front", true)
```

#### Parameters

* **key**: `string` door key from the admin panel
* **locked**: `boolean` new lock state

#### Returns

* `boolean` `false` when the door does not exist

***

### GetDoorsByGroup

Keys of every enabled door that belongs to a group (General tab > Group).

```lua
local keys = exports["tgiann-doorlock"]:GetDoorsByGroup("mrpd")
```

#### Parameters

* **group**: `string` group name

#### Returns

* `string[]` door keys, empty when the group is unknown

***

### SetGroupLocked

Locks or unlocks every door of a group at once (lockdown).

```lua
local count = exports["tgiann-doorlock"]:SetGroupLocked("mrpd", true)
```

#### Parameters

* **group**: `string` group name
* **locked**: `boolean` new lock state

#### Returns

* `number` doors changed

***

### GetDoorCoords

Center of a door, the midpoint of both leaves on a double door.

```lua
local coords = exports["tgiann-doorlock"]:GetDoorCoords("mrpd_front")
```

#### Parameters

* **key**: `string` door key from the admin panel

#### Returns

* `vector3?` door center, `nil` when the door does not exist
