Jump to content

anti-spam


MAB

Recommended Posts

what is the problem with that anti-spam?

function unmute() 
    if isElement(p) then 
       setElementMuted(p,false) 
    end 
end 
  
spams = {} -- anti chat spam 
function mute() 
local name = getPlayerName(source) 
    for i,v in pairs(spams) do 
        if v == name then 
           setPlayerMuted(source,true) 
           setTimer(unmute,3000,1,source) 
        else 
           table.insert(spams,name) 
        end 
    end 
end 
addEventHandler("onPlayerChat",root,mute) 
setTimer(function() spams={} end,3000,0) 

Link to comment
First of all, I think u should cancell the event.

Seconds, you are only adding a function to mute a player without a reason

try getPlayerName("player")

Im not sure about what I told you, Im beggining on this ...

thanks for helping .. yes it is better to cancel event but there is no argument for reason

Link to comment
function unmute(p) 
    if isElement(p) then 
       setPlayerMuted(p, false) 
    end 
end 
  
spams = {} -- anti chat spam 
function mute() 
    if spams[source] then 
        setPlayerMuted(source, true) 
        setTimer(unmute, 3000, 1, source) 
    else 
        spams[source] = true 
    end 
end 
addEventHandler("onPlayerChat", root, mute) 
setTimer(function() spams={} end, 3000, 0) 

Link to comment
function unmute(p) 
    if isElement(p) then 
       setPlayerMuted(p, false) 
    end 
end 
  
spams = {} -- anti chat spam 
function mute() 
    if spams[source] then 
        setPlayerMuted(source, true) 
        setTimer(unmute, 3000, 1, source) 
    else 
        spams[source] = true 
    end 
end 
addEventHandler("onPlayerChat", root, mute) 
setTimer(function() spams={} end, 3000, 0) 

thanks

Link to comment

Thats a really bad way to handle this.

You create too many timers.

Better use getTickCount():

local antiChatSpam = {} 
  
addEventHandler ( "onPlayerChat", root, function () 
    if not antiChatSpam[source] or antiChatSpam[source] + 3000 <= getTickCount() then 
        antiChatSpam[source] = getTickCount() 
    else 
        cancelEvent() 
        outputChatBox ( "Don't spam little fa*got.", source, 200 ) 
    end 
end ) 

Link to comment

getTickCount() is the time in ms your system is running.

When your system is running for 12356 ms:

local lastChat = {} 
  
if not lastChat[source] or lastChat[source] + 3000 <= getTickCount() then 
    lastChat[source] = getTickCount() 
else 
    cancelEvent() 
end 

Is nearly like:

-- 1. Time Chat --  
local lastChat = {} 
  
-- lastChat[source] is nil 
if not nil or nil + 3000 <= 12356 then      -- getTickCount() | its true cause "not nil" 
    lastChat[source] = 12356          -- getTickCount() 
else 
    cancelEvent() 
end 
  
  
-- 2. Chat after 2000 ms -- 
-- lastChat[source] is 12356 because of 1. chat 
if not 12356 or 12356 + 3000 <= 14356 then      -- its false 
    lastChat[source] = 14356           
else        <-- because 12356 + 3000 > 14356 
    cancelEvent()    
end 
  
  
-- 3. Chat after 3000 ms -- 
-- lastChat[source] is 12356 because of 1. chat 
if not 12356 or 12356 + 3000 <= 15356 then      -- its true because 12356 + 3000 = 15356 
    lastChat[source] = 15356           <--  
else 
    cancelEvent()  
end 

I hope you understand that.

Link to comment
getTickCount() is the time in ms your system is running.

I didn't understand your code but from this word i understood

i thought that when you do "time = getTickCount" for example it starts counting from 0 not the server running time

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