View Single Post
12-13-13, 06:17 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well here is an example tag from my own layout that is definitely working with a "unitless" event:

Code:
oUF.Tags.Events["restingicon"] = "PLAYER_UPDATE_RESTING"
oUF.Tags.SharedEvents["PLAYER_UPDATE_RESTING"] = true
oUF.Tags.Methods["restingicon"] = function(unit)
	if unit == "player" and IsResting() then
		return [[|TInterface\CharacterFrame\UI-StateIcon:0:0:0:-6:64:64:28:6:6:28|t]]
	end
end
Based on that, here is how I would write a mushroom counter tag (with your coloring):

Code:
oUF.Tags.Events["mushrooms"] = "PLAYER_TOTEM_UPDATE"
oUF.Tags.SharedEvents["PLAYER_TOTEM_UPDATE"] = true
oUF.Tags.Methods["mushrooms"] = function(unit)
	if unit == "player" then
		local count = 0
		for i = 1, MAX_TOTEMS do
			local _, _, _, duration = GetTotemInfo(i)
			if duration > 0 then
				count = count + 1
			end
		end
		print("UPDATE TAG: mushrooms", count)
		if count > 0 then
			local color = cfg.colors.power.CP[2 * count - 1]
			return format("|cff%02x%02x%02x%d|r", color[1] * 255, color[2] * 255, color[3] * 255, count)
		end
	end
end
I don't have a druid to test that on, though.

For your health tag, I suspect the problem is the way you are listing events. Rather than concatenating the events from other tags (which may or may not be defined yet when your code runs) just write out the events; there are only two of them. Also, you don't need to explicitly return an empty string or a zero if there's no value; just don't return anything, and the fontstring will be emptied.

Code:
oUF.Tags.Events["BossBars:health"] = "UNIT_HEALTH UNIT_MAXHEALTH"
oUF.Tags.Methods["BossBars:health"] = function(unit)
	local m = UnitHealthMax(unit)
	if m > 0 then
		return floor(UnitHealth(unit) / m * 100 + 0.5)
	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