> For the complete documentation index, see [llms.txt](https://docs.gkshop.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gkshop.org/tablet/configuration/dispatch-integration.md).

# Dispatch Integration

**Two ways to send a call:**

1. **Export** — recommended for new scripts
2. **Bridge** — auto-captures events from known third-party dispatch resources

***

### 1. Direct Export (Recommended)

Call from any **server** script:

```lua
exports['gks-tablet']:createDispatch({
    title    = "Store Robbery",
    message  = "Armed suspect at 24/7",
    coords   = vector3(-47.0, -1757.0, 29.0),
    code     = "10-90",
    priority = "high",       -- "high" | "medium" | "low"
    job      = "police",     -- "police" | "ambulance"
    location = "Grove St",   -- optional street label
    blip     = { sprite = 161, color = 1 },
    fields   = {             -- optional extra info rows
        { icon = "fas fa-car", label = "Plate", value = "ABC 123" },
    },
})
```

**Minimal example:**

```lua
exports['gks-tablet']:createDispatch({
    title   = "Medical Emergency",
    message = "Civilian down",
    coords  = GetEntityCoords(GetPlayerPed(source)),
    job     = "ambulance",
    priority = "high",
})
```

#### Payload reference

| Field                     | Required | Values                                       |
| ------------------------- | -------- | -------------------------------------------- |
| `title`                   | yes      | Call title shown in MDT                      |
| `message` / `description` | yes      | Call details                                 |
| `coords`                  | yes      | `vector3` or `{ x, y, z }`                   |
| `job`                     | no       | `"police"` (default) or `"ambulance"`        |
| `priority`                | no       | `"high"`, `"medium"`, `"low"` (default: low) |
| `code`                    | no       | e.g. `"10-90"`                               |
| `location`                | no       | Street/area label                            |
| `blip`                    | no       | `{ sprite, color, size, label }`             |
| `fields`                  | no       | Array of `{ icon, label, value }` (max 8)    |

***

### 2. Built-in Bridges

If your server already uses a third-party dispatch resource, GKS can listen for its events automatically. No changes needed in robbery/heist scripts.

Enable in `config/config.lua`:

```lua
Config.Dispatch.Bridges = {
    ps_dispatch         = true,
    qs_dispatch         = true,
    cd_dispatch         = true,
    rcore_dispatch      = true,
    qb_police_alert     = true,
    qb_ambulance_alert  = true,
    emergencydispatch   = true,
}
```

Set a bridge to `false` to disable it without turning off dispatch entirely.

***

### 3. Add Your Own Bridge

For a dispatch system not listed above, add a file under `server/dispatch/`:

```lua
-- server/dispatch/my_dispatch.lua
if not DispatchBridge.IsBridgeEnabled("my_dispatch") then return end

local BRIDGE = "my_dispatch"

AddEventHandler("my-dispatch:server:alert", function(data)
    if type(data) ~= "table" then return end

    DispatchBridge.ForwardDispatch({
        title       = data.title or "Dispatch Call",
        description = data.message or "",
        code        = data.code or "10-00",
        priority    = DispatchBridge.MapPriority(data.priority),
        coords      = DispatchBridge.NormalizeCoords(data.coords),
        job         = DispatchBridge.ResolveJobTarget(data.jobs, BRIDGE),
        blip        = data.blip and DispatchBridge.MapBlip(data.blip),
    }, BRIDGE)
end)

debugprint("^2[DISPATCH-BRIDGE]^7 my_dispatch bridge loaded")
```

Then register it:

1. Add `my_dispatch = true` to `Config.Dispatch.Bridges`
2. Add `"server/dispatch/my_dispatch.lua"` to `fxmanifest.lua` (after `init.lua`)

Reference implementations: `server/dispatch/ps_dispatch.lua`, `server/dispatch/emergencydispatch.lua`

***

### Troubleshooting

| Problem            | Fix                                                                       |
| ------------------ | ------------------------------------------------------------------------- |
| No call appears    | `Config.Dispatch.Enabled = true` and correct `job` value                  |
| Duplicate calls    | Disable GKS `AutoAlerts` or the external dispatch auto-detect             |
| Bridge not working | Check `Bridges.<name> = true` and resource load order in `fxmanifest.lua` |
