Thread Tools Display Modes
11-13-15, 02:06 PM   #1
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
KGpanels target color script help!

Hi, im making an ui and i want my target panel to be hostile colored.. aka "faction colored" and class color if its a friendly target :P my script only uses class color but i need help to make it better:P

on load:

self:RegisterEvent("PLAYER_TARGET_CHANGED")

on event:

if UnitExists("target") then
local _, Class = UnitClass("target")
local Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
self.bg:SetVertexColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
end

Any help appriciated
  Reply With Quote
11-13-15, 02:34 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Something like:

Code:
local Color = { r=1, g=0, b=0 } -- red for any hostile
if UnitExists("target") then
	if not UnitCanAttack("player", "target") then
		local _, Class = UnitClass("target")
		Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
	end
	self.bg:SetVertexColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
else
	self.bg:Hide() -- or set it to some generic colour
end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-13-15 at 02:56 PM.
  Reply With Quote
11-13-15, 04:15 PM   #3
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Fizzlemizz View Post
Something like:

Code:
local Color = { r=1, g=0, b=0 } -- red for any hostile
if UnitExists("target") then
	if not UnitCanAttack("player", "target") then
		local _, Class = UnitClass("target")
		Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
	end
	self.bg:SetVertexColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())
else
	self.bg:Hide() -- or set it to some generic colour
end
Thank you, ive tried this and this did not work how i wanted it to work. I got a image here of what happened ingame with this script!

I pasted the script in "onEvent" and kept the same "onLoad" script as my original post, is the mistake there?

http://i.imgur.com/YXpwBBk.jpg

Hope this helps you find the mistake either you or i did :P
  Reply With Quote
11-13-15, 07:30 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
This might be closer to what you'r looking for, it doesn't account for tapped or dead.

Code:
if UnitExists("target") then
	local r, g, b
	local playerFaction, targetFaction = UnitFactionGroup("player"), UnitFactionGroup("target")
	if targetFaction == "Neutral" then -- level less than 20 Panda or 55-58 DK
		-- r, g, b, = 1, 1, 1 -- whatever color works for you
	elseif targetFaction and playerFaction ~= targetFaction then -- enemy faction NPC or player
		r, g, b = 1, 0, 0 -- red
	elseif UnitIsPlayer("target") then -- friendly player
		local _, Class = UnitClass("target")
		local Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
		r, g, b = Color.r, Color.g, Color.b
	else -- non "factioned" NPC
		r, g, b = UnitSelectionColor("target") -- your "reaction" to the target (neutral, friendly, die you sob)
	end
	self.bg:SetVertexColor(r, g, b)
else -- target out of range
	self.bg:SetVertexColor(0, 0, 0) -- or hide or...
end
Someone might have better or more definitive solution.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-14-15 at 03:07 AM.
  Reply With Quote
11-14-15, 03:57 AM   #5
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Fizzlemizz View Post
This might be closer to what you'r looking for, it doesn't account for tapped or dead.

Code:
if UnitExists("target") then
	local r, g, b
	local playerFaction, targetFaction = UnitFactionGroup("player"), UnitFactionGroup("target")
	if targetFaction == "Neutral" then -- level less than 20 Panda or 55-58 DK
		-- r, g, b, = 1, 1, 1 -- whatever color works for you
	elseif targetFaction and playerFaction ~= targetFaction then -- enemy faction NPC or player
		r, g, b = 1, 0, 0 -- red
	elseif UnitIsPlayer("target") then -- friendly player
		local _, Class = UnitClass("target")
		local Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
		r, g, b = Color.r, Color.g, Color.b
	else -- non "factioned" NPC
		r, g, b = UnitSelectionColor("target") -- your "reaction" to the target (neutral, friendly, die you sob)
	end
	self.bg:SetVertexColor(r, g, b)
else -- target out of range
	self.bg:SetVertexColor(0, 0, 0) -- or hide or...
end
Someone might have better or more definitive solution.
http://i.imgur.com/VLZVVue.jpg

Okay this seem to work how i want it to be, but i can't get the colors to match :S

As you can see in the preview, this is what my bars look like, they don't match my hp bars! I've included the colors i want the bars to be on the certain targets like neutral(yellow), green/faction/friendly mob(green) and hostile (red).

I tried to edit the "r,g,b" values i could in the script but they still didn't match the colors..

This is how my script looks like after i edited something, what am i doing wrong?

OnEvent

if UnitExists("target") then
local r, g, b
local playerFaction, targetFaction = UnitFactionGroup("player"), UnitFactionGroup("target")
if targetFaction == "Neutral" then -- level less than 20 Panda or 55-58 DK
-- r, g, b, = 247, 236, 54
elseif targetFaction and playerFaction ~= targetFaction then -- enemy faction NPC or player
r, g, b = 247, 88, 54
elseif UnitIsPlayer("target") then -- friendly player
local _, Class = UnitClass("target")
local Color = RAID_CLASS_COLORS[Class] or {r = 1, g = 1, b = 1}
r, g, b = Color.r, Color.g, Color.b
else -- non "factioned" NPC
r, g, b = UnitSelectionColor("target") -- your "reaction" to the target (neutral, friendly, die you sob)
end
self.bg:SetVertexColor(r, g, b)
else -- target out of range
self.bg:SetVertexColor(0, 0, 0)
end

OnLoad

self:RegisterEvent("PLAYER_TARGET_CHANGED")
  Reply With Quote
11-14-15, 07:06 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If your goal is just "make this thing the same color as that other thing, always" then you shouldn't be rewriting tons of code -- just grab the color from "that other thing" and apply it to "this thing":

Lua Code:
  1. hooksecurefunc(ThatOtherThing, "SetStatusBarColor", function(self, ...)
  2.      ThisThing:SetVertexColor(...)
  3. end)

You should be able to put that in your OnLoad script, as long as "that other thing" already exists when your panel loads.

Also, the above code assumes that "that other thing" is actually a StatusBar object. If it's just a texture, you'd need to hook SetVertexColor instead of SetStatusBarColor.
__________________
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

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » KGpanels target color script help!


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