Setting timer in command
#1

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!
Reply
#2

Код:
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...
Reply
#3

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.
Reply
#4

Thank you both of you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)