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,871
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,871
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
11-14-15, 07:25 AM   #7
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Phanx View Post
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.
Im confused .. xD The bigger bar in the screenshots are my healthbar from stuf unitframes. I just want that little bar the same color as the hp bar u see above it.. so if i target a mage it shows the mage class color, if i target a neutral target it should show the neutral mob color (the one i use on stuf), same goes for the hostile mob.. sorry if im hard to understand.. i tried understanding what you wrote, but as im new to scripts i ended up confused.. xD
  Reply With Quote
11-14-15, 10:20 AM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I had to look at your screenshots like 3 times to see what you actually were doing/wanting.


Your statusbar texture on your healthbars isn't white. It's a touch gray. So it's making the color a touch darker. Switch your statusbar texture to be a white one, or switch your kgPanels background texture to be the same as your healthbars.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-14-15, 10:51 AM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
We need to see your whole code. I think the black textures you are having issues is caused by creating a new texture inside of the event trigger, and it builds to a big black bulk.
  Reply With Quote
11-14-15, 10:58 AM   #10
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Seerah View Post
I had to look at your screenshots like 3 times to see what you actually were doing/wanting.


Your statusbar texture on your healthbars isn't white. It's a touch gray. So it's making the color a touch darker. Switch your statusbar texture to be a white one, or switch your kgPanels background texture to be the same as your healthbars.
the statusbar is actually using a white statusbar.tga i created so yeah.. xD
  Reply With Quote
11-14-15, 12:20 PM   #11
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
so no update? I have a white statusbar BG so that theory is gone.
  Reply With Quote
11-14-15, 01:46 PM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
If all you want is for your panel colour to change to the same as the healthbar colour whenever it changes then Phanx's method is the way to go.

It assumes the healthbar is a StatusBar widget and you know the name of it, which you should be able to get with /fstack, and that STUF is loaded before your panels OnLoad fires.

IF the name of the healthbar is say STUF_TargetHealth then in your panels OnLoad (delete the RegisterEvent and all the OnEvent code you have) and add:

Code:
    hooksecurefunc(STUF_TargetHealth, "SetStatusBarColor", function(self, ...)
         self.bg:SetVertexColor(...)
    end)
Every time the healthbar changes it will also change your panel colour.

You might need something additional depending on what you want to do when the target goes out-of-range.
__________________
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 01:57 PM.
  Reply With Quote
11-14-15, 01:58 PM   #13
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Fizzlemizz View Post
If all you want is for your panel colour to change to the same as the healthbar colour whenever it changes then Phanx's method is the way to go.

It assumes the healthbar is a StatusBar widget and you know the name of it, which you should be able to get with /fstack, and that STUF is loaded before your panels OnLoad fires.

IF the name of the healthbar is say STUF_TargetHealth then in your panels OnLoad (delete the RegisterEvent and all the OnEvent code you have) and add:

Code:
    hooksecurefunc(STUF_TargetHealth, "SetStatusBarColor", function(self, ...)
         self.bg:SetVertexColor(...)
    end)
Every time the healthbar changes it will also change your panel colour.

You might need something additional depending on what you want to do when the target goes out-of-range.
Im really thankfull for all you guys help! I tried this but this gave me an error!

what did i do wrong now :P?

http://i.imgur.com/RbI9tSB.jpg
  Reply With Quote
11-14-15, 02:03 PM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
What was the error? If the healthbar is not a StatusBar widget or the panels Onload fires before STUF is loaded that will cause errors as mentioned in Phanx's post.

It looks like the healthbar is not a statusbar but several seperate frames so my best guess would be:

Code:
hooksecurefunc(Stuf.units.target.hpbar.bar, "SetVertexColor", function(self, ...)
         self.bg:SetVertexColor(...)
    end)
__________________
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 02:15 PM.
  Reply With Quote
11-14-15, 02:15 PM   #15
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Fizzlemizz View Post
What was the error? If the healthbar is not a StatusBar widget or the panels Onload fires before STUF is loaded that will cause errors as mentioned in Phanx's post.

It looks like the healthbar is not a statusbar but several seperate frames so my best guess would be:

Code:
hooksecurefunc(Stuf.units.target.hpbar.bar, "SetVertexColor", function(self, ...)
         self.bg:SetVertexColor(...)
    end)
This is the error from the first script

