.:HyPeX:. Posted September 23, 2013 Share Posted September 23, 2013 Can someone tell my why its not working properly? its outputting the 3 messages(like it activated the 3 functions) when just saying 1 thing. ----Anti-Spam-Script-by-HyPeX-- ----Locals---- local resRoot = getResourceRootElement(getThisResource()) ------------------------------- ----Messages of Startup---- outputChatBox ("#00aaff[AntiSpam]: Script v1.2 by HyPeX Started.",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) antiSpam = {} antiSpamFlood = {} antiSpamTime = {} function AntiSpam (message, messageType) if messageType == 0 and isTimer(antiSpam[source]) then killTimer(antiSpam[source]) antiSpamFlood[source] = setTimer(function(source) antiSpamFlood[source] = nil end, 10000, 1, source) 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) else antiSpam[source] = setTimer(function(source) antiSpam[source] = nil end, 1000, 1, source) end end addEventHandler("onPlayerChat", getRootElement(), AntiSpam) function AntiSpamMute (message, messageType) if isTimer(antiSpamFlood[source]) then outputChatBox("[AntiSpam]: You have been muted for flooding for 5 Mins.", source, 0, 170, 255) outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255) antiSpamTime[source] = setTimer(function(source) antiSpamTime[source] = nil end, 300000, 1, source) AntiSpam1 = True end end addEventHandler("onPlayerChat", getRootElement(), AntiSpamMute) function PreventFromMute (message, messageType) if messageType == 0 and isTimer(antiSpamTime[source]) then cancelEvent() outputChatBox("[AntiSpam]: Your message was cancelled becouse you are muted.", source, 0, 170, 255) outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255) end end addEventHandler("onPlayerChat", getRootElement(), PreventFromMute) function timerDetails(source) if isTimer(antiSpamTime[source]) then remaining, executesRemaining, totalExecutes = getTimerDetails( antiSpamTime[source] ) outputChatBox("[AntiSpam]: Time left muted: "..remaining/1000, source, 0, 170, 255) else outputChatBox("[AntiSpam]: You are not muted.", source, 0, 170, 255) end end addCommandHandler("sleft", timerDetails) function stopping () timers = getTimers ( 310000 ) for timerKey, timerValue in ipairs(timers) do killTimer ( timerValue ) end end addEventHandler( "onClientResourceStop", resRoot, stopping) Thanks in advance HyPeX Link to comment
iPrestege Posted September 24, 2013 Share Posted September 24, 2013 Because you have more than one event for the player chat. Link to comment
3NAD Posted September 24, 2013 Share Posted September 24, 2013 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]: Your message was cancelled becouse you are muted.", source, 0, 170, 255) outputChatBox("[AntiSpam]: Type /sleft to get your time left muted.", source, 0, 170, 255) cancelEvent ( ) 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 SpamTable[player].Mute = false end end, 5*60*1000, 1, source ) outputChatBox("[AntiSpam]: You have been muted for flooding for 5 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 then if 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 ) 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 ) Link to comment
.:HyPeX:. Posted September 24, 2013 Author Share Posted September 24, 2013 Wow, thanks. I was actually thinking this was caused becouse the functions just triggered altogether (timers just were supposed to be a barrier as same time as timers itself.. but they were triggering themselves in once). But this should work. Also, you showed me there that i could make a table inside another one, wich helps alot. Thanks 3NAD Link to comment
.:HyPeX:. Posted September 24, 2013 Author Share Posted September 24, 2013 Anytime. i also noticed you did the time 5*60*1000 and remaining/60/1000, that will output seconds and minutes alone? Thanks again HyPeX Link to comment
3NAD Posted September 25, 2013 Share Posted September 25, 2013 At this code Yes, But you can use it anytime. Link to comment
.:HyPeX:. Posted September 26, 2013 Author Share Posted September 26, 2013 (edited) Noticed the code takes ALL messages into account, in a server with lots of players a player can get muted alone (if Player A Writes and player B in less than 1sec, you get the warning). Should the usage of "source" fix it? Edited September 26, 2013 by Guest Link to comment
3NAD Posted September 26, 2013 Share Posted September 26, 2013 @ Server Side: The variable is general to all players. For example: addCommandHandler ( "test", function ( player ) thePlayer = player end ) if i say /test the variable ( thePlayer ) the Definition will be on me then if you say /test the Definition will be on you So i Advise you to use tables. Link to comment
.:HyPeX:. Posted September 28, 2013 Author Share Posted September 28, 2013 @ Server Side: The variable is general to all players.For example: addCommandHandler ( "test", function ( player ) thePlayer = player end ) if i say /test the variable ( thePlayer ) the Definition will be on me then if you say /test the Definition will be on you So i Advise you to use tables. tables arent being used already by the [source]? Link to comment
3NAD Posted September 28, 2013 Share Posted September 28, 2013 You can make this: Table = { } addCommandHandler ( "test", function ( player ) Table[player] = player end ) addEventHandler ( "onPlayerQuit", root, function ( ) if Table[source] then outputChatBox ( getPlayerName(source), root ) end end ) Link to comment
.:HyPeX:. Posted September 29, 2013 Author Share Posted September 29, 2013 Regardless everyhing, i tried to give the players mute even if they left to avoid them from reconnecting and unmuting.. but i really dont see any error here, can someone tell me why the player isnt being muted after loggin in.. ----Anti-Spam-Script-by-HyPeX-- ----Locals---- ------------------------------- ----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 SpamTable[player].Mute = false end end, 5*60*1000, 1, source ) setPlayerMuted(source, true) setTimer(UnMutePlayer, 5*60*1000, 1) outputChatBox("[AntiSpam]: ".. (string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "")) .." has have been muted for flooding for 5 Mins.", 0, 170, 255) 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 then if 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 ) 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() if isPlayerMuted( source ) then setPlayerMuted(source, false) else outputchatbox ( "[AntiSpam]:".. (string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "")) .."is now unmuted!", 0, 175 ,255 ) end end ----Manage on quit or join function OnPlayerMutedLeft() if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime )then local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime ) local playerAccount = getPlayerAccount(source) setAccountData( playerAccount, MutedTimeScript, remaining ) setPlayerMuted( source, false) killTimer(SpamTable[source].MuteTime) else setAccountData( playerAccout, MutedtimeScript, 0 ) end end addEventHandler("onPlayerQuit", getRootElement(), OnPlayerMutedLeft) function OnPlayerMutedJoint() local playerAccount = getPlayerAccount(source) if getAccountData(playerAccount,MutedTimeScript) > 0 then local MutedLeft = getAccountData( playerAccount, MutedTimeScript ) setPlayerMuted(source, true) setAccountData( playerAccount, MutedTimeScript, 0 ) setTimer(UnmutePlayer, MutedLeft, 1 ) SpamTable[source].MuteTime = setTimer ( function ( player ) if isElement ( player ) then SpamTable[player].Mute = false end end, 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(remaining/60/1000), math.fmod(math.floor(remaining/1000),60)), source, 0, 170, 255, true ) end end addEventHandler("onPlayerLogin", getRootElement(), OnPlayerMutedJoint) ----Prevent Muted from changing nick function StopMuted() if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime ) then outputchatbox ( "[AntiSpam]:".. (string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "")) .."was kicked for trying to change his nick while muted!", 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(p), "#%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 ) Link to comment
3NAD Posted September 30, 2013 Share Posted September 30, 2013 Try this. function OnPlayerMutedLeft() local playerAccount = getPlayerAccount(source) if not isGuestAccount ( playerAccount ) then if isPlayerMuted( source ) or isTimer ( SpamTable[source].MuteTime )then local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime ) if remaining then setAccountData( playerAccount, "MutedTimeScript", tostring(remaining) ) setPlayerMuted( source, false) killTimer(SpamTable[source].MuteTime) end else setAccountData( playerAccount, "MutedtimeScript", false ) end end end addEventHandler("onPlayerQuit", root, OnPlayerMutedLeft) function OnPlayerMutedJoint ( _, acc ) local MutedLeft = getAccountData( acc, "MutedTimeScript" ) if MutedLeft then setPlayerMuted(source, true) setAccountData( acc, "MutedTimeScript", false ) setTimer(UnmutePlayer, tonumber(MutedLeft), 1 ) 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(remaining/60/1000), math.fmod(math.floor(remaining/1000),60)), source, 0, 170, 255, true ) end end addEventHandler("onPlayerLogin", root, OnPlayerMutedJoint) Link to comment
.:HyPeX:. Posted September 30, 2013 Author Share Posted September 30, 2013 Nothing, i'm just muted after loging in. Link to comment
3NAD Posted October 1, 2013 Share Posted October 1, 2013 at second function, move this line: setAccountData( acc, "MutedTimeScript", false ) under outputChatBox Functions. And you need to definition 'remaining' word Link to comment
.:HyPeX:. Posted October 1, 2013 Author Share Posted October 1, 2013 at second function, move this line: setAccountData( acc, "MutedTimeScript", false ) under outputChatBox Functions. And you need to definition 'remaining' word isnt it already defined as local on the previous function? Link to comment
3NAD Posted October 2, 2013 Share Posted October 2, 2013 If you used 'local' It will be definition on his function, You can make it general definition by removing 'local' word Link to comment
.:HyPeX:. Posted October 2, 2013 Author Share Posted October 2, 2013 If you used 'local' It will be definition on his function,You can make it general definition by removing 'local' word but that would interfer the rest of the script, so i'll keep to the locals PD: still not working, im muted after logging in and its not saying anything. Also sleft will not work unless i say something. i'm not seeing any message when i'm muted for 5 mins. Link to comment
3NAD Posted October 3, 2013 Share Posted October 3, 2013 ----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 then if 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 ) 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 )then local remaining, executesRemaining, totalExecutes = getTimerDetails ( SpamTable[source].MuteTime ) if remaining then setAccountData( playerAccount, "MutedTimeScript", tostring(remaining) ) setPlayerMuted( source, false) killTimer(SpamTable[source].MuteTime) 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 ) 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 ) Link to comment
.:HyPeX:. Posted October 3, 2013 Author Share Posted October 3, 2013 Oh and if i use different messages (bind say a and bind say b) i can totally spam the thing. Link to comment
.:HyPeX:. Posted October 4, 2013 Author Share Posted October 4, 2013 How could i prevent it? Link to comment
3NAD Posted October 6, 2013 Share Posted October 6, 2013 bind .. say b will be under "onPlayerChat". so the previous code will do that. Link to comment
.:HyPeX:. Posted October 6, 2013 Author Share Posted October 6, 2013 Wich one, mine or the one you posted? the one you posted will only block message repeating, and i want to block players if they manage to flood the chat too Link to comment
3NAD Posted October 7, 2013 Share Posted October 7, 2013 I think you can block it with 'onPlayerCommand'. if find 'bind' then cancelEvent 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