iPanda Posted February 1, 2014 Share Posted February 1, 2014 Hi guys. I have a script render the player's health. That is, as it is now in games, health regeneration happens by itself. My following code does not work. Help solve the problem. addEventHandler("onClientRender", root, function() local health = getElementHealth( player ) local renderH = 1 if health < 100 then setTimer( setElementHealth, 1000, 0, player, + renderH ) end end) Link to comment
Moderators IIYAMA Posted February 1, 2014 Moderators Share Posted February 1, 2014 (edited) local lastTime = 0 addEventHandler("onClientRender", root, function() local timeNow = getTickCount() if timeNow > lastTime then local health = getElementHealth( localPlayer ) if health > 0 and health < 100 then local newHealth = health+1 setElementHealth(localPlayer,newHealth < 100 and newHealth or 100) end lastTime = timeNow+1000 end end) Or you set a timer or you use onClientRender with tickCount, but not both. The benefit of onClientRender is that you can render it directly at your screen with dx functions. Edited February 1, 2014 by Guest Link to comment
TAPL Posted February 1, 2014 Share Posted February 1, 2014 local renderH = 1 setTimer(function() local health = getElementHealth(localPlayer) if health < 100 then setElementHealth(localPlayer, health + renderH) end end, 1000, 0) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now