delay command
#1

Helo i try to make an delay to commands but i get this...
PHP Code:
new delay[MAX_PLAYERS];
ptask delaytime[1000](playerid
{
    if(
delay[playerid] != 0)
    {
        
delay[playerid]--;
    }
    return 
1;
}
YCMD:money(playeridparams[], help)
{
    if(
delay[playerid] != 0)
        return 
SendFormatMessage(playerid,-1,"Nu poti sa utilizezi aceasta comanda timp de %i secunde",delay[playerid]);
    
GivePlayerMoney(playeridstrval(params));
    
delay[playerid] = 10;
    return 
1;

Is work great but when i try to use other command who have delay is take the delay from comand [/money]
I wanna that delay to be only to /money not to all comands with delay
PHP Code:
YCMD:buylevel(playeridparams[], help)
{
    if(
delay[playerid] != 0)
    return 
SendFormatMessage(playerid,-1,"[ANTI-SPAM]:Nu poti sa utilizezi aceasta comanda timp de %i secunde",delay[playerid]);
    
// my code...
    
delay[playerid] = 10;
    return 
1;

Reply
#2

There's an easier way to do that. At first you define a variable which saves the timestamp at the moment where the player used that command.
And when he uses the command again, you simply subtract that value from the current timestamp and check whether the value is less than 10 (for 10 seconds) or not.

pawn Code:
new lastCommandUsed[MAX_PLAYERS];

YCMD:money(playerid, params[], help)
{
    if((gettime() - lastCommandUsed[playerid]) < 10)
    return SendFormatMessage(playerid,-1,"Nu poti sa utilizezi aceasta comanda timp de %i secunde",delay[playerid]);
    // your code
    lastCommandUsed[playerid] = gettime();
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)