Originally Posted by alpmave
I have a question regarding scripts in panels.
I want to create a backgroundpanel for my raidframes, but it should only be displayed, when i´m actually in a raid/group.
Does anyone know, if
1. this is possible
2. if it is: how can i reach that goal?
I´m pretty new to the whole lua/wow api world and would be grateful if you have any hints
|
Should be doable, with a little research!
First, you have to have 2 diffirent scripts for the panel, an OnLoad = function(self).
And a OnEvent = function(self).
In the OnLoad script, you should check if your in a raid:
Code:
-- All the other stuff goes here.
OnLoad = function(self)
if UnitInRaid("player") or UnitInParty("player") then -- We check if the player is in a raid or party.
self:Show()
else -- If we aren't, then we hide the frame.
self:Hide()
end,
Now, this only does the trick for when you load the AddOn.
So now you have to make it check almost constantly, we could do this with an OnUpdate script, but it costs too many ressources, so we need to use events. Events are something that is triggeret by certain things in WoW:
Fx the "UNIT_HEALTH" event fires when the health level of a unit changes.
But we need an event that fires, when the player enters or leaves a group or raid.
I can't find it right now, but you could search around
this page and check the events.
But when you've found the event, you need to make your panel check for the event, this is done in the OnLoad script:
So, we take the code from above, and alter it to this:
Code:
-- All the other stuff goes here.
OnLoad = function(self)
self:RegisterEvent("THE_EVENT_YOU_HAVE_FOUND") -- Remember, spaces are equal to _ and everything is in CAPS!
if UnitInRaid("player") or UnitInParty("player") then -- We check if the player is in a raid or party.
self:Show()
else -- If we aren't, then we hide the frame.
self:Hide()
end,
And then we have to make it do something in the OnEvent script:
Code:
-- The usual stuff, like before
OnEvent(self, event, ...)
if (event == "THE_EVENT_YOU_HAVE_FOUND") and (select(1, "THE_EVENT_YOU_HAVE_FOUND") == "player") then
if self:IsShown() then
self:Hide()
else
self:Show()
end
end
end,
Something like that, though I'm not sure about the OnEvent part
Hope it helps, good hunting!