Jump to content

Help with Anti-Flood Script


Evil-Cod3r

Recommended Posts

Hi All i have Made this i want if i spam in the NormalChat Only 3 times give me wirnning 3 times after that give Kick with Msg

and can i add sesting in meta.xml ?

for example

< sesting = "true" = give him kick

sesting = "false" = give him mute Only ?

Help please

local timer = { } 
function flood (msg, msgType) 
elseif timer = {3} then 
if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) then 
if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 1/0",source,255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 2/2",source,255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 3/3",source,255,255,0) 
    outputChatBox(getPlayerName(source) .."Has Been Kicked For Flooding the Chat 3/3",255,0,255) 
   kickPlayer ( source, "You Have Been Kicked For Flooding The Chat !") 
end 

Link to comment

Please read all comments.

  
local timer = { } 
function flood (msg, msgType) -- where is source ? or maybe you use event?If you use event then you not needed add source to argument function. 
elseif timer = {3} then -- this is syntax error. Delete this row. 
if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) then 
if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then -- accountname is nil 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 1/0",source,255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 2/2",source,255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 3/3",source,255,255,0) 
    outputChatBox(getPlayerName(source) .."Has Been Kicked For Flooding the Chat 3/3",255,0,255) 
   kickPlayer ( source, "You Have Been Kicked For Flooding The Chat !") 
end 
-- missing end 
  

Updated.

Link to comment

You Mean Like this ?

local timer = { } 
local yes = true 
function flood (msg, msgType) 
if yes then --- if yes = give him Kick else = mute only for 15 sec .. who to do that ? 
if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) then 
local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) 
if isObjectInACLGroup ( "user." .. accName, aclGetGroup ( "BigAdmin" ) ) then 
else 
    outputChatBox("You Have To Be Big Admin To Run This Script !!!",source, 255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 1/0",source,255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 2/2",source,255,255,0) 
    outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 3/3",source,255,255,0) 
    outputChatBox(getPlayerName(source) .."Has Been Kicked For Flooding the Chat 3/3",255,0,255) 
   kickPlayer ( source, "You Have Been Kicked For Flooding The Chat !") 
end 
end 

Link to comment
local setting = get("kick") 
  
function flood(msg,msgType) 
         if setting == true then 
                 outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 1/0",source,255,255,0) 
                 outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 2/2",source,255,255,0) 
                 outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 3/3",source,255,255,0) 
                 outputChatBox(getPlayerName(source) .."Has Been Kicked For Flooding the Chat 3/3",255,0,255) 
                 kickPlayer ( source, "You Have Been Kicked For Flooding The Chat !") 
         else 
                 setPlayerMuted(source,true) 
                 setTimer(setPlayerMuted,15000,1,source,false) 
         end 
end 

Like this?

Or like this:

function flood(msg,msgType) 
       local setting = get("kick") 
             if setting == true then 
                 setTimer ( outputChatBox, 1500, 1, "Don't repeat again or you will be kicked! - First time" ) 
                 setTimer ( outputChatBox, 3000, 1, "Don't repeat again or you will be kicked! - Second time" ) 
                 setTimer ( outputChatBox, 5000, 1, "Don't repeat again or you will be kicked! - Third time" ) 
                 outputChatBox(getPlayerName(source).." has been kicked for flooding chat!",root,255,0,255,false) 
                 kickPlayer(source,"You have been kicked for flooding!") 
             else 
                 setPlayerMuted(source,true) 
                 setTimer( 
                     function() 
                             setPlayerMuted(source,false) 
                             outputChatBox("You have been unmuted!",source,0,255,0,false) 
                     end, 
                 15000,1) 
             end 
end 
  

You have to integrate this in your code.

Link to comment

clearly that will give all the warnings in one go and is nothing like what hes after..

he asked for: after 3 lines of spam to give a warning 1/3 + msg , then warning 2/3 + msg and finally warning 3/3 + msg + kick

the script posted is nothing like what he needs, its more like a function with a load of outputchatbox lines :roll:

