Thread Tools Display Modes
03-26-09, 08:21 AM   #1
Darthgnomer
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 7
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.
  Reply With Quote
03-26-09, 09:41 AM   #2
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
I think UnitFactionGroup("unit") is what you are looking for.

http://www.wowprogramming.com/docs/api/UnitFactionGroup
__________________
  Reply With Quote
03-26-09, 12:26 PM   #3
Darthgnomer
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 7
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'.
  Reply With Quote
03-26-09, 12:46 PM   #4
Gemini_II
A Molten Giant
 
Gemini_II's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 762
Be sure that the NPC you test against actually has a faction, as many of them do not.
__________________
Retired prior to 3.2, before all challenge was removed.

  Reply With Quote
03-26-09, 12:58 PM   #5
Darthgnomer
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 7
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.
  Reply With Quote
03-26-09, 01:04 PM   #6
Gemini_II
A Molten Giant
 
Gemini_II's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 762
Looks like GetFactionInfo is what you want...
__________________
Retired prior to 3.2, before all challenge was removed.

  Reply With Quote
03-26-09, 01:22 PM   #7
Darthgnomer
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 7
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.

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.

Last edited by Darthgnomer : 03-26-09 at 01:26 PM.
  Reply With Quote
03-27-09, 01:27 AM   #8
Freki
A Deviate Faerie Dragon
 
Freki's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 18
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.

Last edited by Freki : 03-27-09 at 01:32 AM.
  Reply With Quote
03-27-09, 03:18 AM   #9
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
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.
__________________
  Reply With Quote
03-27-09, 04:24 AM   #10
Fritos
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 4
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.
  Reply With Quote
03-27-09, 04:53 AM   #11
Aezay
A Theradrim Guardian
 
Aezay's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 66
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
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How do you find out a NPC's faction?

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