BriGhtx3 Posted October 19, 2012 Share Posted October 19, 2012 Hey, I want to set a limit for a command. You should only can use this command once in 6h. I use a database and not accountData. How can I set a 6h limit in REALLIFE-Time not ingame time. So for example when he uses this command at 4pm the limit should be until 10pm. Also if he is not online. Link to comment
Techial Posted October 19, 2012 Share Posted October 19, 2012 You can use setTimer, which sets a server sided value like setAccountData. (On join, it sets the players "command" data ( setAccountData(accountpointer,"command", "0") ) ) Then you can use that in a timer, I hope you understand me. You may want to read up on these: Client sided: https://wiki.multitheftauto.com/wiki/SetTimer https://wiki.multitheftauto.com/wiki/KillTimer https://wiki.multitheftauto.com/wiki/TriggerServerEvent Server sided: https://wiki.multitheftauto.com/wiki/SetAccountData Hope that helps you Regards, Techial. Link to comment
BriGhtx3 Posted October 19, 2012 Author Share Posted October 19, 2012 I know how to use setTimer, but I want to count the time even if the player is not online. When the player leaves, the timer cancels. Link to comment
Techial Posted October 19, 2012 Share Posted October 19, 2012 Well you could try to use setAccountData onPlayerLeave etc etc, setAccountData(accountpointer, "lastTime", tostring(timervaluepointer)) then you could load that on startup. if(not tonumber(getAccountData(accountpointer, "lastTime"))==0)then.. etc etc Link to comment
BriGhtx3 Posted October 19, 2012 Author Share Posted October 19, 2012 Just like I said, I use a database. Link to comment
myonlake Posted October 19, 2012 Share Posted October 19, 2012 Save the current timestamp and check the timestamp in database and compare it with the current time and date and it should work. Link to comment
BriGhtx3 Posted October 19, 2012 Author Share Posted October 19, 2012 I wanted to try it like this, but isn't there an easier method? Link to comment
Techial Posted October 20, 2012 Share Posted October 20, 2012 As far as I know, there isn't any easier methods. Sorry but my knowledge stops here Link to comment
Castillo Posted October 20, 2012 Share Posted October 20, 2012 getTickCount should do the trick, you can check the time that has passed, if it's 6 hours, let him use it again. Link to comment
Callum Posted October 21, 2012 Share Posted October 21, 2012 Just create a server-side table and when the command is used; cooldownTable[playersAccountName] = getTickCount() When they next come to use the command, check that getTickCount()-cooldownTable[theirAccountName] is more than 6 hours (providing the index exists). Link to comment
50p Posted October 21, 2012 Share Posted October 21, 2012 Just create a server-side table and when the command is used; cooldownTable[playersAccountName] = getTickCount() When they next come to use the command, check that getTickCount()-cooldownTable[theirAccountName] is more than 6 hours (providing the index exists). That would work as long as the server is running. Once the server stops, the countdownTable would be empty. It's best to store timestamp of the "start" in player's account/database (wherever you prefer) and then check if "current timestamp" - "start timestamp" is greater than 6hrs. This will work even if the server restarts. Can't think of any simpler way. Link to comment
Scooby Posted October 21, 2012 Share Posted October 21, 2012 I wanted to try it like this, but isn't there an easier method? for something simple u could use ur setTimer method but store the timer on the players IP or serial. just start the timer when they use the command, it will remain till 6hrs has passed. playerTimer = {} -- create a table with the active timers in playerTimer[playersIP] = setTimer(removeTimerInfo,21600000,1,playersIP) -- store the ip or serial when they use the command function removeTimerInfo(ip) -- function to remove the table info when the timer is up. playerTimer[ip] = nil end unless u mean u want it to work for 6hrs in real life time, but only count when the player is in game... then ignore this Link to comment
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