View Single Post
03-04-14, 03:18 PM   #8
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Originally Posted by Phanx View Post
The simplest solution is probably going to be to hook the function that sets the text:

Code:
hooksecurefunc("UnitFrame_Update", function(self)
	if not self.name then return end

	if UnitIsPlayer(self.unit) then
		-- Color by class:
		local _, class = UnitClass(self.unit)
		local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
		self.name:SetTextColor(color.r, color.g, color.b)
	else
		-- Not a player. Return to default color:
		self.name:SetTextColor(1, 0.82, 0)
	end
end)
Feel free to color non-players by reaction instead of using the default color.

If you wanted to color pets by their owner's class, the simplest solution would probably be to look at the pet's creature type and just make an assumption -- eg. beast = hunter, demon = warlock, etc.

Thank you for this it works great.

Im confused on trying to do the "reaction" part.

I've tried:
Code:
		self.name:SetTextColor(FACTION_BAR_COLORS[reaction].r, FACTION_BAR_COLORS[reaction].g, FACTION_BAR_COLORS[reaction].b)
but I keep getting errors.

Even tried:
Code:
		FACTION_BAR_COLORS = {
			[1] = {r = 0.8, g = 0.3, b = 0.22},
			[2] = {r = 0.8, g = 0.3, b = 0.22},
			[3] = {r = 0.75, g = 0.27, b = 0},
			[4] = {r = 0.9, g = 0.7, b = 0},
			[5] = {r = 0, g = 0.6, b = 0.1},
			[6] = {r = 0, g = 0.6, b = 0.1},
			[7] = {r = 0, g = 0.6, b = 0.1},
			[8] = {r = 0, g = 0.6, b = 0.1},
		};		
		local reaction = UnitReaction(self.unit, "player");
		self.name:SetTextColor(FACTION_BAR_COLORS[reaction].r, FACTION_BAR_COLORS[reaction].g, FACTION_BAR_COLORS[reaction].b)
so any help would be great.

and thanks again for all your help.

Coke

P.S.
Error I keep getting:
Code:
Message: ...ace\AddOns\BasicUI\Modules\Unitframes\Unitframes.lua:199: attempt to index field '?' (a nil value)
Time: 03/04/14 13:18:37
Count: 5
Stack: ...ace\AddOns\BasicUI\Modules\Unitframes\Unitframes.lua:199: in function <...ace\AddOns\BasicUI\Modules\Unitframes\Unitframes.lua:188>
[C]: in function `UnitFrame_Update'
...terface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:275: in function `ArenaEnemyFrame_UpdatePet'
...terface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:47: in function <...terface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:25>

Locals: self = ArenaEnemyFrame5PetFrame {
 0 = <userdata>
 menu = <function> defined @Interface\AddOns\Blizzard_ArenaUI\Blizzard_ArenaUI.lua:295
 name = ArenaEnemyFrame5PetFrameName {
 }
 DropDown = ArenaEnemyFrame5PetFrameDropDown {
 }
 manabar = ArenaEnemyFrame5PetFrameManaBar {
 }
 portrait = ArenaEnemyFrame5PetFramePortrait {
 }
 healthbar = ArenaEnemyFrame5PetFrameHealthBar {
 }
 unit = "arenapet5"
}
reaction = nil
(*temporary) = <function> defined =[C]:-1
(*temporary) = ArenaEnemyFrame5PetFrameName {
 0 = <userdata>
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field '?' (a nil value)"

Last edited by cokedrivers : 03-04-14 at 03:23 PM.
  Reply With Quote