Jump to content

Render health


iPanda

Recommended Posts

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
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 by Guest
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...