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. :banana: |
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 |
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. |
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. |
You can get the raid leader by doing something like this:
Code:
local raidLeader; |
Quote:
Code:
for i = 1, 40 do |
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 :) |
Sorry I'll try to be more structured :p
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). |
Ok, thanks so much. I think I've got it now. If not I'll be replying back :p
|
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 Code:
if SLASH_TEST2 then |
Code:
for i = 1, 40 do 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. |
Are all of these different frames supposed to have a different .lua file or not?
|
Quote:
|
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.
|
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) Once again, thanks SO much for all of your help. |
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. |
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:
|
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.
|
Okay, thanks man. Once again you saved me some long extraneous hours tweaking things here and there till I got it right. :P
|
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() |
All times are GMT -6. The time now is 12:30 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI