Hey everyone, i was playing around with the GetPedLastDamagedBone native but it does not seem to return the bone even through it is returning true. here is the code ive written:
Citizen.CreateThread(function()
local outBone = nil
while true do
ped = GetPlayerPed(-1)
r = GetPedLastDamageBone(GetPlayerPed(PlayerId()), outBone)
if r then
TriggerEvent("YTBase:Notify", 'Damaged Bone: '..tostring(outBone)..' ( '..tostring(r)..' )')
ClearPedLastDamageBone(ped)
end
Citizen.Wait(100)
end
end)
Anyhelp on this greatly appreciated
if CurrentHealth ~= GetEntityHealth(CurrentPed) then
local _, bone = GetPedLastDamageBone(CurrentPed)
local BodyPart = FindBodyPart(bone)
Works fine for me
To go into more detail, LUA does not support pointers.
local bone
local success = GetPedLastDamageBone(ped,bone)
This just copied the value of bone when calling the function, you’re just giving GetPedLastDamageBone nil as the 2nd argument, not giving it anything relating to the address of the bone variable, because LUA doesn’t support that like in C.
With any function that returns a pointer in C++'s version of the natives, FiveM makes a pointer for you and returns the result, resulting in what you did being correct. The first value doesn’t need to be an underscore though, you can still use it to make sure a valid bone was returned.
local success,bone = GetPedLastDamageBone(ped)
if success then
-- do something with bone
else
-- couldn't get the bone, uh oh
end
1 Like
Thanks for your input and it being very accurate. +1 for additional info