# Exports

Use `MedicalListeners` when you want to extend the resource from inside `modules/medical_listeners/*.lua`.

Use exports when another resource wants to query medical state or trigger a supported medical action.

Public event alternatives are documented in:

{% content-ref url="/pages/HenUKNwpAnardHIl9tbU" %}
[Events](/0resmon/0r-resources/0r-ambulancejob/events.md)
{% endcontent-ref %}

## Server Exports

### `GetDoctorCount()`

Returns the current on-duty medical count.

### `addFacilityLog(payload)`

Creates a facility log entry and returns the inserted log id.

Returns `false` when the payload is invalid or the insert fails.

```lua
local logId = exports["0r-ambulancejob"]:addFacilityLog({
    facility_id = 1,
    action_key = "staff_hired",
    action_label = "Staff Hired",
    actor_identifier = "license:xxxx",
    actor_name = "Doctor Smith",
    target_identifier = "license:yyyy",
    target_name = "John Doe",
    detail = "Hired into the facility staff roster.",
    metadata = {
        role = "doctor",
    }
})
```

### `CreateFacilityInvoice(payload)`

Creates a facility invoice and returns `success, invoiceOrMessage`.

```lua
local success, invoice = exports["0r-ambulancejob"]:CreateFacilityInvoice({
    facility_id = 1,
    patient_source = 23,
    amount = 750,
    preset_key = "revive",
    reason = "Revive"
})
```

You can pass `patient_identifier` and `patient_name` instead of `patient_source` when the patient is not online.

### `MarkFacilityInvoicePaid(invoiceId, options)`

Marks an unpaid invoice as paid. When `depositPaidInvoicesToFacilityAccount = true`, the paid amount is deposited into the facility account.

```lua
exports["0r-ambulancejob"]:MarkFacilityInvoicePaid(invoiceId, {
    source = source,
})
```

### `CancelFacilityInvoice(invoiceId, reason)`

Cancels an unpaid invoice.

```lua
exports["0r-ambulancejob"]:CancelFacilityInvoice(invoiceId, "Cancelled by staff")
```

### `GetFacilityInvoices(facilityId, filters)`

Returns facility invoices. `filters.status` can be `all`, `unpaid`, `paid`, or `cancelled`.

```lua
local invoices = exports["0r-ambulancejob"]:GetFacilityInvoices(1, {
    status = "unpaid",
})
```

### `GetPlayerUnpaidFacilityInvoices(identifier)`

Returns unpaid facility invoices for a player identifier.

```lua
local invoices = exports["0r-ambulancejob"]:GetPlayerUnpaidFacilityInvoices("license:xxxx")
```

### `GetMedicalState(source)`

Returns the backward-compatible server state:

* `alive`
* `dead`

`laststand` is intentionally folded into `alive` in this export. If you need the exact canonical state, use `IsLaststand(source)` or `GetMedicalStatePayload(source)`.

### `IsDead(source)`

Returns `true` if the player is dead.

### `IsLaststand(source)`

Returns `true` if the player is in laststand.

### `IsDowned(source)`

Returns `true` if the player is `dead` or `laststand`.

### `GetMedicalStatePayload(source)`

Returns the canonical medical state payload, including:

* `state`
* `deathTimer`
* `laststandTimer`
* `isDead`
* `isLaststand`
* `isDowned`
* `bleedLevel`
* `painLevel`
* `shockLevel`
* `injuryState`

### `GetPlayerInjuryState(source)`

Returns the full regional injury state for a target player.

### `ApplyBodyDamage(source, region, amount, options)`

Applies regional injury damage to the target player through the medical core.

### `HealBodyRegion(source, region, amount, reason)`

Heals one body region without resetting the whole injury state.

### `ResetInjuries(source, mode)`

Supported modes:

* `full`
* `revive`
* `partial`

### `GetBodyRegionSeverity(source, region)`

Returns the derived severity for a single region.

### `IsPlayerCritical(source)`

Returns `true` if the target is in a critical regional injury state.

### `SetFatalInjuries(source)`

Marks all canonical body regions as fatal on the target client.

Pair this with `SetMedicalState(source, "dead", options)` if you also want to force the death state.

### `RevivePlayer(source, options)`

Supported options:

* `source`
* `reason`
* `context`
* `silentGetUp`

```lua
exports["0r-ambulancejob"]:RevivePlayer(targetId, {
    source = source,
    reason = "my_resource",
    context = {
        from = "my_resource:server:revive",
    },
    silentGetUp = true,
})
```

### `SetMedicalState(source, state, options)`

Accepted states:

* `alive`
* `laststand`
* `dead`

Supported options:

* `source`
* `reason`
* `context`
* `silentGetUp` only used when `state = "alive"`

```lua
exports["0r-ambulancejob"]:SetMedicalState(targetId, "dead", {
    source = source,
    reason = "my_resource",
    context = {
        from = "my_resource:server:setDead",
    }
})
```

This is a trusted server-side API and does not apply the public event admin gate.

## Client Exports

### `GetMedicalState()`

Returns the local medical state.

### `IsDead()`

Returns `true` if the local player is dead.

### `IsLaststand()`

Returns `true` if the local player is in laststand.

### `IsDowned()`

Returns `true` if the local player is `dead` or `laststand`.

### `GetDeathTime()`

Returns the local death timer.

### `GetLaststandTime()`

Returns the local laststand timer.

### `CanRespawn()`

Returns `true` if the player is dead, the timer is finished, and hospital respawn is allowed.

### `GetMedicalStatePayload()`

Returns the local canonical state payload.

### `GetLocalInjuryState()`

Returns the local player's full injury state.

### `ApplyBodyDamage(region, amount, options)`

Applies regional injury damage to the local player.

### `HealBodyRegion(region, amount, reason)`

Heals one local body region.

### `ResetInjuries(mode)`

Resets local injury data using:

* `full`
* `revive`
* `partial`

### `GetBodyRegionSeverity(region)`

Returns local severity for the given region.

### `IsPlayerCritical()`

Returns `true` if the local player is in a critical regional injury state.

## Notes

* Exports are for external resources.
* `MedicalListeners` are for direct in-resource customization.
* Export-triggered actions still go through the normal medical lifecycle and listeners.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.0resmon.org/0resmon/0r-resources/0r-ambulancejob/exports.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
