17.06.2013, 05:35
Step 1 - How many seconds in a day?
60 seconds in a minute
60 minutes in an hour
24 hours in a day
60 * 60 * 24 = 86400
Step 2 - Save the current timestamp PLUS 86400 in their account
gettime() returns the number of seconds passed since 1 Jan 1970 (or something). Using this, get the current timestamp and add 86400 to it and save that to their account, this can then to be used to tell whether a day (86400 seconds) has passed. You'll want to save it in mySQL/files because of course variables get reset.
Step 3 - Check if it's been a day
Very simple:
To find out how long until they can use the command (in seconds):
gettime() - the_value_you_saved_to_their_account
For example, say the current timestamp is a million: 1,000,000
At this time, they use the command, the value of when they can use it again gets saved to their account:
1,000,000
+ 86400
= 1,086,400
They can only use this command after the timestamp is over 1,086,400, meaning a day has passed.
60 seconds in a minute
60 minutes in an hour
24 hours in a day
60 * 60 * 24 = 86400
Step 2 - Save the current timestamp PLUS 86400 in their account
gettime() returns the number of seconds passed since 1 Jan 1970 (or something). Using this, get the current timestamp and add 86400 to it and save that to their account, this can then to be used to tell whether a day (86400 seconds) has passed. You'll want to save it in mySQL/files because of course variables get reset.
Step 3 - Check if it's been a day
Very simple:
pawn Код:
if(gettime() < the_value_you_saved_to_their_account) return SendClientMessage(playerid, COLOR_RED, "You can only use this command once a day.");
gettime() - the_value_you_saved_to_their_account
For example, say the current timestamp is a million: 1,000,000
At this time, they use the command, the value of when they can use it again gets saved to their account:
1,000,000
+ 86400
= 1,086,400
They can only use this command after the timestamp is over 1,086,400, meaning a day has passed.