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 acontexttable when the player dies. Returntrueto block the death screen.
- Returns:
function— call it to unsubscribe the listener.
Context
The callback receives a context table with the following keys:
| Key | Type | Description |
|---|---|---|
attacker | number | Entity handle of the attacker (0 if unknown). |
weaponHash | number | Hash of the weapon/cause of death. |
reason | string | Origin of the death check ("deathscreenMonitor", "export", "gameEventTriggered"). |
playerPed | number | Entity handle of the player ped. |
playerId | number | Server ID of the player. |
Behavior
| Return Value | Result |
|---|---|
true | Death screen is blocked. Player stays dead until revived. |
false / nil | Normal 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)
-- When the player is done with the prison respawn menu, revive them
RegisterNetEvent("prison:requestRespawn", function()
local src = source
-- Your prison checks here
-- e.g. if not IsPlayerInPrison(src) then return end
exports["sky_ambulancejob"]:revive(src)
end)
Support
Need help? Our support team is always ready to assist
Join Discord