Jump to content

about getTimerDetails


SkatCh

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) 

Link to comment
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) 

Link to comment
  • MTA Team

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) 

Link to comment

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 ) 

Link to comment
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) 

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