AntiSpam commands
#1

How to make an AntiSpam commands system?
I tried with a Timer but failed not much but i couldnt use on all cmds i want

Thanks!
Reply
#2

Very simple, but should work (as always untested):

pawn Code:
new lastcmd[MAX_PLAYERS];

public OnPlayerCommandText(playerid, cmdtext[]) {
    if(GetTickCount() - lastcmd[playerid] < 1000 && lastcmd[playerid] != 0)
    {
        SendClientMessage(playerid, 0xAA3333AA, "You are using commands too fast! Slow down.");
        return 1;
    }
    lastcmd[playerid] = GetTickCount();

(...)
If you want to, you can add an counter, that increases with every spam and kick the player if he spams e.g. 5 times i a row.
Reply
#3

Other mode:
I made a tutorial in Portuguese for a forum Brazilian, I translate using ****** Translator and here is he:

This tutorial will teach basically how to avoid flood command on your server.
Requirement: Server Version 0.3A or newer R7.

First step (it is good that you go doing there):

Every time the the player enters the chat this: "/", OnPlayerCommandText the callback is called once to prevent him from sending several commands at once just when the callback is called, set the player who used to command and after a while adjust as who did not use, of course, so he can use commands again.

Then in early OnPlayerCommandText put it:
pawn Code:
SetTimerEx ("CmdTimerOff", 3000, false,"i", playerid);
Timer (in milliseconds) to be able to use it again within 3 seconds.
"CmdTimerOff" is also a callback to be called at 3 seconds
to adjust how the player who did not use command. I will detail it better later on.
pawn Code:
if (GetPVarInt (playerid, "UsouCMD") == 0)
it verifies that it is set as one who used Command.
pawn Code:
SetPVarInt (playerid, "UsouCMD", 1);
it sets him as one who used Command.
The key is open until the end of his commands see below:
pawn Code:
public OnPlayerCommandText (playerid, cmdtext [])
{
  SetTimerEx ("CmdTimerOff ", 3000, false,"i", playerid);
  if (GetPVarInt (playerid, "UsouCMD") == 0)
  {
       SetPVarInt (playerid, "UsouCMD", 1);
       if (strcmp ("/cmd", cmdtext, true) == 0)
       {
       SendClientMessage (playerid, COLOR, "TEXT");
       return 1;
       }

       if (strcmp ("/ cmd2" cmdtext, true) == 0)
       {
       SendClientMessage (playerid, COLOR, "STRING2");
       return 1;
       }
   } / / Close key
//Okay, now let's make an error message if it is Flood, right here.
   else {
   return SendClientMessage (playerid, COLOR, "Wait a moment please (anti-flood ).");
   }

return 0; //return if the command is invalid
}
Ready to do what was in the callback OnPlayerCommandText was it, now let the timer function and adjust the player who did not use as command.

It's simple, see:
pawn Code:
forward CmdTimerOff (playerid);
public CmdTimerOff (playerid)
{
return DeletePVar (playerid, "UsouCMD");
}
As you may remember we had a timer in there OnPlayerCommandText to perform this callback,
it deletes the variable from the player so he can use command again.
So that's it, I used the functions pVar because they are simpler and more advantageous when it comes to variables for many players specifically.
Reply
#4

I only tested the first Script,works perfectly
Thanks
Reply
#5

Quote:
Originally Posted by ColdXX
View Post
I only tested the first Script,works perfectly
Thanks
Whatever, is good learn the two modes for use in other functions, this is my opinion.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)