Jump to content

6h Limit (Reallife Time)


BriGhtx3

Recommended Posts

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

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

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

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