SA-MP Forums Archive
SetTimer for so many days? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetTimer for so many days? (/showthread.php?tid=444542)



SetTimer for so many days? - Goldilox - 17.06.2013

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?


Respuesta: SetTimer for so many days? - JustBored - 17.06.2013

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


Re: SetTimer for so many days? - MP2 - 17.06.2013

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.


Re: SetTimer for so many days? - Goldilox - 17.06.2013

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.


AW: SetTimer for so many days? - BigETI - 17.06.2013

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)



Re: SetTimer for so many days? - Goldilox - 17.06.2013

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;
}



AW: SetTimer for so many days? - BigETI - 17.06.2013

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


Re: SetTimer for so many days? - cessil - 17.06.2013

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


Re: SetTimer for so many days? - Goldilox - 18.06.2013

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