# Cell Creator

### Overview

**NTeam Cell Creator** is a FiveM resource for creating and managing prison cells directly in-game. The script provides:

* creation of new cells through a menu or target interaction
* storage of cell data in a MySQL database
* definition of a polyzone area for each cell
* prevention of leaving the cell by teleporting players back to the zone center
* assigning and releasing prisoners
* sentence timer display through NUI
* a prisoner overview UI with mugshot images
* support for **ESX** and **QBCore**
* localization through JSON files

***

### Dependencies

This resource uses the following dependencies:

* **ox\_lib**
* **oxmysql**
* **ox\_target** *(if `Config.EnableTarget = true`)*
* **ESX** or **QBCore** *(optional in theory, but practically needed for job checks)*

#### Required in `server.cfg`

Recommended start order:

```cfg
ensure oxmysql
ensure ox_lib
ensure ox_target
ensure es_extended   # or qb-core
ensure cfx-nteam-cell-creator
```

If you are not using `ox_target`, you can set:

```lua
Config.EnableTarget = false
```

***

### Installation

1. Place the resource folder inside your `resources` directory.
2. Make sure `ox_lib` and `oxmysql` are installed.
3. Make sure you are using **ESX** or **QBCore**.
4. Add the resource to your `server.cfg`:

```cfg
ensure cfx-nteam-cell-creator
```

5. Start the server.
6. On first startup, the script automatically creates the database table:

**`RestoreNeeds()`**

A client-side function called **every minute** while a player is jailed inside a cell that has `restoreFood` enabled.

You can add your own logic here to restore hunger and thirst.

Example for ESX-style integration:

```lua
RestoreNeeds = function()
    TriggerEvent('esx_status:add', 'hunger', 200000)
    TriggerEvent('esx_status:add', 'thirst', 200000)
end
```

Example using a custom export:

```lua
RestoreNeeds = function()
    exports.my_needs:RestorePlayerNeeds()
end
```

***

### Commands

#### `/cellcreator`

Opens the main menu for creating and managing cells.

Only players whose job is listed in `Config.AllowedJobs` can use this command.

***

### Main Features

### 1. Creating a New Cell

From the **New Cell** menu, the following data is entered:

* cell name
* maximum prisoner count
* whether food/thirst needs should be restored
* whether the player should be teleported back when leaving the cell

After that, the zone is drawn manually.

#### Zone Drawing Controls

* **Arrow Up / Down / Left / Right** — move the marker
* **Q** — move marker up
* **CTRL** — move marker down
* **E** — add point
* **G** — finish drawing
* **ESC** — cancel creation

A valid cell requires **at least 3 points**.

After finishing the zone, the script asks you to place the **target position** by pressing **E** at the desired location.

Finally, the data is sent to the server and stored in the database.

***

### 2. Viewing Existing Cells

In the **Cells** section, all database cells are displayed.

For each cell, the following is shown:

* current prisoner count
* maximum capacity
* whether exit teleport is enabled
* whether needs restoration is enabled

***

### 3. Cell Management

Each cell provides these options:

* **Add Prisoner**
* **Prisoners**
* **Edit Cell**
* **Delete Cell**

#### Add Prisoner

The following is entered manually:

* Player ID
* Prisoner Name
* Sentence (minutes)

The sentence is stored internally in **seconds**, so the minute value is multiplied by `60` before being sent to the server.

The script checks:

* whether the cell exists
* whether the cell has free space
* whether the prisoner is already inside another cell

#### Prisoners

Displays the prisoner list for that cell and allows:

* **Release Prisoner**

#### Edit Cell

You can change:

* cell name
* maximum prisoner count
* `restoreFood`
* `teleportExit`
* zone coordinates

During editing, the user can choose whether to redefine the zone coordinates.

#### Delete Cell

Permanently removes the cell from:

* server memory
* the MySQL database
* active client zones and target zones
