Jump to content

help me with timer function


jah

Recommended Posts

Posted

Well i have problems with timers in last time when i made function it works when i add timer it doesn't work :(

function minutes()

local thePlayer = getPlayerAccount ( source )

setAccountData(thePlayer,"Minutes",tonumber(getAccountData(thePlayer,"Minutes"))+1)

end

setTimer ( minutes, 60000, 0 )

doesnt work then i tried

addEventHandler ( "onResourceStart" , resourceRoot ,

function ( )

local timer = setTimer ( minutes , 6000 , 0 , player )

end

)

function minutes()

local thePlayer = getPlayerAccount ( source )

setAccountData(thePlayer,"Minutes",tonumber(getAccountData(thePlayer,"Minutes"))+1)

end

error is

lua:65: attempt to perform arithmetic on a nil value

65: setAccountData(thePlayer,"Minutes",tonumber(getAccountData(thePlayer,"Minutes"))+1)

Posted

remove all of that and add this, this timer already starts when resource starts, i suggest using elementdatas tho...:

try this:

function minutes() 
local thePlayer = getPlayerAccount ( source ) 
local Minutes = getAccountData(thePlayer,"Minutes") 
if Minutes then 
setAccountData(thePlayer,"Minutes",tonumber(getAccountData(thePlayer,"Minutes"))+1) 
end 
end 
setTimer ( minutes, 60000, 0 ) 

element data:

i might have missing / non-needed ends here, you edit it if wrong.

function minutes() 
for i, thePlayer in ipairs(getElementsByType("player")) do 
local Minutes = getElementData(thePlayer,"Minutes") 
if Minutes then 
setElementData(thePlayer,"Minutes",tonumber(getElementData(thePlayer,"Minutes"))+1) 
end 
end 
setTimer ( minutes, 60000, 0 ) 

Aftermath

Posted
remove all of that and add this, this timer already starts when resource starts, i suggest using elementdatas tho...:

try this:

function minutes() 
local thePlayer = getPlayerAccount ( source ) 
local Minutes = getAccountData(thePlayer,"Minutes") 
if Minutes then 
setAccountData(thePlayer,"Minutes",tonumber(getAccountData(thePlayer,"Minutes"))+1) 
end 
end 
setTimer ( minutes, 60000, 0 ) 

element data:

i might have missing / non-needed ends here, you edit it if wrong.

function minutes() 
for i, thePlayer in ipairs(getElementsByType("player")) do 
local Minutes = getElementData(thePlayer,"Minutes") 
if Minutes then 
setElementData(thePlayer,"Minutes",tonumber(getElementData(thePlayer,"Minutes"))+1) 
end 
end 
setTimer ( minutes, 60000, 0 ) 

both doesn't work for the first one i have error

[2016-07-10 12:51:44] WARNING:.lua:53: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil]

[2016-07-10 12:51:44] WARNING:.lua:54: Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean]

secound one just dont work and yes needed 1 more end

before i had no problems with scripting at all but now i can't even do simple scripts like +1 Minute i dont get it why

it is not working... and in all scripts i have made in last time where i had to use timer nothing worked... it is some new update or i am getting old?

Posted

remove the onResourceStart, etc ,etc and just replace it with this.

function minutes() 
local thePlayer = getPlayerAccount ( source ) 
local Minutes = getAccountData(thePlayer,"Minutes") 
if Minutes then 
setAccountData(thePlayer,"Minutes",tonumber(Minutes)+1) 
end 
end 
setTimer ( minutes, 60000, 0 ) 

Aftermath

Posted
remove the onResourceStart, etc ,etc and just replace it with this.
function minutes() 
local thePlayer = getPlayerAccount ( source ) 
local Minutes = getAccountData(thePlayer,"Minutes") 
if Minutes then 
setAccountData(thePlayer,"Minutes",tonumber(Minutes)+1) 
end 
end 
setTimer ( minutes, 60000, 0 ) 

still it dont want to work same errors as before

Posted

12098af1ee.png

@Shaman123 , source is not defined in your code more than that you can't use it with setTimer so you need get a table of all the players that exist and loop through it.

Example:

function minutes() 
    for i, thePlayer in ipairs(getElementsByType("player")) do 
        local account = getPlayerAccount(thePlayer) 
        if account and not isGuestAccount(account) then  
            local Minutes = getAccountData(account,"Minutes") 
            if Minutes then 
                setAccountData(account,"Minutes",tonumber(Minutes)+1) 
            end  
        end 
    end 
end  
setTimer ( minutes, 60000, 0 ) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
12098af1ee.png

@Shaman123 , source is not defined in your code more than that you can't use it with setTimer so you need get a table of all the players that exist and loop through it.

Example:

function minutes() 
    for i, thePlayer in ipairs(getElementsByType("player")) do 
        local account = getPlayerAccount(thePlayer) 
        if account and not isGuestAccount(account) then  
            local Minutes = getAccountData(account,"Minutes") 
            if Minutes then 
                setAccountData(account,"Minutes",tonumber(Minutes)+1) 
            end  
        end 
    end 
end  
setTimer ( minutes, 60000, 0 ) 

Thanks Walid!

Thank you Shaman123 for trying to help me!

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