Thread Tools Display Modes
06-02-09, 02:20 PM   #1
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Question Raid Leader Button

Im trying to make a button for an addon that i made that, if the raid leader clicks this button, it would open the addon ui for everyone in the raid. The ui has three buttons on it, yes no and unsure. I then like what button they pressed sent back to the raid leader in another frame. I already have the basic ui done. I just need the button and to have the info sent back.

Any help would be greatly appreciated.

  Reply With Quote
06-02-09, 04:16 PM   #2
Nirrudn
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 17
What you'll need to use are the SendAddonMessage function on each of the 3 buttons, and the CHAT_MSG_ADDON event to parse out the information sent by the above.

http://www.wowwiki.com/API_SendAddonMessage
  Reply With Quote
06-02-09, 06:48 PM   #3
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Acual Function

Okay i was trying to use that...but how exactly would i do it...

I was trying this

function Frame_SendAnswer(a)
SendAddonMessage("ab", a, "WHISPER", UnitName('raid1'))

end


then i would call this method after each code. Here's an example of one of the buttons

function Button1_OnClick()
a = "Yes"
Frame_SendAnswer(a)
Frame1:Hide()

end


I was just wondering how i would make it so only the raid leader would be able to get the information and on a different Frame.

Last edited by goris29 : 06-02-09 at 07:16 PM.
  Reply With Quote
06-02-09, 08:39 PM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
1. The raid leader is not always "raid1" unlike in parties. You should store the "sender" from the request (optionally check if they're the raid leader first) and then reply back to that person.

2. That code will work fine. Your "received answers" frame needs to be shown when your "raid leader" button gets pressed, and it should have an OnShow handler that clears any previous names, and also registers the frame for "CHAT_MSG_ADDON". It should then have an event handler for that event which checks for events with type "WHISPER" and prefix "ab" (although I'd suggest something more detailed than that for your prefix). When it sees one, it can then place the sender name and their answer in the frame.
  Reply With Quote
06-02-09, 09:06 PM   #5
Nirrudn
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 17
You can get the raid leader by doing something like this:

Code:
local raidLeader;

for i=1, GetNumRaidMembers() do
if UnitIsPartyLeader("raid"..i) then
raidLeader = UnitName("raid"..i); break;
end
end
You can stick that at the top of your Frame_SendAnswer function, so even if the party leader changes it'll find the new one for you automagically.
  Reply With Quote
06-02-09, 10:20 PM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Nirrudn View Post
You can get the raid leader by doing something like this:
The problem with that is that other people could spam the RL by clicking the button. The addon should respond to whoever actually sent the request, which you get as part of the CHAT_MSG_ADDON event. The above code *would* be a good way to confirm if that person is the RL, although I would modify it a little bit to:

Code:
for i = 1, 40 do
    local name,rank = GetRaidRosterInfo(i)
    if name == sender and rank > 1 then --sender will have already been set to whoever sent the request
         --display your frame with the request
         break
    end
end

Last edited by Akryn : 06-02-09 at 10:33 PM.
  Reply With Quote
06-03-09, 02:41 PM   #7
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Okay thanks for the help with that, I'm going to try it later tonight when I get a chance. But I didn't see an answer as to how I could get the addon to appear on everyone's screen.

Would i set the sender (as you said above) to the raid leader who pressed the button and do another send addon message, and if the addon message was from the raid leader and if the message said like "open" or something it would do Frame:Show() ?

Could I also get help parsing the getAnswer() for what the sendAnswer() sends.

Any further help would be wonderful. And thanks the help you've already given this

Last edited by goris29 : 06-03-09 at 02:46 PM.
  Reply With Quote
06-03-09, 04:55 PM   #8
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Sorry I'll try to be more structured

Top-level frames you need are:

1. The RL Button
2. The RL's "status" frame which lists replies
3. The "Request" frame that displays on clients when the RL presses the button.

"2" should have some way of displaying data and a button to :hide() the frame when it's done.
"3" should of course have its child buttons to respond and hide itself.

Flow:
a) The RL presses "1" , this calls :show() on "2" and also does SendAddonMessage("MYADDON_REQUEST", "question, or something", "RAID").
b) "2" has an OnShow handler which clears it of any previous data, and registers itself for the event "CHAT_MSG_ADDON" -- so it is now visible to the RL and listening for replies.
c) Your main frame (possibly "1") is registered for the event "CHAT_MSG_ADDON" and has an event handler that calls :show() on "3" whenever it gets a message with "sender" corresponding to the RL's name and a "prefix" of "MYADDON_REQUEST" or whatever you want to use. So "3" is now visible to the raid.
d) A raid member presses "yes" which calls :hide() on "3" and also calls SendAddonMessage("MYADDON_REPLY", "yes", "WHISPER", sender) **sender here is the RL.
e) The RL's "2" is, as noted above, listening for "CHAT_MSG_ADDON" and has an event handler which triggers on "WHISPER" messages with the prefix "MYADDON_REPLY" -- it displays the fact that sender said "yes" **sender here is the raid member.
f) Once the RL has the information they want, they click "close" which calls :hide() on "2" and also unregisters "CHAT_MSG_ADDON" from "2" ("1" should have it registered all the time -- you could make this a bit more efficient by using "1" for all event handling, if you want).

