> For the complete documentation index, see [llms.txt](https://tk-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tk-scripts.gitbook.io/docs/tk_jail/exports/server.md).

# Server

Server-side Jail exports that let other FiveM resources jail, release and track prisoners without permission checks.

Server exports skip the job and admin checks; check permissions in your own resource.

## jail

Jails or locks up a player.

```lua
exports.tk_jail:jail(targetId, time, jailType, cellIndex, teleport, notes)
```

* `targetId`: `number` or `string`
  * A server ID, or the identifier of an online player: `identifier` on ESX, `citizenid` on QBCore and Qbox
* `time?`: `number`
  * Minutes; without it the sentence has no end and lasts until the player is released
* `jailType?`: `'jail'` or `'lockup'`
  * Default `'jail'`
* `cellIndex?`: `number`
  * A position in `Config.Coords.lockup.cells`, starting at 1; used with `'lockup'` only, and without it the player is neither moved into a cell nor kept there
* `teleport?`: `boolean`
  * False to leave the player where they are; default `true`
* `notes?`: `string`
  * Shown in the Prison MDT

```lua
exports.tk_jail:jail(source, 20, 'lockup', 2)
```

Items are taken as `Config.TakeItems` sets. `Config.MaxJailTime` does not apply. Called for a player who is already jailed, it starts a new sentence with the new time.

## unjail

Releases a player.

```lua
exports.tk_jail:unjail(targetId, teleport)
```

* `targetId`: `number` or `string`
  * A server ID, or the identifier of an online player: `identifier` on ESX, `citizenid` on QBCore and Qbox
* `teleport?`: `boolean`
  * False to leave the player where they are; default `true`, which moves them outside when `Config.TeleportOnUnjail` is `true`

If the player has no sentence, nothing happens.

## seizeItems

Takes a player's items into jail storage, where the player reclaims them at `Config.Reclaim.coords`.

```lua
exports.tk_jail:seizeItems(targetId)
```

* `targetId`: `number` or `string`
  * A server ID, or the identifier of an online player: `identifier` on ESX, `citizenid` on QBCore and Qbox

Items in `Config.ItemsToNotTake` stay with the player.

## getSentence

Gets a player's sentence time left.

```lua
local minutes = exports.tk_jail:getSentence(targetId)
```

* `targetId`: `number`
  * The server ID of an online player

Returns `number`: minutes left, or `0` if the player is not jailed or the sentence has no end.

## removeSentence

Takes time off a player's timed sentence and releases them when it reaches zero.

```lua
exports.tk_jail:removeSentence(targetId, time)
```

* `targetId`: `number`
  * The server ID of an online player
* `time`: `number`
  * Minutes to take off

A sentence without an end cannot be shortened, and [getSentence](#getsentence) returns `0` for it.

## getJailedPlayers

Gets every jailed and locked-up player from the database.

```lua
local players = exports.tk_jail:getJailedPlayers(includeOffline)
```

* `includeOffline?`: `boolean`
  * True to include offline players; default online players only

Returns `table[]`, one entry per player, or an empty table:

| Field        | Type              | Meaning                                                                                                                |
| ------------ | ----------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `name`       | `string`          | The character name.                                                                                                    |
| `identifier` | `string`          | `identifier` on ESX, `citizenid` on QBCore and Qbox.                                                                   |
| `timeLeft`   | `number` or `nil` | Minutes left; `nil` if the sentence has no end.                                                                        |
| `jailType`   | `string`          | `'jail'`, or `'lockup'` followed by the cell number, for example `'lockup2'`; `'lockup'` alone when no cell was given. |
| `jailCell`   | `number` or `nil` | The home cell, a position in `Config.Coords.jail.cell`.                                                                |

## escapePrison

Releases a player as an escape. Police get the escape alert, police see the player's blip for `Config.Blips.escape.duration`, and the player is listed on the MDT fugitives page.

```lua
exports.tk_jail:escapePrison(playerId, teleport)
```

* `playerId`: `number`
  * The server ID of an online player
* `teleport?`: `boolean`, `'explosive'`, `'utensils'` or `'fence'`
  * False leaves the player where they are; an escape route drops them at a random `outCoords` of that route; default `true`, the release spot when `Config.TeleportOnUnjail` is `true`

```lua
exports.tk_jail:escapePrison(source, 'explosive')
```

The export does not check that the player is jailed: the alert and the fugitive entry are added for any player.

## removeAnkleMonitor

Removes a player's ankle monitor and its police blip.

```lua
exports.tk_jail:removeAnkleMonitor(targetId)
```

* `targetId`: `number`
  * The server ID of an online player

With `Config.AnkleMonitor.enable = false`, nothing happens. `RemovedAnkleMonitorFromPlayer` in `server/main_editable.lua` runs with `src` set to `nil`.
