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

# Ambulance

The resource only cares about two moments, the player died and the player is up again. Both live in one file, `shared/ambulance.lua`, and nothing else in the resource knows which script you run.

Out of the box it listens to `esx:onPlayerDeath` and `esx:onPlayerSpawn`, which every common ambulance script fires, so it runs on a plain ESX server without knowing anything about yours. If your script does not fire them, point the functions in that file at your own events.

### 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.

With **osp\_ambulance** the block runs off its `BodyDamage` bag, last stand included, which the server can read for itself.

**wasabi\_ambulance** works the same way through their `wasabi:deathState` bag on v2 or `dead` on v1. Last stand counts there too, so getting back up from a last stand starts the block just like a real death.

**visn\_are** only keeps that state on the client, so the file checks visn's health buffer twice a second and reports a change to the server.

### Why the death matters at all

The block is started when the player gets up, not when they go down, but the death is what arms it. Without the death being seen first, a plain login or a character spawn would start a block on a player who never died. That is why both moments are in the file, and why the server, not the client, decides that a block starts.

### Wiring up anything else

Keep these four working on both sides and the rest of the resource does not change:

| Function                 | Side   | What it does                                                                                                                                                    |
| ------------------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Ambulance.OnDeath(cb)`  | server | `cb(src)`, once per death. This arms the block.                                                                                                                 |
| `Ambulance.OnRevive(cb)` | server | `cb(src)`, on a revive and on a respawn. This starts the block, so it has to fire once the player is on their feet again, not while they are still lying there. |
| `Ambulance.OnDeath(cb)`  | client | `cb()`, ends a running block when the player dies again.                                                                                                        |
| `Ambulance.OnRevive(cb)` | client | `cb()`, kept so both sides match.                                                                                                                               |

Fire each one only on a real change of state, once per death and once per getting up, not on every tick. The esx\_ambulancejob part at the bottom of the file is the one to copy when you write your own.
