SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/12/2011, 08:35 PM   #1
BlackWolf120
Gangsta
 
BlackWolf120's Avatar
 
Join Date: Nov 2010
Location: Germany
Posts: 761
Reputation: 50
Lightbulb Simple and effective Anti-Spam

hi SAMPers

Due to some requests via pm and the need of an anti-spam script myself i decided to make one and also post it as a tutorial as it seems there wouldnt be any good anti spam scripts released.
I dont like any additional timers in my gamemode, so i didnt use any in this script as well. (except the automatic unmute timer)

So, what is this tutorial about?

This tutorial shows you how to make a simple and effective anti spam for your server chat (you can use the same method/variables also for a command anti spam ofc ) without any timers.

Difficulity: Easy

So lets get started:

pawn Code:
//Definings:
new SpamCount[MAX_PLAYERS];
new ChatSpamTime[MAX_PLAYERS][3];
new muted[MAX_PLAYERS];

//How long it takes a player gets unmuted automatically (in minutes):
#define AutoUnmuteTime 2 //You can adjust this to your needs ofc ;)

pawn Code:
public OnPlayerText(playerid, text[])//This Callback is called as soon as a player types smth. into the chat.
{

    if(muted[playerid] == 1)//If the player has been muted he will get this message:
    {
        SendClientMessage(playerid, 0xFF0000FF, "You have been muted!");
        return 0;
    }
    else
    {
        if(Player[playerid][AdminLevel]==0)//To prevent admins beeing muted. Ofc you have to adjust this!
        {
            AntiSpam(playerid);//A stock function we will set up later...
        }
        //Your other chat codes here...
    }
    return 1;
}

pawn Code:
stock AntiSpam(playerid)//stock function
{
    SpamCount[playerid]++;//Everytime a player types smth. in the chat this variable gets increased by one.
    switch (SpamCount[playerid])//switch between the SpamCount variable.
    {
        case 1://If a player types smth. into the chat for the first time...
        {
            ChatSpamTime[playerid][0]=gettime();//Get the unix timestamp and save it into a variable.
            //ChatSpamTime[playerid][0] this variable is our first variable. The array is "0" for the first one not "1"!
        }
        case 2://If the player types smth. into the chat the second time...
        {
            if((gettime()-ChatSpamTime[playerid][0])<4)//We check if the Time between the players first and
            {
                //second chat is more or less than 4 seconds. In case the player chatted faster than 4 seconds
                //We will give him his first warning ...
                SendClientMessage(playerid,0xFF0000FF,"You have received a warning (1/3)! (Reason: Spam)");
                ChatSpamTime[playerid][1]=gettime();//and we save his chat time again to another variable.

                //Lets take a closer look at this: gettime()-ChatSpamTime[playerid][0].
                //We use gettime() to get the current unix timestamp and we simply subtract the time we
                //saved before (as the player chatted the first time). Always make sure to subtract the older
                //timestamp from the newer one as the newer timestamp is always bigger!
            }
            else SpamCount[playerid]=0;//If the player needed longer than 4 seconds to send another
            //chat message we reset his SpamCount variable bac to 0. (as he is obviously not spamming or a very slow spammer ;) )
        }
        case 3://If the player types smth. into the chat the third time...
        {
            if((gettime()-ChatSpamTime[playerid][1])<4)//We check how long it took the player to send another message after the 2nd one.
            {
                //If the player send another message faster than 4 seconds he is obviously spamming and we give
                //him a 2nd warning as we dont want to be that cruel to spammers right? ;)
                SendClientMessage(playerid,0xFF0000FF,"You have received a warning (2/3)! (Reason: Spam)");
                ChatSpamTime[playerid][2]=gettime();//Again save his chat time for this message to another variable.
            }
            else SpamCount[playerid]=0;//In case the player calmed down, reset his SpamCount variable.
        }
        case 4..50://In case the certain player gets the idea to spam again...
        {
            new string[128],name[24];
            GetPlayerName(playerid,name,24);//Save the spammers name into the string variable "name".
            if((gettime()-ChatSpamTime[playerid][2])<4)//We get sure again if it took the player less than 4 secs.
            {
                //If so then ...
                format(string,sizeof(string),"Player %s has been muted for 2 minutes! (Reason: Spam!)",name);
                SendClientMessageToAll(0xFF0000FF,string);
                //We send a message visible for all players...
                SendClientMessage(playerid,0xFF0000FF,"You have received your final warning (3/3)! (Reason: Spam)");
                //Send the player another warning messsage ;)
                muted[playerid]=1;//we mute him
                SetTimerEx("AutoUnMute",AutoUnmuteTime*60000,false,"i",playerid);//And finally set the timer for the automatic unmute.
//==> 60000 milliseconds = 1 minute. So AutoUnmuteTime that has been defined on top of the script can be used
//with minutes (you dont have to enter the time in milliseconds but in minutes)
            }
            //Lets take a closer look at this: case 4..50:
            //A player could possibly get a higher SpamCount variable than 4, in this case he wouldnt be muted!
            //But its impossible to chat 50 times within 4 seconds right? ;)
        }
    }
    return 1;
}

pawn Code:
public OnPlayerConnect(playerid)
{
    SpamCount[playerid]=0;//Reset the SpamCount variable so no player can get muted wrongly after connect!
    muted[playerid]=0;//same for mute variable!
    return 1;
}

