# AI Medic

> Reference for AI Medic in ambulancejob.

[All client exports](/docs/jobs/ambulancejob/api/client-exports)

## AI Medic

### `setAiMedicState(state, reason?)`

- **Purpose**: Updates the AI medic status shown on the death screen UI. Use this when you override the built-in AI medic via `Config.Functions.onAiMedicRequest` and need to update the UI from your own system.
- **Arguments**:

  - `state` (`string`): One of `"idle"`, `"requesting"`, `"dispatched"`, `"driving"`, `"arrived"`, `"reviving"`, `"finished"`, `"failed"`, `"cooldown"`.
  - `reason` (`string?`): Optional failure reason when state is `"failed"` — `"not_enough_money"`, `"medics_online"`, `"spawn_failed"`, `"disabled"`.

```lua
-- Show "AI medic on the way"
exports["sky_ambulancejob"]:setAiMedicState("driving")

-- Show failure
exports["sky_ambulancejob"]:setAiMedicState("failed", "spawn_failed")

-- Reset to idle
exports["sky_ambulancejob"]:setAiMedicState("idle")
```

### `getAiMedicState()`

- **Purpose**: Returns the current AI medic state.
- **Returns**: `string` — the current state (e.g. `"idle"`, `"driving"`, `"reviving"`).

```lua
local state = exports["sky_ambulancejob"]:getAiMedicState()
```

### `isAiMedicActive()`

- **Purpose**: Checks if the AI medic is currently active or pending.
- **Returns**: `boolean`

```lua
local active = exports["sky_ambulancejob"]:isAiMedicActive()
```

<callout color="info" icon="i-lucide-info">

To override the built-in AI medic with your own system, use the `Config.Functions.onAiMedicRequest` hook in `config/functions.lua`. Return `false` to prevent the default AI medic from dispatching, then use the exports above to update the death screen UI.

</callout>

```lua
-- config/functions.lua
Config.Functions.onAiMedicRequest = function()
    exports['my-medic-resource']:sendHelp()
    return false -- prevent built-in AI medic
end
```

<br />
