local fHealth2 = -1
gHealth2 = fHealth2
local fOldTime = CurTime()
local fDecayRate = 0.05 --[[examples: 0 = no delay at all,
1 = -1HP every second,
0.5 = -1HP every half second/-2HP every second ]]
hook.Add( "Think", "HealthSubstractionSmoother",
function()
local ply = LocalPlayer()
local alive = ply:Alive()
local curHealth = ply:Health()
if ply and ply:IsValid() and alive and fHealth2 == -1 then fHealth2 = curHealth end
if fHealth2 > 0 and fHealth2 > curHealth and CurTime() > fOldTime + fDecayRate then
fHealth2 = fHealth2 - 1
fOldTime = CurTime()
elseif alive and fHealth2 < curHealth then
fHealth2 = curHealth
end
if gHealth2 != fHealth2 then gHealth2 = fHealth2 end
end
)
--for debugging purposes
hook.Add( "HUDPaint", "fHealth2", function() draw.DrawText("Health2: "..gHealth2, "ScoreboardText", ScrW()/2, ScrH()/2, Color(255, 0, 0, 255), TEXT_ALIGN_LEFT ) end )