# Client Exports

## 0r-Dispatch — Client Exports

This document describes all **client-side** export functions for the **0r-dispatch** script. Client exports run on the local player's machine and are used to send alerts to dispatch or to read alert data received by this client.

***

### Table of Contents

* General Information
* Send911
* SendAlert
* GetDispatchAlerts
* GetSelectedAlerts
* GetSelectedEmsAlerts
* VehicleTheft
* HouseRobbery
* ATMRobbery
* ShopRobbery
* Quick Reference

***

### General Information

| Item              | Description                              |
| ----------------- | ---------------------------------------- |
| **Resource name** | `0r-dispatch`                            |
| **Call format**   | `exports['0r-dispatch']:ExportName(...)` |

Add the resource as a dependency in your `fxmanifest.lua`:

```lua
dependencies {
    '0r-dispatch',
}
```

Client exports are invoked from **client scripts** only. When you send an alert (e.g. `SendAlert`), the event is sent to the server, which then distributes it to all clients whose job is in the alert’s receivers.

***

### Send911

Creates a **911 / civil report**-style alert. The player's position, gender, and optional message are sent to dispatch. Typically used from a "Civil Reporting" or "911" style UI.

| Parameter    | Type      | Required | Description                                                                    |
| ------------ | --------- | -------- | ------------------------------------------------------------------------------ |
| `alertLabel` | `string`  | Yes      | Alert type label (e.g. `"civilreporting"`). Can match a rule type in settings. |
| `code`       | `string`  | No       | Code (e.g. `"10-90"`).                                                         |
| `icon`       | `string`  | No       | Font Awesome icon name (e.g. `"fa-phone"`). Default: `'fa-hand'`.              |
| `blipData`   | `table`   | No       | Map blip settings.                                                             |
| `takePhoto`  | `boolean` | No       | If `true`, a screenshot is taken and attached to the alert.                    |
| `msg`        | `string`  | No       | The citizen's message; used as the alert description.                          |

**blipData** fields:

* `blipId` (number) — Blip sprite ID. Default: `161`
* `blipScale` (number) — Blip scale. Default: `1.5`
* `blipColor` (number) — Blip color. Default: `1`

**Note:** The alert is not sent if the player is in a dispatch exclusion zone.

**Example:**

```lua
exports['0r-dispatch']:Send911(
    "civilreporting",
    "10-90",
    "fa-phone",
    { blipId = 161, blipScale = 1.5, blipColor = 1 },
    false,
    "Suspicious vehicle in the park."
)
```

***

### `SendAlert` (client)

Sends a **custom** dispatch alert. Collects the **local player** context: position, weapon, vehicle (if any), nearby players, witness-style count, etc. Receivers come from the **`jobs` argument** if provided, otherwise from **`settings.json`** for `alertLabel`, otherwise `blipData.jobs`, otherwise `{"police"}`. **Signature (client):**

```lua
exports['0r-dispatch']:SendAlert(alertLabel, code, icon, blipData, takePhoto, jobs, coords)
```

| Argument      | Type     | Description                                              |
| ------------- | -------- | -------------------------------------------------------- |
| `alertLabel`  | string   | Type key + locale / config lookup.                       |
| `code`        | string   | Dispatch code.                                           |
| `icon`        | string   | Font Awesome class.                                      |
| `blipData`    | table    | Blip + optional `priority`, optional `jobs` fallback.    |
| `takePhoto`   | bool?    | Screenshot; `nil` → follow `includeImage`.               |
| `jobs`        | table?   | Array of job name strings (e.g. `{ "police", "bcso" }`). |
| `coords`      | vector3? | World position; omit for player coords.                  |
| **Examples:** |          |                                                          |

```lua
-- Vehicle shooting; jobs from settings / defaults
exports['0r-dispatch']:SendAlert(
    "vehicleshooting",
    "10-90",
    "fa-bell",
    { blipColor = 1, blipId = 161, blipScale = 1.0, priority = "high" },
    false
)
-- Explicit jobs + custom location
exports['0r-dispatch']:SendAlert(
    "shooting",
    "10-31",
    "fa-crosshairs",
    { blipId = 110, blipColor = 37, blipScale = 2.0 },
    false,
    { "police", "bcso" },
    vector3(100.0, 200.0, 21.0)
)
-- blipData.jobs as fallback when jobs argument is empty (SendAlert only)
exports['0r-dispatch']:SendAlert(
    "customRobbery",
    "10-31",
    "fa-mask",
    { blipId = 161, blipColor = 1, blipScale = 1.0, jobs = { "police", "bcso" } },
    false
)
```

***

### GetDispatchAlerts

Returns the **list of all dispatch alerts** currently received on this client. The list includes every alert the server has sent to this client.

