MAB Posted February 15, 2016 Posted February 15, 2016 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)
Overkillz Posted February 15, 2016 Posted February 15, 2016 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 ...
MAB Posted February 15, 2016 Author Posted February 15, 2016 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
TAPL Posted February 15, 2016 Posted February 15, 2016 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)
MAB Posted February 15, 2016 Author Posted February 15, 2016 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
Bonus Posted February 16, 2016 Posted February 16, 2016 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 )
MAB Posted February 16, 2016 Author Posted February 16, 2016 I don't understand if not antiChatSpam[source] or antiChatSpam[source] + 3000 <= getTickCount() then antiChatSpam[source] = getTickCount()
Bonus Posted February 16, 2016 Posted February 16, 2016 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.
MAB Posted February 17, 2016 Author Posted February 17, 2016 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
Bonus Posted February 17, 2016 Posted February 17, 2016 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.
MAB Posted February 17, 2016 Author Posted February 17, 2016 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
Bonus Posted February 17, 2016 Posted February 17, 2016 I didn't understand getTickCount() at the beginning too 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now