WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   KGpanels target color script help! (https://www.wowinterface.com/forums/showthread.php?t=52876)

Soulcleaver 11-13-15 02:06 PM

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 :)

Fizzlemizz 11-13-15 02:34 PM

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


Soulcleaver 11-13-15 04:15 PM

Quote:

Originally Posted by Fizzlemizz (Post 311753)
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

Fizzlemizz 11-13-15 07:30 PM

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.

Soulcleaver 11-14-15 03:57 AM

Quote:

Originally Posted by Fizzlemizz (Post 311762)
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")

Phanx 11-14-15 07:06 AM

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.

Soulcleaver 11-14-15 07:25 AM

Quote:

Originally Posted by Phanx (Post 311771)
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

Seerah 11-14-15 10:20 AM

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.

Resike 11-14-15 10:51 AM

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.

Soulcleaver 11-14-15 10:58 AM

Quote:

Originally Posted by Seerah (Post 311773)
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

Soulcleaver 11-14-15 12:20 PM

so no update? I have a white statusbar BG so that theory is gone.

Fizzlemizz 11-14-15 01:46 PM

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.

Soulcleaver 11-14-15 01:58 PM

Quote:

Originally Posted by Fizzlemizz (Post 311777)
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

Fizzlemizz 11-14-15 02:03 PM

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)


Soulcleaver 11-14-15 02:15 PM

Quote:

Originally Posted by Fizzlemizz (Post 311779)
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)"


Fizzlemizz 11-14-15 02:24 PM

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.

Soulcleaver 11-14-15 04:39 PM

Quote:

Originally Posted by Fizzlemizz (Post 311781)
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

Fizzlemizz 11-14-15 04:42 PM

If Targetbottom (case sensitive) is the name of your panel it would be:

Targetbottom.bg:SetVertexColor(...)

Phanx 11-14-15 08:03 PM

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".

Soulcleaver 11-15-15 02:25 AM

Quote:

Originally Posted by Phanx (Post 311785)
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>



All times are GMT -6. The time now is 01:52 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI