> For the complete documentation index, see [llms.txt](https://mango-5m.gitbook.io/mango5m-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mango-5m.gitbook.io/mango5m-docs/resources/mango-dispatch/developer-guide/events.md).

# Events

Server events fired when calls are created, resolved and responded to.

Three server-side events, fired for any other resource to listen to. All of them are local server events - use `AddEventHandler`, not `RegisterNetEvent`.

```lua
AddEventHandler('mango_dispatch:callCreated', function(call)
    print(('new call #%s: %s'):format(call.id, call.title))
end)

AddEventHandler('mango_dispatch:callResolved', function(id, byIdentifier)
    -- byIdentifier is the officer who cleared it, or nil for an automatic close
end)

AddEventHandler('mango_dispatch:responderChanged', function(id, identifier, action)
    -- action: 'respond' | 'cancel' | 'primary'
end)
```

### `mango_dispatch:callCreated`

| Argument | Is                                                                                                                            |
| -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `call`   | The full call, in the shape described on [Call Fields](/mango5m-docs/resources/mango-dispatch/developer-guide/call-fields.md) |

Fires for every call, including silent ones - so a Discord logger sees everything, even calls that never interrupted a player.

### `mango_dispatch:callResolved`

| Argument       | Is                                                     |
| -------------- | ------------------------------------------------------ |
| `id`           | The call id                                            |
| `byIdentifier` | The identifier of the officer who cleared it, or `nil` |

`byIdentifier` is `nil` for the two automatic paths: `RemoveCall` from another resource, and the auto-resolve sweep. It is set when a player pressed Code 4.

### `mango_dispatch:responderChanged`

| Argument     | Is                                     |
| ------------ | -------------------------------------- |
| `id`         | The call id                            |
| `identifier` | The responder's identifier             |
| `action`     | `'respond'`, `'cancel'` or `'primary'` |

A unit responding to a second call while already on one produces a `'respond'` for the new call; the removal from the old one is silent.

### A worked example - Discord logging

```lua
AddEventHandler('mango_dispatch:callCreated', function(call)
    PerformHttpRequest(WEBHOOK, function() end, 'POST', json.encode({
        embeds = { {
            title = ('[%s] %s'):format(call.code, call.title),
            description = call.description,
            fields = {
                { name = 'Caller',   value = call.caller_name or 'Unknown', inline = true },
                { name = 'Location', value = ('%s, %s'):format(call.street or '?', call.suburb or '?'), inline = true },
            },
        } },
    }), { ['Content-Type'] = 'application/json' })
end)
```

{% hint style="info" %}
There are no client-side events for other resources to hook. Everything a client needs is available through the client exports on [Client Exports](/mango5m-docs/resources/mango-dispatch/developer-guide/client-exports.md).
{% endhint %}
