API:Brainstorming through the WAR API

From TheWarWiki

Jump to: navigation, search

WAR API Help

Hey, Jack! Suppose you had a good friend Jill. Suppose you and Jill got together a lot to quest together, do scenarios as a party, and otherwise have a good time. There's no chance you'd turn down an opportunity to group with Jill. So why should you have to click the accept button when Jill invites you to group with her? It should be automatic. This calls for an important, gamebreaking addon!

AutoAcceptInviteFromBFF 0.1alpha addon

Okay so we have an idea of what we want. We know that this little window pops up on our screen when Jill gives us an invite. Sometimes about when that window pops up, we want to have the invite accepted (and that window should close... if in fact we let it open with our addon running when Jill invites us!).

Usually, you have at least six ways of getting your addon functions fired:

  • On initializing (setting in .mod)
  • On update (frame refresh--setting in .mod)
  • On shutdown (setting in .mod)
  • On registered game event handler
  • On registered other addon event handler (e.g. LibSlash, LibTimer)
  • On call to exposed WAR interface function (function hooking)

So a basic design decision is to go down this list and figure out the best way to get your functionality called. More often than not, it is by hook or by other addon's event handler. The game system messages are also sometimes useful, but often kinda overkill or underkill one way or another. OnUpdate works because it gets called as much as possible, but you have to remember to throttle (with a timer) when you actually do anything in that update function.

Anyway, getting to the point... check out these functions...

PlayerMenuWindow.OnGroupInvite GroupInviteCallback GroupInviteAccept

You can quickly discover that this code is used by the other player to send you the invite...

   SystemData.UserInput.ChatText = L"/invite " .. PlayerMenuWindow.curPlayer.name
   BroadcastEvent( SystemData.Events.SEND_CHAT_TEXT )

This code accepts the invite on your side:

   BroadcastEvent( DataRegistry.Events.GROUP_INVITE_ACCEPT )

Now check this out:

   function GroupInviteCallback()
       windowName = GetTwoButtonDlg();
       
       SetLabelText( windowName, DataRegistry.Dialogs.GroupInviteText );
       
       button1Name = windowName.."Button1";
       button2Name = windowName.."Button2";
       
       SetButtonText( button1, "Accept" );
       SetButtonText( button2, "Decline" );
       
       SetScript( button1, "OnLButtonUp", "GroupInviteAccept" );
       SetScript( button1, "OnLButtonUp", "GroupInviteDecline" );
   end

This is the function being fired in your client to draw the group invite accept/decline window.

So... drumroll please...

   oldGroupInviteCallback = GroupInviteCallback
   GroupInviteCallback = function() oldGroupInviteCallback() GroupInviteAccept() end

This should make your client show the invite window (through the original callback) and then accept the invite (which we know is achieved through broadcasting a message), no matter who the invite is from. (You could have disabled showing the window before it ever got displayed you did it differently, of course... this may be what you go for... see below... )

No, this is not a "true" group invite window, as it is general purpose. This is the window whose name is determined by GetTwoButtonDlg(), which seems to be a C function (as opposed to a lua function in interface.myp that is exposed to us addon writers).

The only thing left to do is to find out who the heck is actually inviting you, so that your hooked callback function can be selective about when to invite.

I haven't tested it, but the data there might be found with:

   GameData.Player.Group

so that your final solution might look something close to this...

   oldGroupInviteCallback = GroupInviteCallback
   GroupInviteCallback = myGroupInviteCallback
   function myGroupInviteCallback()
   
       if (GameData.Player.Group.nameofsomedudemaybe == "I dunno my bff Jill") then
   
           GroupInviteAccept()
   
       else
   
           oldGroupInviteCallback()
   
       end
   
   end

On second thought, maybe it is DataRegistry.Events.GROUP_INVITE_ACCEPT == "JOIN_GROUP_WITH I dunno my BFF Jill" or something related to the DataRegistry somehow... because, if you notice above, that's also the place where DataRegistry.Dialogs.GroupInviteText comes from, and you know that includes the name of your BFF Jill, because that's what appears on the dialogue window when she invites you. Or maybe the data about who invited you can be found in all of the above? Only one way to find out... after you have a good idea of how to code something, start coding, hack at it, and fix it until it works!

The concept of this guide is to help you with brainstorming your way through the WAR API. If you'd like to give a polished version of the BFF addon, add it below the main part of this guide which ends here. What is above is totally untested, but for a reason! To illustrate brainstorming technique... and, to some extent, give you room for some of the joy of discovery for yourself.

With a bare minimimum of testing, one finds that none of our brainstorming yet has picked up on the right way to do this. Feel free to update with better attempts, similarly documented.

Personal tools