onPlayerDied Incorrect Arguments

According to all the posts I’ve found on the forums, and the FiveM documentation, the arguments passed to ‘baseevents:onPlayerDied’ is (Player victim, String reason). However, I am getting (Player victim, Table vector3).


AddEventHandler('baseevents:onPlayerDied', function(victim, reason)
	local ply   = GetPlayerFromServerId(victim)
	local x,y,z = table.unpack(reason)
	print("Person died.")
	print("ply:    "..tostring(ply))
	print("victim: "..tostring(victim))
	print("reason: "..json.encode(reason))
	print("pos:    "..tostring(pos))
	preDeath = true
end)

Result (F8):
Person died.
ply: -1
victim: 2
reason: [414.0212097168, -661.76226806641, 27.861423492432]
pos: vector3(0,0,0)

Can anyone tell me what I’m doing wrong so I can fix this annoying issue I’ve been troubleshooting for over an hour now? How do I get the reason of death in addition to the coordinates? GetEntityCoords(victim) or similar returns vector3(0,0,0). So I want to keep the coordinates if possible, but why am I not getting String reason?

1 Like

According to deathevents.lua from the baseevents resource, the arguments should be this:

  1. killerType, killer type aka ped type, which is represented as an int, determined using the following native:
  2. coordinates a table (vector3) containing the coords of where the player died.

probably the best way is to listen for this event, and then figure out the cause of death in your own script by getting the entity that killed the player, and checking if it’s a weapon/vehicle, or some other cause. Then based on that create your own “reason” messages.

1 Like

Just located the baseevents Lua thanks to your advice, looking through it now I’m realizing it’s just a TriggerEvent with predetermined values. Can easily write my own. I thought it was a custom function the FiveM developers wrote for us (in a way it is, but not the sense I’m thinking of).

Many thanks!

2 Likes