Script Name: TempBan Spammers
Script Description: This code will allow you to punish people for spamming in your server.
For example: If somebody spams 4 times within a 2 second period then temp ban them for 2 minutes (default settings)
Original Author(s): Bmekim
Core Version: 2.5.4
Code:
const
ALLOWED_SPAM_TIMES = 4;
SPAM_TIME = 2; //in seconds
SPAM_BAN_TIME = 2; //in minutes
var
spamID,spamTimes,spamTime: integer;
function IDtoIP(PlayerID: integer):String;
begin
case PlayerID of
1: Result:= Player_IP_1;
2: Result:= Player_IP_2;
3: Result:= Player_IP_3;
4: Result:= Player_IP_4;
5: Result:= Player_IP_5;
6: Result:= Player_IP_6;
7: Result:= Player_IP_7;
8: Result:= Player_IP_8;
9: Result:= Player_IP_9;
10: Result:= Player_IP_10;
11: Result:= Player_IP_11;
12: Result:= Player_IP_12;
13: Result:= Player_IP_13;
14: Result:= Player_IP_14;
15: Result:= Player_IP_15;
16: Result:= Player_IP_16;
17: Result:= Player_IP_17;
18: Result:= Player_IP_18;
19: Result:= Player_IP_19;
20: Result:= Player_IP_20;
21: Result:= Player_IP_21;
22: Result:= Player_IP_22;
23: Result:= Player_IP_23;
24: Result:= Player_IP_24;
25: Result:= Player_IP_25;
26: Result:= Player_IP_26;
27: Result:= Player_IP_27;
28: Result:= Player_IP_28;
29: Result:= Player_IP_29;
30: Result:= Player_IP_30;
31: Result:= Player_IP_31;
32: Result:= Player_IP_32;
end;
end;
procedure handleSpam(ID: integer);
var
time,timeDiff: integer;
begin
time := strtoint(FormatDate('n')) * 60 + strtoint(FormatDate('s'));
if ID <> spamID then begin
spamID := ID;
spamTimes := 1;
spamTime := time;
end
else begin
spamTimes := spamTimes + 1;
timeDiff := time - spamTime;
if timeDiff < 0 then timeDiff := (3600 - spamTime + time);
if timeDiff <= SPAM_TIME then begin
if spamTimes >= ALLOWED_SPAM_TIMES then begin
SayToPlayer(ID, 'Spam Punishment: ' +inttostr(SPAM_BAN_TIME) +' Minute Ban');
Command('/tempban ' +inttostr(SPAM_BAN_TIME) +' ' +IDtoIP(ID));
Command('/kick ' +inttostr(ID));
spamID := 0;
end;
end
else begin
spamTimes := 1;
spamTime := time;
end;
end;
end;
procedure OnJoinTeam(IP, Nickname: string;Team: byte);
begin
if NameToID(Nickname) = spamID then spamID := 0;
end;
procedure OnLeaveGame(IP, Nickname: string;Team: byte);
begin
if NameToID(Nickname) = spamID then spamID := 0;
end;
procedure OnPlayerSpeak(Name,Text: string);
begin
handleSpam(NameToID(Name));
end;