Jump to content

cancelEvent doesn't work with onPlayerChatEvent


JeViCo

Recommended Posts

Hello everyone. I used an example (2) from wiki but cancelEvent() doesn't work so i can see double messages in chat

--This function is executed when a player joins, it sets the player's name-tag color to a random color.
local function playerJoin()
	local red, green, blue = math.random (50, 255), math.random (50, 255), math.random (50, 255)
        setPlayerNametagColor(source, red, green, blue)
end
addEventHandler ("onPlayerJoin", root, playerJoin)

--This function is executed when a player says something in chat, it outputs the player's message, with their nick colored to match their name tag color.
local function playerChat(message, messageType)
	if messageType == 0 then --Global (main) chat
                cancelEvent()
                local red, green, blue = getPlayerNametagColor(source)
		outputChatBox(getPlayerName(source)..": #FFFFFF"..message, root, red, green, blue, true )
		outputServerLog("CHAT: "..getPlayerName(source)..": "..message)--NOTE: Beacuse we cancelled the onPlayerChat event, we need to log chat manually.
	end
end
addEventHandler("onPlayerChat", root, playerChat)

 

Link to comment
1 hour ago, JeViCo said:

double messages in chat

i think you should stop the freeroam resource or what ever it's name but i mean the resource that contain the onPlayerChat Event

if you don't know what is the name of the resource then use 

addDebugHook

to get the name of resource with preevent parameter

  • Like 1
Link to comment
--This function is executed when a player joins, it sets the player's name-tag color to a random color.
local function playerJoin()
	local red, green, blue = math.random (50, 255), math.random (50, 255), math.random (50, 255)
        setPlayerNametagColor(source, red, green, blue)
end
addEventHandler ("onPlayerJoin", root, playerJoin)

--This function is executed when a player says something in chat, it outputs the player's message, with their nick colored to match their name tag color.
local function playerChat(message, messageType)
  cancelEvent () 
	if messageType == 0 then --Global (main) chat
           local red, green, blue = getPlayerNametagColor(source)
		outputChatBox(getPlayerName(source)..": #FFFFFF"..message, root, red, green, blue, true )
		outputServerLog("CHAT: "..getPlayerName(source)..": "..message)--NOTE: Beacuse we cancelled the onPlayerChat event, we need to log chat manually.
	end
end
addEventHandler("onPlayerChat", root, playerChat)

 

Link to comment
10 hours ago, Master_MTA said:

i think you should stop the freeroam resource or what ever it's name but i mean the resource that contain the onPlayerChat Event

if you don't know what is the name of the resource then use 

addDebugHook

to get the name of resource with preevent parameter

ok, i'll try it

 

7 hours ago, Dimos7 said:

--This function is executed when a player joins, it sets the player's name-tag color to a random color.
local function playerJoin()
	local red, green, blue = math.random (50, 255), math.random (50, 255), math.random (50, 255)
        setPlayerNametagColor(source, red, green, blue)
end
addEventHandler ("onPlayerJoin", root, playerJoin)

--This function is executed when a player says something in chat, it outputs the player's message, with their nick colored to match their name tag color.
local function playerChat(message, messageType)
  cancelEvent () 
	if messageType == 0 then --Global (main) chat
           local red, green, blue = getPlayerNametagColor(source)
		outputChatBox(getPlayerName(source)..": #FFFFFF"..message, root, red, green, blue, true )
		outputServerLog("CHAT: "..getPlayerName(source)..": "..message)--NOTE: Beacuse we cancelled the onPlayerChat event, we need to log chat manually.
	end
end
addEventHandler("onPlayerChat", root, playerChat)

 

thanks for reply too :3

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