Thread Tools Display Modes
09-04-12, 11:28 AM   #1
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Faction from GetPlayerInfoByGUID()

It would be nice to have faction as a return from GetPlayerInfoByGUID(). Currently, lack of this information hinders the default language set support for addons that add custom languages. For now, this specifically applies to Pandaren since both factions share the same racial language.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
09-04-12, 07:58 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
http://wowprogramming.com/docs/api/UnitFactionGroup

Converting between GUID and unit is up to you.
  Reply With Quote
09-05-12, 02:13 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you're using GetPlayerInfoByGUID, it's probably because you're dealing with people who are talking in chat, or doing something else where no UnitID is available.

If a UnitID was available, there'd be no reason to use GetPlayerInfoByGUID, because all of the information it provides -- class, race, gender, name, server -- is available through other, more specific, UnitID-based API functions.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-30-12, 08:37 AM   #4
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
I remember asking for this ability during the beta... One of my addons needs to be able to tell if a person is of the same faction from only the guid... and there is no way for me that doesn't introduce some sort of lag... I could try a search but then I have to make the addon wait for the who list update event... and then users would see I did it... If SendAddonChatMessage had a return value instead of printing the error to chat that could help too
  Reply With Quote
11-30-12, 05:14 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you're getting GUIDs from chat (the usual reason for calling GetPlayerInfoByGUID) then you can determine the faction based on the message language.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-01-12 at 01:56 AM.
  Reply With Quote
11-30-12, 05:51 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Phanx View Post
If you're using GetPlayerInfoByGUID, it's probably because you're dealing with people who are talking in chat, or doing something else where no UnitID is available.
Yes, this is for code responding to chat events where there are no valid UnitIDs. An example is for a custom language addon like Tongues to be able to tell an Alliance Pandaren from a Horde one and act accordingly. Both factions use the [Pandaren] language tag for their racial languages. More specifically, this request was to add faction-specific icons for ChatLinkIcons in order to differentiate the same problem with the same race being available to both factions. Even though the character creation screen shows one button for Pandaren, there are actually two icons in the game files (one set of texcoords is the horizontal flipped image of the other set).
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-30-12 at 06:02 PM.
  Reply With Quote
12-01-12, 01:55 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Can't you use ChatFrame_AddMessageEventFilter and just catch the language argument (arg3) passed with the chat message? I can't recall the last time I saw anyone /say or /yell anything in a language other than their faction's default language, so just checking for Orcish or Common should catch 99% of cases.

Another option would be to do what BadBoy_Levels does to check levels, and attempt to add the player to your friends list and catch the result message. If it's successful, the player is part of your faction; if it failed, the player is of the opposing faction. This wouldn't work for cross-realm players, but I think the chances of someone of the opposite faction from another server /saying or /yelling anything in a non-default language are pretty slim.

Finally, SendAddonMessage doesn't need a return value, as it's trivial to catch the message printed to the chat frame when sending fails, and hide it from the user.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 12-01-12 at 01:59 AM.
  Reply With Quote
12-01-12, 10:31 AM   #8
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
I, myself, am using the guid from achievements and as such, I get no information that can tell me what faction besides race... now with the Pandaren, I am out of luck... There is no valid unit for me to check the affiliation with... I mean if Blizz is going to classify them as 3 different races then they should return 3 different race returns or supply some method for distinguishing from guid or something besides by units.
  Reply With Quote
12-01-12, 10:31 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Phanx View Post
Can't you use ChatFrame_AddMessageEventFilter and just catch the language argument (arg3) passed with the chat message? I can't recall the last time I saw anyone /say or /yell anything in a language other than their faction's default language, so just checking for Orcish or Common should catch 99% of cases.
As mentioned, even with the slim chance of it ever happening, the language passed isn't specific enough when dealing with the Pandaren racial language. This was one of the first solutions I checked out previously.



Originally Posted by Phanx View Post
Another option would be to do what BadBoy_Levels does to check levels, and attempt to add the player to your friends list and catch the result message. If it's successful, the player is part of your faction; if it failed, the player is of the opposing faction. This wouldn't work for cross-realm players, but I think the chances of someone of the opposite faction from another server /saying or /yelling anything in a non-default language are pretty slim.
This method is similar to what GAOA does to check if a player is online, the only difference is it uses the addon channel to ping the chat server (not the player, resulting in an addon that works one-sided). If the server comes back with a player offline message, the addon reacts accordingly. Otherwise, it waits a timeout period before assuming the player is online. There may be better methods for that addon, but that's irrelevant at this moment.

As for the other addon examples, this may be an option, but for ChatLinkIcons, requesting additional data from the servers costs additional time that doesn't fit the time restraint I feel is appropriate.



