# Functions/Events

## client/editable-main.lua

#### 1. `customReviveLogic(extraVars)`

This function allows you to insert custom code for the revival of a player with your ambulance job script if we do not support it.

**Example:**

```lua
local function customReviveLogic(extraVars)
    TriggerEvent('brutal_ambulancejob:revive')
    --print("Using custom revive logic for a custom ambulance jobs script.")
    --print("Please go to the client/editable-main.lua to add your revive logic.")
end
```

#### 2. `isDeadCustom()`

Customizes the death check logic for your server. If you have a custom state or variable that determines if a player is dead, implement that logic in this function.

**Example:**

```lua
local function isDeadCustom()
    return exports.brutal_ambulancejob:IsDead()
    --print("Using custom death check logic for a custom ambulance jobs script.")
    --print("Please go to the client/editable-main.lua to add your death check logic.")

    -- Custom death check logic
    --local customDeathState = false  -- Replace with actual logic
    --return customDeathState
end
```

#### 3. `sendBill(amount, reason)`

Sends a bill to the player for revival services. This is dependent on whether you're using ESX or QB frameworks.

**Code Snippet:**

```lua
local function sendBill(amount, reason)
    if Config.Bill > 0 then
        if Config.core == "ESX" then
            TriggerServerEvent('esx_billing:sendBill', amount, reason)
        else
            TriggerServerEvent('qb-billing:sendBill', amount, reason)
        end
    end
end
```

### Event Handlers

#### 1. `enyo-aiambulance:client:revivehandle`

This event is triggered to handle player revival. It calls the `handleRevive()` function with provided parameters.

#### 2. `enyo-aiambulance:client:notifyEMS`

This event triggers a notification to EMS players when a distress signal is sent. It works with both ESX and QB frameworks to notify EMS about player distress.

#### 3. `enyo-aiambulance:client:isAmbulanceDispatchAllowed`

Checks if the ambulance dispatch is allowed based on custom conditions and responds to the server.

#### 4. `crossNotify(QB, MSG)`

This function is used to send notifications to the player, either through QB's notification system or ESX's advanced notifications.

5. **`fillFuel(vehicle)`**

This function sets a vehicle's fuel level to 100% and updates its fuel decoration for compatibility with fuel systems.

***

## server/editable-main.lua

#### 1. `countAmbulancePlayers_QB`

Counts the number of on-duty EMS players for QBCore framework.

* Retrieves all players and checks job details.
* Sends the count to clients via `ambulancePlayerCount`.

#### 2. `countAmbulancePlayers_ESX`

Counts the number of EMS players for ESX framework.

* Iterates through players and counts those with EMS jobs.
* Sends the count to clients via `ambulancePlayerCount`.

#### 3.`esx_billing:sendBill`

Handles billing for ESX framework.

* Deducts the amount from the player's bank account if sufficient funds exist.
* Notifies the player of the transaction or insufficient funds.

#### 4. `qb-billing:sendBill`

Handles billing for QBCore framework.

* Deducts the amount from the player's bank account if sufficient funds exist.
* Notifies the player of the transaction or insufficient funds.


---

# 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-ambulance/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.
