Jump to content

[HELP] Globalchat


Recommended Posts

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

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

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