Jump to content

onPlayerChat problem


itHyperoX

Recommended Posts

so, i making a "chat system", but i got some problems.

Here is the code

cancelableworld = {
    ":~",
    ":Oyou",
    "bitch"
}


addEventHandler("onPlayerChat", root,
    function(message, msgTyp)
        local message = string.lower(message)
        for i,v in ipairs(cancelableworld) do
            if (string.find(message, cancelableworld[i])) then
                outputChatBox("*NO*", source, 255, 0, 0, false)
                cancelEvent()
            end
        end
    end)
--—————————————————————————————————————————————————————————
--—————————————————————————————————————————————————————————
--< CustomChat >--
addEventHandler ( "onPlayerChat", root,
local Level = getElementData(source,"Level" or 0)
    function(message)
    outputChatBox("#4C7759[LVL "..Level.."] #FFFFFF"..getPlayerName(source)..": #FFFFFF"..message,getRootElement(),255,2555,255,true)
    end)

The script first half is canceling the worlds, but the second is enable the world.

So i cancel the "Weid" worlds, but it keep showing on the chat, becase the second half not ignor that. I want to make, when player typing blocked worlds in chat, thats not showing up, 

 

what should i do?

Edited by TheMOG
Link to comment

I think you can just make it inside one function, maybe something like this, I'm not quite sure tho.

cancelableworld = {
    ":~",
    ":Oyou",
    "bitch"
}


addEventHandler("onPlayerChat", root,
    function(message, msgTyp)
    	local Level = getElementData(source,"Level" or 0)
    	outputChatBox("#4C7759[LVL "..Level.."] #FFFFFF"..getPlayerName(source)..": #FFFFFF"..message,getRootElement(),255,2555,255,true)	
    	
        local message = string.lower(message)
        for i,v in ipairs(cancelableworld) do
            if (string.find(message, cancelableworld[i])) then
                outputChatBox("*NO*", source, 255, 0, 0, false)
                cancelEvent()
            end
        end
    end)

 

Link to comment
local aData = "Level"
addEventHandler("onPlayerChat",getRootElement(),
  function ( aMsg )
    if ( getElementData ( source , aData ) == true ) then 
      cancelEvent ()
      outputChatBox ("[ level  "..getElementData ( source , aData ).." ] "..getPlayerName ( source ).." : "..aMsg , root ) 
      end
    end
  )

 

Edited by #_iMr.[E]coo
Link to comment
Just now, #_iMr.[E]coo said:

local aData = "Level"
addEventHandler("onPlayerChat",getRootElement(),
  function ( aMsg )
    if ( getElementData ( source , aData ) == true ) then 
      outputChatBox ("[ level  "..getElementData ( source , aData ).." ] "..getPlayerName ( source ).." : "..msg , root ) 
      end
    end
  )

 

You just made it more complex, that's not what he needs, his problem is that he don't want some words being shown, but because of the two onPlayerChat events he still can see the word he doesn't want to show. It could be an option to check on the other event - where you show the level of the chatting player - if the message has a bad word, but you would have to check it everywhere if you make another onPlayerChat event, I think there is an easier way where you don't have to check the bad words everytime.

  • Like 1
Link to comment

correction code Dzsozi

cancelableworld = {
    ":~",
    ":Oyou",
    "bitch"
}


addEventHandler("onPlayerChat", root,
    function(message, msgTyp)
    	local Level = getElementData(source,"Level")
    	outputChatBox("#4C7759[LVL "..Level.."] #FFFFFF"..getPlayerName(source)..": #FFFFFF"..message,getRootElement(),255,255,255,true)	
    	
        local message = string.lower(message)
        for i,v in ipairs(cancelableworld) do
            if (string.find(message, cancelableworld[i])) then
              cancelEvent()  outputChatBox("*NO*", source, 255, 0, 0, false)
           
            end
        end
    end)

 

Link to comment

Try this one:
 

addEventHandler("onPlayerChat", root, function(message, msgTyp)
	local message = string.lower(message)
	for i,v in ipairs(cancelableworld) do
 		if (string.find(message, cancelableworld[i])) then
        	outputChatBox("*NO*", source, 255, 0, 0, false)
        	cancelEvent()
			return
		end
	end
	local Level = getElementData(source,"Level" or 0)
	outputChatBox("#4C7759[LVL "..Level.."] #FFFFFF"..getPlayerName(source)..": #FFFFFF"..message,getRootElement(),255,2555,255,true)
end)

 

Edited by Patrik91
  • Like 1
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...