SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/05/2020, 06:50 PM   #1
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default delay command

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;

Calinut200 is offline   Reply With Quote
Old 16/05/2020, 07:02 PM   #2
Skimmer
Gangsta
 
Skimmer's Avatar
 
Join Date: Oct 2012
Location: Germany
Posts: 484
Reputation: 56
Default Re: delay command

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;
}
Skimmer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A delay when using this command. danielpalade Scripting Help 6 06/12/2016 04:32 AM
Delay after writing a command BoomShnizel Scripting Help 8 06/11/2012 03:37 AM
[Help] Setting a timer to delay rest of command Ace_Menace Help Archive 8 20/07/2010 05:47 AM
[How to] make delay this command eixas10 Help Archive 1 01/04/2010 09:12 AM
[UNSOLVED]Command Delay Problem Hijolion Help Archive 3 04/03/2010 11:30 PM


All times are GMT. The time now is 02:35 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.