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 :) |
Something like:
Code:
local Color = { r=1, g=0, b=0 } -- red for any hostile |
Quote:
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 |
This might be closer to what you'r looking for, it doesn't account for tapped or dead.
Code:
if UnitExists("target") then |
Quote:
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") |
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:
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. |
Quote:
|
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. |
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.
|
Quote:
|
so no update? I have a white statusbar BG so that theory is gone.
|
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, ...) You might need something additional depending on what you want to do when the target goes out-of-range. |
Quote:
what did i do wrong now :P? http://i.imgur.com/RbI9tSB.jpg |
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, ...) |
Quote:
Code:
Message: [string "Targetbottom_OnLoad"]:1: hooksecurefunc(): SetStatusBarColor is not a function Code:
Message: [string "Targetbottom_OnLoad"]:2: attempt to index field 'bg' (a nil value) |
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.
|
Quote:
http://i.imgur.com/CPHTTXF.jpg |
If Targetbottom (case sensitive) is the name of your panel it would be:
Targetbottom.bg:SetVertexColor(...) |
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, ...) |
Quote:
Code:
Message: [string "Targetbottom_OnLoad"]:1: hooksecurefunc(): SetVertexColor is not a function |
All times are GMT -6. The time now is 01:52 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI