> For the complete documentation index, see [llms.txt](https://lscripts.gitbook.io/lscripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lscripts.gitbook.io/lscripts/scripts/l-deathscreen/medics.md).

# Medics

The second button on the death screen calls a medic. It runs in one of two modes, set in `Config.Medic.mode`, and both share the same server side cooldown.

```lua
Config.Medic = {
    mode = 'notify',
    cooldown = 120,
    jobs = { 'ambulance' },
    onDutyOnly = false,
    showName = true,
    blip = {
        sprite = 310,
        color = 1,
        scale = 1.0,
        flash = true,
        route = true,
        duration = 300
    }
}
```

| Field        | Description                                                                                    |
| ------------ | ---------------------------------------------------------------------------------------------- |
| `mode`       | `'notify'` for the built in way, `'dispatch'` to hand the call to your dispatch script.        |
| `cooldown`   | Seconds before the same player can call again. Counted down inside the button.                 |
| `jobs`       | Jobs that count as medics in notify mode.                                                      |
| `onDutyOnly` | `true` notifies only medics that are on duty.                                                  |
| `showName`   | `false` sends an anonymous call without the player name.                                       |
| `blip`       | The blip medics get in notify mode.                                                            |
| `dispatch`   | Which dispatch script gets the call in dispatch mode, and what the call looks like. See below. |

### Notify mode

The built in way, and it needs nothing from you. Every online medic with one of the jobs above gets a notification and a blip on the injured player, with a GPS route when `route = true`. The blip flashes while `flash = true` and removes itself as soon as the patient is helped, respawns, disconnects or `duration` seconds have passed, so nobody chases a marker across the map to an empty street.

`sprite`, `color` and `scale` are the usual FiveM blip values.

When no medic can be reached, the call medic button is greyed out and a press tells the player that no medic is available right now. The cooldown does not start then. A dead medic does not count as a medic for their own call. The button comes back on its own the moment a medic comes on duty.

### Dispatch mode

The call goes to the dispatch script you already run. Pick it in the `dispatch` block of `Config.Medic`, nothing else is needed for the supported scripts:

```lua
dispatch = {
    system = 'lb-tablet',
    jobs = { 'ambulance' },
    code = '10-52',
    priority = 'high',
    duration = 300,
    blip = {
        sprite = 310,
        color = 1,
        scale = 1.0,
        flash = true
    },
    lbTablet = {
        mdt = ''
    }
}
```

| `system`           | Dispatch script   | What is called                          |
| ------------------ | ----------------- | --------------------------------------- |
| `'lb-tablet'`      | LB Tablet         | `exports['lb-tablet']:AddDispatch`      |
| `'cd_dispatch'`    | Codesign dispatch | `cd_dispatch:AddNotification`           |
| `'qs-dispatch'`    | Quasar dispatch   | `qs-dispatch:server:CreateDispatchCall` |
| `'rcore_dispatch'` | rcore dispatch    | `rcore_dispatch:server:sendAlert`       |
| `'custom'`         | Anything else     | Your own code, see below                |

| Field          | Description                                                                                                           |
| -------------- | --------------------------------------------------------------------------------------------------------------------- |
| `jobs`         | Jobs that receive the call.                                                                                           |
| `code`         | The call code the medics see, `10-52` by default.                                                                     |
| `priority`     | `'high'`, `'medium'` or `'low'`.                                                                                      |
| `duration`     | Seconds the call and its blip stay.                                                                                   |
| `blip`         | Sprite, colour, scale and flashing of the blip the dispatch script places.                                            |
| `lbTablet.mdt` | LB Tablet only. The MDT from the lb-tablet config the call opens in. Leave empty and lb-tablet routes it by the jobs. |

Every call carries the code, a title, the player name (or the anonymous line when `showName` is off), the street the player is on and the position. The title and the lines come from your locale file, so the medics read them in your language.

{% hint style="info" %}
If the chosen dispatch resource is not running, the button tells the player that no medic could be reached, the cooldown does not start and the server console prints why, once.
{% endhint %}

### Another dispatch script

Set `system = 'custom'` and fill in the last block in `shared/functions.lua`:

```lua
Dispatch.custom = function(src, coords, name, street, cfg)
    return false
end
```

| Argument | Description                                                                    |
| -------- | ------------------------------------------------------------------------------ |
| `src`    | Server id of the dead player.                                                  |
| `coords` | `vector3` the player died at, read on the server and never sent by the client. |
| `name`   | The player name, or `nil` when `showName` is off.                              |
| `street` | The street the player is on, or an empty string.                               |
| `cfg`    | The `dispatch` block from the config: jobs, code, priority, duration and blip. |

Put your dispatch call in and `return true` once it has the call. Anything other than `true` tells the player that no medic could be reached and the cooldown does not start, so they can try again.

The ready-made blocks for the supported scripts sit in the same file, right above this one. If your setup needs one field of the LB Tablet call changed, change it there instead of writing a new block.

If your script only offers a client export, send the data to the injured player with a client event of your own and call the export there. The function runs on the server, so it cannot call a client export directly.

### The medic counter

The number on the screen counts the players holding a job from `Config.Medic.jobs`, and follows `onDutyOnly`. It updates live while the screen is open, whenever a medic logs in, logs out, changes job or goes on or off duty, so a player can see whether calling is worth anything before they press the button. `Config.ShowMedicCount = false` hides the line.

In dispatch mode the counter still counts `Config.Medic.jobs`, but the button is never greyed out for missing medics, because your dispatch script decides who receives the call.

### Notifications

Everything the resource says to a player goes through one function in `shared/functions.lua`, on the client for the player themselves and on the server for the medics being called:

```lua
Func.Notify(message, msgType)
Func.Notify(src, message, msgType)
```

The message arrives finished and localized, so the function never gets a locale key. `msgType` is `inform`, `success` or `error`. Set your title, your position and your duration in there once and every call site stays as it is.
