Jump to content

Health Regen


Darkneblade

Recommended Posts

Posted

setTimer(

function ()

setElementHealth ( localPlayer, ( getElementHealth ( localPlayer ) + 15 ) )

end,5000,0)

end

i have this but i need add function when damaged for example

if you dont damage in 5 seconds you start healing i wanna help with this code

Posted (edited)
  
playerDamage = {} 
  
addEventHandler("onClientPlayerDamage", root, function() 
      playerDamage[localPlayer] = getTickCount() 
end 
) 
  
setTimer( 
function () 
if not playerDamage[localPlayer] or playerDamage[localPlayer] > 5000 then 
setElementHealth ( localPlayer, ( getElementHealth ( localPlayer ) + 15 ) ) 
end 
end,5000,0) 
end 
  

Edited by Guest
Posted
  
  
local lastDmg = 0; 
  
addEventHandler("onClientPlayerDamage",localPlayer, function() 
      lastDmg = getTickCount() 
end 
) 
  
setTimer( 
function () 
if lastDmg+5000 < getTickCount() and getElementHealth(localPlayer) < 100 then 
setElementHealth ( localPlayer, ( getElementHealth ( localPlayer ) + 15 ) ) 
end 
end,5000,0) 
end 

Posted
  
local lastDmg = 0; 
  
addEventHandler("onClientPlayerDamage",localPlayer, function() 
      lastDmg = getTickCount() 
end 
) 
  
setTimer( 
            function () 
            if lastDmg+5000 < getTickCount() and getElementHealth(localPlayer) < 100 then 
                setElementHealth ( localPlayer, ( getElementHealth ( localPlayer ) + 15 ) ) 
     end 
end,5000,0) 
  

Posted

What does not work? Is/Are there any debugscript 3 error(s)? Just by saying constantly "It doesn't work :( " is not going to help us too to help you.

Posted
local lastDamaged = 0 -- Define variable with default value '0' 
  
addEventHandler ( "onClientPlayerDamage", localPlayer, 
    function ( ) 
        lastDamaged = getTickCount ( ) -- Update the variable using getTickCount, which returns an integer containing the number of milliseconds since the system the server is running on started. 
    end 
) 
  
setTimer ( 
    function ( ) 
        if ( ( getTickCount ( ) - lastDamaged ) >= 5000 ) then -- If 5 seconds passed since last time the player got damaged.. 
            setElementHealth ( localPlayer, ( getElementHealth ( localPlayer ) + 15 ) ) -- Increase the player health by 15% 
        end 
    end 
    ,5000, 0 
) 

Posted
local lastDamaged = 0 -- Define variable with default value '0' 
  
addEventHandler ( "onClientPlayerDamage", localPlayer, 
    function ( ) 
        lastDamaged = getTickCount ( ) -- Update the variable using getTickCount, which returns an integer containing the number of milliseconds since the system the server is running on started. 
    end 
) 
  
setTimer ( 
    function ( ) 
        if ( ( getTickCount ( ) - lastDamaged ) >= 5000 ) then -- If 5 seconds passed since last time the player got damaged.. 
            setElementHealth ( localPlayer, ( getElementHealth ( localPlayer ) + 15 ) ) -- Increase the player health by 15% 
        end 
    end 
    ,5000, 0 
) 

thanks its working perfectly now :)

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...