.:HyPeX:. Posted October 7, 2013 Author Share Posted October 7, 2013 I think you can block it with 'onPlayerCommand'. if find 'bind' then cancelEvent With the code i did i should be able to cancel it inside the server, but they can come with the binds from outside. I can block the player from using the say(the bind will do that) but im not sure if it would or not cancel the normal command, since its: Bind = say T = chatbox:say Link to comment
3NAD Posted October 8, 2013 Share Posted October 8, 2013 Hmm.. i don't think so. But the 'spam code' will block any repeated messages. And you can make table to block some words. Link to comment
.:HyPeX:. Posted October 8, 2013 Author Share Posted October 8, 2013 Okay.. havent tested yet, but lets see, is it too carzy? ----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 and 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 ) elseif isTimer( ClearCount[thePlayer] ) then local remaining2, executesRemaining2, totalExecutes2 = getTimerDetails ( ClearCount[thePlayer] ) outputChatBox ( "[AntiSpam]: Time left muted: "..string.format ( '%02d:%02d', math.floor(remaining2/60/1000), math.fmod(math.floor(remaining2/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 ) or isTimer( ClearCount[thePlayer] ) then local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime ) local remaining2, executesRemaining2, totalExecutes2 = getTimerDetails ( ClearCount[thePlayer] ) if remaining then setAccountData( playerAccount, "MutedTimeScript", tostring(remaining) ) setPlayerMuted( source, false) killTimer(SpamTable[source].MuteTime) elseif remaining2 then setAccountData( playerAccount, "MutedTimeScript", tostring(remaining2) ) setPlayerMuted( source, false) killTimer(ClearCount[thePlayer]) 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 ) elseif not ClearCount[thePlayer] then setPlayerMuted(source, true) setTimer(UnMutePlayer, tonumber(MutedLeft), 1, source ) ClearCount[thePlayer] = setTimer( function(thePlayer) ClearCount[thePlayer] = 0 end, tonumber(MutedLeft), 1, thePlayer) 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 ) ----Functions--- ClearCount = {} g_MessageCount = {} function AntiSpam2 (message, messageType) thePlayer = getPlayerName( source ) if messageType == 0 if g_MessageCount = 1 then killTimer(ClearCount[thePlayer]) g_MessageCount[thePlayer] = 2 ClearCount[thePlayer] = setTimer( function(thePlayer) ClearCount[thePlayer] = 0 end, 10000, 1, thePlayer) 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) elseif g_MessageCount[thePlayer] = 0 then g_MessageCount[Player] = 1 ClearCount[thePlayer] = setTimer( function(thePlayer) ClearCount[thePlayer] = 0 end, 1500, 1, thePlayer) elseif g_MessageCount[thePlayer] = 2 then killTimer(ClearCount[thePlayer]) g_MessageCount[thePlayer] = 3 setPlayerMuted(thePlayer, true) ClearCount[thePlayer] = setTimer( function(thePlayer) ClearCount[thePlayer] = 0 setPlayerMuted(thePlayer, false) end, MuteTimePerMins*60*1000, 1, thePlayer) elseif g_MessageCount[thePlayer] = 3 then cancelEvent() end end end addEventHandler("onPlayerChat", getRootElement(), AntiSpam2) addEventHandler("onPlayerChat", getRootElement(), PreventFromMute) Link to comment
3NAD Posted October 8, 2013 Share Posted October 8, 2013 xDD ?? if g_MessageCount = 1 then Link to comment
.:HyPeX:. Posted October 8, 2013 Author Share Posted October 8, 2013 xDD ??if g_MessageCount = 1 then whats so strange about it? Link to comment
3NAD Posted October 8, 2013 Share Posted October 8, 2013 This will be definition, Not ( matching / comparing ) on Conditional clause. You must make it like this: if xxx == 1 then Link to comment
.:HyPeX:. Posted October 8, 2013 Author Share Posted October 8, 2013 Ah, didnt knew = was definition and == comparing/matching.. thanks Link to comment
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