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.
|
|
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. |
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
|
If you're getting GUIDs from chat (the usual reason for calling GetPlayerInfoByGUID) then you can determine the faction based on the message language.
|
Quote:
|
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. |
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.
|
Quote:
Quote:
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. Quote:
|
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... |
Quote:
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? |
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) |
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?
|
Quote:
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: Quote:
|
Here'a a "quick" and dirty method for getting the faction from a unit's GUID using its tooltip:
Lua Code:
Probably not the best solution but maybe it'll help somebody. |
Quote:
Quote:
|
Quote:
|
Quote:
|
Quote:
|
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. |
Quote:
Quote:
|
so... thanks for the help on this. The string constant is ERR_CHAT_PLAYER_NOT_FOUND_S and my filter is designed so I don't have to remove it as it will only filter exact matches to pandaren I am looking for. I think I will try out the tooltip method now as that is an instant answer and seems to be a smaller solution in both coding and in table usage.
|
Quote:
Quote:
If you have 1000 ms ping, there is either something wrong with your connection or you're bringing it on yourself by playing on a server far outside of your region, but in any case it's hardly the end of the world if you delay showing chat messages from/about opposite faction panadren anyway. It's not like it's actually relevant information. |
Quote:
Quote:
Quote:
There is an entire history of various data Blizzard granted access to over the years. In vanilla WoW, HP values for any unit other than the player were strictly provided as an integer percent. This changed in BC because of addons that calculated mob HP from how much damage they took before dying, then applied that to exact copies of the same mob. At one time, GUIDs weren't available to addons. The same time Blizzard overhauled the Combat Log system, they added this as a way to track info about a specific entity. Up until LK, Blizzard didn't provide information about mob threat levels. Addons like Omen had to calculate this themselves by taking in damage and healing info from the combat log. There are more examples, but this is all I can think of at the moment. All of which fall into different categories of necessity and luxury, things people suggested and things people worked on to obtain themselves. |
Quote:
If you think eliminating a one-second-at-most delay to determine someone's faction in the one-in-a-million event of them being an enemy pandaren /saying or /yelling something in Pandaren instead of their faction default language is really so critical Blizzard needs to spend time adding to the API, I guess we just have radically different ideas about what is important. I'd much rather they spend time fixing actual bugs instead, and there are certainly plenty of those for them to work on. |
Quote:
If you don't believe me, check the links. Quote:
If I'm not mistaking, this is the entire purpose of this subforum. Description of Developer Discussions » Wish List taken from the main forum page. Quote:
|
so this is currently what I have the tooltip down to and it works fine (well it did as I made some changes here and have yet to test them)... you call it and it returns true if they are the same faction and false if not. I still think an added return to for GetPlayerInfoByGUID would be a better solution... and since this is a WISH LIST... I can wish all I want lol
Lua Code:
|
I'll have to do some further tests with the tooltips for the unit hyperlink. Previously, I've noticed it only returns useful data if the player in question is within the game client's visible range. If it does still work past that range, I might take a look into it and already have some optimizations in mind for the code.
Lua Code:
Assuming the tooltip works beyond the game client's visual range and no addons hook into the global metatable for tooltips, this modification should function in the same way UnitFactionGroup() does, but operate on GUIDs instead. |
Okay, I didn't take into account that the faction might change, so you probably should avoid caching it if it's neutral. However, I warn you against skipping OnTooltipSetUnit, I've had issues before making the assumption that a tooltip's text is going to be available immediately after I set it.
Also, don't assume that it's neutral because it doesn't match the alliance or horde string because sometimes the faction isn't mentioned in the tooltip, which I believe always means it's not your faction, but could be either neutral or the opposing faction. |
I'm not sure if Tooltip:SetHyperlink() fires OnTooltipSetUnit on unit hyperlinks. Again, all this is pending results of a series of tests I need to do and unfortunately, I can't perform them at work right now. The "Neutral" handling is just a fall through in case it's unable to identify a specific faction. With lack of other options, I don't see any harm in letting it do that as long as it doesn't throw them into either of the Alliance or Horde category blindly. If you insist, you can have it pass nil,nil instead as that's the default response of UnitFactionGroup() for neutral NPCs.
|
That is why I used IsPlayerNeutral() in my function first as if you are neutral, so every other char near you will be too. Also if it doesn't come back with a faction for a player then it is safe to assume that the player is of the opposing faction (as I did). I suppose that since a clear is issued before the set you could test to make sure that numlines is greater than 0 to make sure that the tooltip has been set... and possibly loop until it is but who knows how long that could hang you up for...
|
OnTooltipSetUnit fires when it's populated with unit information whether it's from SetUnit or SetHyperlink.
I don't know for sure that you need to wait for it, but I would be careful. |
sure beats the following... this is what I was doing before, modified for the SendAddonMessage and to catch the thrown error if it happens
if it is passed just a GUID it will return true if the person is part of your faction or if you are a panda if you pass a GUID, and a function to run if true / false and char name and unlimited args for the passed functions ... if a non panda it will automatically call the proper function (if it exists) and return true/false depending... if a panda it queues up the required info in a table, sends the addon message and waits up to 1 second for the error. if the error is thrown, it will call the ifFalse function and remove the panda from the queue... after the 1 second, the addon calls the ifTrue function if supplied and then removes the panda from the queue it will call ifTrue/ifFalse with GUID, unpack(...) Lua Code:
|
Quote:
The only way around this is to recode the entire thing into a request-and-callback code style, which would add another layer of complexity to it. |
I was scraping the tooltip for spell information and can say with absolute certainty that attempting to do it soon after loading/zoning and possibly other situations would result in the tooltip being empty.
|
Quote:
Well technically it is but you get my point. (Routes and Weakauras - that I know off - use coroutines to simulate multi-threaded execution) |
A coroutine represents a thread, but isn't a real one. If you have a coroutine run an infinite loop in the game client, it'll freeze it the same way as if you had code in the main stack do so. This is because the coroutine needs to yield in order for the main stack to continue running. If it never yields, the thread it's running on (the only thread the Lua engine is given) gets stuck. Since MoP though, the game client has a WatchDog thread that activates while in combat and monitors how long the Lua engine thread runs. If the Lua thread exceeds a specific amount of time, the WatchDog thread interrupts it by forcing a Lua error.
Note WatchDog is an old term for a program or circuit specifically designed to detect when another critical program/component freezes and restarts it as necessary. |
OK... So here is what I have now. It will return Neutral when the player is neutral, as you can only run into neutral players then, it tests the race of all chars and figures out by that, faction, except for pandas which it uses the tooltip. I combined how I was originally testing and incorporated the tooltip for scanning pandas only.
Lua Code:
|
From some of my testing, the same conclusion happens that I had observed earlier pre-MoP. Tooltips from the unit hyperlink only displays useful information past race/class only if said unit is within the game client's visual range. As soon as a unit leaves this range, existing information is discarded and is no longer available.
|
All times are GMT -6. The time now is 02:57 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI