Help! Player Ped damage

Hey guys, I would like to know how to detect player damage. ( on specific positions) like if player got shot on foot or stapped in the chest or smth. Like an output that sais: player has been damaged at the head 25% of its health

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

Okay, thats helpful thank you.
Where do i get all that aeguments from? Like arg6?

Edit: and where can I get the type of bones from? So i dont really now how many bones there sre and all this

I’ve taken the args from different some documentation on a GitHub page I can’t find anymore, but the post I linked to does document the ones I know.

args[1] --entity that received the damage.
args[2] --entity (or -1 for falling or drowning) that caused the damage.
args[3] --unknown, but it looks like a hash
args[4] --unknown, always 0
args[5] --unknown, always 0
args[6] --damage caused entity to die. Boolean.
args[7] --weapon hash. This can be a pistol, a grenade, unarmed, drowned, drowned in vehicle, fallen, etc. There's a lot of them, but it works with already known player weapon hashes.
args[8] --sometimes this is a hash, but usually 0. Something to do with vehicle collision? 
args[9] --sometimes this is a hash, but usually 0. Something to do with vehicle collision? 
args[10] --unk, always 0 in my testing
args[11] --unk, sometimes 1, but mostly 0. I think something to do with cops.
args[12] --always 1 if you hit a parked car. Otherwise 0
args[13] --some sort of flag. parked cars is 116. Otherwise mostly 0.

I usually get the bones from here: https://wiki. r a g e . m p /index.php?title=Bones. But a list like this: Bone indices - Pastebin.com will also do.

Note: The splitting of the r word is intentional as this forum does not allow it to be typed, just remove the spaces.