View Single Post
12-26-13, 04:41 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you need to know the actual message type (rather than just what color the message was printed in) you will need to either (a) use chat filters or (b) hook ChatFrame_MessageEventHandler. Both suffer from the same problem, in that both will get you every single chat message, whether or not it's set to show in a specific frame, or any frame, so you'll have to figure that out yourself.

Code:
local eventToCategory = {}

local function SaveLastMessageType(frame, event, ...)
	local category = eventToCategory[event]
	-- This maps eg. "CHAT_MSG_PARTY_LEADER" to "PARTY"
	-- which you can look up in ChatTypeInfo etc.
	
	-- Insert code here to figure out whether this frame
	-- should display this category, and return out if not.
	
	frame.lastMessageType = category
	-- Now you can reference this value in your other scripts.
end

for category, events in pairs(CHAT_CATEGORY_LIST) do
	for i = 1, #events do
		local event = "CHAT_MSG_" .. events[i]
		eventToCategory[event] = category
		ChatFrame_RegisterMessageEventFilter(event, SaveLastMessageType)
	end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote