Browse docs

Before Death

Hook to intercept and block the death screen before it opens.

Export

The onBeforeDeath export lets external resources block the death screen. When a registered callback returns true, the death screen is not opened and the player stays dead until revived manually.

client.lua
local unsubscribe = exports["sky_ambulancejob"]:onBeforeDeath(callback)
  • Side: client only
  • Arguments:
    • callback (function): Called with a context table when the player dies. Return true to block the death screen.
  • Returns: function — call it to unsubscribe the listener.

Context

The callback receives a context table with the following keys:

KeyTypeDescription
attackernumberEntity handle of the attacker (0 if unknown).
weaponHashnumberHash of the weapon/cause of death.
reasonstringOrigin of the death check ("deathscreenMonitor", "export", "gameEventTriggered").
playerPednumberEntity handle of the player ped.
playerIdnumberServer ID of the player.

Behavior

Return ValueResult
trueDeath screen is blocked. Player stays dead until revived.
false / nilNormal death flow continues (death screen opens).

After blocking the death screen, revive the player from the server using:

server.lua
exports["sky_ambulancejob"]:revive(playerId)

Unsubscribing

Every onBeforeDeath call returns an unsubscribe function:

client.lua
local unsub = exports["sky_ambulancejob"]:onBeforeDeath(function(ctx)
    return true
end)

-- Later, when no longer needed:
unsub()

Example: Prison Script

Block the death screen while a player is in prison. The prison script shows its own respawn UI and revives the player when ready.

local isInPrison = false

-- Block death screen while in prison
exports["sky_ambulancejob"]:onBeforeDeath(function(context)
    if isInPrison then
        -- Show your own prison respawn UI here
        -- e.g. TriggerEvent("prison:showRespawnMenu")
        return true -- block death screen
    end
end)

-- Your prison enter/exit logic
RegisterNetEvent("prison:setState", function(state)
    isInPrison = state
end)

Support

Need help? Our support team is always ready to assist

Join Discord