Originally Posted by Phanx View Post
Finally, SendAddonMessage doesn't need a return value, as it's trivial to catch the message printed to the chat frame when sending fails, and hide it from the user.
Did this get posted on the wrong thread?
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
12-01-12, 10:44 AM   #10
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
As for the SendAddonChatMessage() needing a return, what I meant was that if it had a return value then it could be used for a opposing faction test without needing to wait for another event to fire. I get person's name from the guid, send an addon whisper, and if it failed with a return code then I wouldn't need faction from the GUID. I could also do the same thing with who-s but again I would have to wait for another event to continue on in the program( which I am guessing is my best bet to filter out the horde achievements )

I chose SendAddonChatMessage() as it would be invisible to the person receiving the message for my example...
  Reply With Quote
12-01-12, 01:39 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by SDPhantom View Post
Did this get posted on the wrong thread?
No. See Billtopia's previous post:

If SendAddonChatMessage had a return value instead of printing the error to chat that could help too.

Also, the delay between you trying to send an addon message and the client printing a "player not found" or similar error message to the chat frame is so infinitesimally small that I can't imagine it being unacceptable for something that is really just cosmetic, especially since you'd only "need" to do it for pandaren in /say and /yell. How often does that really happen, anyway?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-01-12, 07:32 PM   #12
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
what I am doing is trying to filter out non same faction achievements out from my addon... who wants a popup asking if you want to congratulate a person of the opposing faction when they get an achievement? my problem is that the addon can work for people near you as well as people in your group and guild that nearby opposing pandaren can trigger the frame to appear. I can rewrite my faction test to treat them differently but what I was hoping for was some way to test within that event cycle instead of having to wait for another event to fire...

I looked through the events that I can register for the chat frame but http://www.wowwiki.com/Events/Communication has no listing for an error event... does anyone know what event fires when the SendAddonChatMessage fails to find its whisper target?

I figure I will just put the Pandaren achievements into a queue for a second and send the message... if a error pops on the name the chat filter can remove them from the queue... if they still exist the onupdate handler can send them off to continue on their way to the grat frame.

I looked into using the SendWho but it says that the WHO_LIST_UPDATED event only fires when the who list is open so that is a no go

I already broke my achievement processing function into 2 pieces so it can now wait for a response from SendAddonChatMessage without freezing the computer. (I also rewrote my SameFaction function so it can call one of two passed functions to continue the processing if they match or not so it can handle waiting on pandaren)
  Reply With Quote
12-01-12, 09:30 PM   #13
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Wow Instant Messenger tries to look up the guild, class and level of whatever name you whisper. It appears to be using LibWho-2.0 for that. The call is made in Modules/Filters.lua. Maybe you can use that or its methodologies?
  Reply With Quote
12-02-12, 06:58 AM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Billtopia View Post
what event fires when the SendAddonChatMessage fails to find its whisper target?
CHAT_MSG_SYSTEM is the event that fires, and the message argument should match a global string. Get the exact message in-game and then find it in your locale's GlobalStrings listing to get the global name. If it just says "Player not found." then it's probably ERR_FRIEND_NOT_FOUND.

However, you'd want to use ChatFrame_AddMessageEventFilter to catch and hide the message instead of registering your frame for the CHAT_MSG_SYSTEM event:

Code:
-- Have a filter function ready:
local CatchSystemMessage = function(frame, event, message)
    -- Remove the filter:
    ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", CatchSystemMessage)
    -- Check the message:
    if message == ERR_FRIEND_NOT_FOUND then
         -- Sending the message failed.
         -- Do something here if needed.
         -- Hide the message from the user:
         return true
    end
end

-- When you try to send a message, register the filter first:
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", CheckSystemMessage)
SendAddonMessage("TEST", "faction test", "WHISPER", nil, "Someguy")
This will catch the next system message after you send a message. If you wanted to be really fancy, you could add a timeout to remove the filter after some amount of time (probably 1 second would be more than enough). Otherwise you run the minor risk of catching the next system message even if it's not related to your event, and if the message is "Player not found." then it will get hidden.

