SA-MP Forums Archive
anti cmd flood - 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 cmd flood (/showthread.php?tid=582701)



anti cmd flood - PepsiCola23 - 22.07.2015

YES ! I used the search button,could not find any useful tutorials.

My question is : I want to set a timer so you can not type something in chat for 2 or 3 seconds.If you try to spam you get something [ Don`t Spam ! You can use the chat every 3 seconds ] or something like that .

I want tips on how to make it?


Re: anti cmd flood - Threshold - 22.07.2015

pawn Code:
#include <a_samp>

new LastChat[MAX_PLAYERS], ChatWarns[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    LastChat[playerid] = 0; // Not really necessary, but you can add it if you want.
    ChatWarns[playerid] = 0; // Reset the chat warnings for new players
    return 1;
}

public OnPlayerText(playerid, text[])
{
    new time = gettime(); // Gets the current time as a unix timestamp (seconds)
    if((time - LastChat[playerid]) <= 3) // If the time between their last message and now is less than 3 seconds
    {
        SendClientMessage(playerid, -1, "[ Don`t Spam ! You can use the chat every 3 seconds ]");
        if(++ChatWarns[playerid] >= 3) Kick(playerid); // Kick player if they have spammed at least 3 times
        return 0; // Stops the message being sent to main chat
    }
    LastChat[playerid] = time; // Saving the time of their new message
    ChatWarns[playerid] = 0; // Reset the chat warnings

    // Rest of your OnPlayerText
   
    return 1;
}



Re: anti cmd flood - dominik523 - 22.07.2015

I would try to make something like this using OnPlayerCommandPerformed:
pawn Code:
new LastCommand[MAX_PLAYERS];

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(tickcount() - LastCommand[playerid] < interval)
        return 0;

    LastCommand[playerid] = tickcount();
    return 1;
}
EDIT: I'm really sorry. I thought you want to make anti command flood. Well, you could use the same thing but only in other callback (OnPlayerText).


Re: anti cmd flood - PepsiCola23 - 22.07.2015

Thanks Threshold ,it worked .
@dominik,i did not try yours ,but thanks !

I have one more question Threshold,if a players has an COMMAND FLOODER,and he is flooding,will the server be affected?
If yes,can you tell me how to make something like if send too many messages and dont stop,to get kicked?


Re: anti cmd flood - Threshold - 22.07.2015

I have updated the code in my previous post.

This line:
pawn Code:
if(++ChatWarns[playerid] >= 3) Kick(playerid);
will increase the variable 'ChatWarns[playerid]' by 1. If that reaches 3 or more, they will be kicked. It's up to you to customise this kick, but this will just kick them with no warnings. You can change the limit of '3' to whatever you want.

The warnings get reset if the player stops spamming.


Re: anti cmd flood - PepsiCola23 - 22.07.2015

@Threshold you are awesome mate,thanks !