Class Colored Personal Resource Display?

I’ve searched everywhere and can’t find an addon that makes the health bar on the personal resource display match the player’s class color. I don’t want it to do anything else, so no nameplate overhaul addons. I have my own addon with various scripts in it, so if anyone knows how to do this, please help me out and paste the script? :slight_smile:

Something like:

local color, defColor, PRD
hooksecurefunc(NamePlateBaseMixin, "OnAdded", function(self, namePlateUnitToken, driverFrame)
	if not color then
		color = C_ClassColor.GetClassColor(select(2, UnitClass("player")))
	end
	if self == C_NamePlate.GetNamePlateForUnit("player", issecure()) then
		if not defColor then
			defColor = CreateColor(self.UnitFrame.healthBar:GetStatusBarColor())
		end
		self.UnitFrame.healthBar:SetStatusBarColor(color:GetRGB())
		PRD = self
	end
end)
hooksecurefunc(NamePlateBaseMixin, "OnRemoved", function(self, namePlateUnitToken, driverFrame)
	if self.UnitFrame and self == PRD then
		self.UnitFrame.healthBar:SetStatusBarColor(defColor:GetRGB())
		PRD = nil
	end
end)

I don’t use the PRD so I might need to be refined.

1 Like

No luck. The script doesn’t break my addon, but it doesn’t seem to do anything either. I appreciate the help though, I remember you helped me with an aura filter for nameplates a couple of years ago.

Edit: If I stand in place near nameplates (friendly or enemy) and start spinning my camera around, the nameplates will change to and from my class color when they appear or disappear. The script is definitely functioning, but not as intended.

Sorry, I’ve been wanting to do this since this thread started:

“I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their personal resource display but by the content of their dynamic statistics.”

2 Likes

Amen, brother.

1 Like
-- code didn't work as intended!
1 Like

It stops working after a bit of playing. As long as the health bar is showing after you load the script, it will have the class color. Once it fades out, it starts to come in as the default green (not consistently, but once it’s green, it seems to stay green).

I changed the code in my OP. I had some time to run around with it today and it seems to do what you want.

1 Like

I’ve noticed a problem with the script. If a friendly player with a class-colored nameplate spawns on my screen, their nameplate will first appear green until I look away from it and then back at it. This makes it hard to distinguish friendly players from friendly NPC’s. I’m not sure if this happens with enemies or not because I’m in a sanctuary where enemy players don’t have nameplates.

Edit: It seems to happen more randomly than I thought. I’m not sure why, but some nameplates appear green at first.

The class colouring should only apply to your character’s PRD health bar. Everyone elses should be the default color. I found it strange where the class and power colours are both the same hence both heath and “mana” bar would be the same coloiur like yellow for a rogue.

Unless we’ve been talking about different things as to me, the PRD is the custom player plate that appear under your character (when you turn PRD on under Names in the interface options).

1 Like

You’re right, you know exactly what I’m asking for. It’s just that the script is a little buggy. I have friendly nameplates on with the console variable for class-colored friendly nameplates enabled. With this script active, my personal resource display’s health bar is always my class color. That part seems to be working. But occasionally, a friendly nameplate which is supposed to be that player’s class color will instead be green. This may or may not be limited to friendly nameplates, I’ve yet to find out.

I haven’t seen but it I can see how it could happen. I’ll play with it and post a new version.

Let you know.

1 Like

I’ve found that I can reproduce it by enabling class-colored friendly nameplates and walking around the Ring of Fates until I see a green one.

Any chance you could do this with the tooltip HP bar too? It’s the only one that’s still green for players. I have a script that changes the name text, maybe that could help.

GameTooltip:HookScript("OnTooltipSetUnit", function(GameTooltip)
	--print("OnTooltipSetUnit")
	local _, unit = GameTooltip:GetUnit()
	--print(unit)
	if UnitIsPlayer(unit) then
		--print("UnitIsPlayer")
		local _, class = UnitClass(unit)
		--print(class)
		local color = class and (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
		if color then
			local text = GameTooltipTextLeft1:GetText()
			--print(text)
			GameTooltipTextLeft1:SetFormattedText("|cff%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, text:match("|cff\x\x\x\x\x\x(.+)|r") or text)
		end
	end
end)

Updated the OP code (I was using the NPC default colour :slightly_frowning_face:).

For the tooltip, I use TipTac but I imagine that after (or before) you’ve done the :SetFormattedText(...)

you could:
_G[GameTooltip:GetName().."StatusBar"]:SetStatusBarColor(color.r, color.g, color.b)

Edit: Left off the PRD = nil, fixed.

1 Like

Whenever the health bar on the tooltip updates (HP values change), it defaults back to green. Oh well, I’ll just leave that where it is. The personal resource display script seems to work now! I really appreciate you doing this for me, I never would have figured it out myself.

1 Like

Excuse me would you share the personal resource script? I’m only interested in that one, I really dislike the way the yellow energy resource looks with monk’s green class color. I envy DH’s and Spriest so much lol! :smiley:

Did you not scroll up?

Know this is old, this was what i was looking for, but on Evoker, whenever i press hover, it changes the color back. Any reason why?