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) Failure is simply an opportunity to begin again more intelligently - Henry Ford
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) http://i.imgur.com/CSE28MJ.png Don't hesitate to contact me for anything! If I can help, I will for sure! Education is the most powerful weapon which you can use to change the world. - Castillo
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 didn't work always "Timer no longer exists" . Failure is simply an opportunity to begin again more intelligently - Henry Ford
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) GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
joaosilva099 Posted November 4, 2014 Posted November 4, 2014 As i said. you need to change the "source" acording to your needings and codes http://i.imgur.com/CSE28MJ.png Don't hesitate to contact me for anything! If I can help, I will for sure! Education is the most powerful weapon which you can use to change the world. - Castillo
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. Failure is simply an opportunity to begin again more intelligently - Henry Ford
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 ]) GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
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 ) Failure is simply an opportunity to begin again more intelligently - Henry Ford
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" GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 so what can i do to save it . Failure is simply an opportunity to begin again more intelligently - Henry Ford
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)
SkatCh Posted November 4, 2014 Author Posted November 4, 2014 didn't work . Failure is simply an opportunity to begin again more intelligently - Henry Ford
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 GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
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 Failure is simply an opportunity to begin again more intelligently - Henry Ford
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. "The humble beet is the answer to all riddles." - Rolf
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 Failure is simply an opportunity to begin again more intelligently - Henry Ford
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. GitHub: Debug Console • MTA-Discord Relay Scripting: How to draw a line chart with DirectX functions? • Doppler Effect in MTA • Get the client's FPS • Customizable Blur Shader
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