Jump to content

Save timer to accountData onQuit and continue onPlayerLogin


Adde

Recommended Posts

Hello, I have a question. I am making a savesystem to my timer or how i should say. Is this close if I want to save the timer "onQuit" and then launch the rest next time the player login if the timer still was running onquit? I may have understood wiki wrong bcs I can´t figure it out. There are a lot like missiontimer also, but I choose this.

Thankfull for answears.

I have a function here, included:

theTimer = setTimer(setElementPosition, 240000,1,x,y,z)

then theese functions:

   function onQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
    if isTimer( theTimer ) then 
    local timer = getTimerDetails( theTimer ) 
     setAccountData ( playeraccount, "jailTimer", timer ) 
     end 
        end 
           end 
    addEventHandler ( "onPlayerQuit", root, onQuit ) 
      
    function onLogin () 
    if ( playeraccount ) then 
     local Timer = getAccountData ( playeraccount, "jailTimer" ) 
                if ( Timer ) then 
                setTimer(setElementPosition,"timer",1,source,634.37,-567.09,16.33 ) 
                end 
                   end 
                      end 
    addEventHandler ( "onPlayerLogin", getRootElement ( ), onLogin) 

Edited by Guest
Link to comment

Oh, my bad. Should have thought about that. Is it not just checking if there is any timer running atm? Or is it checking if the timer is on 240000?

Is this possible right?

  function onQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
    local timer = getTimerDetails( theTimer ) 
     setAccountData ( playeraccount, "jailTimer", timer ) 
     end 
        end 
    addEventHandler ( "onPlayerQuit", root, onQuit ) 
      
    function onLogin () 
    if ( playeraccount ) then 
     local Timer = getAccountData ( playeraccount, "jailTimer" ) 
                if ( Timer ) then 
                setTimer(setElementPosition,"Timer",1,source,634.37,-567.09,16.33 ) 
                end 
                   end 
                      end 
    addEventHandler ( "onPlayerLogin", getRootElement ( ), onLogin) 

Link to comment
  • 2 weeks later...

Still, you are setting a timer, you should start a timer, on play login (setTimer is a countdown)

I'm not sure wich function does this, but you should start checking arround on the wiki, since Timer doesnt do it.

(Not sure if GetElementData with GetTickCount could do it)

A timer object refers to a timer set to execute a function a certain number of times with a specified delay.

Note that after a timer has completed all its iterations, it is destroyed and any stored pointers to it become invalid. Also timers are not under the resource hierarchy, becouse they are not elements, for instance, if you create a timer, it will not be destroyed when the resource in which it was created is stopped, so in this case you should kill the timer manually.

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