WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   KGPanels Scripts target (https://www.wowinterface.com/forums/showthread.php?t=37239)

Kendian 11-30-10 07:30 PM

KGPanels Scripts target
 
HIyas, Im trying to make a panel (for target UF to be class colored). Meaning, does anyone know the script to make a panel the TARGETS class color? My thanks, in advance for any and all help~

Fake edit: I tried the page at wowace, but no one ever answers questions there >.<

Waky 11-30-10 09:49 PM

Writing one, just a sec.

Edit:
Code:

-- OnLoad
self:RegisterEvent("UNIT_TARGET")


-- OnEvent
if (event=="UNIT_TARGET") then
local _, class = UnitClass("target")
        if (class=="DEATHKNIGHT") then
                self.bg:SetVertexColor(0.77, 0.12, 0.23, self.bg:GetAlpha())
        elseif (class=="DRUID") then
                self.bg:SetVertexColor(1,0.49,0.04, self.bg:GetAlpha())
        elseif (class=="HUNTER") then
                self.bg:SetVertexColor(0.67,0.83,0.45, self.bg:GetAlpha())
        elseif (class=="MAGE") then
                self.bg:SetVertexColor(0.41,0.8,0.94, self.bg:GetAlpha())
        elseif (class=="PALADIN") then
                self.bg:SetVertexColor(0.96,0.55,0.73, self.bg:GetAlpha())
        elseif (class=="PRIEST") then
                self.bg:SetVertexColor(1,1,1, self.bg:GetAlpha())
        elseif (class=="ROGUE") then
                self.bg:SetVertexColor(1,0.96,0.41, self.bg:GetAlpha())
        elseif (class=="SHAMAN") then
                self.bg:SetVertexColor(0,0.44,0.87, self.bg:GetAlpha())
        elseif (class=="WARLOCK") then
                self.bg:SetVertexColor(0.58,0.51,0.79, self.bg:GetAlpha())
        elseif (class=="WARRIOR") then
                self.bg:SetVertexColor(0.78,0.61,0.43, self.bg:GetAlpha())
        end
end


Seerah 11-30-10 10:02 PM

Quote:

Originally Posted by Waky (Post 220860)
Writing one, just a sec.

Edit:
Code:

-- OnLoad
self:RegisterEvent("PLAYER_TARGET_CHANGED")


Fixed. :) That one there will only fire for your target.

/edit: you also need to change the OnEvent (btw, checking for the event isn't needed since we're only registering for one event anyway)

Code:

-- OnEvent
local _, class = UnitClass("target")
if class then
        if (class=="DEATHKNIGHT") then
                self.bg:SetVertexColor(0.77, 0.12, 0.23, self.bg:GetAlpha())
        elseif (class=="DRUID") then
                self.bg:SetVertexColor(1,0.49,0.04, self.bg:GetAlpha())
        elseif (class=="HUNTER") then
                self.bg:SetVertexColor(0.67,0.83,0.45, self.bg:GetAlpha())
        elseif (class=="MAGE") then
                self.bg:SetVertexColor(0.41,0.8,0.94, self.bg:GetAlpha())
        elseif (class=="PALADIN") then
                self.bg:SetVertexColor(0.96,0.55,0.73, self.bg:GetAlpha())
        elseif (class=="PRIEST") then
                self.bg:SetVertexColor(1,1,1, self.bg:GetAlpha())
        elseif (class=="ROGUE") then
                self.bg:SetVertexColor(1,0.96,0.41, self.bg:GetAlpha())
        elseif (class=="SHAMAN") then
                self.bg:SetVertexColor(0,0.44,0.87, self.bg:GetAlpha())
        elseif (class=="WARLOCK") then
                self.bg:SetVertexColor(0.58,0.51,0.79, self.bg:GetAlpha())
        elseif (class=="WARRIOR") then
                self.bg:SetVertexColor(0.78,0.61,0.43, self.bg:GetAlpha())
        end
end


Waky 11-30-10 10:12 PM

Pssh :P Thanks Seerah

Kendian 11-30-10 10:14 PM

My thanks, ever so much, both of you~ :banana::rolleyes::D:banana:

Kendian 01-26-11 09:34 PM

Quote:

Originally Posted by Seerah (Post 220862)
Fixed. :) That one there will only fire for your target.

/edit: you also need to change the OnEvent (btw, checking for the event isn't needed since we're only registering for one event anyway)

Code:

-- OnEvent
local _, class = UnitClass("target")
if class then
        if (class=="DEATHKNIGHT") then
                self.bg:SetVertexColor(0.77, 0.12, 0.23, self.bg:GetAlpha())
        elseif (class=="DRUID") then
                self.bg:SetVertexColor(1,0.49,0.04, self.bg:GetAlpha())
        elseif (class=="HUNTER") then
                self.bg:SetVertexColor(0.67,0.83,0.45, self.bg:GetAlpha())
        elseif (class=="MAGE") then
                self.bg:SetVertexColor(0.41,0.8,0.94, self.bg:GetAlpha())
        elseif (class=="PALADIN") then
                self.bg:SetVertexColor(0.96,0.55,0.73, self.bg:GetAlpha())
        elseif (class=="PRIEST") then
                self.bg:SetVertexColor(1,1,1, self.bg:GetAlpha())
        elseif (class=="ROGUE") then
                self.bg:SetVertexColor(1,0.96,0.41, self.bg:GetAlpha())
        elseif (class=="SHAMAN") then
                self.bg:SetVertexColor(0,0.44,0.87, self.bg:GetAlpha())
        elseif (class=="WARLOCK") then
                self.bg:SetVertexColor(0.58,0.51,0.79, self.bg:GetAlpha())
        elseif (class=="WARRIOR") then
                self.bg:SetVertexColor(0.78,0.61,0.43, self.bg:GetAlpha())
        end
end


Sigh...I need to wear a helmet in public, I suppose ( my brain is mushy)...how would I apply this to BORDER of targets panel?

Nibelheim 01-26-11 11:04 PM

A bit more compact, should work:

-- OnEvent
Code:

local _, Class = UnitClass("target")
local Color = RAID_CLASS_COLORS[Class]
self.bg:SetVertexColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())

As for borders.

-- OnEvent
Code:

local _, Class = UnitClass("target")
local Color = RAID_CLASS_COLORS[Class]
self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())


Kendian 01-26-11 11:32 PM

How lame is it that I spent 2.5 hours trying to figure this out, lol?
My thanks, Nibleheim, it's much appreciated~

Kendian 01-27-11 12:00 AM

This is doing the same thing.....it's fine if I click on target to target, but everytime I DEselect a target (no target at all) it throws a huge error >.<


Message: [string "a_OnEvent"]:3: attempt to index local 'Color' (a nil value)
Time: 01/27/11 00:57:24
Count: 3
Stack: [string "a_OnEvent"]:3: in function <[string "a_OnEvent"]:1>
[C]: in function `CameraOrSelectOrMoveStop'
[string "CAMERAORSELECTORMOVE"]:4: in function <[string "CAMERAORSELECTORMOVE"]:1>

Locals: self = kgPanel1 {
0 = <userdata>
missing_parent_at_load = false
missing_anchor_at_load = false
text = <unnamed> {
}
bg = <unnamed> {
}
scripts_loaded = false

Is the gist of it.

Nibelheim 01-27-11 01:07 AM

Quote:

Originally Posted by Kendian (Post 227826)
This is doing the same thing.....it's fine if I click on target to target, but everytime I DEselect a target (no target at all) it throws a huge error >.<


Message: [string "a_OnEvent"]:3: attempt to index local 'Color' (a nil value)
Time: 01/27/11 00:57:24
Count: 3
Stack: [string "a_OnEvent"]:3: in function <[string "a_OnEvent"]:1>
[C]: in function `CameraOrSelectOrMoveStop'
[string "CAMERAORSELECTORMOVE"]:4: in function <[string "CAMERAORSELECTORMOVE"]:1>

Locals: self = kgPanel1 {
0 = <userdata>
missing_parent_at_load = false
missing_anchor_at_load = false
text = <unnamed> {
}
bg = <unnamed> {
}
scripts_loaded = false

Is the gist of it.

Ahh, thought you were already accounting for no target situations. Here you go:

Code:

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


Nibelheim 01-27-11 01:18 AM

You know, may as well go all the way :p

Colored by Pet, Player, Hostility.

Code:

local Color = {r = 1, g = 1, b = 1};
       
if UnitExists("target") then
        if ( UnitExists("pet") and UnitIsUnit("target", "pet") ) then
                Color = {r = 1, g = 1, b = 1}
        elseif UnitIsPlayer("target") then
                local _, class = UnitClass("target");
                Color = RAID_CLASS_COLORS[class];
        else
                if UnitIsEnemy("player", "target") then
                        Color = {r = 1, g = 0, b = 0}
                elseif UnitCanAttack("player", UFD.unitname) then
                        Color = {r = 1, g = 1, b = 0}
                else
                        Color = {r = 0, g = 1, b = 0}
                end
        end
end
       
self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())


Kendian 01-27-11 01:55 AM

That worked perfectly. You have my thanks, and my gratitude, hero~

Kendian 01-27-11 05:19 AM

Rofl, now this got me thinking if theres a script to show pets happiness?

Edit: To change a panels color depending on pets happiness, i.e red/yellow/green.

Nibelheim 01-27-11 01:48 PM

Quote:

Originally Posted by Kendian (Post 227838)
Rofl, now this got me thinking if theres a script to show pets happiness?

Edit: To change a panels color depending on pets happiness, i.e red/yellow/green.

There's a script for almost anything :p

Code:

local Color = {r = 1, g = 1, b = 1}
if UnitExists("pet") then
        local happiness = GetPetHappiness()
        if happiness == 1 then
                Color = {r = 1, g = 0, b = 0}
        elseif happiness == 2 then
                Color = {r = 1, g = 1, b = 0}
        elseif happiness == 3 then
                Color = {r = 0, g = 1, b = 0}
        end