Code:
Message: [string "Targetbottom_OnLoad"]:1: hooksecurefunc(): SetStatusBarColor is not a function
Time: 11/14/15 21:15:51
Count: 1
Stack: [C]: in function `hooksecurefunc'
[string "Targetbottom_OnLoad"]:1: in function `y'
Interface\AddOns\kgPanels\kgPanels.lua:1115: in function `SetupScript'
Interface\AddOns\kgPanelsConfig\PanelHelper.lua:1330: in function <Interface\AddOns\kgPanelsConfig\PanelHelper.lua:1327>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[2]"]:9: in function <[string "safecall Dispatcher[2]"]:5>
(tail call): ?
...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:799: in function <...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:614>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[3]"]:9: in function <[string "safecall Dispatcher[3]"]:5>
(tail call): ?
...terface\AddOns\Masque\Libs\AceGUI-3.0\AceGUI-3.0.lua:314: in function `Fire'
...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:67: in function <...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:64>

Locals: <none>
And this is from the new script you just wrote

Code:
Message: [string "Targetbottom_OnLoad"]:2: attempt to index field 'bg' (a nil value)
Time: 11/14/15 21:17:37
Count: 2
Stack: [string "Targetbottom_OnLoad"]:2: in function <[string "Targetbottom_OnLoad"]:1>
[C]: in function `SetVertexColor'
Interface\AddOns\Stuf\bars.lua:97: in function `func'
Interface\AddOns\Stuf\core.lua:895: in function <Interface\AddOns\Stuf\core.lua:857>
Interface\AddOns\Stuf\core.lua:822: in function <Interface\AddOns\Stuf\core.lua:795>
Interface\AddOns\Stuf\core.lua:834: in function `?'
Interface\AddOns\Stuf\core.lua:110: in function <Interface\AddOns\Stuf\core.lua:109>
[C]: in function `CameraOrSelectOrMoveStop'
[string "CAMERAORSELECTORMOVE"]:4: in function <[string "CAMERAORSELECTORMOVE"]:1>

Locals: self = <unnamed> {
 sv = <function> defined @Interface\AddOns\Stuf\core.lua:718
 SetVertexColor = <function> defined =[C]:-1
 0 = <userdata>
 SetValue = <function> defined @Interface\AddOns\Stuf\core.lua:718
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field 'bg' (a nil value)"

Last edited by Soulcleaver : 11-14-15 at 02:18 PM.
  Reply With Quote
11-14-15, 02:24 PM   #16
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
My bad, the self in self.bg needs to be the actual name of your panel asuming KgPanels gives it a name. You should be able to get this with /fstack.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-14-15, 04:39 PM   #17
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Fizzlemizz View Post
My bad, the self in self.bg needs to be the actual name of your panel asuming KgPanels gives it a name. You should be able to get this with /fstack.
Like this? Or did i understand this wrong :P?

http://i.imgur.com/CPHTTXF.jpg
  Reply With Quote
11-14-15, 04:42 PM   #18
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
If Targetbottom (case sensitive) is the name of your panel it would be:

Targetbottom.bg:SetVertexColor(...)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
11-14-15, 08:03 PM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Rather than making the script dependent on your panel name, just use the "self" that's passed into your panel's script and rename the "self" parameter in the hook function something else, since it's not used anyway:

Code:
hooksecurefunc(Stuf.units.target.hpbar.bar, "SetVertexColor", function(bar, ...)
         self.bg:SetVertexColor(...)
    end)
^ Now "self.bg" should be fine, since "self" automatically refers to the panel the script is set on, and isn't overwritten by a different "self".
__________________
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-15-15, 02:25 AM   #20
Soulcleaver
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 65
Originally Posted by Phanx View Post
Rather than making the script dependent on your panel name, just use the "self" that's passed into your panel's script and rename the "self" parameter in the hook function something else, since it's not used anyway:

Code:
hooksecurefunc(Stuf.units.target.hpbar.bar, "SetVertexColor", function(bar, ...)
         self.bg:SetVertexColor(...)
    end)
^ Now "self.bg" should be fine, since "self" automatically refers to the panel the script is set on, and isn't overwritten by a different "self".
gave me an error..

Code:
Message: [string "Targetbottom_OnLoad"]:1: hooksecurefunc(): SetVertexColor is not a function
Time: 11/15/15 09:25:16
Count: 4
Stack: [C]: in function `hooksecurefunc'
[string "Targetbottom_OnLoad"]:1: in function `y'
Interface\AddOns\kgPanels\kgPanels.lua:1115: in function `SetupScript'
Interface\AddOns\kgPanelsConfig\PanelHelper.lua:1330: in function <Interface\AddOns\kgPanelsConfig\PanelHelper.lua:1327>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[2]"]:9: in function <[string "safecall Dispatcher[2]"]:5>
(tail call): ?
...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:799: in function <...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:614>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[3]"]:9: in function <[string "safecall Dispatcher[3]"]:5>
(tail call): ?
...terface\AddOns\Masque\Libs\AceGUI-3.0\AceGUI-3.0.lua:314: in function `Fire'
...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:67: in function <...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:64>

Locals: <none>
  Reply With Quote

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

Thread Tools
Display Modes

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