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
I am trying to use KGPanels with Grid I am trying to figure out how get a background to stretch horizontally as the party grows.
I tried making separate panels for each on but the issue is that there are
GridLayoutHeader1UnitButton1 GridLayoutHeader1UnitButton2 GridLayoutHeader1UnitButton3 GridLayoutHeader1UnitButton4 GridLayoutHeader1UnitButton5
Is there a way to script the gradient to stretch as the GridLayoutFrame grows, or even get the graphic to grow as say GridLayoutHeader1UnitButton1, 2, 3, 4 or 5 enters the group?
i was wondering if i could maybe have some help with an onClick script
what i want to be able to do, is make a button panel, just some simple words or something i can make in-game with the kgpanels config menu, nothing very extravagant
but what i want the button to do, is show/hide my pets HP/hotkey bar panel
now, i can make the button, but i dont know how to have it find the panel i want, to show/hide
---what my first idea was, was to have kgpanels recognize when my pet was out, and show/hide the background panel for when my pet was out, but that would be a lot harder
Kakumei there is a function in the standard keybinding set up a bind to tell you what the framenames you are moused over. Then you can set either your pet bar, or you pets stats as the parent.
I think this is what your looking for.
Hi there.
Been mucking about with a panel to show/hide recount, but what I can't get it to do is have 2 different opacity settings.
example: recount is hidden, the bars opacity is aprox 0.1. the bar is clicked. recount is shown, the bars opacity goes to 1. the bar is clicked. recount is hidden, the bars opacity goes back to 0.1. ...
Thanks to anyone who can help me!
ps: couldn't
get simplified to
i would make a panel with my gold info. i have create a testpanel with the "Make your own spell damage display Create a panel OnLoad self:RegisterEvent("PLAYER_AURAS_CHANGED") OnEvent: dmg = GetSpellBonusDamage(6); self.text:SetText(dmg)"
...settings, but this script dont working :( I dont become a error or other infos.
what is the current settings or what is the mistake ?
Sorry for my bad englisch :(
I'd like to show/hide an addon that recycles frames (so they can only be accessed as variables), there is no normal frame name etc. Is it possible with kgpanels?
@ Magieus
try this:
OnLoad
OnEvent
This will display something like 342g 32s 54c, but only AFTER you reload UI or make/lose money for the first time to update.
How would I make a panel show/hide based on whether I have active cooldowns? (To use with SexyCooldown) Thanks!
Is there any way to make a single graphic continuously spin around in a circle (like a wheel) at all times? I want to create a spinning spiral in my UI... but I suck at scripting.
Referencing a remote panel by name.
local myMapPanel = kgPanels:FetchFrame("mapPanel") myMapPanel:Hide()
I now have the Onclick working to show my bars but when im in combat i cant hide or show the bars any script needed for that to work?
The OnUpdate script under "Resizing your panel on the fly" is very poorly written. Most significantly, it fails to set the "self.resized" flag after setting the script, so it will create a new function and set it as ChatFrame1's OnSizeChanged script every time a new video frame is drawn, which can occur over 100 times per second depending on your hardware and settings. Also, it's a poor example in the first place, as no scripts at all are necessary to achieve the result. The panel should simply be parented to ChatFrame1, with two points set anchoring it to the frame's opposing corners (eg. TOPLEFT and BOTTOMRIGHT) so that its size automatically changes along with the frame.
Phanx, fixed your right that script was very bad and shouldn't have been up there. most of the samples were from the forum and i just pasted them in here for a quick reference
I m trying to hide and show the xp bar and rep bar in bartender4 but every time the xp bar updates it shows and everytime the rep bar updates it shows now I m looking at a way to disable them and enable them in the db file for bartender please help?
** that's not the way it is here **
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
Hey guys,
here a little script i found to find out what frame your mouse is over, handy to attach artwork to unitframes/minimap and so on.. works for realy everything!
/run local e,m,n,f=EnumerateFrames,MouseIsOver;ChatFrame1:AddMessage("The mouse is over the following frames:")f=e()while f do n=f:GetName()if n and f:IsVisible()and m(f)then ChatFrame1:AddMessage(" - "..n)end;f=e(f)end
i did not write this my self but couldnt find any other script macro's for it. Enjoy
hi fellows, I have a background panel for my pet bar. First I tried to parent it to one of the bartender 4 pet bar buttons since I could not find a frame for the entire bar. But no matter how often I tried I could not get it to work. I solved it by using OnClick script instead, it works good for its purpose (when I click the bar it disapears and a button shows up and when I click the button the pet bar frame shows and the button goes away:
Pet Bar script:
if pressed then
kgPanels:FetchFrame("Pet Bar"):Hide() kgPanels:FetchFrame("button test"):Show()
end
button test script:
if pressed then
kgPanels:FetchFrame("button test"):Hide() kgPanels:FetchFrame("Pet Bar"):Show()
end
Only thing is that when logging on or reloading ui both frames show, its a very small bother but was wondering if there is a easy way to make sure just the button shows at login and reload?
@WGSXFrank
Yeah you can have weakauras do it. Just add your artwork to weakauras by getting the .tga name, then in animation main on preset there is a circle setting. You can adjust the speed with the duration # and set the trigger to always if you want the artwork to show all the time. Or set the trigger to whatever you need it for really. Inverse will make the circle rotate the other way.
How can you Lock/Unlock other KgPanels by clicking on another?