Hi there.
I have some issues with ApplyDamageToPed.
I managed something like “car crash damage”, if you speed to high and you ramming something = you take damage
-- inside Citizen.Thread of course
driving_speed_last = 0.0
function ManageDriving()
local ped = GetPlayerPed(-1)
local veh = GetVehiclePedIsIn(ped, false)
if (veh ~= 0 and DoesEntityExist(ped) and not IsEntityDead(ped) and GetVehiclePedIsIn(ped, false)) then
local driving_speed = GetEntitySpeed(veh)*3.6
local diff = math.abs(driving_speed_last - driving_speed)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.50)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString("~r~Possible damage:~s~ "..string.format('%.0f', driving_speed / 250 * GetEntityMaxHealth(ped)).."/"..GetEntityHealth(ped).."/"..GetEntityMaxHealth(ped))
DrawText(0.90, 0.80)
if diff > 30 then
local damage = tonumber(string.format("%.f", diff / 250 * GetEntityMaxHealth(ped)))
local hp = GetEntityHealth(ped)
print('On paper: '..hp..' - '..damage..' = '..hp - damage)
ApplyDamageToPed(ped, damage, false)
print('In fact: '..hp..' - '..damage..' = '..GetEntityHealth(ped))
end
driving_speed_last = driving_speed
end
end
But, damage are not real
After taking 40 damage In console i have
On paper: 137 - 40 = 97
In fact: 137 - 40 = 0
So, damage are greater then need. I need to have 97 hp but i die with 0 hp. Where i made a mistake?
Sometimes it works perfect, some damage have real numbers, but last damage anyway is bigger then need