Last edited by Akryn : 06-03-09 at 08:17 PM.
  Reply With Quote
06-03-09, 05:17 PM   #9
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Ok, thanks so much. I think I've got it now. If not I'll be replying back
  Reply With Quote
06-03-09, 07:19 PM   #10
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
My first step was getting the RL button to open the addon on everyone's screen. This didn't work and i don't know why.

Code:
for i = 1, 40 do
    name,rank = GetRaidRosterInfo(i)
end


if rank > 1 then
    sender = name;
end
function Frame_OnLoad()
    
        Frame:RegisterEvent("CHAT_MSG_ADDON");
    end
    
function Frame_OnEvent()
    if (event=="CHAT_MSG_ADDON") then
        if (arg1=="rol") then
            if(arg4==sender) then
            if Frame1:IsShown() then
                Frame1:Hide()
            else
                Frame1:Show()
                
            end
            end
        end 
    end
end
And the "button" I'm using atm is actually a slash command. Which is coded as follows:

Code:
if SLASH_TEST2 then
            if(IsRaidLeader()) then
                SendAddonMessage("rol", "roll", "RAID")
             end
        end
when i do /rol i.e. SLASH_TEST2, It opens on the character I type it on, but not on the other characters in the raid. Would anyone happen to know why?
  Reply With Quote
06-03-09, 08:03 PM   #11
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Code:
for i = 1, 40 do
    name,rank = GetRaidRosterInfo(i)
end


if rank > 1 then -- this if block needs to be *inside* the for block or it won't work
    sender = name;
end
function Frame_OnLoad()
    
        Frame:RegisterEvent("CHAT_MSG_ADDON");
    end
    
function Frame_OnEvent()
    if (event=="CHAT_MSG_ADDON") then
        if (arg1=="rol") then
            if(arg4==sender) then --where are you defining what sender is? you need to do that inside of this function
            if Frame1:IsShown() then
                Frame1:Hide()
            else
                Frame1:Show()
                
            end
            end
        end 
    end
end
see the two comments above.

Edit: I think I see now what you're trying to do WRT my second comment; but you still need to check for the RL inside of your event handler; in case the RL changes--and more importantly because most of the time your UI won't be loading while already in a raid. Note that you can of course create a function and call *that* from inside your event handler, just as long as you're checking each time as opposed to once when the addon loads.

Last edited by Akryn : 06-03-09 at 08:09 PM.
  Reply With Quote
06-04-09, 04:05 PM   #12
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Are all of these different frames supposed to have a different .lua file or not?
  Reply With Quote
06-04-09, 04:49 PM   #13
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by goris29 View Post
Are all of these different frames supposed to have a different .lua file or not?
No, you can define them all in one Lua and/or XML file.
  Reply With Quote
06-04-09, 05:11 PM   #14
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Okay, before i thought that lua was like java in the fact that all variables were local unless otherwise declared. So now i understand how to do it with multiple "classes" (I'm a java programmer by trade) and just call the appropriate function in my main lua file.

Last edited by goris29 : 06-04-09 at 06:33 PM.
  Reply With Quote
06-04-09, 07:10 PM   #15
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Is it possible for me to do send this, which is, inside of a function fired when a button is clicked...this is in a file called "Frame.lua"

Code:
SendAddonMessage("AnswerUnsure", UnitName("Player"), "WHISPER", sender)
and have that sent to an event listener in a file called "Frame_Roll.lua"?

Once again, thanks SO much for all of your help.
  Reply With Quote
06-04-09, 07:34 PM   #16
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Yes, there shouldn't be any problem doing that.

You also don't actually have to send UnitName("player"), since that's going to be arg4 for the receiver anyway; although there's no real reason not to.
  Reply With Quote
06-04-09, 07:46 PM   #17
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Ok thanks man. Any idea as to why this code isn't working. I've looked at other addons and on forums and this seems to be correct but when I load WoW to test it, it says there's an unknown symbol on line 21

Code:
function Frame1_OnEvent()
Frame1:RegisterEvent("CHAT_MSG_ADDON")
Frame1:SetScript("OnEvent", local function(self, event, prefix, text, channel, sender)--line 21
        if prefix == "Roll" then 
            Frame1:Show()
        end
    end
 end )
end
  Reply With Quote
06-04-09, 07:55 PM   #18
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Just get rid of the word "local" -- there's no distinction for functions that don't have a name. You also have an extra "end" I think.
  Reply With Quote
06-04-09, 08:17 PM   #19
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Okay, thanks man. Once again you saved me some long extraneous hours tweaking things here and there till I got it right. :P
  Reply With Quote
06-04-09, 08:55 PM   #20
goris29
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 16
Now that code doesn't have any errors when WoW loads, but it doesn't display the frame, or show this message that I put in there just to make sure I knew it didn't work.

Code:
function Frame1_OnEvent()
Frame1:RegisterEvent("CHAT_MSG_ADDON")
Frame1:SetScript("OnEvent", 
 function(self, event, prefix, text, channel, sender)
     if event == "CHAT_MSG_ADDON" then
        if prefix == "Roll" then 
            Frame1:Show()
            message("text")
        end
     end 
    end
    )
 end
Is the name of the OnEvent() function supposed to be named after the FRAME or after the name of the LUA file?
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Raid Leader Button


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off