Skip to main content

onPlayerDeath

AddEventHandler('esx:onPlayerDeath', function(data)

end)

data Table Information

childtypeexplanation
victimCoordstable
killerCoordstable
deathCausestringReturns the hash of the weapon/model/object that killed the victim.
killedByPlayerbooleanWas the player killed by another player? The data below is only generated when killed by a player.
distancenumberThe distance (in GTA units) between the victim and killer upon death
killerServerIdnumberThe killer's server id
killerClientIdnumberThe killer's client id

Example Server-Side Usage

Simple Kill Notifications

RegisterServerEvent('esx:onPlayerDeath')
AddEventHandler('esx:onPlayerDeath', function(data)
data.victim = source

if data.killedByPlayer then
TriggerClientEvent('esx:showNotification', -1, GetPlayerName(data.victim) .. 'was killed by ' .. GetPlayerName(data.killerServerId) .. ' from ' .. data.distance .. ' units')
else
TriggerClientEvent('esx:showNotification', -1, GetPlayerName(data.victim) .. ' died')
end
end)

Example Client-Side Usage

Here is a perfect example for checking if the player (client side) is dead, which is useful for a lot of things, for example only allowing menus to be open if alive.

local IsDead = false

AddEventHandler('esx:onPlayerDeath', function(data)
IsDead = true
end)

AddEventHandler('playerSpawned', function(spawn)
IsDead = false
end)