sorry i dont have time right now to help tho :oops:

Link to comment

Settings registry is my area :D.

Get returns a string, not a Boolean.

I hope you have added your spam count.

Assuming your using onPlayerChat.

  
function flood (msg, msgType) 
if ( hasObjectPermissionTo ( getThisResource (), "function.kickPlayer", true ) ) and ( hasObjectPermissionTo ( getThisResource (), "function.setPlayerMuted", true ) ) then 
    if not isObjectInACLGroup ( "user." .. getAccountName(getPlayerAccount(source)), aclGetGroup ( "admin" ) ) then -- doesnt kick admin for spamming. 
        if get("kick") == "true" then 
            outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 1/0",source,255,255,0) 
            outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 2/2",source,255,255,0) 
            outputChatBox("Please Dont Repate more then 3 Times or You Well Be Kicked. 3/3",source,255,255,0) 
            outputChatBox(getPlayerName(source) .." Has Been Kicked For Flooding the Chat 3/3",255,0,255) 
            kickPlayer ( source, "You Have Been Kicked For Flooding The Chat !") 
        elseif get("kick") == "false" then 
            outputChatBox("Please Dont Repate more then 3 Times or You Well Be Muted. 1/0",source,255,255,0) 
            outputChatBox("Please Dont Repate more then 3 Times or You Well Be Muted. 2/2",source,255,255,0) 
            outputChatBox("Please Dont Repate more t hen 3 Times or You Well Be Muted. 3/3",source,255,255,0) 
            outputChatBox(getPlayerName(source) .."Has Been Muted For Flooding the Chat 3/3",255,0,255) 
            setPlayerMuted(source,"You Have Been Kicked For Flooding The Chat!") 
        end 
    end 
end 
end 
  

Link to comment

I know this isnt exactly what youve asked for evil, but this is close, i used it on my server for a long time and it seemed to work pretty well for me. give it a try and see what u think.

dont forget to give rights for the script to kick/mute in the acl. (im sure u wouldnt but :mrgreen:)

local spam = {} 
local setting = get("kick") -- true = kick, false = mute 
  
function loseSpam(player) 
    if spam[player] > 0 then 
        spam[player] = spam[player] - 1 
    end  
end 
  
function onChat ( message, messageType ) 
    --if messageType == 0 then -- this will work for all chat, remove the -- to change to just normal chat. 
        spam[source] = spam[source] or 0 
        spam[source] = spam[source] + 1 
        if spam[source] == 3 then  
            outputChatBox("Warning - Do Not Spam! ",source,255,0,0) 
        else 
            if spam[source] > 3 then 
                if setting then 
                    outputChatBox("Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",getRootElement(),255,0,0) 
                    kickPlayer(source,"You Have Been Kicked For Flooding!") 
                else 
                    setPlayerMuted(source,true) 
                    outputChatBox(getPlayerName(source) .. " Has Been Auto Muted [3 mins]",getRootElement(),255,0,0) 
                    setTimer(setPlayerMuted,180000,1,source,false) 
                end 
            end 
        end 
        setTimer(loseSpam,2000,1,source) 
    --end 
end 
addEventHandler ( "onPlayerChat", getRootElement(), onChat) 
  
function quitPlayer() 
        spam[source] = nil 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) 

Link to comment

You Mean Like This

local spam = {} 
local setting = get("kick") 
  
function loseSpam(player) 
    if spam[player] > 0 then 
        spam[player] = spam[player] - 1 
    end  
end 
  
function onChat ( message, messageType ) 
        spam[source] = spam[source] or 0 
        spam[source] = spam[source] + 1 
        if spam[source] == 3 then  
            outputChatBox("Warning - Do Not Spam! ",source,255,0,0) 
        else 
            if spam[source] > 3 then 
                if setting then 
                    outputChatBox("Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",getRootElement(),255,0,0) 
                    kickPlayer(source,"You Have Been Kicked For Flooding!") 
                else 
                    setPlayerMuted(source,true) 
                    outputChatBox(getPlayerName(source) .. " Has Been Auto Muted [20 sec]",getRootElement(),255,0,0) 
                    setTimer(setPlayerMuted,20000,1,source,false) 
                end 
            end 
        end 
        setTimer(loseSpam,2000,1,source) 
