Jump to content

SOLVED


Bean666

Recommended Posts

Posted (edited)

how could you save a timer onplayerquit and set it back right onplayerlogin? im using a timer like this, this is my first time trying to save a timer. so i'm kinda curious how?

any tips/help, appreciated.

local timer = {} 
  
function ex(source) 
if timer[source] and isTimer(timer[source]) then 
return end 
     timer[source] = setTimer(function() 
     timer[source] = nil 
     outputChatBox("blablablabla", source) 
     end, 3600*500, 1) 
     end 
addCommandHandler ( "ex", ex ) 

Edited by Guest

Aftermath

Posted

'source' is a userdata which is unique for every each element. so every time a player quits/joins they'll have a different userdata. you can save the timer's details with getTimerDetails function on player's account data when they quit and then work it after they join

Posted

EDIT: ah , doesn't work, any tips/help?

function onQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
    local timerget = getTimerDetails( timer[source] ) 
     setAccountData ( playeraccount, "timercd", timerget ) 
     end 
        end 
    addEventHandler ( "onPlayerQuit", root, onQuit ) 

Aftermath

Posted

i did smth like this.

  
function onQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
    local timerget = getTimerDetails( timer[source] ) 
     setAccountData ( playeraccount, "timercd", timerget ) 
     end 
        end 
    addEventHandler ( "onPlayerQuit", root, onQuit ) 
  
function onLogin () 
    if ( playeraccount ) then 
     local Timer = getAccountData ( playeraccount, "timercd" ) 
             if ( Timer ) then 
             timer[source] = setTimer(function() 
             timer[source] = nil 
             outputChatBox("You can now use the advert again", source) 
              end, Timer, 1) 
                end 
                   end 
                      end 
    addEventHandler ( "onPlayerLogin", getRootElement ( ), onLogin) 

Aftermath

Posted
  
function onLogin (_, playeraccount) 
    if ( playeraccount ) then 
     local Timer = getAccountData ( playeraccount, "timercd" ) 
             if ( Timer ) then 
             timer[source] = setTimer(function() 
             timer[source] = nil 
             outputChatBox("You can now use the advert again", source) 
              end, Timer, 1) 
                end 
                   end 
                      end 
    addEventHandler ( "onPlayerLogin", getRootElement ( ), onLogin) 

Posted

Here is all what you need.

local timerTable = {} -- timer table 
  
-- save the time on player quit 
function save () 
        local playerAccount = getPlayerAccount ( source ) -- get the player account 
        if (isTimer(timerTable[source])) then -- if the timer exist then  
        local remaining = getTimerDetails(timerTable[source]) -- then get the timer details 
        if playerAccount and not isGuestAccount(playerAccount) then -- check if it's not a guest account 
            setAccountData(playeraccount,  "timer", tonumber(remaining)) -- save the timer using setAccountData 
            killTimer(timerTable[source]) -- kill the timer 
            timerTable[source] = nil 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", root, save ) 
  
-- load the timer on player login 
function loadTimer (_,account) 
    local timer = getAccountData(account, "timer") -- get the timer using getAccountData 
    if (timer) then -- if the timer exist then 
        timerTable[source] = setTimer(function() end, tonumber(time), 1) -- start it again using setTimer 
    end 
end 
addEventHandler ("onPlayerLogin", root, loadTimer) 

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
Here is all what you need.
local timerTable = {} -- timer table 
  
-- save the time on player quit 
function save () 
        local playerAccount = getPlayerAccount ( source ) -- get the player account 
        if (isTimer(timerTable[source])) then -- if the timer exist then  
        local remaining = getTimerDetails(timerTable[source]) -- then get the timer details 
        if playerAccount and not isGuestAccount(playerAccount) then -- check if it's not a guest account 
            setAccountData(playeraccount,  "timer", tonumber(remaining)) -- save the timer using setAccountData 
            killTimer(timerTable[source]) -- kill the timer 
            timerTable[source] = nil 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", root, save ) 
  
-- load the timer on player login 
function loadTimer (_,account) 
    local timer = getAccountData(account, "timer") -- get the timer using getAccountData 
    if (timer) then -- if the timer exist then 
        timerTable[source] = setTimer(function() end, tonumber(time), 1) -- start it again using setTimer 
    end 
end 
addEventHandler ("onPlayerLogin", root, loadTimer) 

your code won't work

Posted

should i delete the current timer table i have here

and change the current timer[source] names? to timerTable[source] as wel?

local timer = {} 
  
function ex(source) 
if timer[source] and isTimer(timer[source]) then 
return end 
     timer[source] = setTimer(function() 
     timer[source] = nil 
     outputChatBox("blablablabla", source) 
     end, 3600*500, 1) 
     end 
addCommandHandler ( "ex", ex ) 

Aftermath

Posted

Use my code :

local timerTable = {} -- timer table 
  
-- save the time on player quit 
function save () 
        local playerAccount = getPlayerAccount ( source ) -- get the player account 
        if (isTimer(timerTable[source])) then -- if the timer exist then 
        local remaining = getTimerDetails(timerTable[source]) -- then get the timer details 
        if playerAccount and not isGuestAccount(playerAccount) then -- check if it's not a guest account 
            setAccountData(playeraccount,  "timer", tonumber(remaining)) -- save the timer using setAccountData 
            killTimer(timerTable[source]) -- kill the timer 
            timerTable[source] = nil 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", root, save ) 
  
-- load the timer on player login 
function loadTimer (_,account) 
    local timer = getAccountData(account, "timer") -- get the timer using getAccountData 
    if (timer) then -- if the timer exist then 
        timerTable[source] = setTimer(function() end, tonumber(timer), 1) -- start it again using setTimer 
    end 
end 
addEventHandler ("onPlayerLogin", root, loadTimer) 

ofc it won't work you need to put this somewhere in your code:

-- Example:

if not isTimer(timerTable[thePlayer]) then  
    timerTable[thePlayer] = setTimer(function() end, 900000, 1 )  
end  

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 (edited)
  
function ex(source) 
if timerTable[source] and isTimer(timerTable[source]) then 
return end 
     if not isTimer(timerTable[thePlayer]) then 
    timerTable[thePlayer] = setTimer(function() 
    --blabla-- 
     end, 900000, 1 ) 
     end 
addCommandHandler ( "ex", ex ) 

Edited by Guest

Aftermath

Posted

Should be like this:

function ex(player) 
    -- if the timer exist then  
    if isTimer(timerTable[player]) then  
        outputChatBox( "Please wait!", player, 255, 0, 0)  
        return  
    end 
    timerTable[player] = setTimer(function() end, 900000, 1 ) 
end 
addCommandHandler ("ex",ex) 

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
SOLVED,

Thanks to Tox and Walid.

now i know how to save a timer ^-^

Simply to optimize your code you could use the player serial to save the timer without using setAccountData() , getAccountData() , onPlayerQuit bla bla bla > waste of time.

timerTable[getPlayerSerial(player)] = setTimer(function() end, 900000, 1 ) 

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

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