Hello, I have a question, how to add a timer function, in which every second example would give HP a player, I can not figure out how to do this, please help me!
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Create]timer.Create[/url]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetHealth]Entity:SetHealth[/url]
[CODE]
timer.Create( 'SomeHealthTimer', 1, 0, function()
local ply = Entity(1) -- or any player
ply:SetHealth( ply:Health() + 5 )
end )
[/CODE]
[editline]20th September 2016[/editline]
It takes less time to check the wiki than it does to make a thread
Thank you.
It seems to i understood.
How to stop the timer, for example if you reach 100 HP to not go further?
if ply:Health = 100 then
stop timer
how to stop him then?
Use math clamp to clanp values from 0 to 100, otherwise you might get sometimes 103hp when you are with 98hp
[QUOTE=gonzalolog;51079463]Use math clamp to clanp values from 0 to 100, otherwise you might get sometimes 103hp when you are with 98hp[/QUOTE]
thanks.
but then stop the timer, if reached 100 hp? Just when consuming HP, it further continues to recover, what remains, well, so for now it is 100 HP not leaves
max 100 hp now