From cba360490612e0c4d65e443d936c4d25869087e2 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri, 24 Jul 2026 17:06:12 -0500 Subject: [PATCH] Use UnitGUID instead of UnitExists for GUID Replace the previous extended UnitExists GUID retrieval with UnitGUID and simplify the Nampower health lookup flow. Also minor whitespace/formatting cleanup. --- api/unitframes.lua | 51 ++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/api/unitframes.lua b/api/unitframes.lua index e6369548..33c922aa 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -148,42 +148,35 @@ function pfUI.api.GetUnitStats(unitstr, trackStats) -- Use the standard check first, then get guid separately local exists = _G.UnitExists(unitstr) if exists then - -- Get guid via the extended UnitExists for Nampower - local _, guid = _G.UnitExists(unitstr) - - if guid then - hp = GetUnitField(guid, "health") - maxHp = GetUnitField(guid, "maxHealth") - - -- Check if Nampower gave valid health data - if hp and hp > 0 and maxHp and maxHp > 0 then - usedNampower = true - - -- Track Nampower success - NUR bei echten Änderungen - if trackStats and pfUI.uf and pfUI.uf.stats and pfUI.uf.stats.enabled then - local lastStats = pfUI.api.lastUnitStats[unitstr] - if not lastStats or lastStats.hp ~= hp or lastStats.maxHp ~= maxHp or - lastStats.power ~= power or lastStats.maxPower ~= maxPower then - pfUI.uf.stats.nampowerUsed = (pfUI.uf.stats.nampowerUsed or 0) + 1 - pfUI.api.lastUnitStats[unitstr] = { - hp = hp, - maxHp = maxHp, - power = power, - maxPower = maxPower - } - end + local guid = _G.UnitGUID(unitstr) + hp = GetUnitField(guid, "health") + maxHp = GetUnitField(guid, "maxHealth") + -- Check if Nampower gave valid health data + if hp and hp > 0 and maxHp and maxHp > 0 then + usedNampower = true + -- Track Nampower success - NUR bei echten Änderungen + if trackStats and pfUI.uf and pfUI.uf.stats and pfUI.uf.stats.enabled then + local lastStats = pfUI.api.lastUnitStats[unitstr] + if not lastStats or lastStats.hp ~= hp or lastStats.maxHp ~= maxHp or + lastStats.power ~= power or lastStats.maxPower ~= maxPower then + pfUI.uf.stats.nampowerUsed = (pfUI.uf.stats.nampowerUsed or 0) + 1 + pfUI.api.lastUnitStats[unitstr] = { + hp = hp, + maxHp = maxHp, + power = power, + maxPower = maxPower + } end - - return hp, maxHp, power or 0, maxPower or 1, powerType end + return hp, maxHp, power or 0, maxPower or 1, powerType end end end - + -- Fallback to standard API (for players when Nampower fails) hp = UnitHealth(unitstr) or 0 maxHp = UnitHealthMax(unitstr) or 1 - + -- Track Fallback usage - NUR bei echten Änderungen if trackStats and not usedNampower then if pfUI.uf and pfUI.uf.stats and pfUI.uf.stats.enabled then @@ -200,7 +193,7 @@ function pfUI.api.GetUnitStats(unitstr, trackStats) end end end - + return hp, maxHp, power, maxPower, powerType end