Jump to content

AntiSpam


.:HyPeX:.

Recommended Posts

Can someone tell my why its not working properly? its outputting the 3 messages(like it activated the 3 functions) when just saying 1 thing.

----Anti-Spam-Script-by-HyPeX-- 
  
----Locals---- 
local resRoot = getResourceRootElement(getThisResource()) 
  
------------------------------- 
  
----Messages of Startup---- 
outputChatBox ("#00aaff[AntiSpam]: Script v1.2 by HyPeX Started.",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) 
  
antiSpam = {} 
antiSpamFlood = {} 
antiSpamTime = {} 
  
function AntiSpam (message, messageType) 
     if messageType == 0 and isTimer(antiSpam[source]) then  
        killTimer(antiSpam[source]) 
        antiSpamFlood[source] = setTimer(function(source) antiSpamFlood[source] = nil end, 10000, 1, source) 
        outputChatBox("[AntiSpam]: You have been Warned.", source, 0, 170, 255) 
        outputChatBox("[AntiSpam]: If you Spam again withing 10 secs, you will be muted.", source, 0, 170, 255) 
            else 
            antiSpam[source] = setTimer(function(source) antiSpam[source] = nil end, 1000, 1, source) 
            end 
            end 
      
addEventHandler("onPlayerChat", getRootElement(), AntiSpam)    
  
function AntiSpamMute (message, messageType) 
     if isTimer(antiSpamFlood[source]) then  
        outputChatBox("[AntiSpam]: You have been muted for flooding for 5 Mins.", source, 0, 170, 255) 
        outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255) 
    antiSpamTime[source] = setTimer(function(source) antiSpamTime[source] = nil end, 300000, 1, source) 
    AntiSpam1 = True 
            end 
            end 
      
addEventHandler("onPlayerChat", getRootElement(), AntiSpamMute)   
  
function PreventFromMute (message, messageType) 
     if messageType == 0 and isTimer(antiSpamTime[source]) then 
    cancelEvent()  
        outputChatBox("[AntiSpam]: Your message was cancelled becouse you are muted.", source, 0, 170, 255) 
        outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255) 
            end 
            end 
      
addEventHandler("onPlayerChat", getRootElement(), PreventFromMute)  
  
function timerDetails(source) 
    if isTimer(antiSpamTime[source]) then 
        remaining, executesRemaining, totalExecutes = getTimerDetails( antiSpamTime[source] ) 
        outputChatBox("[AntiSpam]: Time left muted: "..remaining/1000, source, 0, 170, 255) 
        else 
        outputChatBox("[AntiSpam]: You are not muted.", source, 0, 170, 255) 
    end 
end 
addCommandHandler("sleft", timerDetails) 
  
function stopping () 
timers = getTimers ( 310000 ) 
for timerKey, timerValue in ipairs(timers) do 
      killTimer ( timerValue ) 
end 
    end 
addEventHandler( "onClientResourceStop", resRoot, stopping) 

Thanks in advance

HyPeX

