diff --git a/libs/libunitscan.lua b/libs/libunitscan.lua index 1153f0bc..99996ff4 100644 --- a/libs/libunitscan.lua +++ b/libs/libunitscan.lua @@ -10,10 +10,12 @@ setfenv(1, pfUI:GetEnvironment()) -- on further expansions. -- -- External functions: --- GetUnitInfo(name, active) +-- GetUnitInfo(name, active, isPlayer) -- Returns information of the given unitname. Returns nil if no match is found. -- When nothing is found and the active flag is set, the autoscanner will -- automatically pick it up and try to fill the missing entry by targetting the unit. +-- Pass isPlayer=true/false to restrict the lookup to the players or mobs table +-- (avoids name-collision false positives, e.g. a player and an NPC named Chromie). -- -- class[String] - The class of the unit -- level[Number] - The level of the unit @@ -44,11 +46,11 @@ local function RememberByUnit(unit, name, class) C_PlayerCache.RememberPlayer(guid, name, class, UnitRace(unit), UnitSex(unit)) end -function GetUnitInfo(name, active) - if units["players"][name] then +function GetUnitInfo(name, active, isPlayer) + if isPlayer ~= false and units["players"][name] then local ret = units["players"][name] return ret.class, ret.level, ret.elite, true, ret.guild - elseif units["mobs"][name] then + elseif isPlayer ~= true and units["mobs"][name] then local ret = units["mobs"][name] return ret.class, ret.level, ret.elite, nil, ret.guild elseif active then diff --git a/modules/nameplates.lua b/modules/nameplates.lua index cc537f2d..25763a90 100644 --- a/modules/nameplates.lua +++ b/modules/nameplates.lua @@ -1023,15 +1023,21 @@ end local hpmin, hpmax = plate.original.healthbar:GetMinMaxValues() local name = plate.original.name:GetText() local level = plate.original.level:IsShown() and plate.original.level:GetObjectType() == "FontString" and tonumber(plate.original.level:GetText()) or "??" - local class, ulevel, elite, player, guild = GetUnitInfo(name, true) - + + if not plate.cache.player and plate.cachedGuid then + plate.cache.player = UnitIsPlayer(plate.cachedGuid) and "PLAYER" or "NPC" + end + local isPlayer + if plate.cache.player then isPlayer = plate.cache.player == "PLAYER" end + local class, ulevel, elite, player, guild = GetUnitInfo(name, true, isPlayer) + -- Use database level ONLY if current level is ?? (fixes ?? after reload, but doesn't override visible levels) local levelFromDB = false if level == "??" and ulevel and ulevel > 0 then level = ulevel levelFromDB = true end - + local target = plate.istarget local mouseover = UnitExists("mouseover") and plate.original.glow:IsShown() or nil local unitstr = target and "target" or mouseover and "mouseover" or nil