Thread Tools Display Modes
11-03-13, 02:27 PM   #1
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Question Need help with Event "CHAT_MSG_SYSTEM"

I need a way to filter the event "CHAT_MSG_SYSTEM", for friends online / offline and guild online / offline.

And discard the rest.

(or another event that fires when a friend / guild mate, conect or disconect).

I need a conditional (for Kgpanels) that change the color of a text when a friend or guild mate conect or disconect, using that event.

how can I do it?

Thanks!!
  Reply With Quote
11-03-13, 09:45 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The online/offline messages don't distinguish between friends and guildmates, so you have to scan your friends list and figure that out yourself:

Code:
local ONLINE = ERR_FRIEND_ONLINE_SS:gsub("%%s", "(.-)"):gsub("[%[%]]", "%%%1")
local OFFLINE = ERR_FRIEND_OFFLINE_S:gsub("%%s", "(.-)")

local function IsFriend(name)
	for i = 1, GetNumFriends() do
		if GetFriendInfo(i) == name then
			return true
		end
	end
end

ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", function(frame, event, message)
	local action = "OFFLINE"
	local _, name = strmatch(message, ONLINE)
	if name then
		action = "ONLINE"
	else
		name = strmatch(message, OFFLINE)
	end
	if not name then
		return
	end

	if action == "ONLINE" then
		if IsFriend(name) then
			-- A friend came online.
		else
			-- A guildmate came online.
		end
	elseif action == "OFFLINE" then
		if IsFriend(name) then
			-- A friend went offline.
		else
			-- A guildmate went offline.
		end
	end
end)
For kgPanels you'd probably want to put that in the OnLoad script for your panel. I assume you only want to change the color temporarily, in which case you'd want to (a) change the color and (b) set a variable indicating what time the color was changed in the above function, and then add an OnUpdate script to change the color back to the default after a specified amount of time:

Code:
self.text:SetTextColor(0, 1, 0) -- change it to green
self.colorTimeout = 5 -- change it back 5 seconds from now
OnUpdate:
Code:
if not self.colorTimeout then
	return
end
self.colorTimeout = self.colorTimeout - elapsed
if self.colorTimeout <= 0 then
	self.text:SetTextColor(1, 1, 1) -- change it back to white
	self.colorTimeout = nil
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
11-04-13, 09:59 AM   #3
Akatosh
A Black Drake
AddOn Compiler - Click to view compilations
Join Date: Jun 2013
Posts: 84
Ok thanks for the code, at this moment works very well, only I change 3 lines to adapit to me, I put the results here, cause Its directly related:

http://www.wowinterface.com/forums/s...t=46786&page=4


Thanks for all!!.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Need help with Event "CHAT_MSG_SYSTEM"


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off