end
self:SetBackdropBorderColor(Color.r, Color.g, Color.b)


Othgar 01-27-11 04:52 PM

Quote:

Originally Posted by Nibelheim (Post 227881)
There's a script for almost anything :p

So then would there be a script that could hide a panel when you're not moving, but show the panel when you are moving? I was thinking of this earlier for a minimap mod, but couldn't come up with a way to do it. Closest I got was
Code:

if movementspeed == 0 then
hide
else show

but I've said it before and I'll say it again....I suck with lua...for now :cool:

Nibelheim 01-27-11 06:13 PM

Quote:

Originally Posted by Othgar (Post 227901)
So then would there be a script that could hide a panel when you're not moving, but show the panel when you are moving? I was thinking of this earlier for a minimap mod, but couldn't come up with a way to do it. Closest I got was
Code:

if movementspeed == 0 then
hide
else show

but I've said it before and I'll say it again....I suck with lua...for now :cool:

Yeah, that's doable.

Code:

local FrameToHide = Minimap
local MovementTimer = CreateFrame("Frame")
MovementTimer.UpdateInterval = 0.1
MovementTimer.ToggleDelay = 1
MovementTimer.Elapsed = 0
MovementTimer.StoppedElapsed = 0
MovementTimer.LastPosition = {x = 0, y = 0}
MovementTimer:Show()
MovementTimer:SetScript("OnUpdate", function(self, elapsed)
        MovementTimer.Elapsed = MovementTimer.Elapsed + elapsed
        if MovementTimer.Elapsed >= MovementTimer.UpdateInterval then
                local x, y = GetPlayerMapPosition("Player")
                if x == MovementTimer.LastPosition.x and y == MovementTimer.LastPosition.y then
                        MovementTimer.StoppedElapsed = MovementTimer.StoppedElapsed + MovementTimer.Elapsed
                        if MovementTimer.StoppedElapsed >= MovementTimer.ToggleDelay then
                                FrameToHide:Hide()
                        end
                else
                        MovementTimer.StoppedElapsed = 0
                        if not FrameToHide:IsShown() then FrameToHide:Show() end
                end
                MovementTimer.LastPosition.x = x
                MovementTimer.LastPosition.y = y
                MovementTimer.Elapsed = 0
        end
end)

If you want to hide a kgPanel with this code, then you'll need to create another kgPanel with this code in it's OnLoad section. And, instead of the top line local FrameToHide = Minimap, use local FrameToHide = kgPanels:FetchFrame("my panel") where mypanel is what you named the panel you want to hide in kgPanels.

Reason you need another panel, is that when you hide a frame, it's OnUpdate scripts no longer work.

Adjust MovementTimer.ToggleDelay to your liking. It's how long in seconds after you stop to hide the Minimap.

Kendian 01-27-11 10:29 PM

The pet panel didnt work ( in onload/onevent/onupdate) but it showed no errors, so it was ME that did something wrong, lol. I'm not getting it, and that frustrates me SOOOO much, rofl. Anyhow, I did want to say thank you, the time and effort was MUCH appreciated =)

Nibelheim 01-27-11 10:38 PM

Quote:

Originally Posted by Kendian (Post 227923)
The pet panel didnt work ( in onload/onevent/onupdate) but it showed no errors, so it was ME that did something wrong, lol. I'm not getting it, and that frustrates me SOOOO much, rofl. Anyhow, I did want to say thank you, the time and effort was MUCH appreciated =)

Woops, forgot to give you the Events.

-- OnLoad
Code:

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_PET")
self:RegisterEvent("UNIT_POWER")

-- OnEvent
Code:

local Color = {r = 1, g = 1, b = 1}
if UnitExists("pet") then
        local happiness = GetPetHappiness()
        if happiness == 1 then
                Color = {r = 1, g = 0, b = 0}
        elseif happiness == 2 then
                Color = {r = 1, g = 1, b = 0}
        elseif happiness == 3 then
                Color = {r = 0, g = 1, b = 0}
        end
end
self:SetBackdropBorderColor(Color.r, Color.g, Color.b, self.bg:GetAlpha())


Kendian 01-27-11 11:56 PM

Simply said, you rock. Thanks again! :eek:

Still can't get it to fire, tho. >.<
Was going to put a cropped screenie here to show you, but am not intelligent to figure out how~

Nibelheim 01-28-11 01:14 AM

Quote:

Originally Posted by Kendian (Post 227927)
Simply said, you rock. Thanks again! :eek:

Still can't get it to fire, tho. >.<
Was going to put a cropped screenie here to show you, but am not intelligent to figure out how~

Hmm, there's no reason it shouldn't work. Does your panel have a border? Try changing the last line to:

Code:

self.bg:SetVertexColor(Color.r, Color.g, Color.b, 1)


All times are GMT -6. The time now is 12:55 AM.

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