Setting timer in command - 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: Setting timer in command (
/showthread.php?tid=600018)
Setting timer in command -
eikzdej - 02.02.2016
Hi! How can i add timers in command? Like if i use /hello, i can use it again after 5 secs, this is the message:
You can use this command after %d seconds. %d must show seconds not milliseconds, thank you!
Re: Setting timer in command -
Sascha - 02.02.2016
Код:
new last[MAX_PLAYERS];
COMMAND:hello(playerid, params[])
{
new string[256];
if(GetTickCount() - last[playerid] < 5000)
{
new towait = floatround((5000 - (GetTickCount() - last[playerid])) / 1000, floatround_ceil);
format(string, sizeof(string), "You have to wait %d seconds", towait);
}
else
{
last[playerid] = GetTickCount();
//your hello command code
}
return 1
}
The keyword would be "GetTickCount" for you
https://sampwiki.blast.hk/wiki/GetTickCount
not tried to compiled, so typos or missing brackets might be possible...
Re: Setting timer in command -
Mencent - 02.02.2016
PHP код:
new last[MAX_PLAYERS]; //global
COMMAND:hello(playerid,params[])
{
if(last[playerid] < gettime())
{
last[playerid] = gettime()+5;
//your "hello"-command
return 1;
}
else
{
new string[145];
format(string,sizeof(string),"You have to wait %i seconds.",last[playerid]-gettime());
SendClientMessage(playerid,-1,string);
}
return 1;
}
Here is a second example with gettime(). Now you have two options how you want to realize this command.
@Sascha:
SendClientMessage can maximal sends 145 letters.
Re: Setting timer in command -
eikzdej - 03.02.2016
Thank you both of you.