# Server

### Unjail

* Unjail target user if he is prisoner.
* Side: `server`
* Type: `export`
* Usage:

```lua
local playerId = 1

exports['rcore_prison']:Unjail(playerId)

-- Note: If you want to unjail user without being teleported in front of prison, useful for other resources that for prison break(s).

exports['rcore_prison']:Unjail(playerId, {
    skipTeleport = true
})
```

### IsPrisoner

* Returns true/false if player is prisoner
* Side: `client`
* Type: `export`
* Usage:

```lua
local playerId = 1
local state, statusCode = exports.rcore_prison:IsPrisoner(playerId)

if state then
    print('User is in prison.')
else
    print('User is not prisoner.)
end
```

### Jail

* Jail target user if he is not prisoner.
* Side: `server`
* Type: `export`
* Usage:

```lua
local playerId = 1 -- playerId
local jailTime = 5 -- 5 minutes
local jailReason = 'multiple felonies' -- jailReason is optional, not needed

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

### GetPrisonerdata

* Returns table of cached user prisoner data, if he is prisoner with statusCode
* Side: `server`
* Type: `export`
* Usage:

```lua
local playerId = 1
local data, statusCode = exports.rcore_prison:GetPrisonerData(playerId)

--- {

--- serverId: int,
--- officerName: string,
--- owner: string,
--- state: string,
--- jail_time: float,
--- accountId: number,
--- prisonerName: string, 

--- }: table

if data and next(data) and statusCode == 'PLAYER_PRISONER_DATA_EXIST' then
    local serverId = data.serverId -- Prisoner playerId
    local officerName = data.officerName -- Who jailed this prisoner
    local state = data.state -- jailType: ['jailed', 'cs]
    local jail_time = data.jail_time -- jailTime
    local accountId = data.accountId -- Prison account ID if exist
    local prisonerName = data.prisonerName -- Prisoner name
end
```

¨

### GetPrisonerAccount

* Returns table of cached user prisoner account data if data exist for target user with statusCode response.
* Side: `server`
* Type: `export`
* Usage:

```lua
local playerId = 1
local data, statusCode = exports.rcore_prison:GetPrisonerAccount(playerId)

--- {

--- account_id: int,
--- owner: string,
--- giftState: number,
--- balance: number,

--- }: table

if data and next(data) and statusCode == 'PLAYER_PRISONER_ACCOUNT_DATA_EXIST' then
    local account_id = data.account_id -- Account id
    local owner = data.owner -- Account owner (charId)
    local giftState = data.giftState -- number: [1 = true, 2 = false]
    local balance = data.balance -- Account credit balance
end
```

### EditPrisonerSentence

* You can use this export to modify the prisoner sentence from your script.
* Side: `server`
* Type: `export`
* Usage:

```lua
local playerId = 1 -- Target player
local sentenceTime = 30 -- By default this is 30 minutes.
local sentenceState, sentenceStatusCode = exports.rcore_prison:EditPrisonerSentence({
    serverId = playerId,
    time = sentenceTime,
    reduceType = 'total' -- Only add total if you want to override prisoner sentence, remove it if you want to reduce his sentence.
})

if sentenceState then
    print('User sentence was updated')
end
```

### EditPrisonerAccountCredits

* You can use this export to modify the prisoner account credits from your script.
* Side: `server`
* Type: `export`
* Usage:

```lua
local playerId = 1 -- Target player
local reward = math.random(300, 800) -- The random amount between 300 <-> 800 which user receive on his account if action is type.
local state, statusCode = exports.rcore_prison:EditPrisonerAccountCredits({
    serverId = playerId,
    amount = reward,
    action = 'add' -- ['add', 'remove']
})


if state then
    print('Prisoner account was updated')
end
```

### rcore\_prison:prisonerState

* Used for monitoring actions inside prison, which are being called to this event.
* Side: `server`
* Type: `event`
* Usage:

```lua

--- {
--- state = string, -- ['jailed, 'cs']
--- serverId = number, -- playerId
--- charId = number/string, -- Player characterId
--- userName = string, -- Player username
--- prisoner = {
---     name = string, -- Prisoner name (IC)
---     prisonerId = number, -- Prisoner unique ID
---     jailTime = number, -- Prisoner jail time
---    jailReason = string, -- Prisoner jail reason
---     cellId = number, -- Prisoner cell ID
--- }
--- }: table


AddEventHandler('rcore_prison:prisonerState', function(data)
    local data = data
    local state = data and data.state or nil

    if state == 'released' then
    elseif state == 'jailed' then
        local jobName = fetchJobFreeActivities()

        if jobName then
            Bridge.Notify(data.serverId, {
                title = l('WARDEN_TITLE'),
                subtitle = l('PRISON_TITLE'),
                description = 'There is free job to do [' .. jobName .. ']',
                position = 'top',
                lenght = 4000,
                style = {
                    backgroundColor = '#141517',
                    color = '#909296'
                }
            })
        end
    end
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.rcore.cz/paid-resources/rcore_prison/v1/index/exports.server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
