# Functions/Events

## client/editable-main.lua

### `sendToJail` Function

Sends a player to jail for a specified duration. The implementation varies depending on the configured framework (QB-Core or ESX).

Functionality

1. **Framework Detection**:\
   Uses `Config.framework` to determine whether to use QB-Core or ESX logic.
2. **QB-Core Implementation**:
   * Triggers two server events:
     * `enyo-policebackup:qb-jail`: Custom event for jailing.
     * `police:client:SendToJail`: Standard QB-Core jail event.
3. **ESX Implementation**:
   * Converts `time` from minutes to seconds (`time * 60`).
   * Triggers `esx_jail:sendToJail` with the player's server ID and converted time.

#### Customization Notes

* Replace `enyo-policebackup:qb-jail` with your QB-Core jail event.
* Adjust `esx_jail:sendToJail` if your ESX jail system uses different parameters/events.
* Ensure `Config.framework` is set to `"QB"` or `"ESX"` in your configuration.

***

### `sendFine` Function

Issues a monetary fine to a player. Only processes fines greater than $0.

Functionality

1. **Validation**:\
   Only triggers if `amount > 0`.
2. **Framework Detection**:\
   Uses `Config.framework` to determine the billing system.
3. **QB-Core Implementation**:
   * Triggers `enyo-policebackup:qb-billing:sendBill` with the amount and issuer (`"police"`).
4. **ESX Implementation**:
   * Triggers `enyo-policebackup:esx-billing:sendBill` with the amount and issuer (`"police"`).

#### Customization Notes

* Replace `enyo-policebackup:qb-billing:sendBill`/`enyo-policebackup:esx-billing:sendBill` with your billing system's events/exports.
* Ensure your billing system accepts parameters in the format `(amount, issuer)`.

***

## server/editable-main.lua

### Jail System

#### Event: `enyo-policebackup:qb-jail`

**Triggered when a player is sent to jail for QB-Core**

Modify logic if your jail system uses exports like `qb-jail:server:SendToJail`.

**Functionality**

1. **Retrieve Player Data**:
   * Uses `source` to get the player's server ID.
   * Fetches the QB-Core object with `exports[Config.core]:GetCoreObject()`.
   * Retrieves the player's data with `QBCore.Functions.GetPlayer(serverID)`.
2. **Metadata Handling**:
   * Checks the player's current jail time via `OtherPlayer.Functions.GetMetaData('injail')`.
   * Updates the jail time **only if the new `time` is greater than the current value**.

***

### 💸 Billing Systems

#### 1. ESX Billing Event: `enyo-policebackup:esx-billing:sendBill`

**Deducts money directly from the player's bank account.**

Adjust the notification event to match your client-side script.

**Functionality**

1. **Deduct Funds**:
   * Retrieves the ESX player object with `ESX.GetPlayerFromId(src)`.
   * Removes money from the bank using `player.removeAccountMoney('bank', amount)`.
2. **Notification**:
   * Triggers a client-side notification with `enyo-policebackup:crossNotify`.

***

#### 2. QB-Core Billing Event: `enyo-policebackup:qb-billing:sendBill`

**Deducts money from the player's bank and adds it to police funds.**

**Functionality**

1. **Deduct Funds**:
   * Retrieves the QB-Core player object with `QBCore.Functions.GetPlayer(src)`.
   * Removes money from the bank using `player.Functions.RemoveMoney('bank', amount)`.
2. **Add to Police Funds**:
   * Uses `qb-banking` export to deposit funds into the police account:\
     `exports['qb-banking']:AddMoney('police', amount, 'Fine paid')`.
3. **Notification**:
   * Triggers a client-side notification with `enyo-policebackup:crossNotify`.

**Customization Notes**

* Replace `qb-banking` with `qb-management` if using an alternative resource.
* Modify `RemoveMoney` to use cash instead of bank with `'cash'`.


---

# 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://enyo-scripts.gitbook.io/documentations/fivem-scripts/ai-police-backup/functions-events.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.
