> For the complete documentation index, see [llms.txt](https://grp-development.gitbook.io/titan-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://grp-development.gitbook.io/titan-scripts/resources/titan-tablet/exports-and-events/server-exports.md).

# Server exports

Exports you can call from server scripts.

#### Tablet

| Export                 | Returns | Description                          |
| ---------------------- | ------- | ------------------------------------ |
| `IsTabletOpen(source)` | boolean | Whether the player's tablet is open. |

#### Dispatch

Send calls from your dispatch, robbery or alarm scripts to the MDT map.

```lua
local id = exports['ttn-tablet']:AddDispatchCall({
    dept = 'police',
    code = '10-90',
    title = 'Store robbery',
    description = 'Clerk reports an armed male, black hoodie.',
    priority = 1,
    coords = vec3(26.0, -1347.0, 29.5),
    street = 'Innocence Blvd, Strawberry',
    caller = { name = 'Store clerk', phone = '5550142' },
})
```

| Field         | Description                                                                           |
| ------------- | ------------------------------------------------------------------------------------- |
| `title`       | Required. Up to 100 characters.                                                       |
| `dept`        | `police` or `ems`. Sends the call to every department of that type. Default `police`. |
| `department`  | A single department instead, by job name or `Id`, like `'lspd'`.                      |
| `code`        | Code shown on the call. Default `911`.                                                |
| `priority`    | `1` (highest) to `3`. Default `3`.                                                    |
| `coords`      | Location, or `x`, `y` and `z` fields.                                                 |
| `street`      | Street name. Default the coordinates.                                                 |
| `description` | Details, up to 2000 characters.                                                       |
| `caller`      | Optional `{ name, phone }`.                                                           |
| `bucket`      | Routing bucket. Default `0`.                                                          |

| Export                     | Returns        | Description                          |
| -------------------------- | -------------- | ------------------------------------ |
| `AddDispatchCall(call)`    | id or false    | Adds a call.                         |
| `RemoveDispatchCall(id)`   | boolean        | Removes a call.                      |
| `GetDispatchCalls(source)` | table or false | The calls this player's MDT can see. |

Server scripts can also `TriggerEvent('ttn-tablet:server:AddDispatchCall', call)`.

#### Mail

| Export                    | Returns               | Description                                             |
| ------------------------- | --------------------- | ------------------------------------------------------- |
| `SendMail(mail)`          | boolean, id or reason | Sends a mail. With sync on it goes through TITAN Phone. |
| `GetEmailAddress(source)` | string or nil         | The player's mail address.                              |

```lua
exports['ttn-tablet']:SendMail({
    to = 'alex.mercer@titan.com',
    sender = 'Los Santos Customs',
    subject = 'Your car is ready',
    message = 'Pick it up at the Burton garage.',
})
```

#### MDT

| Export                                                          | Returns       | Description                                                                                                                                        |
| --------------------------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CreateMdtCase(source, { defendant, reports, judge, defense })` | case or false | Files a court case as that Justice player. `defendant` is a citizen id, `reports` a list of report ids, `judge` and `defense` optional roster ids. |
| `RegisterMdtWeapon({ serial, owner, name, seller, ammo })`      | boolean       | Adds a weapon to the registry, or moves it to a new owner. Call it from your gun shop.                                                             |
| `RegisterMdtSourceProvider(kind, handler)`                      | boolean       | Use your own data for MDT searches, see below.                                                                                                     |
| `RegisterMdtCaptureProvider(kind, handler)`                     | boolean       | Use your own screenshot tool for `evidence` or `mugshot`. The handler gets `(source, target)` and returns `{ url = 'https://...' }`.               |

`RegisterMdtSourceProvider` replaces the built-in lookups:

| Kind         | Handler                     | Returns a list of                                                |
| ------------ | --------------------------- | ---------------------------------------------------------------- |
| `people`     | `(query, citizenid)`        | `{ cid, name, dob, gender, phone, job, fingerprint, licenses }`  |
| `vehicles`   | `(query, citizenid, plate)` | `{ plate, owner, model, color, registered, insured, impounded }` |
| `properties` | `(citizenid)`               | `{ label, type }`                                                |

The server event `ttn-tablet:server:MdtVerdict` fires when a judge closes a case, with `(source, caseId, citizenid, sentence)`.

#### Work apps

| Export                                             | Returns                                      | Description                                                                                                                                                                         |
| -------------------------------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SetMapPlace(source, { name, x, y, area, kind })`  | `{ id, saved }` or false                     | Saves a place in the player's Maps. `kind` is `pin`, `home` or `work`; Home and Work replace the old one.                                                                           |
| `RegisterContractSourceProvider(kind, handler)`    | boolean                                      | Sign: list `vehicles` or `properties` from your own scripts. The handler gets the player `{ source, citizenid, name, job }` and returns `{ { id, label } }` of what they own.       |
| `RefundRegisterOrder(source, orderNo)`             | `{ ok, amount }` or `{ ok = false, reason }` | Refunds a paid order to the customer. The employee needs a grade in `RefundGrades` and the customer must be online.                                                                 |
| `SetBoardSteps(source, boardId, steps)`            | boolean                                      | Replaces a Blueprint run sheet. Each step is `{ time, who, text, done }`, where `who` is a crew member id. Only the board owner.                                                    |
| `InstallCamera(source, { label, place, address })` | `{ ok, id }` or `{ ok = false, reason }`     | Installs a personal camera where the player stands. Uses up one `CameraItem`.                                                                                                       |
| `RemoveInstalledCamera(source, cameraId)`          | `{ ok }`                                     | Removes the player's own camera within five metres.                                                                                                                                 |
| `CameraEvent(source, cameraId, kind)`              | boolean                                      | Adds a `motion` or `door` alert, with the same access and cooldown checks.                                                                                                          |
| `RegisterCameraActionProvider(action, handler)`    | boolean                                      | Your own `snapshot`, `clip` or `talk` for cameras. The handler gets `(source, camera, coords)`. Snapshots and clips return `{ url = 'https://...' }`, talk returns `{ ok = true }`. |
| `RecallDrone(source)`                              | boolean                                      | Sends the player's drone home. Returns whether it was flying.                                                                                                                       |
| `IsCasting(source)`                                | boolean                                      | Whether the player is casting to a TV.                                                                                                                                              |
| `StopCast(source, reason)`                         | boolean                                      | Ends the player's cast, for example when another script takes the TV.                                                                                                               |

#### Custom apps

The same app exports as on the client, with the player first: `IsAppOpen(source, id)`, `OpenApp(source, id)`, `CloseApp(source, id)`, `SendAppMessage(source, id, data)`, `SendAppNotification(source, id, payload)` and `SetAppBadge(source, id, count)`. `RegisterApp`, `UnregisterApp`, `IsAppRegistered`, `GetApp` and `GetApps` take no player. See [Custom apps](https://grp-development.gitbook.io/titan-scripts/resources/titan-tablet/custom-apps).
