> For the complete documentation index, see [llms.txt](https://documentation.rcore.cz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.rcore.cz/paid-resources/rcore_prison/api/server.md).

# Server

Server-side events and exports exposed by `rcore_prison`. Call them from other resources running on the same server.

## 📡 Events

<details>

<summary>Prison Action Listener</summary>

This event is listener for actions happening in prison.

```lua
--- Action Types ---

-- PRISONER_RELEASED: Player is released from prison
-- PRISONER_LOADED: Player rejoins and is jailed since they have a remaining sentence
-- PRISONER_NEW: New player is jailed
-- PLAYER_ESCAPE_FROM_PRISON: Player escaped from prison (Prison break)
-- PLAYER_DESTROYED_WALL: Player destroyed a wall in prison (Prison break)

--- Prisoner Data Structure ---
--  data.prisoner: {
--     state: string,
--     officerName: string,
--     owner: string,
--     id: int,
--     jail_time: float,
--     source: int,
--     prisonerName: string,
--     jail_reason: string,
-- }

---@param actionType string
---@param data table

AddEventHandler('rcore_prison:server:heartbeat', function(actionType, data)
    -- Your event handling logic here

    if not next(data) then
        return
    end

    local prisoner = data.prisoner

    if not prisoner then
        return
    end

    if actionType == 'PRISONER_NEW' then
        print('New prisoner loaded')
    end
end)
```

</details>

## 🔒 Jail

<details>

<summary>Jail</summary>

This export is used when you want to jail target citizen.

```lua
---@param playerId number
---@param jailTime number - jail time in minutes
---@param jailReason? string - optional, not needed
---@param officerPlayerId? number - optional, if used it will be logged in ./jailcp Logs

local playerId = 1 -- playerId
local jailTime = 5 -- 5 minutes
local jailReason = 'multiple felonies' -- jailReason is optional, not needed
local officerPlayerId = 2 -- officerPlayerId is optional, if used it will be logged in ./jailcp Logs

exports['rcore_prison']:Jail(playerId, jailTime, jailReason, officerPlayerId)
```

</details>

<details>

<summary>Unjail</summary>

This export is used when you want to unjail citizen which is in Prison.

```lua
---@param playerId number
---@param skipTeleport? bool - if true, does not teleport the player in front of the prison

local playerId = 1
local skipTeleport = true -- If you dont want to teleport in front of Prison

exports['rcore_prison']:Unjail(playerId, skipTeleport)
```

</details>

<details>

<summary>UnjailOffline</summary>

This export is used when you want to unjail citizen which is offline

```lua
---@param charId string

local charId = "ZW32561A"

exports['rcore_prison']:UnjailOffline(charId)
```

</details>

## 📋 Prisoner Data

<details>

<summary>GetPrisonerData</summary>

This export is used when you want to get more informations about target prisoner.

```lua
---@param playerId number
---@return table data

local playerId = 1
local data = exports['rcore_prison']:GetPrisonerData(playerId)

--- {

--- state: string,
--- officerName: string,
--- owner: string,
--- id: int,
--- jail_time: float,
--- source: int,
--- prisonerName: string,
--- jail_reason: string,
 

--- }: table
```

</details>

<details>

<summary>EditPrisonerSentence</summary>

This export is used when you want to modify target prisoner sentence

```lua
---@param playerId number
---@param amount number - sets target player sentence

local playerId = 1
local amount = 10 -- Set target player sentence
exports['rcore_prison']:EditPrisonerSentence(playerId, amount)
```

</details>

<details>

<summary>IsPrisoner</summary>

This export is used when you want to check if target citizen is Prisoner

```lua
---@param playerId number
---@return boolean isPrisoner

local playerId = 1
local state = exports['rcore_prison']:IsPrisoner(playerId)

if state then
    print('Player is prisoner')
else
    print('Player is citizen')
end
```

</details>

## 💰 Credits

<details>

<summary>AddCredits</summary>

This export is used when you want to give target Prisoner credits, if he has account!

```lua
---@param playerId number
---@param giveAmonunt number

local playerId = 1
local giveAmonunt = 500

exports['rcore_prison']:AddCredits(playerId, giveAmonunt)
```

</details>

<details>

<summary>RemoveCredits</summary>

This export is used when you want to remove credits from Prisoner account.

```lua
---@param playerId number
---@param removeAmount number

local playerId = 1
local removeAmount = 500

exports['rcore_prison']:RemoveCredits(playerId, removeAmount)
```

</details>

## 🚫 Solitary

<details>

<summary>SetSolitary</summary>

This export is used when you want to sent Prisoner to Solitary cell

```lua
---@param playerId number
---@param sentenceAmount number - in minutes, 5 by default
---@param sentenceReason? string - optional, not required

local playerId = 1
local sentenceAmount = 5 -- This is 5 mins by default
local sentenceReason = 'Attacked Prison Guard' -- optional, not requred

exports['rcore_prison']:SetSolitary(playerId, sentenceAmount)
```

</details>

<details>

<summary>ReleaseFromSolitary</summary>

This export is used when you want to release prisoner from solitary

```lua
---@param playerId number

local playerId = 1

exports['rcore_prison']:ReleaseFromSolitary(playerId)
```

</details>

<details>

<summary>IsPrisonerInSolitary</summary>

This export is used when you want to check if Prisoner is in Solitary cell

```lua
---@param playerId number
---@return boolean inSolitary

local playerId = 1
local state=  exports['rcore_prison']:IsPrisonerInSolitary(playerId)

if state then
    print('Prisoner is in solitary cell')
end
```

</details>

## 👮 Community Service

<details>

<summary>StartCOMS</summary>

This export is used when you want to send citizen to Community service

```lua
---@param officerPlayerId? number - if nil, the action is not logged since the initiator is not a player but "server"
---@param targetPlayerId number - target player which should have parolle
---@param parolleAmount number - how many COMS citizen have to do in cycle
---@param perollReason? string - optional, not required

local officerPlayerId = 1 -- If you sent nil instead, the action is not going to logged since initiator is not player but "server"
local targetPlayerid = 2 -- Target player which should have parolle
local parolleAmount = 10 -- How many COMS citizen have to do in cycle
local perollReason = 'Abusing' -- Optional (not required)


exports['rcore_prison']:StartCOMS(officerPlayerId, targetPlayerId, parolleAmount, perollReason)
```

</details>
