> For the complete documentation index, see [llms.txt](https://hane-mod-studio.gitbook.io/hane-mod-studio/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hane-mod-studio.gitbook.io/hane-mod-studio/hane-scripts/hane-dispatch/exports-and-api.md).

# Exports & API

Hane Dispatch provides server-side exports that allow any third-party script to send alerts and query dispatch data.

***

### Server Exports

#### `SendAlert`

Send a predefined alert type with location data.

```lua
exports['hane_dispatch']:SendAlert(alertType, data)
```

**Parameters:**

| Parameter   | Type   | Description                                                               |
| ----------- | ------ | ------------------------------------------------------------------------- |
| `alertType` | string | Alert type key from `Alerts.Types` (e.g., `'bank_robbery'`, `'shooting'`) |
| `data`      | table  | Alert data table (see below)                                              |

**Data table:**

| Field    | Type    | Description                       |
| -------- | ------- | --------------------------------- |
| `coords` | vector3 | Location of the alert             |
| `street` | string  | Street name                       |
| `zone`   | string  | Zone/area name                    |
| `fields` | table   | (Optional) Additional info fields |

**Returns:** `boolean` — `true` if successful, `false` if alert type not found.

**Example:**

```lua
-- From a bank robbery script
exports['hane_dispatch']:SendAlert('bank_robbery', {
    coords = vector3(150.26, -1040.20, 29.37),
    street = 'Boulevard Del Perro',
    zone = 'Pillbox Hill',
    fields = {
        { label = 'Suspects', value = '3 armed individuals' },
        { label = 'Vehicle', value = 'Black Sultan RS' }
    }
})
```

***

#### `CustomAlert`

Send a fully custom alert without using predefined types.

```lua
exports['hane_dispatch']:CustomAlert(data)
```

**Data table:**

| Field          | Type    | Description                             |
| -------------- | ------- | --------------------------------------- |
| `code`         | string  | Alert code (e.g., `'CODE 99'`)          |
| `title`        | string  | Alert title                             |
| `description`  | string  | Alert description                       |
| `priority`     | string  | `'high'`, `'medium'`, or `'low'`        |
| `coords`       | vector3 | Location                                |
| `street`       | string  | Street name                             |
| `zone`         | string  | Zone name                               |
| `blip`         | table   | `{ sprite, color, scale }`              |
| `jobs`         | table   | List of job names to receive the alert  |
| `duration`     | number  | Alert duration in seconds               |
| `fields`       | table   | (Optional) Additional info fields       |
| `jobOverrides` | table   | (Optional) Per-job code/title overrides |

**Returns:** `boolean` — `true` if successful.

**Example:**

```lua
exports['hane_dispatch']:CustomAlert({
    code = 'CUSTOM-01',
    title = 'Warehouse Break-In',
    description = 'Suspicious activity at Industrial District',
    priority = 'high',
    coords = vector3(1000.0, -2000.0, 30.0),
    street = 'Elysian Island',
    zone = 'Industrial',
    blip = { sprite = 161, color = 1, scale = 1.0 },
    jobs = { 'police', 'sheriff' },
    duration = 90,
    fields = {
        { label = 'Reporter', value = 'Anonymous 911 Call' }
    }
})
```

***

#### `GetActiveDispatches`

Retrieve all currently active dispatch alerts.

```lua
local dispatches = exports['hane_dispatch']:GetActiveDispatches()
```

**Returns:** `table` — A table of active dispatch objects keyed by dispatch ID.

***

#### `GetPlayerUnit`

Get the unit name a player is assigned to.

```lua
local unitName = exports['hane_dispatch']:GetPlayerUnit(source)
```

**Parameters:**

| Parameter | Type   | Description      |
| --------- | ------ | ---------------- |
| `source`  | number | Player server ID |

**Returns:** `string | nil` — The unit name, or `nil` if the player is not in a unit.

***

#### `GetPlayerUnitData`

Get the full unit data for a player.

```lua
local unitData = exports['hane_dispatch']:GetPlayerUnitData(source)
```

**Returns:** `table | nil` — The full unit table (name, status, officers), or `nil`.

***

### Integration Examples

#### Store Robbery Script

```lua
-- Trigger when robbery starts
RegisterNetEvent('myrobbery:started', function()
    local ped = PlayerPedId()
    local coords = GetEntityCoords(ped)
    
    exports['hane_dispatch']:SendAlert('store_robbery', {
        coords = coords,
        street = GetStreetName(coords),
        zone = GetZoneName(coords),
    })
end)
```

#### Custom Drug Bust Alert

```lua
exports['hane_dispatch']:CustomAlert({
    code = 'NARC-01',
    title = 'Drug Manufacturing Detected',
    description = 'Chemical odor reported by civilians',
    priority = 'high',
    coords = playerCoords,
    street = streetName,
    zone = zoneName,
    blip = { sprite = 140, color = 2, scale = 1.0 },
    jobs = { 'police' },
    duration = 120,
})
```
