[Tutorial] Simple anti-spam
#1

Hello everyone this is my 1st TUT
I Hope you will like it
Big but easy to understand
Quote:

#define MAX_SPAMWARNS 3
You Can Change 3 to the max_warns you want like MAX_SPAMWARNS 5
Same with spam lines
Quote:

#define SPAMRATESECS 2000

You can change 2000 to 3000 - 4000 etc etc [Here 1000 = 1 sec 2000 = 2 secs and so on]
Code:
// global vairiables
new SPAMwarns[MAX_PLAYERS]; //SPAM WARNS R DEFAULT TO 3 YOU CAN CHANGE THEM IN Max_SPAMwarns :)

new playersSPAM[MAX_PLAYERS]; //it will increase +1 as player types text later when we give instructions :D

new timer[MAX_PLAYERS];
new timer2[MAX_PLAYERS];
// now the forwards call back functions
forward cSPAM(playerid); //to check the number of SPAMs by a player
forward cSPAMwarns(playerid); // checking number of SPAM warns
new Text:warn;
new Text:credits;
Everything is given in comments though

Code:
public cSPAM(playerid)
{
if (playersSPAM[playerid] >= SPAMLINES) // if playerspam is greater then SPAMlines then SPAM warns will be +1
    {
	SPAMwarns[playerid] +=1;
    SendClientMessage(playerid,0x10F441AA,"You have been warned for SPAMing");
    new string[256];
    TextDrawShowForPlayer(playerid,warn);
    format(string,256, "Warned~n~~r~~n~You are warned for~n~~r~~n~SPAMing~n~~n~~w~Click Fire Button to close ~n~this box");
    TextDrawSetString(warn,string);

   	playersSPAM[playerid] =0;
	}
else playersSPAM[playerid] =0;
return 1;
}
1st of all we will check if playerspam is more then spamlines or not if its true then the player will be give a warn with the a textdraw else playerspam will be reseted to 0

Code:
public cSPAMwarns(playerid)
{
   if (SPAMwarns[playerid] >= MAX_SPAMWARNS ) // if SPAM warns are more then or = 3 the player will get kicked :D
   {
   new string[256];
   new pname[126];
   GetPlayerName(playerid,pname,sizeof(pname));
   SetPlayerInterior(playerid,10);
   SetPlayerPos(playerid,215.5644,110.7332,999.0156);
   Kick(playerid);
   format(string,sizeof(string),"%s[%d] has been kicked from the server for SPAMing");
   SendClientMessageToAll(0xFF0000C8,string);
   SPAMwarns[playerid] =0;
   }
   return 1;
}
Same here too If warns are greater than max_spamwarns then the player will be telelported to jail and then will be kicked

Code:
public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("Anti SPAM by Pulkit :D");
	print("--------------------------------------\n");
    warn = TextDrawCreate(7.000000, 123.000000, "");
    TextDrawAlignment(warn, 0);
    TextDrawLetterSize(warn, 0.399999, 0.800000);
    TextDrawColor(warn, 0xffff00ff);
    TextDrawSetOutline(warn, 1);
    TextDrawSetProportional(warn, 1);
    TextDrawSetShadow(warn, 1);
    
    credits = TextDrawCreate(7.000000, 123.000000, "");
    TextDrawAlignment(credits, 0);
    TextDrawLetterSize(credits, 0.399999, 0.800000);
    TextDrawColor(credits, 0xffff00ff);
    TextDrawSetOutline(credits, 1);
    TextDrawSetProportional(credits, 1);
    TextDrawSetShadow(credits, 1);
	return 1;
}
Here we are creating textdraw for the players at 7.000000, 123.000000 pixels of the screen [640*480 i guess]

Code:
public OnPlayerConnect(playerid)
{
	playersSPAM[playerid] = 0;
	SPAMwarns[playerid] =0;
    timer[playerid] = SetTimerEx("cSPAM",SPAMRATESECS,true,"i",playerid);
    timer2[playerid] = SetTimerEx("cSPAMwarns",SPAMRATESECS,true,"i",playerid);
	return 1;
}
Here when the player connects his/her spam is setted to 0 and spam warns too
and a timer is started
It will restart forwards every 2secs [#define SPAMRATESECS 2000 //here ]

Code:
public OnPlayerDisconnect(playerid, reason)
{
    playersSPAM[playerid] = 0;
    KillTimer(timer[playerid]);
    KillTimer(timer2[playerid]);
	return 1;
}
here when the player disconnects his spam is setted to 0 and the timers are killed
Code:
public OnPlayerText(playerid, text[])
{
    playersSPAM[playerid] +=1;
	return 1;
}
Then here when the player types text playersSpam is added +1 and if this is not reached to 3 then its resseted in our
Code:
public cSPAM(playerid)
Here is the fs
Here
Thats all
Reply
#2

Okay let's forget the code and tutorial for a minute, But why the hell are you using [Quote] tags!!
Reply
#3

where? ......
Reply
#4

Why textdraws for an anti-spam?
Reply
#5

Cause they are cool?
Reply
#6

No they aren't.
Reply
#7

That with the Textdraw is a little bit useless.
Reply
#8

Derp. SPAMLINES is nothing, it would be impossible to make this work (i think)
Reply
#9

This it's not simple
Reply
#10

Just set the player's health to infinity for 5 seconds..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)