> 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/ambulance.md).

# Ambulance

l-deathscreen is not tied to esx\_ambulancejob. Everything it needs to know about your death and revive system sits in one file, `shared/ambulance.lua`. Nothing else in the resource names an ambulance script, so that file is the only one you touch.

### Recognised on their own

`visn_are`, `osp_ambulance` and `wasabi_ambulance` are detected on start and the file switches over by itself, with nothing to set up. If more than one is installed the order is visn, osp, wasabi. esx\_ambulancejob is the default when none of them is found.

**osp\_ambulance** reports the death state through its `BodyDamage` bag, last stand included, the same way OSP's own check reads it. The respawn fires the revive event OSP listens to before it puts the player down at the respawn point.

**visn\_are** keeps the player alive and unconscious, and that information only exists on the client, so the file checks visn's health buffer twice a second and reports a change to the server. The respawn resets that buffer instead of resurrecting a dead ped.

**wasabi\_ambulance** works in both v1 and v2. The death state comes from their player state bags, `wasabi:deathState` on v2 and `dead` on v1, and only a full death opens the screen: while wasabi has the player in last stand they keep crawling and wasabi's own last stand display stays up, which is how it should be. Nothing is polled, the state bags and wasabi's own events do the work. The respawn button asks the server to run their `RevivePlayer` export and then puts the player down at the respawn point.

Two things to do on a wasabi server. Turn their own death screen off in the wasabi config, otherwise both screens draw at once. And if you renamed the death state bag in `config/shared/config.lua`, put the new name in `wasabiStateKey` at the top of the file, or leave it, the fallbacks still catch the death.

### Wiring up anything else

Keep these working and the rest of the resource does not change:

| Function                             | Side   | What it does                                                                  |
| ------------------------------------ | ------ | ----------------------------------------------------------------------------- |
| `Ambulance.GetDeathCause(data)`      | shared | Turns your death payload into a cause key for the locales, plus the distance. |
| `Ambulance.GetDeathCoords(data)`     | shared | Where the player died, or `nil`.                                              |
| `Ambulance.IsDead(src)`              | server | `true` while that player is down.                                             |
| `Ambulance.OnDeath(cb)`              | server | `cb(src, data)`, once per death.                                              |
| `Ambulance.OnRevive(cb)`             | server | `cb(src)`, on a revive and on a respawn.                                      |
| `Ambulance.OnDeath(cb)`              | client | `cb(data)`, this opens the death screen.                                      |
| `Ambulance.OnRevive(cb)`             | client | `cb()`, this closes it.                                                       |
| `Ambulance.ClearDeathState()`        | client | Tells your script the player is alive again.                                  |
| `Ambulance.RemoveDeathItems(cb)`     | client | The item and cash loss on death. Has to call `cb()` when done.                |
| `Ambulance.Respawn(coords, heading)` | client | Revive the player and move them to the hospital.                              |

If your script has no equivalent for `ClearDeathState` or `RemoveDeathItems`, leave them empty. `RemoveDeathItems` still has to call `cb()`, otherwise the respawn never continues.

### The cause of death

The cause line is a lookup from a weapon hash to a locale key, at the top of the same file:

```lua
local deathCauses = {
    [joaat('WEAPON_FALL')] = 'fall',
    [joaat('WEAPON_DROWNING')] = 'drowning'
}
```

Another hash needs one line here plus the matching `cause_<key>` line in `locales/en.lua` and `locales/de.lua`.

Worth knowing on every script that is not esx\_ambulancejob: the cause is read off the ped with `GetPedCauseOfDeath`, and a script that keeps the player alive while unconscious does not always fill that in, so the line can end up as unknown. And the two respawn steps that only exist in esx\_ambulancejob, the death state flag and the RP death item removal, do nothing there, because those scripts handle their own.