**Returns:** `table` — Each element is an alert object (id, type, title, coords, job, etc.).

**Example:**

```lua
local alerts = exports['0r-dispatch']:GetDispatchAlerts()
for i, alert in ipairs(alerts) do
    print(alert.id, alert.type, alert.title)
end
```

***

### GetSelectedAlerts

Returns alerts filtered by dispatch rules for the given **job** — i.e. only alerts whose type has that job as a receiver.

| Parameter | Type     | Required | Description                                |
| --------- | -------- | -------- | ------------------------------------------ |
| `job`     | `string` | Yes      | Job name (e.g. `"police"`, `"ambulance"`). |

**Returns:** `table` — Alert objects for that job.

**Example:**

```lua
local policeAlerts = exports['0r-dispatch']:GetSelectedAlerts("police")
for _, v in ipairs(policeAlerts) do
    print(v.id, v.type, v.title)
end
```

***

### GetSelectedEmsAlerts

For **EMS** use: returns all alerts where the **sender's job** matches `job`. Filtered by "who sent this alert" (e.g. alerts sent by ambulance).

| Parameter | Type     | Required | Description                    |
| --------- | -------- | -------- | ------------------------------ |
| `job`     | `string` | Yes      | Job name (e.g. `"ambulance"`). |

**Returns:** `table` — Alert objects where `v.job == job`.

**Example:**

```lua
local emsAlerts = exports['0r-dispatch']:GetSelectedEmsAlerts("ambulance")
```

***

### VehicleTheft

Creates a **vehicle theft** alert. Plate, model name, direction, and location are taken from the given vehicle entity. No alert is sent if the `vehicletheft` rule is disabled or the player is in an exclusion zone. Cooldown applies.

| Parameter | Type               | Required | Description                                              |
| --------- | ------------------ | -------- | -------------------------------------------------------- |
| `Vehicle` | `entity` (vehicle) | Yes      | The vehicle to report as stolen (script/vehicle handle). |

**Example:**

```lua
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
if veh and veh ~= 0 then
    exports['0r-dispatch']:VehicleTheft(veh)
end
```

***

### HouseRobbery

Sends a **house robbery** alert. The given coordinates are used as the incident location; the player's gender and heading are included. No alert is sent if the `houseRobbery` rule is off or the player is in an exclusion zone. Cooldown applies.

| Parameter    | Type                | Required | Description                  |
| ------------ | ------------------- | -------- | ---------------------------- |
| `HouseCoord` | `vector3` / `table` | Yes      | Incident location (x, y, z). |

**Example:**

```lua
local coords = GetEntityCoords(PlayerPedId())
exports['0r-dispatch']:HouseRobbery(coords)
```

***

### ATMRobbery

Sends an **ATM robbery** alert. The given coordinates are used as the incident location. No alert is sent if the `atmRobbery` rule is off or the player is in an exclusion zone. Cooldown applies.

| Parameter  | Type                | Required | Description            |
| ---------- | ------------------- | -------- | ---------------------- |
| `AtmCoord` | `vector3` / `table` | Yes      | ATM incident location. |

**Example:**

```lua
local atmCoords = vector3(89.0, 2.0, 68.0)
exports['0r-dispatch']:ATMRobbery(atmCoords)
```

***

### ShopRobbery

Sends a **store / shop robbery** alert. The given coordinates are used as the incident location. No alert is sent if the `ShopRobbery` rule is off or the player is in an exclusion zone. Cooldown applies.

| Parameter   | Type                | Required | Description              |
| ----------- | ------------------- | -------- | ------------------------ |
| `ShopCoord` | `vector3` / `table` | Yes      | Store/incident location. |

**Example:**

```lua
local shopCoords = GetEntityCoords(PlayerPedId())
exports['0r-dispatch']:ShopRobbery(shopCoords)
```

***

### Quick Reference

| Export                 | Description                                          |
| ---------------------- | ---------------------------------------------------- |
| `Send911`              | Civil/911-style alert (with message).                |
| `SendAlert`            | Custom dispatch alert (location, blip, jobs, photo). |
| `GetDispatchAlerts`    | Full list of alerts on the client.                   |
| `GetSelectedAlerts`    | Alerts filtered by job (client data).                |
| `GetSelectedEmsAlerts` | Alerts sent by a given job (for EMS).                |
| `VehicleTheft`         | Vehicle theft alert.                                 |
| `HouseRobbery`         | House robbery alert.                                 |
| `ATMRobbery`           | ATM robbery alert.                                   |
| `ShopRobbery`          | Store/shop robbery alert.                            |

***

For **server exports**, see exports-server.md.

*Rules and codes are read from `data/settings.json` and `shared/config.lua`.*
