View Single Post
10-12-17, 12:34 PM   #1
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Identify heirloom mount drivers without list of IDs

So I have this peculiar issue where I need to be able to identify heirloom mount drivers, mercenaries and other NPCs that are glued to you or behaves sort of like a pet.

In essence, what I'm looking for is a robust way to distinguish NPCs that are tethered to me without a blacklist.
I'm using the following code to process units and check if they seem to be NPCs.
Lua Code:
  1. local BLACKLIST = {
  2.     ['89713'] = true;   -- Koak Hoburn, heirloom mount chauffeur
  3.     ['89715'] = true;   -- Franklin Martin, heirloom mount chauffeur
  4. }
  5.  
  6. local function IsNPC(unit)
  7.     local guid = UnitGUID(unit)
  8.     if not guid then return end
  9.     local unitType, _, _, _, _, ID = strsplit('-',guid)
  10.     return  not UnitIsBattlePet(unit) and   -- unit should not be battlepet
  11.             not UnitIsPlayer(unit) and      -- unit should not be player
  12.             not UnitIsMercenary(unit) and   -- unit should not be mercenary
  13.             UnitIsFriend('player', unit) and    -- unit should be friendly
  14.             (unitType == 'Creature') and    -- GUID should start with Creature
  15.             (not BLACKLIST[ID])         -- check with blacklist
  16. end

Looking through the API, I can't seem to find a function that tells me if a unit/GUID is part of the game world or following me around. Is this at all possible to find out?
__________________
  Reply With Quote