From fa7e4f8b403afb00c744fa40f461ad5cf300f4c8 Mon Sep 17 00:00:00 2001 From: Meow <30401521+me0wg4ming@users.noreply.github.com> Date: Wed, 4 Mar 2026 02:27:11 +0100 Subject: [PATCH] Range Check: UnitXP mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added Range Check Mode dropdown (Vanilla / UnitXP) and UnitXP Range Threshold input field under the 40y-Range Check settings in the GUI In UnitXP mode, UnitInRange bypasses librange entirely and queries UnitXP("distanceBetween") directly with the configured yard threshold librange scan loop is disabled when UnitXP mode is active — no TargetUnit cycling, no spellbook scanning, no combat interruption Fixed UnitInRange referencing librange as an undefined local instead of pfUI.api.librange, which caused silent nil returns --- api/api.lua | 17 +++++++++++++++-- api/config.lua | 2 ++ libs/librange.lua | 3 ++- modules/gui.lua | 6 ++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/api/api.lua b/api/api.lua index a29f6686..1ee70401 100644 --- a/api/api.lua +++ b/api/api.lua @@ -141,9 +141,22 @@ function pfUI.api.UnitInRange(unit) return nil elseif CheckInteractDistance(unit, 4) then return 1 - else - return librange:UnitInSpellRange(unit) end + + -- UnitXP precise mode: skip librange entirely, use direct distance check + if C.unitframes.rangecheck_mode == "unitxp" and _G.UnitXP then + local threshold = tonumber(C.unitframes.rangecheck_distance) or 40 + local success, distance = pcall(_G.UnitXP, "distanceBetween", "player", unit) + if success and distance then + return distance <= threshold and 1 or nil + end + -- fallthrough to librange if UnitXP fails + end + + if pfUI.api.librange then + return pfUI.api.librange:UnitInSpellRange(unit) + end + return nil end -- [ RunOOC ] diff --git a/api/config.lua b/api/config.lua index a2454c51..54b19484 100644 --- a/api/config.lua +++ b/api/config.lua @@ -216,6 +216,8 @@ function pfUI:LoadConfig() pfUI:UpdateConfig("unitframes", nil, "portraittexture", "1") pfUI:UpdateConfig("unitframes", nil, "layout", "default") pfUI:UpdateConfig("unitframes", nil, "rangecheck", "0") + pfUI:UpdateConfig("unitframes", nil, "rangecheck_mode", "vanilla") + pfUI:UpdateConfig("unitframes", nil, "rangecheck_distance", "40") pfUI:UpdateConfig("unitframes", nil, "buffdetect", "0") pfUI:UpdateConfig("unitframes", nil, "druidmanabar", "1") pfUI:UpdateConfig("unitframes", nil, "druidmanaheight", "10") diff --git a/libs/librange.lua b/libs/librange.lua index e7a8f372..e476e5ba 100644 --- a/libs/librange.lua +++ b/libs/librange.lua @@ -189,7 +189,8 @@ librange:SetScript("OnUpdate", function() return UnitXP("distanceBetween", "player", unit) end) if unitxp_success and unitxp_distance then - unitdata[unit] = unitxp_distance < 45 and 1 or 0 + local threshold = (tonumber(C.unitframes.rangecheck_distance) or 40) + 5 + unitdata[unit] = unitxp_distance < threshold and 1 or 0 this.id = this.id + 1 return end diff --git a/modules/gui.lua b/modules/gui.lua index f47167ff..f976d600 100644 --- a/modules/gui.lua +++ b/modules/gui.lua @@ -943,6 +943,10 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () "8:" .. T["Slow"], "16:" .. T["Very Slow"], }, + ["uf_rangecheck_mode"] = { + "vanilla:" .. T["Vanilla (Spellbook)"], + "unitxp:" .. T["UnitXP (Precise)"], + }, ["uf_raidlayout"] = { "1x40:" .. "1x40", "2x20:" .. "2x20", @@ -1998,6 +2002,8 @@ pfUI:RegisterModule("gui", "vanilla:tbc", function () CreateConfig(U[c], T["Group Options"], nil, nil, "header") CreateConfig(nil, T["Enable 40y-Range Check"], C.unitframes, "rangecheck", "checkbox", nil, nil, nil, nil, "vanilla" ) + CreateConfig(nil, T["Range Check Mode"], C.unitframes, "rangecheck_mode", "dropdown", pfUI.gui.dropdowns.uf_rangecheck_mode, nil, nil, nil, "vanilla") + CreateConfig(nil, T["UnitXP Range Threshold (yards)"], C.unitframes, "rangecheck_distance", nil, nil, nil, nil, nil, "vanilla") CreateConfig(nil, T["Range Check Interval"], C.unitframes, "rangechecki", "dropdown", pfUI.gui.dropdowns.uf_rangecheckinterval, nil, nil, nil, "vanilla") CreateConfig(nil, T["Use Raid Frames To Display Group Members"], C.unitframes, "raidforgroup", "checkbox") CreateConfig(nil, T["Always Show Self In Raid Frames"], C.unitframes, "selfinraid", "checkbox")