end 
addEventHandler ( "onPlayerChat", getRootElement(), onChat) 
  
function quitPlayer() 
        spam[source] = nil 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) 

meta.xml

    type="script" name="Anti-Flood" author="Evil-Cod3r" description="" version="1.0" /> 
    

Link to comment

Ive told you once...

Get returns a STRING, NOT A BOOLEAN!

This is incorrect...

     if setting then 
                    outputChatBox("Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",getRootElement(),255,0,0) 
                    kickPlayer(source,"You Have Been Kicked For Flooding!") 
                else 
                    setPlayerMuted(source,true) 
                    outputChatBox(getPlayerName(source) .. " Has Been Auto Muted [20 sec]",getRootElement(),255,0,0) 
                    setTimer(setPlayerMuted,20000,1,source,false) 
     end 

"setting" is returning a string ("true" or false). It is not returning a Boolean value (true or false)

     if setting == "true" then 
                    outputChatBox("Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",getRootElement(),255,0,0) 
                    kickPlayer(source,"You Have Been Kicked For Flooding!") 
                elseif setting == "false" 
                    setPlayerMuted(source,true) 
                    outputChatBox(getPlayerName(source) .. " Has Been Auto Muted [20 sec]",getRootElement(),255,0,0) 
                    setTimer(setPlayerMuted,20000,1,source,false) 
     end 

Link to comment

its say server.lua:21 expected near then

local spam = {} 
local setting = get("kick") 
  
function loseSpam(player) 
    if spam[player] > 0 then 
        spam[player] = spam[player] - 1 
    end 
end 
  
function onChat ( message, messageType ) 
        spam[source] = spam[source] or 0 
        spam[source] = spam[source] + 1 
        if spam[source] == 3 then 
            outputChatBox("Warning - Do Not Spam! ",source,255,0,0) 
        else 
            if spam[source] > 3 then 
                if setting == "true" then 
                    outputChatBox("Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",getRootElement(),255,0,0) 
                    kickPlayer(source,"You Have Been Kicked For Flooding!") 
                elseif setting == "false" 
                    setPlayerMuted(source,true) 
                    outputChatBox(getPlayerName(source) .. " Has Been Auto Muted [20 sec]",getRootElement(),255,0,0) 
                    setTimer(setPlayerMuted,20000,1,source,false) 
end 
addEventHandler ( "onPlayerChat", getRootElement(), onChat) 
  
function quitPlayer() 
        spam[source] = nil 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) 

Link to comment
local spam = {} 
local setting = get("kick") 
  
function loseSpam(player) 
    if spam[player] > 0 then 
        spam[player] = spam[player] - 1 
    end 
end 
  
function onChat ( message, messageType ) 
    spam[source] = spam[source] or 0 
    spam[source] = spam[source] + 1 
    if spam[source] == 3 then 
        outputChatBox("Warning - Do Not Spam! ",source,255,0,0) 
    elseif spam[source] > 3 and setting == "true" then 
        outputChatBox("Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",getRootElement(),255,0,0) 
        kickPlayer(source,"You Have Been Kicked For Flooding!") 
    elseif spam[source] > 3 and setting == "false" then 
        setPlayerMuted(source,true) 
        outputChatBox(getPlayerName(source) .. " Has Been Auto Muted [20 sec]",getRootElement(),255,0,0) 
        setTimer(setPlayerMuted,20000,1,source,false) 
    end 
end 
addEventHandler ( "onPlayerChat", getRootElement(), onChat) 
  
function quitPlayer() 
    spam[source] = nil 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) 
  

Tested.

Edited by Guest
Link to comment
local spam = { } 
local uTimers = { } 
local setting = get( "kick" ) 
  
