Help! Player Ped damage

You can use the game event CEventNetworkEntityDamage to detect damage on entities. This combined with a simple check to see if it’s the player that gets damaged could do the trick.

And for the ped bone you could use the GetPedLastDamageBone native. Now, it must be noted that this native isn’t perfect.

But something like this could be a good starting point:

AddEventHandler('gameEventTriggered', function(event, args)
	if event == "CEventNetworkEntityDamage" then
        local playerPed = PlayerPedId()
        if args[1] == playerPed then
            local attacker = args[2]
            local wasFatal = args[6] == 1
            local weaponHash = args[7]
            local isMelee = args[12] == 1
            local _found, bone = GetPedLastDamageBone(playerPed)

            print("Player ped was damaged! Player ped: "..tostring(playerPed)..", attacker: "..tostring(attacker)..", wasFatal: "..tostring(wasFatal)..", weaponHash: "..tostring(weaponHash)..", isMelee: "..tostring(isMelee)..", bone: "..tostring(bone))
        end
    end
end)

You can read more about the CEventNetworkEntityDamage event as well as other game events here: Some Game Events and how to use them

1 Like