pawn Code:
forward AutoUnMute(pID);//forward our timer.
public AutoUnMute(pID)//This is our timer that unmutes the muted player automatically.
{
    muted[pID] = 0;
    SpamCount[pID]=0;
    //Unmute the player and inform him about the new circumstance ;)
    SendClientMessage(pID, 0xFF0000FF, "You have been unmuted automatically!");
    return 1;
}

Thats pretty much it! You wont see any spammers on your server anymore

Sometimes i suck at explaining so in case you didnt understand smth. i would be glad to help you.
Comments and suggestions are appreciated as well

I hope this will be helpfull to some of you.


Best regards, wolf.
__________________

Last edited by BlackWolf120; 08/12/2011 at 01:28 PM.
BlackWolf120 is offline   Reply With Quote
Old 04/12/2011, 11:00 PM   #2
Tanush123
High-roller
 
Tanush123's Avatar
 
Join Date: Aug 2011
Posts: 1,022
Reputation: 65
Default Re: Simple and effective Anti-Spam

Good job wolf, this looks very good.
Tanush123 is offline   Reply With Quote
Old 07/12/2011, 07:43 PM   #3
BlackWolf120
Gangsta
 
BlackWolf120's Avatar
 
Join Date: Nov 2010
Location: Germany
Posts: 761
Reputation: 50
Default Re: Simple and effective Anti-Spam

thx tanush
__________________
BlackWolf120 is offline   Reply With Quote
Old 07/12/2011, 07:59 PM   #4
Pinguinn
Huge Clucker
 
Join Date: Aug 2011
Location: The Netherlands
Posts: 313
Reputation: 34
Default Re: Simple and effective Anti-Spam

Nice tutorial, well explained, but I think it would be easier for noobs to explain why you used "AutoUnMuteTime*60000" (I am talking about the bold part) and maybe also say whether its in milliseconds, seconds or minutes
Pinguinn is offline   Reply With Quote
Old 08/12/2011, 01:29 PM   #5
BlackWolf120
Gangsta
 
BlackWolf120's Avatar
 
Join Date: Nov 2010
Location: Germany
Posts: 761
Reputation: 50
Thumbs up Re: Simple and effective Anti-Spam

thx.
Ive added a short comment about that as well
__________________
BlackWolf120 is offline   Reply With Quote
Old 16/08/2013, 07:45 AM   #6
qazwsx
Huge Clucker
 
qazwsx's Avatar
 
Join Date: Jun 2013
Location: Semarang,Indonesia
Posts: 409
Reputation: 55
Default Re: Simple and effective Anti-Spam

Good Tutorial, Seems very effective.
Thanks for the tutorial mate
__________________
Ive left SAMP Scripting. I wont keep the update of my gamemodes. I might come back someday later, but didnt think about to come back to scripting ATM. However, I'd always come around to forums, chcking stuffs happened, and responds to thoose who have give their feedback on my gamemode.

-Regard
qazwsx
qazwsx is offline   Reply With Quote
Old 16/08/2013, 08:06 AM   #7
-Prodigy-
Huge Clucker
 
Join Date: Dec 2010
Posts: 399
Reputation: 45
Default Re: Simple and effective Anti-Spam

Quote:
Originally Posted by BlackWolf120 View Post
as it seems there wouldnt be any good anti spam scripts released.
You base that on what? A simple search brings dozens of anti-spam scripts. Some being better than yours.
-Prodigy- is offline   Reply With Quote
Old 10/12/2013, 02:26 AM   #8
AnonymouseSAMP
Big Clucker
 
AnonymouseSAMP's Avatar
 
Join Date: Jan 2013
Posts: 66
Reputation: 4
Default Re: Simple and effective Anti-Spam

THANKS WOLF!
__________________
If your topic says"Rep+" I willKillYou
AnonymouseSAMP is offline   Reply With Quote
Old 10/12/2013, 02:11 PM   #9
Legit X ionz
Little Clucker
 
Join Date: Jul 2012
Posts: 40
Reputation: 0
Thumbs up Re: Simple and effective Anti-Spam

Great work, I really needed something like this.

Although I could barely get it in, my other developer got it working. Thank you.

Legit.
Legit X ionz is offline   Reply With Quote
Old 29/10/2019, 03:49 PM   #10
DarkWorldJack
Big Clucker
 
DarkWorldJack's Avatar
 
Join Date: Dec 2015
Location: Italy
Posts: 54
Reputation: 1
Default Re: Simple and effective Anti-Spam

good job
DarkWorldJack 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
[FilterScript] Very simple car Signaling System v2 with Anti-Spam! useful for RP/GF servers! Edvin Filterscripts 2 20/09/2011 02:04 PM
[FilterScript] Spam Prevention System (Anti Spam) Luka P. Filterscripts 9 14/09/2011 01:56 PM
Anti Money Hack: Is this effective? BlackWolf120 Scripting Help 12 28/08/2011 08:13 PM
[FilterScript] [FS] Simple Anti-Spam. ChristopherM Filterscripts 8 24/01/2011 05:49 AM
[Include] [INC] NoSpam - simple anti spam solution Donny_k Includes 4 13/01/2010 11:19 AM


All times are GMT. The time now is 12:17 PM.


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