function onChat ( message, messageType ) 
    spam[ source ] = tonumber( spam[ source ] or 0 ) + 1 
         
    if spam[ source ] == 1 then 
        outputChatBox( "Warning - Do Not Spam! ",source,255,0,0 ) 
    elseif spam[ source ] > 3 then   
        if setting == "true" then 
            outputChatBox( "Kicking " .. getPlayerName(source) .. " For Flooding The Chat!",root,255,0,0 ) 
            kickPlayer( source,"You Have Been Kicked For Flooding!" ) 
        elseif setting == "false" then 
            setPlayerMuted( source,true ) 
            outputChatBox( getPlayerName(source) .. " Has Been Auto Muted [20 sec]",root,255,0,0 ) 
            if isTimer( uTimers[ source ] ) then 
                killTimer( uTimers[ source ] ) 
            end 
            uTimers[ source ] = setTimer( setPlayerMuted,20000,1,source,false ) 
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, onChat) 
  
function quitPlayer( ) 
    spam[ source ] = nil 
    uTimers[ source ] = nil  
end 
addEventHandler ( "onPlayerQuit", root, quitPlayer ) 

Updated.

its say server.lua:21 expected near then

You can not fix yourself?

:/

Link to comment

i got problem outputChatBox The Name of author and if i get unmute outputChatBox("You Have Been Unmuted!) dont show :(

local spam = { } 
local uTimers = { } 
local setting = get( "kick" ) 
function onChat ( message, messageType ) 
    spam[ source ] = tonumber( spam[ source ] or 0 ) + 1 
        
    if spam[ source ] == 3 then 
        outputChatBox( "Warning - Do Not Spam! ",source,255,0,0 ) 
    elseif spam[ source ] > 5 then   
        if setting == "true" then 
            outputChatBox( "Kicking " .. getPlayerName(source) .. " For Flooding The Chat! 5 Times !",root,255,0,0 ) 
            kickPlayer( source,"You Have Been Kicked For Flooding! 5/5" ) 
        elseif setting == "false" then 
            setPlayerMuted( source,true ) 
            outputChatBox( getPlayerName(source) .. " Has Been Auto Muted [20 sec]",root,255,0,0 ) 
            if isTimer( uTimers[ source ] ) then 
                killTimer( uTimers[ source ] ) 
            end 
            else 
            uTimers[ source ] = setTimer( setPlayerMuted,20000,1,source,false ) 
            outputChatBox( "You Have Been unMuted Dont Try Spam! ",source,255,255,0 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, onChat) 
  
function quitPlayer( ) 
    spam[ source ] = nil 
    uTimers[ source ] = nil 
end 
addEventHandler ( "onPlayerQuit", root, quitPlayer ) 
  
function active2 () 
addEvent( "onStart", true ) 
addEventHandler( "onStart", getRootElement(), active2) 
outputChatBox(".:[ Anti Flood | #FFFF1ABy E ]:.",0,255,0,true) 
end 

  
function active () 
triggerServerEvent ( "onStart", getLocalPlayer() )  
end 
addEventHandler ( "onResourceStart", getRootElement(), active) 

Link to comment
local spam = { } 
local uTimers = { } 
local setting = get( "kick" ) 
function onChat ( message, messageType ) 
    spam[ source ] = tonumber( spam[ source ] or 0 ) + 1 
        
    if spam[ source ] == 3 then 
        outputChatBox( "Warning - Do Not Spam! ",source,255,0,0 ) 
    elseif spam[ source ] > 5 then   
        if setting == "true" then 
            outputChatBox( "Kicking " .. getPlayerName(source) .. " For Flooding The Chat! 5 Times !",root,255,0,0 ) 
            kickPlayer( source,"You Have Been Kicked For Flooding! 5/5" ) 
        elseif setting == "false" then 
            setPlayerMuted( source,true ) 
            outputChatBox( getPlayerName(source) .. " Has Been Auto Muted [20 sec]",root,255,0,0 ) 
            if isTimer( uTimers[ source ] ) then 
                killTimer( uTimers[ source ] ) 
            end 
            uTimers[ source ] = setTimer(setPlayerMuted,20000,1,source,false ) 
            setTimer(outputChatBox,20000,1,"You Have Been unMuted Dont Try Spam!",source,255,255,0) 
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, onChat) 
  
