Auto mute-unmute for spam.

Started by KAKAN, Oct 21, 2015, 06:01 PM

Previous topic - Next topic

KAKAN

1st of all, we need to create the arrays, and some variables:-
Add this on the top of your script.
LIMIT_REP_SPAM <- 3;
MUTE_TIME <- 30000;
LIMT_REP_TIME <- 2;
1st one( LIMIT_REP_SPAM ), is the time the player can spam continuously.
2nd one(MUTE_TIME ), is the time the player will be muted( in ms )
3rd one( LIMIT_REP_TIME ), is the time limit of the player of the spam.
function onScriptLoad() {
IsMuted <- array( GetMaxPlayers(), false);
  antiSpamTime <- array( GetMaxPlayers(), 0 );
  antiSpamWarnings <- array( GetMaxPlayers(), 0 );
}
We need to clear the mute thing when a player leaves the server.
function onPlayerPart( player, reason ) {
IsMuted[ player.ID ] = false;
}
Now, we'll use those variables/arrays created.
function onPlayerChat( player, message ) {
local MUTE_DIVIDE = 1000;
       if ( ( time() - antiSpamTime[ player.ID ] ) <= LIMT_REP_TIME ) {
 antiSpamWarnings[ player.ID ]++;
 if ( antiSpamWarnings[ player.ID ] >= LIMIT_REP_SPAM ) {
  if( !IsMuted[ player.ID ] ){
    IsMuted[ player.ID ] = true;
    Message(format(">> Auto-Muted: %s Reason: Spamming the Chat. Duration[ %d seconds ]",player.Name,MUTE_TIME/MUTE_DIVIDE) );
    NewTimer("autounmute",MUTE_TIME.tointeger(),1,player.ID);
  }
 }
} else {
 antiSpamWarnings[ player.ID ] = 0;
}
antiSpamTime[ player.ID ] = time();

if( IsMuted[ player.ID] ){
return 0;
MessagePlayer(">> You are muted.",player);
}
else{
return 1;
//Have your code here
}
}
We were about to block him for 30 seconds.
So, we need to unmute him.
function autounmute(playerID)
{
local player = FindPlayer(playerID)
if (player && IsMuted[ player.ID ] )
{
        Message(">> Auto-UnMuted " + player.Name + " Reason: Mute time over."+ ".");
                IsMuted [ player.ID ] = false;
}
}
Feel free to post the bugs below.
Don't forget to give me credits.
Peace.
oh no

Decent_946

OnPlayerChat:-

if( IsMuted[ player.ID )
if( IsMuted[ player.ID ] )
only this small error..
everything else is perfect and works fine :)

update it.

KAKAN

That would've caused major errors.
Thanks for finding out the bug,
oh no

EK.IceFlake

...
LIMIT_REP_SPAM <- 3;
MUTE_TIME <- 30000;
LIMT_REP_TIME <- 2;
!!!
Uselessly spamming the root table like ultra noobs. There's a reason constants exist.
const LIMIT_REP_SPAM = 3;
const MUTE_TIME = 30000;
const LIMT_REP_TIME = 2;

KAKAN

"Uselessly spamming "
You used 3 lines and I too. So, no spam.
We can use enum there, local too.
THat's the way I liked the most. So did it, if u want, change it yourself.
oh no

Gito Baloch

Programming is the language I speak, the world I shape, and the future I code

habi