Sample Scripts
Sample scripts culled from the forums, credits to thos who posted in the kgPanel thread.
Adjusting Panels based on Raid or 5 Main party
In each Panel set the OnLoad script
self:RegisterEvent("PLAYER_ENTERING_WORLD") self:RegisterEvent("PARTY_MEMBERS_CHANGED") self:RegisterEvent("RAID_ROSTER_UPDATE")
Then in each Panel OnEvent script:
local pmems = GetNumPartyMembers() local rmems = GetNumRaidMembers() if (pmems < 1 and rmems < 1) or (pmems > 0 and pmems < 6 and rmems < 6) then self:Hide() else self:Show() end
Using a onClick handler
Be sure you enable mouse clicks on your panel Example: Hide/Show recount when you click the panel
if Recount.MainWindow:IsVisible() then Recount.MainWindow:Hide() else Recount.MainWindow:Show() end
Changing a frame based on Target
OnLoad
self:RegisterEvent("UNIT_TARGET") self:Hide()
OnEvent
if UnitExists("target") == nil then self:Hide() return end local cl = UnitClassification("target") if (cl == "elite") or (cl == "worldboss") or (cl == "rareeleite") then self:SetBackdropColor(0.1, 0.1, 0.1, 0.1) self:Show() else self:SetBackdropColor(1, 1, 1, 1) self:Show() end
Hooking another frame to control your own frame
Examples uses Violation Script Dependacy: Violation OnLoad
local myPanel = self if Violation0 then Violation0:SetScript("OnShow",function(frame) myPanel:Show() end) Violation0:SetScript("OnHide",function(frame) myPanel:Hide() end) end if Violation0:IsVisible() then self:Show() else self:Hide() end
Controlling a panel based on entering a major city
OnLoad
self:RegsiterEvent('CHAT_MSG_CHANNEL_NOTICE')
OnEvent:
if event == "CHAT_MSG_CHANNEL_NOTICE" then -- arg1 is either "YOU JOINED", "YOU LEFT" or "THROTTLED" -- arg7 is channel type (trade is type 2) -- so if arg1 == "YOU_JOINED" and arg7 == 2 then self:Show() end if arg1 == "YOU_LEFT" and arg7 == 2 then self:Hide() end end
Make your own spell damage display
Create a panel OnLoad
self:RegisterEvent("PLAYER_AURAS_CHANGED")
OnEvent:
dmg = GetSpellBonusDamage(6); self.text:SetText(dmg)
Change a frame color based on your class
OnLoad
local _, class = UnitClass("player"); if class == "WARRIOR" then self.bg:SetVertexColor(0.95, 0.23, 0.23, self.bg:GetAlpha()) elseif class == "PRIEST" then self.bg:SetVertexColor(1, 0.96, 0.98, self.bg:GetAlpha()) elseif class == "MAGE" then self.bg:SetVertexColor(0.00, 1, 1, self.bg:GetAlpha()) elseif class == "DRUID" then self.bg:SetVertexColor(1, 0.49, 0.04, self.bg:GetAlpha()) elseif class == "PALADIN" then self.bg:SetVertexColor(0.92, 0.22, 0.46, self.bg:GetAlpha()) elseif class == "HUNTER" then self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha()) elseif class == "ROGUE" then self.bg:SetVertexColor(1, 0.94, 0.16, self.bg:GetAlpha()) elseif class == "SHAMAN" then self.bg:SetVertexColor(0.13, 0.42, 1, self.bg:GetAlpha()) elseif class == "WARLOCK" then self.bg:SetVertexColor(0.36, 0.18, 1, self.bg:GetAlpha()) end
Show a panel based on being in combat
OnLoad
self:RegisterEvent("PLAYER_REGEN_DISABLED") self:RegisterEvent("PLAYER_REGEN_ENABLED")
OnEvent
if event == "PLAYER_REGEN_ENABLED" then self:Hide() elseif event == "PLAYER_REGEN_DISABLED" then self:Show() end
How to get 8 value tex coords form 4 value examples
For instance you want to use the raid icons blizz provides as a texture. foirst add teh texture to your art library or add it to sharedmedia up to you.
On a Mac ive found use the / slash when entering items is much easier.
Now lets use the status icon as an exmaple
I used onLoad to quickly get the information i wanted.
-- coords found in the FrameXML files -- left,right,top,bottom self.bg:SetTexCoord(0.5,1,0,0.5) local ULx,ULy,LLx,LLy,URx,URy,LRx,LRy = self.bg:GetTexCoord() print(" ULX: "..ULx) print(" ULy:"..ULy) print(" LLX:"..LLx) print(" LLy:"..LLy) print(" URx: "..URx) print(" URy:"..URy) print(" LRx:"..LRx) print(" LRy:"..LRy)
Now i have the 8 position coords for the combat icon which is UL(0.5,0) LL(0.5,0.5) UR(1,0) LR(1,0.5)
Its a little bit of a pain, but the 8 coord setup allows for so much more flexibility as you can do transforms. The 4 position method only allows you to make rectangles.
Healer mana warning by warlocomotif
OnLoad
self:RegisterEvent("PLAYER_REGEN_ENABLED") HEALERWARNING_TIME = 5 HEALERWARNING_PERCENT = 20 HWSHOWTIMER = 0 self:Hide()
OnEvent
if UnitGroupRolesAssigned("player") then for i=1,GetNumPartyMembers() do if select(2, UnitGroupRolesAssigned("party"..i)) then if (UnitPower("party"..i) / UnitPowerMax("party"..i)) < (HEALERWARNING_PERCENT / 100) then self:Show() HWSHOWTIMER = GetTime() end break end end end
OnUpdate
if HWSHOWTIMER ~= 0 then if (GetTime() - HWSHOWTIMER) > HEALERWARNING_TIME then HWSHOWTIMER = 0 self:Hide() end end
The change a frame color based on your class script doesn't work for me
Put the class based script in OnUpdate and put:
self:RegisterEvent("UNIT_TARGET")
in OnEvent
EDIT - Oh, and the first script that is exampled above:
local _, class = UnitClass("player");
Make 'player' target. SO it should look like this:
local _, class = UnitClass("target");
I am sorry to be a noob and ask, but I have one panel I would like to ONLY show if I am in a party or raid. How would this be done?
I guess it would just be the first example correct?
I tried the first one and couldn't get it to work. When I joined a party the panel didn't show.
Hi, I have never used script before and i was hoping someone could help me, I am looking to set a frame to show on focus target , target of target and my cast bar. I am using Pitbull 4 for unit frames and Macaroon for my bars and my cast bar.
any kind soul out there that is a good mood, if so many thanks.
the focus change got me for a while too. but i just got it, and it works perfectly. in onLoad:
self:RegisterEvent("PLAYER_FOCUS_CHANGED")
self:Hide()
and in onEvent:
if UnitExists("focus") == nil then
self:Hide()
return
else
self:Show()
return
end
this should work.
How could you make it that so when you clicked on frame to open recount or omen it will open recount and a frame behind it for texture. Also how would you make one for when u target someone.
Hi im a Rogue and i would like to Show a panel when im in Stealth and Hide the panel when NOT in stealth
I was wondering if I could modify this that aside from showing up when Im combat, I want a custom panel to show up whenever I have a debuff. example, show a long horizontal red bar and in it my debuffs, so I can easily see whenever I have one
I'am looking for a little on event script that changes the border colors of some of my frames to the energy/mana/rage color. This because I am using the same frame setup for multiple chars atm and I like to make them a bit more specific for each class or form that I am playing in.
Show a panel based on Character Forms
i.e. Priest shadow form, Rogue stealth, Druid forms, Warrior stances, Deathknight presence
OnLoad
OnEvent
If you increase "GetNumShapeshiftForms() > 0" to 2, 3, 4, and so on that panel would only show if its greater then the number you chose. Rogue and Priest if set at 0 and you have stealth or shadow form it will show and for Warrior and DK if set at 2 it will show as long as you have 3 stances or presences same for Druid.
Hi
I'm tying to use sample "Using a onClick handler".
Recount is visible. When I click my panel recount becomes hidden, but when i release mouse button it becomes visible again )
Could you help to write a script that will imitate the "/recount toggle" command, plz?
Hi there, I make some Panels and i want that some of them are hidden. For exsampel the Target or target's target Panel. I want that they only shown when i have an target an the Target have some target.
I am sorry to be a noob and ask, but I have one panel I would like to ONLY show if I am in a party or raid. How would this be done?
I guess it would just be the first example correct?
I tried the first one and couldn't get it to work. when i leave the party the panel will hide but When I joined a party again, the panel didn't show until i reset its settings.
am i doing anything wrong?
Hi. Em, what script should i have in kgps for my panel to appear/disappear when i have a target selected/deselected? Also what is the command to change panel background color?
Hello folks, I have a question, is it possible to link a Panel to a Buttonbar which is faded and appearing when hovering over with mouse ??
Thanks, Fin
OMFG Ive been looking for a script to show a panel when I shapeshift for THREE DAYS no one knows how, and if they DO, the wont tell me, wtf.
"Controlling a panel based on entering a major city" script isn't working, or I fail at life.
Typo - OnLoad should be: self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE')
I would like to show or hide a panel when i open or close recount and/or omen please help
is it possible to make a panel work like a button? as in press the cat picture, and I can set it up to enter/leave catform? what kind of script would this use?