----Anti-Spam-Script-by-HyPeX--
----Locals----
MuteTimePerMins = 5
-------------------------------
----Messages of Startup----
outputChatBox ("#00aaff[AntiSpam]: Script v2.0 by HyPeX Started.",root, 255, 255, 255, true)
outputChatBox ("#00aaff[AntiSpam]: Special Thanks to 3NAD for helping me.",root, 255, 255, 255, true)
outputChatBox ("#00aaff[AntiSpam]: Aviable commands: sleft",root , 255, 255, 255, true)
-------------------------------
----Functions---
function credits(onPlayerJoin)
outputChatBox ( "Anti-Spam Script By HyPeX Loaded", source, 55, 125, 255 )
end
addEventHandler("onPlayerJoin", root, credits)
SpamTable = { };
AntiSpam = function ( msg, type )
if not SpamTable[source] then
SpamTable[source] = {
Timer = { };
Command = { };
Mute = { };
MuteTime = { };
};
end
if type == 0 then
if SpamTable[source] then
if SpamTable[source].Mute == true then
outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255)
return
end
if SpamTable[source].Command == msg then
if isTimer ( SpamTable[source].Timer ) then
if SpamTable[source].Mute ~= true then
SpamTable[source].Mute = true
SpamTable[source].MuteTime = setTimer ( function ( player ) if isElement ( player ) then UnMutePlayer ( player ) SpamTable[player].Mute = false end end, MuteTimePerMins*60*1000, 1, source )
setPlayerMuted(source, true)
outputChatBox("[AntiSpam]: ".. (string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) .." has have been muted for flooding for "..MuteTimePerMins.." Mins.", source, 0, 170, 255)
cancelEvent ( ) return
end
end
cancelEvent ( )
outputChatBox ( "[AntiSpam]: You have been Warned.", source, 0, 170, 255, true )
outputChatBox ( "[AntiSpam]: If you Spam again withing 10 secs, you will be muted.", source, 0, 170, 255, true )
SpamTable[source].Timer = setTimer ( function ( player ) if isElement ( player ) then SpamTable[player].Command = nil end end, 10000, 1, source )
else
SpamTable[source].Command = msg
end
end
end
end
addEventHandler ( "onPlayerChat", root, AntiSpam )
function timerDetails ( source )
if SpamTable[source].MuteTime then
if isTimer ( SpamTable[source].MuteTime ) then
local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime )
outputChatBox ( "[AntiSpam]: Time left muted: "..string.format ( '%02d:%02d', math.floor(remaining/60/1000), math.fmod(math.floor(remaining/1000),60)), source, 0, 170, 255, true )
else
outputChatBox ( "[AntiSpam]: You are not muted.", source, 0, 170, 255, true )
end
end
end
addCommandHandler ( "sleft", timerDetails )
addEventHandler ( "onResourceStop", resourceRoot,
function ( )
for i, v in ipairs ( getElementsByType ( "player" ) ) do
onDeleteTables ( v )
end
end
)
onDeleteTables = function ( player )
if not player then
player = source
end
SpamTable[player] = nil
end
addEventHandler ( "onPlayerQuit", root, onDeleteTables )
----UnmutePlayer
function UnMutePlayer(player)
if isElement ( player ) then
if isPlayerMuted( player ) then
setPlayerMuted(player, false)
else
outputChatBox ( "[AntiSpam]:".. (string.gsub(getPlayerName(player), "#%x%x%x%x%x%x", "")) .."is now unmuted!",player,0, 175 ,255 )
end
end
end
----Manage on quit or join
function OnPlayerMutedLeft()
local playerAccount = getPlayerAccount(source)
if not isGuestAccount ( playerAccount ) then
if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime )then
local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime )
if remaining then
setAccountData( playerAccount, "MutedTimeScript", tostring(remaining) )
setPlayerMuted( source, false)
killTimer(SpamTable[source].MuteTime)
end
else
setAccountData( playerAccount, "MutedtimeScript", false )
end
end
end
addEventHandler("onPlayerQuit", root, OnPlayerMutedLeft)
function OnPlayerMutedJoint ( _, acc )
local MutedLeft = getAccountData( acc, "MutedTimeScript" )
if MutedLeft then
if not SpamTable[source] then
SpamTable[source] = {
Timer = { };
Command = { };
Mute = { };
MuteTime = { };
};
end
setPlayerMuted(source, true)
setTimer(UnMutePlayer, tonumber(MutedLeft), 1, source )
SpamTable[source].MuteTime = setTimer ( function ( player ) if isElement ( player ) then SpamTable[player].Mute = false end end, tonumber(MutedLeft), 1, source )
outputChatBox ( "[AntiSpam]: Welcome back, here's your time left muted:", source, 0, 170, 255, true )
outputChatBox ( "[AntiSpam]: Time left muted: "..string.format ( '%02d:%02d', math.floor(MutedLeft/60/1000), math.fmod(math.floor(MutedLeft/1000),60)), source, 0, 170, 255, true )
setAccountData( acc, "MutedTimeScript", false )
end
end
addEventHandler("onPlayerLogin", root, OnPlayerMutedJoint)
----Prevent Muted from changing nick
function StopMuted()
if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime ) then
outputChatBox ( "[AntiSpam]:".. (string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) .."was kicked for trying to change his nick while muted!", source,0, 175 ,255 )
kickPlayer( source, AntiSpam, "You are muted dont change ur nick!" )
cancelEvent()
end
end
addEventHandler("onPlayerChangeNick", getRootElement(), StopMuted)
local disabledCmds =
{
[ "me" ] = true,
[ "pm" ] = true
}
addEventHandler ( "onPlayerCommand", root,
function ( cmd )
if disabledCmds [ cmd ] then
if isPlayerMuted ( source ) or isTimer ( SpamTable[source].MuteTime) then
outputChatBox ( "[AntiSpam]: ".. (string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) .." was kicked for trying to use commands while muted!", root, 0, 175 ,255 )
kickPlayer ( source, "AntiSpam: Dont try to use commands while muted!" )
end
end
end
)