Link to comment
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]: Your message was cancelled becouse you are muted.", source, 0, 170, 255) 
                outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255) 
                cancelEvent ( ) 
                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 SpamTable[player].Mute = false end end, 5*60*1000, 1, source ) 
                        outputChatBox("[AntiSpam]: You have been muted for flooding for 5 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 ) 

Link to comment

Wow, thanks. I was actually thinking this was caused becouse the functions just triggered altogether (timers just were supposed to be a barrier as same time as timers itself.. but they were triggering themselves in once). But this should work.

Also, you showed me there that i could make a table inside another one, wich helps alot.

Thanks 3NAD

Link to comment

@ Server Side: The variable is general to all players.

For example:

addCommandHandler ( "test", 
    function ( player ) 
        thePlayer = player 
    end 
) 

if i say /test

the variable ( thePlayer ) the Definition will be on me

then if you say /test

the Definition will be on you

So i Advise you to use tables.

Link to comment
@ Server Side: The variable is general to all players.

For example:

addCommandHandler ( "test", 
    function ( player ) 
        thePlayer = player 
    end 
) 

if i say /test

the variable ( thePlayer ) the Definition will be on me

then if you say /test

the Definition will be on you

So i Advise you to use tables.

tables arent being used already by the [source]?

Link to comment

You can make this:

Table = { } 
  
addCommandHandler ( "test", 
    function ( player ) 
        Table[player] = player 
    end 
) 
  
addEventHandler ( "onPlayerQuit", root, 
    function ( ) 
        if Table[source] then 
            outputChatBox ( getPlayerName(source), root ) 
        end 
    end 
) 

Link to comment

Regardless everyhing, i tried to give the players mute even if they left to avoid them from reconnecting and unmuting.. but i really dont see any error here, can someone tell me why the player isnt being muted after loggin in..

  
----Anti-Spam-Script-by-HyPeX-- 
  
----Locals---- 
------------------------------- 
  
----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 SpamTable[player].Mute = false end end, 5*60*1000, 1, source ) 
                        setPlayerMuted(source, true) 
                        setTimer(UnMutePlayer, 5*60*1000, 1) 
                        outputChatBox("[AntiSpam]: ".. (string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "")) .." has have been muted for flooding for 5 Mins.", 0, 170, 255) 
                        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() 
if isPlayerMuted( source ) then 
setPlayerMuted(source, false) 
else 
outputchatbox ( "[AntiSpam]:".. (string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "")) .."is now unmuted!", 0, 175 ,255 ) 
end 
end 
----Manage on quit or join 
function OnPlayerMutedLeft() 
if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime )then 
local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime ) 
local playerAccount = getPlayerAccount(source) 
setAccountData( playerAccount, MutedTimeScript, remaining ) 
setPlayerMuted( source, false) 
killTimer(SpamTable[source].MuteTime) 
else 
setAccountData( playerAccout, MutedtimeScript, 0 ) 
end 
end 
addEventHandler("onPlayerQuit", getRootElement(), OnPlayerMutedLeft) 
  
function OnPlayerMutedJoint() 
local playerAccount = getPlayerAccount(source) 
if getAccountData(playerAccount,MutedTimeScript) > 0 then 
local MutedLeft = getAccountData( playerAccount, MutedTimeScript ) 
setPlayerMuted(source, true) 
setAccountData( playerAccount, MutedTimeScript, 0 ) 
setTimer(UnmutePlayer,  MutedLeft, 1 ) 
SpamTable[source].MuteTime = setTimer ( function ( player ) if isElement ( player ) then SpamTable[player].Mute = false end end, 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(remaining/60/1000), math.fmod(math.floor(remaining/1000),60)), source, 0, 170, 255, true ) 
end 
end 
addEventHandler("onPlayerLogin", getRootElement(), OnPlayerMutedJoint) 
  
  
----Prevent Muted from changing nick 
  
function StopMuted() 
if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime ) then 
outputchatbox ( "[AntiSpam]:".. (string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "")) .."was kicked for trying to change his nick while muted!", 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(p), "#%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 
) 

Link to comment

Try this.

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 
        setPlayerMuted(source, true) 
        setAccountData( acc, "MutedTimeScript", false ) 
        setTimer(UnmutePlayer, tonumber(MutedLeft), 1 ) 
        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(remaining/60/1000), math.fmod(math.floor(remaining/1000),60)), source, 0, 170, 255, true ) 
    end 
end 
addEventHandler("onPlayerLogin", root, OnPlayerMutedJoint) 

Link to comment
If you used 'local' It will be definition on his function,

You can make it general definition by removing 'local' word

but that would interfer the rest of the script, so i'll keep to the locals xD

PD: still not working, im muted after logging in and its not saying anything. Also sleft will not work unless i say something. i'm not seeing any message when i'm muted for 5 mins.

Link to comment
----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 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...