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)

Kendian 01-28-11 01:45 AM

Yes! I can't believe I didn't change that, especially after the problems I had between panels and borders, I'm an idiot.
Thank you very much, hero, you've made my evening~

:banana: :banana: :banana: :banana: :banana:

Kendian 01-28-11 04:16 AM

I hate to ask, Nibleheim, seeing as you've already repaired everything that I was unable to in my personal ui......but, would you happen to know the script, to call a panel based on stance? I.e., bear form, cat form, prot spec/ret spec, aspect of the suck (cheetah) etc? I would be ever so grateful, and would send loads of cookies. :D

Nibelheim 01-28-11 04:42 AM

Quote:

Originally Posted by Kendian (Post 227943)
I hate to ask, Nibleheim, seeing as you've already repaired everything that I was unable to in my personal ui......but, would you happen to know the script, to call a panel based on stance? I.e., bear form, cat form, prot spec/ret spec, aspect of the suck (cheetah) etc? I would be ever so grateful, and would send loads of cookies. :D

Alright, this took me ages to type out, bleh!

To set color based on stance:

-- OnLoad
Code:

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")

-- OnEvent
Code:

if not self.StanceTable then
        self.StanceTable = {
                ["DEATHKNIGHT"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Blood Presence
                        [2] = {r = 1, g = 1, b = 1},        -- Frost Presence
                        [3] = {r = 1, g = 1, b = 1},        -- Unholy Presence
                },
                ["DRUID"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Bear/Dire Bear Form
                        [2] = {r = 1, g = 1, b = 1},        -- Aquatic Form
                        [3] = {r = 1, g = 1, b = 1},        -- Cat Form
                        [4] = {r = 1, g = 1, b = 1},        -- Travel Form
                        [5] = {r = 1, g = 1, b = 1},        -- Moonkin/Tree Form (Unless feral. If no moonkin/tree form present, (swift) flight form is form 5)
                        [6] = {r = 1, g = 1, b = 1},        -- Flight Form
                },
                ["PALADIN"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Devotion Aura
                        [2] = {r = 1, g = 1, b = 1},        -- Retribution Aura
                        [3] = {r = 1, g = 1, b = 1},        -- Concentration Aura
                        [4] = {r = 1, g = 1, b = 1},        -- Shadow Resistance Aura
                        [5] = {r = 1, g = 1, b = 1},        -- Frost Resistance Aura
                        [6] = {r = 1, g = 1, b = 1},        -- Fire Resistance Aura
                        [7] = {r = 1, g = 1, b = 1},        -- Crusader Aura
                },
                ["PRIEST"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Shadowform
                },
                ["ROGUE"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Stealth
                },
                ["SHAMAN"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Ghost Wolf
                },
                ["WARRIOR"] = {
                        [1] = {r = 1, g = 1, b = 1},        -- Battle Stance
                        [2] = {r = 1, g = 1, b = 1},        -- Defensive Stance
                        [3] = {r = 1, g = 1, b = 1},        -- Berserker Stance
                },
        }
end

local Stance = GetShapeshiftForm()
local _, Class = UnitClass("player")
local Color = {r = 1, g = 1, b = 1}

if Stance > 0 then
        Color = self.StanceTable[Class][Stance]
end

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

Note, you'll have to set all the colors in the table. Values are between 0 and 1.


To show a panel based on stance:

-- OnLoad
Code:

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")

-- OnEvent
Code:

local DefaultFrame = kgPanels:FetchFrame("MyDefaultPanelName")
if not self.StanceTable then
        self.StanceTable = {
                ["DEATHKNIGHT"] = {
                        [1] = "MyPanelName",        -- Blood Presence
                        [2] = "MyPanelName",        -- Frost Presence
                        [3] = "MyPanelName",        -- Unholy Presence
                },
                ["DRUID"] = {
                        [1] = "MyPanelName",        -- Bear/Dire Bear Form
                        [2] = "MyPanelName",        -- Aquatic Form
                        [3] = "MyPanelName",        -- Cat Form
                        [4] = "MyPanelName",        -- Travel Form
                        [5] = "MyPanelName",        -- Moonkin/Tree Form (Unless feral. If no moonkin/tree form present, (swift) flight form is form 5)
                        [6] = "MyPanelName",        -- Flight Form
                },
                ["PALADIN"] = {
                        [1] = "MyPanelName",        -- Devotion Aura
                        [2] = "MyPanelName",        -- Retribution Aura
                        [3] = "MyPanelName",        -- Concentration Aura
                        [4] = "MyPanelName",        -- Shadow Resistance Aura
                        [5] = "MyPanelName",        -- Frost Resistance Aura
                        [6] = "MyPanelName",        -- Fire Resistance Aura
                        [7] = "MyPanelName",        -- Crusader Aura
                },
                ["PRIEST"] = {
                        [1] = "MyPanelName",        -- Shadowform
                },
                ["ROGUE"] = {
                        [1] = "MyPanelName",        -- Stealth
                },
                ["SHAMAN"] = {
                        [1] = "MyPanelName",        -- Ghost Wolf
                },
                ["WARRIOR"] = {
                        [1] = "MyPanelName",        -- Battle Stance
                        [2] = "MyPanelName",        -- Defensive Stance
                        [3] = "MyPanelName",        -- Berserker Stance
                },
        }
end

local Stance = GetShapeshiftForm()
local _, Class = UnitClass("player")

local ShowFrame
if Stance == 0 then
        ShowFrame = DefaultFrame
else
        ShowFrame = kgPanels:FetchFrame(self.StanceTable[Class][Stance])
end

if ( self.LastShownFrame and self.LastShownFrame ~= ShowFrame ) then
        self.LastShownFrame:Hide()
elseif ShowFrame ~= DefaultFrame then
        DefaultFrame:Hide()
end

ShowFrame:Show()
self.LastShownFrame = ShowFrame

You'll have to change all the MyPanelName to the names of the panels in kgPanels you want to show/hide.


Edit: All this is completely untested, but hopefully it works and/or it'll provide a base for you to get it to work. I think I'm out of here :)

Othgar 01-28-11 05:31 AM

Perfect! Thanks Nibelheim that was exactly what I was looking for.Not Moving with a target.Idle no targetMoving. Much love...many cookies!

T4YR3L 12-05-11 09:30 PM

Quote:

Originally Posted by Nibelheim (Post 227827)
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


Hello Nibelheim,
ive found you scripts google'ing xD

i want to ask if this code can be done also for party/raid members.
i mean the classcolor border for each player in party or raid. it is possible? :)

ty very much ^^

Taryble 12-05-11 09:44 PM

Just change the part where it says "target" (UnitExists("target"), UnitClass("target")), to "party1", "party2", "party3", "party4", and then raid1 thru raid40 (or however high you want to go).

T4YR3L 12-06-11 08:00 AM

Quote:

Originally Posted by Taryble (Post 248777)
Just change the part where it says "target" (UnitExists("target"), UnitClass("target")), to "party1", "party2", "party3", "party4", and then raid1 thru raid40 (or however high you want to go).

ty for the rapid answer..

so, are something like that in the On Event section:

if UnitExists("party1") then
local _, Class = UnitClass("party1")
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

and in On Load Section?

local _,class = UnitClass("party1") ? ^^'

EDIT: its work, but only with party1 frame :|
what's wrong?


All times are GMT -6. The time now is 11:51 AM.

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