• Drain health to what is previously was
    5 replies, posted
Hey how do I make a players health set to 100, and then slowly return to what it previously was ON USING AN ENTITY? Thanks.
Save their previous health, then reduce on a timer until it matches.
Not sure how to do this though :\
pl.OldHealth = pl:Health() Then set it later in a timer
[QUOTE=|FlapJack|;19903705]pl.OldHealth = pl:Health() Then set it later in a timer[/QUOTE] Haha, that's exactly what I told him to do in chat a few days ago. Try this. [lua] ply.OldHealth = ply:Health --Put a number value into the player's table ply:SetHealth(100) --Set health timer.Create("mytimer_"..ply:EntIndex(), 5, 0, function() removehealth(ply) end) --Timer that is unique to player that runs every 5 seconds function removehealth(ply) --The function run by the timer local sub = ply:Health() - 2 --This is our predicted value to set our health to ply:SetHealth(math.Clamp(sub, ply.OldHealth, ply:Health())) --Setting it to a clamped value if sub <= ply.OldHealth then --If we've returned to original health... timer.Remove("mytimer_"..ply:EntIndex()) --Remove the timer so this isn't repeated. end end [/lua]
Thanks, I didn't understand it. And curse you monkey, letting them know about mah personal lief :argh:
Sorry, you need to Log In to post a reply to this thread.