Hey, I’m currently working on a project and wondering if there is a way or an event that states the following when a player dies:
I want it to print in console the following:
The reason they died
If they where killed by someone the person who killed them
If they got shot the weapon etc
If you know then I would love to have some help
I would advise you to use the low-level game eventCEventNetworkEntityDamage. It gets fired when an entity gets damaged. You could use this to check if a player got damaged and if the player died from the damage. With this event comes a number of parameters such as the weaponHash, attacker etc.
Here is an example of how you could use it for what you are trying to achieve:
AddEventHandler('gameEventTriggered', function(event, args)
-- If the game event was the damage event and it killed the entity (args[6] = wasFatal)
if event == "CEventNetworkEntityDamage" and args[6] == 1 then
-- Checks that the entity that died is a ped and a player
if not IsEntityAPed(args[1]) or not IsPedAPlayer(args[1]) then
return
end
local victimPed = args[1] -- The victim entity (ped).
local victimPlayer = GetPlayerServerId(NetworkGetPlayerIndexFromPed(victimPed)) -- We can safely assume that the victim is a player due to the checks above, otherwise checks would be needed before calling these functions to get the server id.
local attacker = args[2] -- If the attacker was -1, then they most likley fell to their death. It's otherwise the entity that killed the player.
local weaponHash = args[7] -- The hash of the weapon that was used to kill the player, this can be many other things than just weapons.
local isMelee = args[12] == 1
print("A player died!", victimPed, victimPlayer, attacker, weaponHash, isMelee)
end
end)
If you only want to know if the local player died, then you can check if the victim ped is the current ped for example.
You can read more about CEventNetworkEntityDamage’s parameters here.
Note: This event is client-side, for a server-side event check this out (weaponDamageEvent).