Sign in to follow this  
LucasDSNL

Problema com setTimer

Recommended Posts

function enableAccount accountJ )
    if not isGuestAccount ( accountJ ) then
        if accountJ then    
            local source = getAccountPlayer ( accountJ )
          
            local XP = getAccountData ( accountJ, "XP" ) or 0
                setElementData ( source, "XP", XP )
                
            local Level = getAccountData ( accountJ, "Level" ) or 0
                setElementData ( source, "Level", Level )   
 
        end
    end    
end
 
function saveAccount accountJ )
    if accountJ then
        local source = getAccountPlayer ( accountJ )
      
 
            local XP = getElementData(source, "XP" ) or 0
            setAccountData ( accountJ, "XP", XP )
            
            local Level = getElementData(source, "Level" ) or 0
            setAccountData ( accountJ, "Level", Level )
 
      
    end
end
 
----
 
function restartScript res )
    if res == getThisResource ( ) then
        for i, player in ipairs ( getElementsByType ( "player" ) ) do
            local acc = getPlayerAccount ( player )
            if not isGuestAccount ( acc ) then
                enableAccount ( acc )
            end
        end
    end
end
addEventHandler ( "onResourceStart"getRootElement ( ), restartScript )
addEventHandler("onPlayerLogin"root,
function_acc )
 enableAccount ( acc )
 end
)
function stopScript (res)
    if res == getThisResource ( ) then
        for i, player in ipairs ( getElementsByType ( "player" ) ) do
            local acc = getPlayerAccount ( player )
            if not isGuestAccount ( acc ) then
                saveAccount ( acc )
            end
        end
    end
end 
addEventHandler ( "onResourceStop"getRootElement ( ), stopScript )
 
function playerQuit quitType )
    local acc = getPlayerAccount ( source )
    if not isGuestAccount ( acc ) then
        if acc then
            saveAccount ( acc )
        end
    end
end
addEventHandler ( "onPlayerQuit"getRootElement ( ), playerQuit )
 
function uparLevel(source)
    local exp = getElementData(source, "XP")
    local exps = tonumber(getElementData(source, "XP"))
    local lvls = tonumber(getElementData(source, "Level"))
    if lvls and exps then 
        local needexp = 1000
        if not exp then
            setElementData(source, "Level"0)
            setElementData(source, "XP"0)
        else
            if exps >= needexp then
                setElementData(source, "Level", lvls + 1)
                setElementData(source, "XP"0)
            end
        end
    end
end
setTimer(uparLevel, 601)

Esse é meu código de level, mas está com três erros, esse level será exibido em uma hud, já estou ciente 
que não é possível usar source em um setTimer(), ja coloquei um for i, v in pair(getElementByType), mas quando eu coloco
ele generaliza e seta o elementdata para todos os players.

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.