# Supported FFA Scripts

> Integrate supported FFA and faction-fight scripts with the Sky Ambulance Job death, injury, and revive flows.

## Supported scripts

Sky Ambulance Job supports the following FFA, paintball, and faction-fight integrations through
`Config.Functions.beforeDeath` and `Config.Functions.beforeInjuries`.

The integration prevents the ambulance death screen and injury system from taking control while the
player is participating in an FFA or faction fight. The ESX-compatible player death event is still
sent so the external script can run its own death and revive flow.

### nass_paintball

- **Mode:** Paintball
- **Resource:** `nass_paintball`
- **State export:** `exports["nass_paintball"]:inGame()`

The ambulance death and injury flows are blocked while `inGame()` returns `true`.

### pug-paintball

- **Mode:** Paintball
- **Resource:** `pug-paintball`
- **State export:** `exports["pug-paintball"]:IsInPaintball()`

The ambulance death and injury flows are blocked while `IsInPaintball()` returns `true`.

### hex_ffa

- **Mode:** FFA zone
- **Resource:** `hex_ffa`
- **State export:** `exports["hex_ffa"]:isInZone()`

The ambulance death and injury flows are blocked while `isInZone()` returns `true`.

### hex_3_ffa

- **Mode:** FFA zone
- **Resource:** `hex_3_ffa`
- **State export:** `exports["hex_3_ffa"]:isInZone()`

The ambulance death and injury flows are blocked while `isInZone()` returns `true`.

### hex_4_ffa

- **Mode:** FFA zone
- **Resource:** `hex_4_ffa`
- **State export:** `exports["hex_4_ffa"]:isInZone()`

The ambulance death and injury flows are blocked while `isInZone()` returns `true`.

### ws_ffa

- **Mode:** FFA zone
- **Resource:** `ws_ffa`
- **State export:** `exports["ws_ffa"]:isInZone()`

The ambulance death and injury flows are blocked while `isInZone()` returns `true`.

### ws_ffa-v2

- **Mode:** FFA zone
- **Resource:** `ws_ffa-v2`
- **State export:** `exports["ws_ffa-v2"]:isInZone()`

The ambulance death and injury flows are blocked while `isInZone()` returns `true`.

### ws_gangwar-v2

- **Mode:** Gangwar
- **Resource:** `ws_gangwar-v2`
- **State export:** `exports["ws_gangwar-v2"]:isFightActive()`

The ambulance death and injury flows are blocked while `isFightActive()` returns `true`.

### sp_ffa

- **Mode:** FFA
- **Resource:** `sp_ffa`
- **State export:** `exports["sp_ffa"]:inFFA()`

The ambulance death and injury flows are blocked while `inFFA()` returns `true`. This integration
also requires the `OnRevive(lastWeapon)` adjustment documented below.

### sp_frakfights

- **Mode:** Faction fight
- **Resource:** `sp_frakfights`
- **State export:** `exports["sp_frakfights"]:IsFrakFight()`

The ambulance death and injury flows are blocked while `IsFrakFight()` returns `true`.

## Generate the functions.lua hooks

Select the scripts installed on your server. The generator prepares the complete hook block for
`sky_ambulancejob/config/functions.lua`.

<steps>

### Open the original functions.lua

Open `sky_ambulancejob/config/functions.lua`. Do not delete or replace the complete file.

### Find the replacement start

If the file already contains `local function is_in_supported_fight()`, start at the comment above
that helper so it is replaced together with the hooks. Otherwise, start at the comment directly
above this function:

```lua
Config.Functions.beforeDeath = function(context)
```

### Find the replacement end

The replacement ends after the closing `end` of:

```lua
Config.Functions.beforeInjuries = function(context)
```

Keep all code after that closing `end`, including any helper such as `setTgiannDeathState` before
`Config.Functions.onRevive`.

### Generate and paste

Select the installed scripts below, copy the generated configuration, and replace only the marked
`beforeDeath`/`beforeInjuries` section and its existing `is_in_supported_fight` helper, if present.

</steps>

<ffa-script-generator>



</ffa-script-generator>

<warning>

Keep `Config.Functions.onRevive`, `Config.Functions.onDeath`, `Config.Functions.onRespawn`,
`Config.Functions.onAiMedicRequest`, `Config.Functions.sendDispatch`, and every other function
outside the marked replacement range unchanged.

</warning>

Returning `false` from `beforeDeath` disables the Sky Ambulance Job death flow for that death.
Returning `false` from `beforeInjuries` prevents Sky injuries from being generated while the player
is inside the external game mode.

The generated resource-state checks ensure that only installed and running integrations are called.
Each selected mode is checked independently: being outside one running FFA does not prevent an
active gangwar or another selected mode from blocking the ambulance flows.

## sp_ffa: Update the revive callback

This section applies **only to sp_ffa**. Its `OnRevive(lastWeapon)` callback must wait until Sky
Ambulance Job has completely rebuilt the player ped. Otherwise, selecting the previous weapon can
happen before `NetworkResurrectLocalPlayer` finishes.

Replace the existing `OnRevive(lastWeapon)` callback in `sp_ffa` with:

```lua [sp_ffa\config\sh_config.lua]
function OnRevive(lastWeapon)
    CreateThread(function()
        local timeout = GetGameTimer() + 8000

        while LocalPlayer.state.skyAmbulanceReviveState ~= "finished"
            and LocalPlayer.state.skyAmbulanceReviveState ~= "failed"
            and GetGameTimer() < timeout do
            Wait(10)
        end

        if LocalPlayer.state.skyAmbulanceReviveState ~= "finished" then
            return
        end

        local weaponHash = tonumber(lastWeapon)

        if not weaponHash and type(lastWeapon) == "string" then
            weaponHash = joaat(lastWeapon)
        end

        local ped = PlayerPedId()

        if not HasPedGotWeapon(ped, weaponHash, false) then
            GiveWeaponToPed(ped, weaponHash, 0, false, false)
        end

        SetCurrentPedWeapon(ped, weaponHash, true)
    end)
end
```

`SetCurrentPedWeapon` can only select a weapon that already exists on the current ped.
`NetworkResurrectLocalPlayer` can rebuild the ped without its previous native weapon, so the callback
uses `GiveWeaponToPed` before selecting it.

The `lastWeapon` argument restores the weapon model only. If the FFA script also needs to preserve
ammunition, components, or tint, it must save those values before death and restore them in this
callback as well.

## Revive state

Sky Ambulance Job exposes the local `skyAmbulanceReviveState` player StateBag for client-side
integrations:

<table>
<thead>
  <tr>
    <th>
      Value
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        "reviving"
      </code>
    </td>
    
    <td>
      The revive flow is currently rebuilding the player.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        "finished"
      </code>
    </td>
    
    <td>
      The player has been completely revived.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        "failed"
      </code>
    </td>
    
    <td>
      The revive flow could not complete.
    </td>
  </tr>
</tbody>
</table>

The StateBag is local to the player and can be read from other client resources through
`LocalPlayer.state.skyAmbulanceReviveState`.

## Support

Need help? Our support team is always ready to assist

<u-button color="neutral" icon="i-simple-icons-discord" label="Join Discord" target="_blank" to="https://discord.gg/sky-systems" variant="subtle">



</u-button>
