Jump to content

about getTimerDetails


SkatCh

Recommended Posts

Posted

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) 

Posted
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) 

  • MTA Team
Posted

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) 

  • MTA Team
Posted

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 ])

Posted

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 ) 

Posted
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) 

  • MTA Team
Posted

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

playeraccount & PlayerAccount

Posted

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

Posted

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

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