Sign in to follow this  
SkatCh

about getTimerDetails

Recommended Posts

Hi, please i need some help can anyone tell me how can i check the timer if it's inside a table.

like this :

local timer = {} 
  
function ()  
bla  
bla  
antiSpamAds[source] = setTimer(function() end, 900000, 1 ) 
  
etc.... 
end 

Now how can i use this :

function timerDetails() 
    remaining = getTimerDetails(........) ----- What do i write here ? 
    if (remaining) then 
        outputChatBox("Time remaining "..remaining.." seconds .",source,153,51,255) 
    else  
        outputChatBox("Timer no longer exists",source,153,51,255) 
    end 
end 
addCommandHandler("time", timerDetails) 

Share this post


Link to post
function timerDetails() 
    remaining = getTimerDetails(antiSpamAds[source]) ----- Write the timer's variable. if is in same code block. if not replace "source" with the appropriate item in the table 
    if (remaining) then 
        outputChatBox("Time remaining "..remaining.." seconds .",source,153,51,255) 
    else  
        outputChatBox("Timer no longer exists",source,153,51,255) 
    end 
end 
addCommandHandler("time", timerDetails) 

But is better this:

function timerDetails() 
    if (isTimer(antiSpamAds[source])) then 
        remaining = getTimerDetails(antiSpamAds[source]) 
        outputChatBox("Time remaining "..remaining.." seconds .",source,153,51,255) 
    else  
        outputChatBox("Timer no longer exists",source,153,51,255) 
    end 
end 
addCommandHandler("time", timerDetails) 

Share this post


Link to post

Commands don't give the player by hidden variable, but only by parameter (correct me if I am wrong).

function timerDetails(source) 
    if (isTimer(antiSpamAds[source])) then 
        remaining = getTimerDetails(antiSpamAds[source]) 
        outputChatBox("Time remaining "..remaining.." seconds .",source,153,51,255) 
    else 
        outputChatBox("Timer no longer exists",source,153,51,255) 
    end 
end 
addCommandHandler("time", timerDetails) 

Share this post


Link to post

thx bro it's working now please i have one more question it's possible to save this timer onPlayerLogout.

Share this post


Link to post

Use the accountname instead of the player element "source" and then you have to use the player's account name (getPlayerAccount, getAccountName) everytime you want to get the timer (antiSpamAds[ accountname ])

Share this post


Link to post

You mean like this :

function timerDetails(source) 
    if (isTimer(antiSpamAds[source])) then 
        remaining = getTimerDetails(antiSpamAds[source]) 
        outputChatBox("Time remaining "..remaining.." seconds .",source,153,51,255) 
    else 
        outputChatBox("Timer no longer exists",source,153,51,255) 
    end 
end 
addCommandHandler("time", timerDetails) 

-- Save Timer

function save() 
local PlayerAccount = getPlayerAccount ( source ) 
local AccountName = getAccountName (PlayerAccount) 
if ( AccountName ) then 
setAccountData ( playeraccount,  "time", remaining ) 
  end 
end 
addEventHandler ("onPlayerQuit", root, save ) 

Share this post


Link to post

That's not going to work and you wrote that you wanted to use "onPlayerLogout"

Share this post


Link to post
local antiSpamAds = { } 
  
-- Check time 
function timerDetails(source) 
    if (isTimer(antiSpamAds[source])) then 
        local remaining = getTimerDetails(antiSpamAds[source]) 
        outputChatBox("Time remaining "..remaining.." seconds .",source,153,51,255) 
    else 
        outputChatBox("Timer no longer exists",source,153,51,255) 
    end 
end 
addCommandHandler("time", timerDetails) 
  
-- Save time 
function save(_, PlayerAccount ) 
    if (isTimer(antiSpamAds[source])) then 
        local remaining = getTimerDetails(antiSpamAds[source]) 
        setAccountData(playeraccount,  "time", remaining ) 
        killTimer(antiSpamAds[source]) 
        antiSpamAds[source] = nil 
    end 
end 
addEventHandler("onPlayerLogout", root, save ) 
  
-- Load time  
function load(_, PlayerAccount ) 
    local time = getAccountData(playeraccount,  "time") 
    if (time) then 
        antiSpamAds[source] = setTimer(function() end, tonumber(time), 1) 
    end 
end 
addEventHandler("onPlayerLogin", root, load) 

Share this post


Link to post

Because the script he gave you is not using the right variable (case sensitive!!)

playeraccount & PlayerAccount

Share this post


Link to post

If you cannot do that much, perhaps you are not asking for scripting help. You're asking for a scripter to write for you.

Share this post


Link to post

thx guys i fixed it , please i have one more question:

It's possible to keep that timer working even onPlayerLogout ?

i'm sorry about my english

Share this post


Link to post

That is not efficient and you should try to do any calculation when the player logs in.

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.