![]() |
| Snowy Mountains in the Howling Fjord, From Screenshots 2008 |
Last night I didn’t feel as calm as the area in the screen above looks. I started programming on a very simple addon idea and immediately ran into a big huge blob of “doesn’t work as one would have thought”.
The Basic Idea
Our guild has lots of alts, nearly everybody has between two or three alts. Now with everybody making Death Knights there has been a growth spurt that nobody – well at least not me – can keep track of anylonger. As a rule we write the name of the main character in the guild note so it is possible to find out who is behind a character.
I am lazy however and when I see the “[Funny DK Name I never heard of before:74] has come online.” I want to know who it is without having to mouseover some FuBar social thingy or even having to call up the actual social pane to look up the note. I want the info right where I read that they just came online in my nice ChatFrame1!
Who is this Guildie?
It’s easy to find out the event to register for (CHAT_MSG_SYSTEM), it is not quite as easy to parse the message to extract the name and it wasn’t even that hard to find the method that will give me the info I was looking for and then some. Ok it took me about an hour to do the name parsing thing because I tried to use the string from GlobalStrings.lua to escape any need for localization. In the end I caved in and did some puny variant that will work only on the English client for now. But I managed to extract the name from the message and display the info (using GetNumGuildMembers and GetGuildRosterInfo). (There’s still a bug though because the message appears in chat before the guild roster knows the person is online and I tried to optimize … never mind).
Spying on Friends
But then I had this idea that I could extend my addon to include friends. It’s quite easy to extract the info you need from your friendslist with GetNumFriends and GetFriendInfo.
But because I am insanely curious and like to keep track of former guildies and all that (friendslist is much too small IMO) I wanted to output the guild of any friend that came online.
I spent another hour looking for a way to obtain the guild name of a player by the name of that player. The – seemingly? – only function that allows to retrieve the guild of a player is GetGuildInfo. However this method only takes one parameter: UnitId. It took me a lot of time to figure out UnitId actually is the equivalent of an enum and it only allows values like “player”, “target”, “pet”, “mouseover”, “focus” etc.. There is no UnitId value to signify an arbitrary unit. Of course there wouldn’t be. How would I decide which unit that was? Oh the unit has a name … maybe I could take the name of the unit?
It does not work that way.
The only way I found that allowed retrieval of GuildInfo for an arbitrary “unit” was the /who command which can be triggered with the SendWho function. This actually does execute a /who command including the system message you get when who returns 3 or less results. This is not what I wanted.
How bad can an API be designed that there is no obvious way to obtain the guild of a player unless you have that player targeted or in your party or mouseover that player?
Meh.
PS: when I get home I’ll post the code, I forgot to commit to the svn last night after fishing my way up to 450 I felt kind of stupid – brain had gone to sleep two hours before the rest of me
PPS: and now I realized there is a third category of people I need to spy on … those in our in-game chat channel
so at least something good came from this rant.
Yashima plays by Yashima is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License.




0 Responses to “WoW API: UnitId is an enum”
Leave a Reply