function quitPlayer( ) 
    spam[ source ] = nil 
    uTimers[ source ] = nil 
end 
addEventHandler ( "onPlayerQuit", root, quitPlayer ) 
  
function active() 
outputChatBox(".:[ Anti Flood | #FFFF1ABy E ]:.",root,0,255,0,true) 
end 
addEventHandler("onResourceStart", resourceRoot, active) 

Link to comment
local spam = { } 
local uTimers = { } 
local setting = get( "kick" ) 
function onChat ( message, messageType ) 
    spam[ source ] = tonumber( spam[ source ] or 0 ) + 1 
        
    if spam[ source ] == 3 then 
        outputChatBox( "Warning - Do Not Spam! ",source,255,0,0 ) 
    elseif spam[ source ] > 5 then   
        if setting == "true" then 
            outputChatBox( "Kicking " .. getPlayerName( source ) .. " For Flooding The Chat! 5 Times !",root,255,0,0 ) 
            kickPlayer( source,"You Have Been Kicked For Flooding! 5/5" ) 
        elseif setting == "false" then 
            setPlayerMuted( source,true ) 
            outputChatBox( getPlayerName( source ) .. " Has Been Auto Muted [20 sec]",root,255,0,0 ) 
            if isTimer( uTimers[ source ] ) then 
                killTimer( uTimers[ source ] ) 
            end 
            uTimers[ source ] = setTimer( 
                function( player )  
                    setPlayerMuted( player,false ) 
                    outputChatBox( "You Have Been unMuted Dont Try Spam!",player,255,255,0 ) 
                end, 
            20000, 
            1,source )   
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, onChat ) 
  
function quitPlayer( ) 
    spam[ source ] = nil 
    uTimers[ source ] = nil 
end 
addEventHandler ( "onPlayerQuit", root, quitPlayer ) 
  
function active( ) 
    outputChatBox( ".:[ Anti Flood | #FFFF1ABy E ]:.",root,0,255,0,true ) 
end 
addEventHandler( "onResourceStart", resourceRoot, active ) 

Link to comment

You needed to reset the counter.

local spam = { } 
local uTimers = { } 
local setting = get( "kick" ) 
function onChat ( message, messageType ) 
    spam[ source ] = tonumber( spam[ source ] or 0 ) + 1 
        
    if spam[ source ] == 3 then 
        outputChatBox( "Warning - Do Not Spam! ",source,255,0,0 ) 
    elseif spam[ source ] > 5 then   
        if setting == "true" then 
            outputChatBox( "Kicking " .. getPlayerName( source ) .. " For Flooding The Chat! 5 Times !",root,255,0,0 ) 
            kickPlayer( source,"You Have Been Kicked For Flooding! 5/5" ) 
            spam[ source ] = 0 
        elseif setting == "false" then 
            setPlayerMuted( source,true ) 
            spam[ source ] = 0 
            outputChatBox( getPlayerName( source ) .. " Has Been Auto Muted [20 sec]",root,255,0,0 ) 
            if isTimer( uTimers[ source ] ) then 
                killTimer( uTimers[ source ] ) 
            end 
            uTimers[ source ] = setTimer( 
                function( player )  
                    setPlayerMuted( player,false ) 
                    outputChatBox( "You Have Been unMuted Dont Try Spam!",player,255,255,0 ) 
                end, 
            20000, 
            1,source )   
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, onChat ) 
  
function quitPlayer( ) 
    spam[ source ] = nil 
    uTimers[ source ] = nil 
end 
addEventHandler ( "onPlayerQuit", root, quitPlayer ) 
  
function active( ) 
    outputChatBox( ".:[ Anti Flood | #FFFF1ABy E ]:.",root,0,255,0,true ) 
end 
addEventHandler( "onResourceStart", resourceRoot, active ) 

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...