SkatCh Posted November 4, 2014 Posted November 4, 2014 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)
joaosilva099 Posted November 4, 2014 Posted November 4, 2014 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)
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 didn't work always "Timer no longer exists" .
MTA Team botder Posted November 4, 2014 MTA Team Posted November 4, 2014 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)
joaosilva099 Posted November 4, 2014 Posted November 4, 2014 As i said. you need to change the "source" acording to your needings and codes
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 thx bro it's working now please i have one more question it's possible to save this timer onPlayerLogout.
MTA Team botder Posted November 4, 2014 MTA Team Posted November 4, 2014 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 ])
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 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 )
MTA Team botder Posted November 4, 2014 MTA Team Posted November 4, 2014 That's not going to work and you wrote that you wanted to use "onPlayerLogout"
WASSIm. Posted November 4, 2014 Posted November 4, 2014 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 botder Posted November 4, 2014 MTA Team Posted November 4, 2014 Because the script he gave you is not using the right variable (case sensitive!!) playeraccount & PlayerAccount
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 yes i know i already fixed it but didn't work . can you help me; thx
Woovie Posted November 4, 2014 Posted November 4, 2014 If you cannot do that much, perhaps you are not asking for scripting help. You're asking for a scripter to write for you.
SkatCh Posted November 5, 2014 Author Posted November 5, 2014 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
MTA Team botder Posted November 6, 2014 MTA Team Posted November 6, 2014 That is not efficient and you should try to do any calculation when the player logs in.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now