> For the complete documentation index, see [llms.txt](https://tk-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tk-scripts.gitbook.io/docs/tk_ambulancejob/state-bags.md).

# State bags

The Advanced Ambulance Job state bags that other FiveM resources read for death state, heart rate, dragging, body bags and EMS vehicles.

Every key here replicates to the server and all clients. Read them, and change a player's state through the [server exports](/docs/tk_ambulancejob/exports/server.md) instead of setting a key. On the local client, `LocalPlayer.state` gives the same player keys.

To react to a change on the server, use a state bag change handler:

```lua
AddStateBagChangeHandler('isDead', nil, function(bagName, key, value)
    local playerId = GetPlayerFromStateBagName(bagName)
    print(playerId, 'isDead', value)
end)
```

## isDead

```lua
local dead = Player(playerId).state.isDead
```

`boolean`: true in full death, false in last stand and when alive. Set by the player's client.

## isInLastStand

```lua
local downed = Player(playerId).state.isInLastStand
```

`boolean`: true in last stand only. Set by the player's client.

## dead

```lua
local down = Player(playerId).state.dead
```

`boolean`: true in last stand and in full death. Set by the player's client.

## deathState

```lua
local state = Player(playerId).state.deathState
```

`number`: `0` alive, `1` last stand, `2` dead. Set by the player's client.

## bpm

```lua
local bpm = Player(playerId).state.bpm
```

`number`: the player's heart rate. Set by the player's client while `Config.BPM.show` is `true`.

## isBeingRevived

```lua
local reviving = Player(playerId).state.isBeingRevived
```

`boolean`: true while someone runs a revive on the player; the respawn key is blocked meanwhile. Set by the server.

## dragTarget

```lua
local draggedId = Player(playerId).state.dragTarget
```

`number` or `nil`: the server ID of the player this player drags. Set by the dragging player's client.

## isDragged

```lua
local dragged = Player(playerId).state.isDragged
```

`boolean`: true while someone drags the player. Set by the server.

## isInBodyBag

```lua
local bagged = Player(playerId).state.isInBodyBag
```

`boolean`: true while the player is in a body bag. EMS cannot revive the player; the [revive export](/docs/tk_ambulancejob/exports/server.md#revive), `/revive` and a respawn still work. Set by the server.

## isEMSVehicle

```lua
local isEms = Entity(vehicle).state.isEMSVehicle
```

`boolean`: true on vehicles spawned from a hospital garage. Set by the client that spawned the vehicle.

## patient

```lua
local patientId = Entity(stretcher).state.patient
```

`number` or `nil`: the server ID of the player on a stretcher, `nil` when it is empty. Set by the server.
