Thread Tools Display Modes
06-25-13, 10:18 AM   #1
ChronSyn
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 3
WhoLib help

Hey all,
I'm new to the development side of WoW addons despite having years of coding experience on the desktop and web. I released my first addon last night - GuildInviteAssist; http://www.wowinterface.com/download...iteAssist.html

It took around 8 hours of development with most of that being due to a lack of any previous knowledge of LUA.

There was one important thing that I didn't add in prior to release - Guild check. Obviously, the nature of the addon is guild recruitment, and in order to prevent being spammed with the chat message, I could either remove the message completely, or go down the proper route and perform a guild check.

Now, I've made some progress towards fixing this, but I need someone to point me in the right direction. I understand that in order to check if someone is guilded, you have to use the SendWho() and GetWhoInfo() functions. My problem is making this 'seamless'. Here's what I've currently got;
Lua Code:
  1. local function onEvent(self, event, ...)
  2.     SetWhoToUI(1);
  3.    
  4.     --else
  5.     if ( event == "CHAT_MSG_WHISPER" ) then
  6.         local message, senderName = select(1, ...);
  7.         if ( keyphraseHash[strlower(strtrim(message))] ~= nil ) then
  8.             playerName = senderName;
  9.             local whostring = string.format('n-"%s"',playerName);
  10.             SendWho(whostring);
  11.             --if (event == "WHO_LIST_UPDATE") then
  12.             local c,g = GetWhoInfo(1);
  13.                 if (g ~= "") then
  14.                     --SendChatMessage("You are currently in a guild. Please leave yours if you would like to join us!","WHISPER",slanguage,playerName); --uncomment to send a whisper back
  15.                 do return end;
  16.             end
  17.             --end
  18.            
  19.             hlink = string.format("|Hplayer:%s:1:WHISPER:%s|h[%s]|h", playerName, playerName, playerName);
  20.             msg = string.format("|cffff0000GuildInviteAssist:|cffffffff %s would like a guild invite!", hlink);
  21.             if tContains(playerList, playerName) then do return end
  22.             else table.insert(playerList,1,playerName)
  23.             end
  24.             local info = UIDropDownMenu_CreateInfo();
  25.                 info = UIDropDownMenu_CreateInfo()
  26.                 info.text = playerName
  27.                 info.value = playerName
  28.                 info.func = OnClick
  29.             UIDropDownMenu_Initialize(DropDownMenuTest, initialize);
  30.             DEFAULT_CHAT_FRAME:AddMessage(msg);
  31.             end
  32.             end
  33.             end

You can see that I've had to comment out the "WHO_LIST_UPDATE" event handler. Long story short, this is the only way I could get it working. The problem I have is that this will open the who interface panel. Obviously, this is as bad as, if not worse than, the chatbox being spammed. I did try setting SetWhoToUI(0) and use a CHAT_MSG_SYSTEM handler instead, but I couldn't get it to work properly. The rest of the code works fine, it only adds a player to the table if they aren't already there, and it seems like Blizzards UI blocks repeat messages to the same player by default (within the same UI 'session'/between slash_reloadui's) and so you only ever receive one message for each individual player.

I figure that I need to use an "if elseif" statement for the different events, but I don't know exactly how to lay it out. I'm very much used to the PHP style (a hybrid between OOP and Procedural to be more specific) of coding where I'd call my own custom function from within another function in order to (for example) get a value, but LUA seems much different to that due to the RegisterEvent and SetScript handlers. I also imagine I need to do some sort of queueing due to the /who system limits, but again, I'm extremely new to LUA and I've no idea on where to go from here.

I wish there was an easier way to find out if someone was guilded. I know there's a close-range function, but I'd love to know if there's an easier way of finding out from range if a player is in a guild or not (something like a boolean return from a function, as opposed to dealing with event handlers).

Any guidance from the guru's? I want to avoid third-party libs if possible, unless it'll make my life significantly easier and you can provide a relevant example.

Last edited by ChronSyn : 06-26-13 at 09:36 AM.
  Reply With Quote
06-25-13, 10:43 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
WhoLib will make your life significantly easier
(Relevant) Examples
  Reply With Quote
06-25-13, 11:48 AM   #3
ChronSyn
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 3
Originally Posted by Dridzt View Post
WhoLib will make your life significantly easier
(Relevant) Examples
Thanks for that. Ignore my last post, editing this now to say I realized I don't need the callback on UserInfo. Thanks again Dridzt

Last edited by ChronSyn : 06-25-13 at 12:06 PM.
  Reply With Quote
06-25-13, 12:19 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
The reason WhoLib is a good idea is that the /who functionality is quirky.
The alternative to WhoLib would be to have a 'best practices' paper that was mandatory reading for anyone interested in implementing /who (or /inspect for that matter) in their addon.

Having addons using WhoLib (and many do) provides a single point of failure with all the good and bad that entails.
Bad: Library breaks, a bunch of dependent addons break.
Good: Library breaks, a bunch of dependent addon authors have incentive to fix it (and once one does it's fixed for everyone).

The alternative for fickle systems like /who is that everyone makes their own implementation and potentially breaks other addons but there's a very lengthy process of elimination until the conflicting addon is even found.
Fixing it also falls on that particular addon author and only benefits that author and his users.

So - and this is my personal opinion - for some game systems libraries are very good to have, for others it can be alot of extra baggage for doing a simple thing.
  Reply With Quote
06-25-13, 01:40 PM   #5
ChronSyn
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2013
Posts: 3
I understand the benefits of third party libraries. It's not that I'm against them completely as they provide a lot of benefit (not just in WoW LUA of course), but that I enjoy the challenge of coding everything myself. I like to know my systems inside and out, and this has gotten to such an extent with PHP that I much prefer to build my own frameworks as opposed to building on something common. I did that in the past with a well known CMS framework, but decided a few months ago that I much preferred to build systems from the ground up.

I guess learning about the different libs while my knowledge is still limited would be better than trying to adapt to them later. You'd figure I'd learn from that mistake after getting too far into Delphi and not being able to effectively learn other programming languages because of it (primarily syntax and layout differences).

I've now solved the problems with the mod, except one. I've found that a user has to whisper the keyword twice for it to trigger the function and I can't seem to pin down what's causing it, there's nothing in my code that stands out as a cause for it (then again, I'm probably overlooking something). I've attached the addon, so I'd appreciate any help.

The first time they whisper, I receive the keyword as a whisper, the second time they whisper, the dropdown menu item is added to allow me to invite them when clicked and the message is added to the chatframe. This is the same for each user, they need to whisper twice for it to 'register'. This behaviour is the same regardless of the time between the whispers, so it's not an issue with throttling. It also doesn't matter how long I wait after the first whisper, it's as though the function never triggers.

Perhaps related, but my addon's loaded message appears twice even though it's only called once.
Attached Files
File Type: zip GuildInviteAssist.zip (16.2 KB, 396 views)
  Reply With Quote
06-25-13, 02:43 PM   #6
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by ChronSyn View Post
Perhaps related, but my addon's loaded message appears twice even though it's only called once.
Some ppl probably already noticed but ..
You're referencing Frame.lua from both the GuildInviteAssist.toc and Frame.xml files

You should either
  • load the Lua file from the TOC
  • load the XML file which loads the Lua file
  Reply With Quote
06-25-13, 07:58 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
In other words, your addon is doing more things twice than just printing that message.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Multiple Events Help

Thread Tools
Display Modes

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