Jump to content

anti-spam


MAB

Recommended Posts

Posted

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) 

Posted

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

Posted
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

Posted
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) 

Posted
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

Posted

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 ) 

Posted

I don't understand

if not antiChatSpam[source] or antiChatSpam[source] + 3000 <= getTickCount() then 
        antiChatSpam[source] = getTickCount()  

Posted

If the player didnt use the chat before or did it 3000 ms before, the last time the player used the chat will be saved with getTickCount().

If the player used the chat within 3000 ms then the event gets canceled.

Posted
or did it 3000 ms before,

that mean "if the tick count we set to the player crossed 3000 or equal to it." so it should be

if antiSpamChat[source] >= 3000 then

Posted

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.

Posted
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

Posted

I didn't understand getTickCount() at the beginning too :D

And I still don't understand what getTickCount() is clientsided.

getTickCount() clientsided could be the time your CPU is running (have read it somewhere).

Not sure, never tested.

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