Originally Posted by nazrhyn View Post
Wow Instant Messenger ... appears to be using LibWho-2.0 for that. The call is made in Modules/Filters.lua. Maybe you can use that or its methodologies?
LibWho-2.0 is just a wrapper around the /who query system, which is slow, and interferes with the user's ability to /who query people. It also doesn't work very well for players with short names. For example, if you are trying to /who someone named Pat, the results will include every name that includes the letters "pat" in that order at any position, and since it's limited to 49 results, you may not even get the Pat you were looking for. Using /who in an addon to find information about a specific player should be the absolute last resort.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-02-12, 08:56 AM   #15
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Here'a a "quick" and dirty method for getting the faction from a unit's GUID using its tooltip:
Lua Code:
  1. local guidCache = {}
  2. local _, myFaction = UnitFactionGroup('player')
  3. local utip = CreateFrame("GameTooltip", "uTip", UIParent, "GameTooltipTemplate")
  4.  
  5. local function DoSomething(guid)
  6.     local faction = guidCache[guid]
  7.     if faction then
  8.         print(guid, faction, faction == myFaction)
  9.     end
  10. end
  11.  
  12. utip:SetScript("OnTooltipSetUnit", function(self)
  13.     if guidCache[self.guid] then return end
  14.     local tipName, numLines = self:GetName()..'TextLeft', self:NumLines()
  15.     local faction = _G[tipName..numLines]:GetText() == PVP and _G[tipName..(numLines-1)]:GetText() or _G[tipName..numLines]:GetText()
  16.     guidCache[self.guid] = faction
  17.     DoSomething(self.guid)
  18. end)
  19.  
  20. function ScanFaction(guid)
  21.     if guid and tonumber(guid:sub(5,5), 16) % 8 == 0 then
  22.         if guidCache[guid] then
  23.             DoSomething(guid)
  24.         else
  25.             utip.guid = guid
  26.             utip:SetHyperlink('unit:'..guid)
  27.         end
  28.     end
  29. end
Usage: ScanFaction(UnitGUID('example')), calls DoSomething when it's finished.

Probably not the best solution but maybe it'll help somebody.

Last edited by semlar : 12-02-12 at 02:51 PM.
  Reply With Quote
12-02-12, 11:04 AM   #16
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by Phanx View Post
LibWho-2.0 is just a wrapper around the /who query system, which is slow, and interferes with the user's ability to /who query people. It also doesn't work very well for players with short names. For example, if you are trying to /who someone named Pat, the results will include every name that includes the letters "pat" in that order at any position, and since it's limited to 49 results, you may not even get the Pat you were looking for. Using /who in an addon to find information about a specific player should be the absolute last resort.
From your back-and-forth, though, it looks like in the situation where he detects that he doesn't know whether they're a hostile or friendly panda, he might need to use it. I was mostly responding to him thinking that the who window needed to be up to use the who API .

Originally Posted by semlar
Here'a a "quick" and dirty method for getting the faction from a unit's GUID using its tooltip:
That won't still work if someone is using a custom tooltip, will it?
  Reply With Quote
12-02-12, 12:29 PM   #17
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
Originally Posted by nazrhyn View Post
That won't still work if someone is using a custom tooltip, will it?
It should work, because it's using a privately created tooltip, not the normal GameTooltip (not to be confused the GameTooltip object type).
  Reply With Quote
12-02-12, 12:54 PM   #18
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by endx7 View Post
It should work, because it's using a privately created tooltip, not the normal GameTooltip (not to be confused the GameTooltip object type).
Cool! Well, I'd definitely prefer creating an ad-hoc tooltip to doing a who query, for sure. That's a slick idea.
  Reply With Quote
12-02-12, 01:21 PM   #19
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by semlar View Post
Here'a a "quick" and dirty method for getting the faction from a unit's GUID using its tooltip:
Looks promising, though if you're going to make the ScanFaction function a global, I'd suggest giving a less generic name, like GetPlayerFactionFromGUID or something. Also not sure about speed of waiting for the server to send a tooltip vs. waiting for the server to tell you sending a message failed, but I guess it's faster than waiting on a timeout to assume a message succeeded.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-02-12, 02:50 PM   #20
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I left it as a global so I could test it directly in-game, if you're going to use it then it should probably be localized.

I should mention that the reason I had it cache the results wasn't for faster lookups but because sometimes OnTooltipSetUnit would fire more than once and I didn't want it calling the function again.

I actually have to make a slight edit because unit GUIDs on the PTR (which was where I was testing this) are not the same as they are on live, which I didn't realize when I posted it. It's just the check that the GUID belongs to a player-type unit, which isn't strictly necessary anyway.

Using debugprofilestop and scanning a handful of units it takes anywhere between 0.1 and 0.3 milliseconds for the first lookup. For reference, 60 fps is one frame every ~16 milliseconds, so I don't think it'll be too much of a problem.

I did notice one caveat while scanning for players in the combat log to test it: if they're sufficiently higher level than you the tooltip doesn't say what faction they are, just their name and "Level ?? Race Class (Player)". I don't know how much this matters because as long as it doesn't match your faction string it's probably not your faction.

An alternative might be to compare the :GetTextColor of the first line of the tooltip (the name) since it appears to be colored based on reaction.

edit: I don't think it actually does change the color of the text unless it has a unit id or something, so that won't work.

Last edited by semlar : 12-02-12 at 03:44 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Wish List » Faction from GetPlayerInfoByGUID()

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