SetTimer for so many days?
#1

What I want to do is that player can only type this command once in a day, how would I set that?

Is it gonna be like SetTimer for 86400000 ms?
Reply
#2

LOL no!, You should use gettime and getdate. Later i will explain you how.
Reply
#3

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:

pawn Код:
if(gettime() < the_value_you_saved_to_their_account) return SendClientMessage(playerid, COLOR_RED, "You can only use this command once a day.");
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.
Reply
#4

Oh man I am totally lost! How to get the time stamp and I want to make it in dini. I actually want to make something like player can only change their names twice a day.
Reply
#5

https://sampwiki.blast.hk/wiki/Gettime

Get the expiration date and time
pawn Код:
expiration_date_time = gettime()+delay // "delay" in seconds!
If it's expired
pawn Код:
if(gettime() >= expiration_date_time)
Reply
#6

Is that pattern correct?

pawn Код:
CMD:changename(playerid,params[])
{

new expiration_date_time = gettime() + 86400;
if(gettime() >= expiration_date_time)
{
   ChangeName();
}
else
{
SendClientMessage(playerid,0xFFFFFFAA,"Spent a day!";
return 1;
}
return 1;
}
Reply
#7

Save the expiration date and time into a player file, load it after the player has connected, and use it to check in your command instead setting the expiration time and check it after someone attempted to type this command...
Reply
#8

Quote:
Originally Posted by Goldilox
Посмотреть сообщение
Is that pattern correct?

pawn Код:
CMD:changename(playerid,params[])
{

new expiration_date_time = gettime() + 86400;
if(gettime() >= expiration_date_time)
{
   ChangeName();
}
else
{
SendClientMessage(playerid,0xFFFFFFAA,"Spent a day faggot!";
return 1;
}
return 1;
}
no because you're setting the variable and then checking so it'll never be true

pawn Код:
#define TimeHour    3600
#define TimeDay     86400
new expiration_date_time[MAX_PLAYERS];

CMD:changename(playerid,params[])
{
if(expiration_date_time[playerid] < gettime())
{
   expiration_date_time[playerid] = gettime() + TimeDay;
   ChangeName();
}
else//else the variable is greater than the current time
{
   SendClientMessage(playerid,0xFFFFFFAA,"You can only use this command once every 24 hours, Friend!";
return 1;
}
return 1;
}
and then save the variable to their user file and load when they quit/join
Reply
#9

Hmm, do I have enum for that? I have no idea how to do it, can someone help me. I want to make it with dini
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)