WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How do you find out a NPC's faction? (https://www.wowinterface.com/forums/showthread.php?t=21451)

Darthgnomer 03-26-09 08:21 AM

How do you find out a NPC's faction?
 
How do you find out a NPC's faction?

If I mouse over a NPC in the Scryer area of Shatt or one of the many mage looking NPCs in Dalaran my cursor tooltip will reveal their faction such as 'The Scryers' or 'Kirin Tor' for these examples respectively.

How can I find out this information for an addon? I've looked around the APIs on WoWWiki and tried to reverse engineer CowTip but I am lost. Any information or simple examples would be very appreciated.

Tristanian 03-26-09 09:41 AM

I think UnitFactionGroup("unit") is what you are looking for.

http://www.wowprogramming.com/docs/api/UnitFactionGroup

Darthgnomer 03-26-09 12:26 PM

No, this only returns Alliance or Horde; tested it out with a Night Elf armor merchant located in Darnassus and instead of coming back 'Darnassus' it came back 'Alliance'.

Gemini_II 03-26-09 12:46 PM

Be sure that the NPC you test against actually has a faction, as many of them do not. :)

Darthgnomer 03-26-09 12:58 PM

When I moused over the NPC the default Blizzard tooltip said 'Darnassus'. According to wowhead Cylania <Night Elf Armorer> has a Faction of 'Darnassus'.
Source: http://www.wowhead.com/?npc=4164

Also, I tried this with a vendor in Dalaran with a faction of 'Kirin Tor' and still got 'Alliance'.

I believe there is a different method I need to find what faction a NPC belongs to.

Gemini_II 03-26-09 01:04 PM

Looks like GetFactionInfo is what you want...

Darthgnomer 03-26-09 01:22 PM

GetFactionInfo(index) only returns data about the player, the character which I am logged in as. However, I am trying to get data about any given NPC such as a questgiver, city guard, or merchant which I am assumingly interacting with in the form or targeting, mousing over, or having their chat dialog open with such as the 'MERCHANT_SHOW' event has fired.

Quote:

How do you find out a NPC's faction?

If I mouse over a NPC in the Scryer area of Shatt or one of the many mage looking NPCs in Dalaran my cursor tooltip will reveal their faction such as 'The Scryers' or 'Kirin Tor' for these examples respectively.

How can I find out this information for an addon? I've looked around the APIs on WoWWiki and tried to reverse engineer CowTip but I am lost. Any information or simple examples would be very appreciated.

Freki 03-27-09 01:27 AM

Like you, I wasn't able to find an easy way to find this. Maybe it slipped past me and someone else could inform you. The only way I could figure how to it was quite messy and I'm not sure it works 100% of the time (especially with tooltip modifying addons), but from my limited testing it seems to work okay and it might give you a start.

Code:

/script faction = (GameTooltip:NumLines() > 2 and not UnitIsPlayer(select(2,GameTooltip:GetUnit()))) and getglobal("GameTooltipTextLeft"..GameTooltip:NumLines()-1):GetText() DEFAULT_CHAT_FRAME:AddMessage(faction or "NIL")
Edit: This reads straight from the GameTooltip, so it only works when you're mousing over a target. If you want unit to be "target", you'd probably have to set the GameTooltip to that unit then do this.

Tristanian 03-27-09 03:18 AM

After considerable digging and playing around with almost every faction related function in the game, I believe that the NPC faction is unfortunately hardcoded in the tooltip. If that is indeed the case, then your only chance to get the faction without "guessing" the tooltip line each and every time (which can be entirely inaccurate), would be to set the target tooltip, scan each line (except maybe the first) and try to match it to a faction name present in the player's faction index, hoping to get a positive match.

The problem with this method is that the player's faction index does not include inactive factions or factions that belong to collapsed headers, so if any of these 2 conditions are met, you have a problem. Not an impossible one, but would require considerable coding to get around it and at the end of the day, I'm not even sure its worth the trouble.

Fritos 03-27-09 04:24 AM

I'm using this method of scanning the tooltip myself.

Just have a table of all factions in the game and compare it against the scanning of the tooltip like other have mentioned, once the criteria is met have it return a positive.

Aezay 03-27-09 04:53 AM

What I've done to find the faction of an NPC, is to create my own tooltip to use for scanning, do not use GameTooltip. The faction information is always below the level line, if the line after the level line is empty or contains "PvP" or "x% threat" then the unit has no faction.

With that said, there is only the problem about finding the line containing the level information:
http://www.wowinterface.com/forums/s...ad.php?t=21293


All times are GMT -6. The time now is 12:00 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI