Jump to content

What's wrong with this? (setTimer) [SOLVED]


KiffShark

Recommended Posts

Hi everybody!

I've done a shoppanel and in a button that simulates something like adrenaline I want that it give +1 health every second

the button works ok with client.. gui... everything.. function setsalud4 works ok, (but setTimer I guess) because of the console give me error in elements at function setsalud5 (marked with --HERE).. nil value... every second and in the game I don't receive +1/s so maybe timer runs good and the problem is setsalud5 :/

function setsalud5 () 
local Health5 = getElementHealth(source) --HERE 
    setElementHealth ( source, Health5 + 1 )  -- HERE 
end 
addEventHandler ( "salud5", getRootElement(), setsalud5 ) 
  
addEvent( "salud4", true )  
function setsalud4 (player) 
local PlayerMoney = getPlayerMoney(source) 
 if ( PlayerMoney >= 5000) then 
    setElementHealth ( source, 500 )  
    setPedStat(source, 22, 999) 
    setPedStat(source, 23, 999) 
    setPedStat(source, 24, 999) 
    setPedStat(source, 225, 999) --bucear 
    takePlayerMoney(source,5000) 
    outputChatBox ( "*Has comprado virus Génesis por $5000*", source, 255, 0, 0 )  
    outputChatBox ( "*El virus te da +salud, +fuerza, +resistencia +resistencia de buceo. Durante 1 sesión*", source, 255, 0, 0 )  
    setTimer ( setsalud5, 1000, 0 ) 
    else 
        outputChatBox("*No tienes suficiente dinero*", source, 255, 0, 0, true) 
end 
end 
addEventHandler ( "salud4", getRootElement(), setsalud4 ) 

Some Idea?

Edited by Guest
Link to comment
  
--Server-side 
addEvent( "salud4", true ) 
  
function setsalud4 (player) 
local PlayerMoney = getPlayerMoney(source) 
 if ( PlayerMoney >= 5000) then 
    setElementHealth ( source, 500 ) ; 
    setPedStat(source, 22, 999); 
    setPedStat(source, 23, 999); 
    setPedStat(source, 24, 999); 
    setPedStat(source, 225, 999); --bucear 
    takePlayerMoney(source,5000); 
    setTimer ( function() 
    local Health5 = getElementHealth(source) 
    setElementHealth ( source, Health5 + 1 ) 
    end, 1000, 0 ); 
    outputChatBox ( "*Has comprado virus Génesis por $5000*", source, 255, 0, 0 ) ; 
    outputChatBox ( "*El virus te da +salud, +fuerza, +resistencia +resistencia de buceo. Durante 1 sesión*", source, 255, 0, 0 ) ; 
    else 
        outputChatBox("*No tienes suficiente dinero*", source, 255, 0, 0, true) 
end 
end 
addEventHandler ( "salud4", getRootElement(), setsalud4 ) 

try this, not tested, tell me if works or if it doesn't

Link to comment

hi! thanks for answer!!

console give me error at:

    local Health5 = getElementHealth(source) 
    setElementHealth ( source, Health5 + 1 ) 

[2012-11-17 14:43:33] WARNING: itemshop\s_items.lua:87: Bad argument @ 'getElementHealth' [Expected element at argument 1, got nil]

[2012-11-17 14:43:33] ERROR: unzipped\itemshop\s_items.lua:88: attempt to perform arithmetic on local 'Health5' (a boolean value)

the same :(

Link to comment
function setsalud4 ( ) 
    local PlayerMoney = getPlayerMoney ( source ) 
    if ( PlayerMoney >= 5000) then 
        setElementHealth ( source, 500 ) 
        setPedStat ( source, 22, 999 ) 
        setPedStat ( source, 23, 999 ) 
        setPedStat ( source, 24, 999 ) 
        setPedStat ( source, 225, 999 ) --bucear 
        takePlayerMoney ( source, 5000 ) 
        outputChatBox ( "*Has comprado virus Génesis por $5000*", source, 255, 0, 0 ) 
        outputChatBox ( "*El virus te da +salud, +fuerza, +resistencia +resistencia de buceo. Durante 1 sesión*", source, 255, 0, 0 ) 
        setTimer ( 
            function ( thePlayer ) 
                if ( isElement ( thePlayer ) ) then 
                    setElementHealth ( thePlayer, getElementHealth ( thePlayer ) + 1 ) 
                end 
            end 
            ,1000, 0, source 
        ) 
    else 
        outputChatBox ( "*No tienes suficiente dinero*", source, 255, 0, 0, true ) 
    end 
end 
addEvent ( "salud4", true ) 
addEventHandler ( "salud4", getRootElement(), setsalud4 ) 

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