SA-MP Forums Archive
[Tutorial] Simple anti-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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Simple anti-spam (/showthread.php?tid=396895)



Simple Anti-spam - Dark Killer - 02.12.2012

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


Re: Simple anti-spam - iSaad - 02.12.2012

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


Re: Simple anti-spam - Dark Killer - 15.12.2012

where? ......


Re: Simple anti-spam - Lordzy - 15.12.2012

Why textdraws for an anti-spam?


Re: Simple anti-spam - Dark Killer - 03.02.2013

Cause they are cool?


Re: Simple anti-spam - JaKe Elite - 03.02.2013

No they aren't.


AW: Simple anti-spam - Blackazur - 03.02.2013

That with the Textdraw is a little bit useless.


Re: Simple anti-spam - [WA]iRonan - 03.02.2013

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


Re: Simple anti-spam - BlackHorse - 05.08.2013

This it's not simple


Re: Simple anti-spam - Areax - 05.08.2013

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