Furious^ONE! Posted June 6, 2020 Share Posted June 6, 2020 Hi, I have my script for auto-mute system when someone say bad words. the problem is that the script detects that the 'normal chat (/say) ', but not the GlobalChat of the server, If a player says a bad word in globalchat, then the script will detect nothing my code: Words = { ["mum"] = true, ["mother"] = true, } muteTimers = {} interval = 86400000 function findPlayerBySerial(serial) for _, player in ipairs(getElementsByType("player")) do if getPlayerSerial(player) == serial then return player end end return false end addEventHandler("onPlayerChat", getRootElement(), function(msg, msgType) local theMsg = msg if Words[theMsg] then cancelEvent() pName = getPlayerName(source) local serial = getPlayerSerial(source) outputChatBox("#FF0000".. pName .."#FF0000 has been muted by Console.(24h) #A87700Reason:#FFFFFF R.2.2.1.",getRootElement(),255,0,0,true) setPlayerMuted(source, true) muteTimers[serial] = setTimer(function() local player = findPlayerBySerial(serial) if player then setPlayerMuted(player, false) local pName = getPlayerName(player) outputChatBox("#00D117".. pName .."#00D117 has been unmuted by Console.",getRootElement(),255,0,0,true) end end, interval, 1) end end) addEventHandler("onPlayerJoin", root, function() local serial = getPlayerSerial(source) if isTimer(muteTimers[serial]) then local pName = getPlayerName(source) outputChatBox("#FF0000".. pName .." has been muted by Console.(24h) #A87700Reason:#FFFFFF R.2.2.1.",getRootElement(), 255, 0, 0,true) setPlayerMuted(source, true) end end) Code globalchat server function globalMessage(thePlayer, cmd, ...) local message = table.concat({ ... }, " ") local len = string.len(message) if len > 128 then return end local team = getTeamName(getPlayerTeam(thePlayer)) if not team then return end if isPlayerMuted(thePlayer) then outputChatBox("You are muted!", thePlayer, 255, 128, 22, true) return end if not antiFlood[thePlayer] then antiFlood[thePlayer] = true antiFloodTick[thePlayer] = getTickCount() elseif getTickCount() - antiFloodTick[thePlayer] > 800 then antiFloodTick[thePlayer] = getTickCount() else return end local name = getPlayerName(thePlayer) local r, g, b = getTeamColor(getTeamFromName(team)) outputServerLog("[Global Chat]: "..name..": "..message) if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Owner")) then outputChatBox("[Owner] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Administrator")) then outputChatBox("[Administrator] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Moderator")) then outputChatBox("[Moderator] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Support")) then outputChatBox("[Support] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("VIP")) then outputChatBox("[VIP] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end outputChatBox("[Player] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) end addCommandHandler("globalchat", globalMessage) Link to comment
Sisqo0 Posted June 6, 2020 Share Posted June 6, 2020 "onPlayerChat" This event detects local chat Link to comment
Sisqo0 Posted June 6, 2020 Share Posted June 6, 2020 All the code should be in server side You can use in the command function string.find(msg,"bad word") Link to comment
Furious^ONE! Posted June 6, 2020 Author Share Posted June 6, 2020 chat.Lua local antiFlood = {} local antiFloodTick = {} function chatLocal(message, messageType) if messageType == 1 then cancelEvent() end if messageType == 0 then cancelEvent() if not antiFlood[source] then antiFlood[source] = true antiFloodTick[source] = getTickCount() elseif getTickCount() - antiFloodTick[source] > 800 then antiFloodTick[source] = getTickCount() else return end local len = string.len(message) if len > 128 then return end local players = getElementsByType("player") local posX1, posY1, posZ1 = getElementPosition(source) for i = 1, #players do local posX2, posY2, posZ2 = getElementPosition(players[i]) if getDistanceBetweenPoints3D(posX1, posY1, posZ1, posX2, posY2, posZ2) <= 20 then outputChatBox(""..string.gsub((getPlayerName(source)..": "..message), "#%x%x%x%x%x%x", ""), players[i], 211, 211, 211, true) outputServerLog("[Local Chat]: "..string.gsub((getPlayerName(source)..": "..message), "#%x%x%x%x%x%x", "")) end end end end addEventHandler("onPlayerChat", getRootElement(), chatLocal) function adminChat(thePlayer, _,...) local word = {...} local message = table.concat(word, " ") local len = string.len(message) if len > 128 then return end local account = getPlayerAccount(thePlayer) if isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Owner")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Administrator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Moderator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Support")) then showAdminMessage(thePlayer, message) end end addCommandHandler("a", adminChat) function showAdminMessage(player, message) local players = getElementsByType("player") for i = 1, #players do local account = getPlayerAccount(players[i]) if isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Owner")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Administrator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Moderator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Support")) then outputChatBox("#FF4500[Staff Chat]#FFFFFF "..removeHEXFromString(getPlayerName(player))..": #3498DB"..removeHEXFromString(message), players[i], 255, 255, 255, true) outputServerLog("[Admin Chat]: "..removeHEXFromString(getPlayerName(player))..": "..message) end end end function globalMessage(thePlayer, cmd, ...) local message = table.concat({ ... }, " ") local len = string.len(message) if len > 128 then return end local team = getTeamName(getPlayerTeam(thePlayer)) if not team then return end if isPlayerMuted(thePlayer) then outputChatBox("You are muted!", thePlayer, 255, 128, 22, true) return end if not antiFlood[thePlayer] then antiFlood[thePlayer] = true antiFloodTick[thePlayer] = getTickCount() elseif getTickCount() - antiFloodTick[thePlayer] > 800 then antiFloodTick[thePlayer] = getTickCount() else return end local name = getPlayerName(thePlayer) local r, g, b = getTeamColor(getTeamFromName(team)) outputServerLog("[Global Chat]: "..name..": "..message) if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Owner")) then outputChatBox("[Owner] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Administrator")) then outputChatBox("[Administrator] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Moderator")) then outputChatBox("[Moderator] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Support")) then outputChatBox("[Support] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("VIP")) then outputChatBox("[VIP] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end outputChatBox("[Player] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) end addCommandHandler("globalchat", globalMessage) function teamMessage(message, messageType) if messageType == 2 then cancelEvent() local len = string.len(message) if len > 128 then return end local team = getPlayerTeam(source) if not team then return end if not antiFlood[source] then antiFlood[source] = true antiFloodTick[source] = getTickCount() elseif getTickCount() - antiFloodTick[source] > 800 then antiFloodTick[source] = getTickCount() else return end local name = getPlayerName(source) local r, g, b = getTeamColor(team) local members = getPlayersInTeam(team) or {} for i = 1, #members do outputChatBox("[Team Chat] #FFF5EE"..name..": #FFF5EE"..message, members[i], r, g, b, true) end outputServerLog("[Team "..getTeamName(team).."]: "..name..": "..message) end end addEventHandler("onPlayerChat", getRootElement(), teamMessage) function onJoinPlayer() outputChatBox("#ff8800* #EBDDB2"..getPlayerName(source).." #FF6464has joined the game.", getRootElement(), 255, 0, 0, true) setPlayerBlurLevel(source, 0) setPlayerNametagShowing(source, false) end addEventHandler("onPlayerJoin", getRootElement(), onJoinPlayer) function onQuitPlayer(quitType) outputChatBox("#ff8800* #EBDDB2"..getPlayerName(source).." #FF6464has left the game ["..quitType.."]", getRootElement(), 255, 0, 0, true) if antiFlood[source] then antiFlood[source] = nil end if antiFloodTick[source] then antiFloodTick[source] = nil end end addEventHandler("onPlayerQuit", getRootElement(), onQuitPlayer) function disableBlur() setPlayerBlurLevel(getRootElement(), 0) end addEventHandler("onResourceStart", resourceRoot, disableBlur) function onCommandPlayer(commandName) if commandName == "login" or commandName == "logout" or commandName == "register" or commandName == "me" then cancelEvent() end end addEventHandler("onPlayerCommand", getRootElement(), onCommandPlayer) Link to comment
Sisqo0 Posted June 6, 2020 Share Posted June 6, 2020 local antiFlood = {} local antiFloodTick = {} local badwords = { "mom", "dad" } function chatLocal(message, messageType) if messageType == 1 then cancelEvent() end if messageType == 0 then cancelEvent() if not antiFlood[source] then antiFlood[source] = true antiFloodTick[source] = getTickCount() elseif getTickCount() - antiFloodTick[source] > 800 then antiFloodTick[source] = getTickCount() else return end local len = string.len(message) if len > 128 then return end local players = getElementsByType("player") local posX1, posY1, posZ1 = getElementPosition(source) for i = 1, #players do local posX2, posY2, posZ2 = getElementPosition(players[i]) if getDistanceBetweenPoints3D(posX1, posY1, posZ1, posX2, posY2, posZ2) <= 20 then outputChatBox(""..string.gsub((getPlayerName(source)..": "..message), "#%x%x%x%x%x%x", ""), players[i], 211, 211, 211, true) outputServerLog("[Local Chat]: "..string.gsub((getPlayerName(source)..": "..message), "#%x%x%x%x%x%x", "")) end end end end addEventHandler("onPlayerChat", getRootElement(), chatLocal) function adminChat(thePlayer, _,...) local word = {...} local message = table.concat(word, " ") local len = string.len(message) if len > 128 then return end local account = getPlayerAccount(thePlayer) if isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Owner")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Administrator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Moderator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Support")) then showAdminMessage(thePlayer, message) end end addCommandHandler("a", adminChat) function showAdminMessage(player, message) local players = getElementsByType("player") for i = 1, #players do local account = getPlayerAccount(players[i]) if isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Owner")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Administrator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Moderator")) or isObjectInACLGroup("user."..getAccountName(account), aclGetGroup("Support")) then outputChatBox("#FF4500[Staff Chat]#FFFFFF "..removeHEXFromString(getPlayerName(player))..": #3498DB"..removeHEXFromString(message), players[i], 255, 255, 255, true) outputServerLog("[Admin Chat]: "..removeHEXFromString(getPlayerName(player))..": "..message) end end end function globalMessage(thePlayer, cmd, ...) local message = table.concat({ ... }, " ") local len = string.len(message) if len > 128 then return end local team = getTeamName(getPlayerTeam(thePlayer)) if not team then return end if isPlayerMuted(thePlayer) then outputChatBox("You are muted!", thePlayer, 255, 128, 22, true) return end for k,msg ipairs (badwords) do if string.find (message, msg) then setPlayerMuted (thePlayer, true) outputChatBox("You have been muted by Console!", thePlayer, 255, 0, 0, true) return end end if not antiFlood[thePlayer] then antiFlood[thePlayer] = true antiFloodTick[thePlayer] = getTickCount() elseif getTickCount() - antiFloodTick[thePlayer] > 800 then antiFloodTick[thePlayer] = getTickCount() else return end local name = getPlayerName(thePlayer) local r, g, b = getTeamColor(getTeamFromName(team)) outputServerLog("[Global Chat]: "..name..": "..message) if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Owner")) then outputChatBox("[Owner] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Administrator")) then outputChatBox("[Administrator] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Moderator")) then outputChatBox("[Moderator] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("Support")) then outputChatBox("[Support] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end if isObjectInACLGroup("user."..(getAccountName(getPlayerAccount(thePlayer))), aclGetGroup("VIP")) then outputChatBox("[VIP] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) return end outputChatBox("[Player] #FFF5EE"..name..": #FFF5EE"..message, getRootElement(), r, g, b, true) end addCommandHandler("globalchat", globalMessage) function teamMessage(message, messageType) if messageType == 2 then cancelEvent() local len = string.len(message) if len > 128 then return end local team = getPlayerTeam(source) if not team then return end if not antiFlood[source] then antiFlood[source] = true antiFloodTick[source] = getTickCount() elseif getTickCount() - antiFloodTick[source] > 800 then antiFloodTick[source] = getTickCount() else return end local name = getPlayerName(source) local r, g, b = getTeamColor(team) local members = getPlayersInTeam(team) or {} for i = 1, #members do outputChatBox("[Team Chat] #FFF5EE"..name..": #FFF5EE"..message, members[i], r, g, b, true) end outputServerLog("[Team "..getTeamName(team).."]: "..name..": "..message) end end addEventHandler("onPlayerChat", getRootElement(), teamMessage) function onJoinPlayer() outputChatBox("#ff8800* #EBDDB2"..getPlayerName(source).." #FF6464has joined the game.", getRootElement(), 255, 0, 0, true) setPlayerBlurLevel(source, 0) setPlayerNametagShowing(source, false) end addEventHandler("onPlayerJoin", getRootElement(), onJoinPlayer) function onQuitPlayer(quitType) outputChatBox("#ff8800* #EBDDB2"..getPlayerName(source).." #FF6464has left the game ["..quitType.."]", getRootElement(), 255, 0, 0, true) if antiFlood[source] then antiFlood[source] = nil end if antiFloodTick[source] then antiFloodTick[source] = nil end end addEventHandler("onPlayerQuit", getRootElement(), onQuitPlayer) function disableBlur() setPlayerBlurLevel(getRootElement(), 0) end addEventHandler("onResourceStart", resourceRoot, disableBlur) function onCommandPlayer(commandName) if commandName == "login" or commandName == "logout" or commandName == "register" or commandName == "me" then cancelEvent() end end addEventHandler("onPlayerCommand", getRootElement(), onCommandPlayer) Try this and say sentences include "mom" or "dad" words in global chat. Link to comment
Furious^ONE! Posted June 6, 2020 Author Share Posted June 6, 2020 I have error when i start it ERROR: Loading script failed: [CORE]\carwars_core\chat.Lua:57: 'in' expected near 'ipairs' Link to comment
Moderators IIYAMA Posted June 6, 2020 Moderators Share Posted June 6, 2020 3 hours ago, Furious^ONE! said: I have error when i start it ERROR: Loading script failed: [CORE]\carwars_core\chat.Lua:57: 'in' expected near 'ipairs' Add the keyword: in for k,msg in ipairs (badwords) do Syntax: http://www.Lua.org/manual/5.1/manual.html#pdf-ipairs Link to comment
Furious^ONE! Posted June 6, 2020 Author Share Posted June 6, 2020 It's good, but the mute timer and interval deleted, and save mute after /reconnect too Link to comment
MrKAREEM Posted June 7, 2020 Share Posted June 7, 2020 (edited) 17 hours ago, Furious^ONE! said: It's good, but the mute timer and interval deleted, and save mute after /reconnect too OnPlayerQuit OnPlayerJoin SetAccountData GetAccountData or use Database Edited June 7, 2020 by MrKAREEM 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