> For the complete documentation index, see [llms.txt](https://osp-development.gitbook.io/ambulance-job/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://osp-development.gitbook.io/ambulance-job/developer-usage/useful-events-and-exports.md).

# Useful events & exports

Reference for client and server exports, player-state events, and BodyDamage fields.

## Useful events & exports

Use these exports and events to integrate other resources with Ambulance Job.

For the full mutable player-state reference, see [Player Statebag](/ambulance-job/developer-usage/player-statebag.md).

### Client exports

**`exports.osp_ambulance:GetAmbulanceData(playerid?)`**

|         |                                                                                      |
| ------- | ------------------------------------------------------------------------------------ |
| Args    | `playerid` (number, optional) — Player server ID. Uses the local player if omitted.  |
| Returns | `BodyDamage` table from `Player(...).state.BodyDamage`, or `nil` before it is ready. |
| Use     | Read medical state for the local player or another player.                           |

**`exports.osp_ambulance:isDead()`**

|         |                                                                                |
| ------- | ------------------------------------------------------------------------------ |
| Args    | none                                                                           |
| Returns | `true` if local `BodyDamage.isDead` or `BodyDamage.inLastStand`, else `false`. |
| Use     | Check whether the local player is dead or in last stand.                       |

**`exports.osp_ambulance:GetLocalAddictions()`**

|         |                                                                                |
| ------- | ------------------------------------------------------------------------------ |
| Args    | none                                                                           |
| Returns | table: `[drugId] = { addicted = bool, totalUses = number, lastDoseAt = unix }` |
| Use     | Read the local player's addiction map.                                         |

**`exports.osp_ambulance:IsOverdosing()`**

|         |                                                     |
| ------- | --------------------------------------------------- |
| Args    | none                                                |
| Returns | `true` if local overdose is active and not treated. |
| Use     | Check the local player's overdose status.           |

**`exports.osp_ambulance:IsAddictiveDrugItem(itemName)`**

|         |                                                               |
| ------- | ------------------------------------------------------------- |
| Args    | `itemName` (string)                                           |
| Returns | `true` if item is in any `Config.AddictiveDrugs[].itemNames`. |
| Use     | Check whether an inventory item is addictive.                 |

### Server exports

**`exports.osp_ambulance:GetAmbulanceData(playerid)`**

|         |                                                                        |
| ------- | ---------------------------------------------------------------------- |
| Args    | `playerid` (number, required, non-zero)                                |
| Returns | `BodyDamage` table, or prints error and returns nothing if id missing. |
| Use     | Read a player's medical state on the server.                           |

**`exports.osp_ambulance:RegisterAddictiveDrug(drugConfig)`**

|         |                                                                                                                                                                      |
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Args    | `drugConfig` (table) — must include at least `id`. Same shape as `Config.AddictiveDrugs` entries (`label`, `itemNames`, `source`, overdose/withdrawal fields, etc.). |
| Returns | `true` on success, `false` if invalid. Upserts by `id`.                                                                                                              |
| Use     | Register or replace an addictive drug at runtime.                                                                                                                    |

**`exports.osp_ambulance:RecordDrugUse(playerId, itemName, useSource?)`**

|         |                                                                                                                                      |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| Args    | `playerId` (number), `itemName` (string), `useSource` (string, optional; default `'both'`) — `'ems'`, `'prescription'`, or `'both'`. |
| Returns | `true` if recorded, `false` if addiction disabled / no matching drug / source not allowed.                                           |
| Use     | Record a dose. This can apply addiction or trigger an overdose.                                                                      |

**`exports.osp_ambulance:GetPlayerAddictions(playerId)`**

|         |                                                  |
| ------- | ------------------------------------------------ |
| Args    | `playerId` (number)                              |
| Returns | addiction table (same shape as client), or `{}`. |
| Use     | Read a player's addiction map.                   |

**`exports.osp_ambulance:ClearPlayerAddiction(playerId, drugId)`**

|         |                                                              |
| ------- | ------------------------------------------------------------ |
| Args    | `playerId` (number), `drugId` (string)                       |
| Returns | `true` if cleared, `false` if not addicted / missing.        |
| Use     | Clear an addiction. Syncs `BodyDamage` and the client event. |

**`exports.osp_ambulance:IsPlayerOverdosing(playerId)`**

|         |                                   |
| ------- | --------------------------------- |
| Args    | `playerId` (number)               |
| Returns | `true` / `false`                  |
| Use     | Check a player's overdose status. |

**`exports.osp_ambulance:GetDrugConfigByItem(itemName)`**

|         |                                                    |
| ------- | -------------------------------------------------- |
| Args    | `itemName` (string)                                |
| Returns | drug config table, or `nil`.                       |
| Use     | Resolve addictive-drug configuration by item name. |

### `BodyDamage` return shape

`GetAmbulanceData` returns the `BodyDamage` state bag. These fields are commonly useful for integrations.

| Field                                           | Type                                      | Meaning                                         |
| ----------------------------------------------- | ----------------------------------------- | ----------------------------------------------- |
| `isDead`                                        | boolean                                   | Player is dead                                  |
| `inLastStand`                                   | boolean                                   | Player is in last stand                         |
| `Conscious`                                     | boolean                                   | Player consciousness                            |
| `Pulse`                                         | number                                    | Heart rate                                      |
| `BloodPressure`                                 | `{ systolic, diastolic }`                 | Blood pressure                                  |
| `Temp`                                          | number                                    | Temperature                                     |
| `oxygenSaturation`                              | number                                    | Oxygen saturation                               |
| `cardiacState`                                  | string                                    | For example, `'NSR'` or `'asystole'`            |
| `Pain`                                          | number                                    | Pain level                                      |
| `bloodType`                                     | string                                    | Blood type                                      |
| `insurvivable`                                  | boolean                                   | Blocks a normal revive unless bypassed          |
| `isCarried` / `isInBodybag` / `clothesStripped` | boolean                                   | Player status flags                             |
| `BodyPartDamage.Wounds`                         | table per body part                       | `Rarm`, `Larm`, `Rleg`, `Lleg`, `Torso`, `Head` |
| `BodyPartDamage.Bleeding`                       | number per body part                      | Bleed severity                                  |
| `BodyPartDamage.Fractures`                      | boolean per body part                     | Fracture status                                 |
| `BodyPartDamage.BloodLevel`                     | number                                    | Blood volume (\~6.0 healthy)                    |
| `activeConditions`                              | table                                     | Diseases/conditions                             |
| `addictions`                                    | table                                     | Addiction data                                  |
| `overdose`                                      | `{ active, treated, drugId, class, ... }` | Overdose state                                  |
| `insurance`                                     | table or `nil`                            | Insurance plan data                             |

### Client events

Listen for these events from another client resource.

| Event                             | Arguments                            | Fires when                                                                                                            |
| --------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
| `osp_ambulance:OnPlayerDead`      | none                                 | The local player dies or enters last stand. Use this as the primary down-state hook.                                  |
| `osp_ambulance:OnPlayerDeath`     | none                                 | The local player fully dies. It triggers `OnPlayerDead` before death logic runs.                                      |
| `osp_ambulance:OnPlayerLastStand` | `bool`                               | Last stand changes. When `true`, it also triggers `OnPlayerDead`.                                                     |
| `osp_ambulance:OnPlayerSpawn`     | none                                 | The player is revived or leaves death or last stand. This includes full revives, partial revives, and admin restores. |
| `osp_ambulance:addictionStateCl`  | `drugId` (string), `addicted` (bool) | An addiction is gained (`true`) or cleared (`false`).                                                                 |
| `osp_ambulance:overdoseStartCl`   | `drugId` (string)                    | An overdose starts.                                                                                                   |
| `osp_ambulance:overdoseTreatedCl` | none                                 | An overdose is treated, including by Narcan, or cleared by a revive.                                                  |
| `osp_ambulance:overdoseDeathCl`   | none                                 | The Narcan treatment window expires and forces last stand.                                                            |
| `hospital:client:SetDoctorCount`  | `amount` (number)                    | The synced count of on-duty EMS players changes.                                                                      |
