SA-MP Forums Archive
Anti Command Spam - 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: Anti Command Spam (/showthread.php?tid=354077)



Anti Command Spam - kbalor - 25.06.2012

I want that every command can be used only every 3 seconds by a player. So that their chat box will not flood like this.




Re: Anti Command Spam - Hawky133 - 25.06.2012

So you want it so that a player can only use a command once every three seconds?

What command system are you using? E.g. YCMD, ZCMD, RCMD, or just strtok under OnPlayerCommandText.


Re: Anti Command Spam - kbalor - 25.06.2012

Quote:
Originally Posted by Hawky133
View Post
So you want it so that a player can only use a command once every three seconds?

What command system are you using? E.g. YCMD, ZCMD, RCMD, or just strtok under OnPlayerCommandText.
My commands are all ZCMD. And yes im using it. Can you help my figure this out?


Re: Anti Command Spam - leonardo1434 - 25.06.2012

@Failz0rz


Re: Anti Command Spam - kbalor - 25.06.2012

Quote:
Originally Posted by leonardo1434
View Post
This will just block the player to chat/cmds for 3 seconds.
pawn Code:
public OnPlayerText(playerid, text[])
{
   new lol = GetTickCount();
   if(GetTickCount() - lol < 3000)
   {
    SendClientMessage(playerid,-1,"You will have to wait 3 seconds to write/type any cmd again!");
   }
   return 1;
}
By the way, You're probably using a loop inside your teleport command, So better you remove it.
I can type every seconds and it always saying You will have to wait 3 seconds to write/type any cmd again!

What you mean by this You're probably using a loop inside your teleport command?


Re: Anti Command Spam - Hawky133 - 25.06.2012

Ok. When using ZCMD, you can prevent a player from using a command by returning 0 under
pawn Code:
public OnPlayerCommandReceived(playerid, cmdtext[])
You can also detect when a player successfully uses a command with
pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
//success is equal to the value returned from the command.
If you want to limit a player to using a command once every three seconds, you'll need to use a variable to store the last time the player typed a command.
e.g.
pawn Code:
new lastcommand[MAX_PLAYERS];

So this system would need to look like this:
pawn Code:
new lastcommand[MAX_PLAYERS];

public OnPlayerCommandReceived(playerid, cmdtext[]){
    if( lastcommand[playerid]!=0 && gettime()-lastcommand[playerid]<3 ){
        //This will make sure last command is not 0 (will be 0 if the player hasn't typed a command yet)
        //And make sure 3 seconds have NOT passed since the player last typed a command using a UNIX timestamp- see below for details
        SendClientMessage(playerid,0xFF0000FF,"You can only type ONE command every THREE seconds!");
        return 0;
    }
    return 1;
}

public OnPlayerCommandPerformed(playerid, cmdtext[], success){
    if(success){
        lastcommand[playerid]=gettime();
        //sets the variable to the current UNIX timestamp- see below for details
    }
}

public OnPlayerDisconnect(playerid,reason){
    lastcommand[playerid]=0;
    //reset the variable so the next player who connects will not experience issues
    return 1;
}
This system uses a UNIX timestamp, which is basically the number of seconds since Janurary 1st 1970.


Re: Anti Command Spam - kbalor - 25.06.2012

OMG! iThis is kinda tutorial to me. thanks +REP

Anyway. Its saying Server unknown command.


Re: Anti Command Spam - Hawky133 - 25.06.2012

Oh sorry.
Change
pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
    if(success){
        lastcommand[playerid]=gettime();
        //sets the variable to the current UNIX timestamp- see below for details
    }
}
to

pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
    if(success){
        lastcommand[playerid]=gettime();
        //sets the variable to the current UNIX timestamp- see below for details
    }
    return 1;//Forgot this!
}



Re: Anti Command Spam - kbalor - 25.06.2012

Quote:
Originally Posted by Hawky133
View Post
Oh sorry.
Change
pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
    if(success){
        lastcommand[playerid]=gettime();
        //sets the variable to the current UNIX timestamp- see below for details
    }
}
to

pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
    if(success){
        lastcommand[playerid]=gettime();
        //sets the variable to the current UNIX timestamp- see below for details
    }
    return 1;//Forgot this!
}
and now its not working nothing happens.. i have a Luxadmin filterscript with anti spam should i disable it or remove from the script?


Re: Anti Command Spam - Hawky133 - 25.06.2012

So you're using everything from this:
pawn Code:
new lastcommand[MAX_PLAYERS];

public OnPlayerCommandReceived(playerid, cmdtext[]){
    if( lastcommand[playerid]!=0 && gettime()-lastcommand[playerid]<3 ){
        //This will make sure last command is not 0 (will be 0 if the player hasn't typed a command yet)
        //And make sure 3 seconds have NOT passed since the player last typed a command using a UNIX timestamp- see below for details
        SendClientMessage(playerid,0xFF0000FF,"You can only type ONE command every THREE seconds!");
        return 0;
    }
    return 1;
}

public OnPlayerCommandPerformed(playerid, cmdtext[], success){
    if(success){
        lastcommand[playerid]=gettime();
        //sets the variable to the current UNIX timestamp- see below for details
    }
    return 1;
}

public OnPlayerDisconnect(playerid,reason){
    lastcommand[playerid]=0;
    //reset the variable so the next player who connects will not experience issues
    return 1;
}