# Setup

## Configuration

Add the script to your server config

Open the `config.lua`file and make any necessary adjustments.

Make sure to update the framework / script configuration section with the relevant scripts that you use.

{% hint style="info" %}
If you select any OX script (or script that uses ox), be sure to uncomment the `@ox_lib/init.lua` line in the fxmanifest.
{% endhint %}

## Framework Implementations

External script implementations are handled in the `framework.lua` file. This file provides the necessary functions and hooks to integrate with different frameworks and scripts.

Out of the box, the script includes implementations for:

<table><thead><tr><th width="159"></th><th width="77" data-type="checkbox">qb</th><th width="73" data-type="checkbox">qbx</th><th width="61" data-type="checkbox">esx</th><th width="50" data-type="checkbox">ox</th><th data-type="checkbox">wasabi</th></tr></thead><tbody><tr><td><strong>Framework</strong></td><td>true</td><td>true</td><td>true</td><td>false</td><td>false</td></tr><tr><td><strong>Notify</strong></td><td>true</td><td>false</td><td>true</td><td>true</td><td>false</td></tr><tr><td><strong>Ambulance / Hospital</strong></td><td>true</td><td>true</td><td>true</td><td>false</td><td>true</td></tr></tbody></table>

<table><thead><tr><th></th><th data-type="checkbox">LegacyFuel</th><th data-type="checkbox">ox_fuel</th><th data-type="checkbox">ps-fuel</th></tr></thead><tbody><tr><td>Fuel</td><td>true</td><td>true</td><td>true</td></tr></tbody></table>

If you are using a different framework or script, you will need to add the relevant implementations in the `framework.lua` file.

If you are using QBCore + qb-ambulancejob, be sure to implement the custom checkin function&#x20;

## Setup Hospital Locations

Configure the HospitalLocations to align with the hospital locations you are using.

These are defined in the Config under `GenerateHospitalLocations`.

{% hint style="info" %}
Ensure that key matches the keys used in your ambulance/hospital script.
{% endhint %}

## Dispatch AI EMS

Setup the various ways you want the AI EMS to be dispatched to the downed player.&#x20;

#### Example Usage

* Dispatch AI EMS when player presses a button when they are dead
* Dispatch AI EMS automatically when player dies
* Add a command for EMS/Police job to send an AI EMS to the target id
* In your dispatch app, add a button that lets you send an AI EMS to the downed player via the downed player alerts.
* In some cases you may want the EMS dispatched immediately, like when a EMS/police player triggers it to go to a downed person, on the other hand you may want to make it delayed when the person presses a button while dead.

### Command

`/callems`&#x20;

Enable/Disable command with: `Config.EnableCallEMSCommand`&#x20;

Configure whether the command will dispatch immediately or with a delay with `Config.IsEMSCommandInstantDispatch`.

Rename the command in the `server.lua`file.&#x20;

### Client Event

```lua
-- Called on the client where the AI EMS should be dispatched to
--- @param isInstantDispatch: boolean if true dispatch immediately, else delay based on Config.DispatchEMSWaitTime
TriggerClientEvent('wp-ai-ems:client:DispatchAIEMS', isInstantDispatch)
```

### Server Event

```lua
-- Server event to dispatch AI EMS, can be used to dispatch to other players.
--- @param targetId - the serverId of the downed player that the AI EMS is dispatched to
--     Example of how to get the current users serverId: GetPlayerServerId(PlayerId())
--- @param isInstantDispatch: boolean boolean if true dispatch immediately, else delay based on Config.DispatchEMSWaitTime
TriggerServerEvent('wp-ai-ems:server:DispatchAIEMS', targetId, isInstantDispatch)
```

<details>

<summary>Example Implementation: Dispatch AI EMS when player presses G while downed</summary>

*This requires modifying the qb-ambulancejob script.*\
\
Add the following event to the `qb-ambulancejob/server/main.lua` :

```lua
RegisterNetEvent('hospital:server:RequestEMS', function()
    local src = source
    if doctorCount == 0 then
        local isInstantDispatch = false
        TriggerClientEvent('wp-ai-ems:client:DispatchAIEMS', src, isInstantDispatch)
    end
end)
```

In `qb-ambulancejob/client/dead.lua` - look for [`if IsControlJustPressed(0, 47)`](https://github.com/qbcore-framework/qb-ambulancejob/blob/6d2aafabbd5db670af90fdae61bb0d4dacfa321f/client/dead.lua#LL188C14-L188C76) and modify the following code:

```lua
if IsControlJustPressed(0, 47) and not emsNotified then
    TriggerServerEvent('hospital:server:ambulanceAlert', Lang:t('info.civ_down'))
    emsNotified = true
    TriggerServerEvent("hospital:server:RequestEMS")
end
```

{% hint style="info" %}
*Note I've configured it to only dispatch if there are no active EMS players. Remove the `doctorCount` check if you want it to always dispatch.*
{% endhint %}

</details>

## Additional Notes

* It is not 100% guaranteed that the AI EMS will be able to reach the downed players location. There are several factors that contribute to reducing the reliability.
* AI navigation is far from perfect.  There are plenty of variables and obstacles that can result in the AI not reaching a player including but not limited to: downed player location, traffic, other players, etc.
* The AI EMS tends to have the most difficulties / fail, when the downed person is far away from the road, in tight alleyways, on roof tops, or other hard to reach areas. The success rate, is **highly dependent** on the location that the AI EMS is dispatched to. It is most successful when the downed person is in an open, accessible area near a road.
* **Custom MLOs are a known problematic area**. Often this is due to MLOs not properly setting up a navmesh, which is required for the AI to properly pathfind its way in the world. This often results in the AI EMS not being able to enter or navigate interiors of these MLOS. *This is not something that this script can solve.*
  * If you have an interior with improper navmesh, it is recommended to have players bring the downed player outside of the building first and then trigger the dispatch AI EMS.

Support Discord: <https://discord.gg/3B6bznh4mV>


---

# 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://waypoint-scripts.gitbook.io/waypoint-scripts/scripts/waypoint-ai-ems/setup.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.
