# Server Exports

## 0r-Dispatch — Server Exports

This document describes all **server-side** export functions for the **0r-dispatch** script. Server exports run only on the server and are used to trigger custom alerts for specific players or to read the server’s report list.

***

### Table of Contents

* General Information
* SendAlert
* Reports
* GetSelectedAlerts
* 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',
}
```

Server exports must be called from **server scripts** only (e.g. other resources’ server-side Lua). They are typically used to send a custom alert as if a specific player had reported it, or to read the global list of dispatch reports.

***

### `SendAlert` (server)

Triggers the **target player’s** client to run the same path as `SendCustomAlert`, then syncs to dispatch receivers. **Signature (server):**

```lua
exports['0r-dispatch']:SendAlert(source, alertLabel, code, icon, jobs, blipId, priority)
```

| Argument     | Type    | Description                                 |
| ------------ | ------- | ------------------------------------------- |
| `source`     | number  | Player server id.                           |
| `alertLabel` | string  | Alert label / type.                         |
| `code`       | string  | Code.                                       |
| `icon`       | string  | Icon class.                                 |
| `jobs`       | table   | Receiver job names.                         |
| `blipId`     | number? | Blip sprite id (client default if nil).     |
| `priority`   | string? | Optional `"high"` \| `"medium"` \| `"low"`. |
| **Example:** |         |                                             |

```lua
exports['0r-dispatch']:SendAlert(src, "Atm Robbery", "10-60", "fa-dollar-sign", { "police", "bcso" }, 279, "high")
```

***

### Reports

Returns the **table of all dispatch reports (alerts)** held on the server. Reports are updated with every alert received via the `0R:Dispatch:SendAlert` event.

**Returns:** `table` — All report/alert records (id, type, coords, job, title, etc.).

**Example:**

```lua
local reports = exports['0r-dispatch']:Reports()
for id, data in pairs(reports) do
    print(id, data.type, data.title)
end
```

***

### GetSelectedAlerts

From the server’s **Reports** list, returns alerts that the given **job** should receive according to the dispatch rules (receivers).

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

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

**Example:**

```lua
local policeAlerts = exports['0r-dispatch']:GetSelectedAlerts("police")
```

***

### Quick Reference

| Export              | Description                                    |
| ------------------- | ---------------------------------------------- |
| `SendAlert`         | Triggers a custom alert for a specific player. |
| `Reports`           | Full list of reports on the server.            |
| `GetSelectedAlerts` | Alerts filtered by job (server data).          |

***

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

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


---

# 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://docs.0resmon.org/0resmon/0r-resources/0r-dispatch-1/exports/server-exports.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.
