Add spotter from weakaura

This commit is contained in:
2024-12-12 13:09:13 +01:00
parent b8adb2bcd9
commit 9be889d2d2

59
Spotter.lua Normal file
View File

@@ -0,0 +1,59 @@
---@type HeimdallData
local _, data = ...
local function FormatHP(hp)
if hp > 1e9 then
return string.format("%.1fB", hp / 1e9)
elseif hp > 1e6 then
return string.format("%.1fM", hp / 1e6)
elseif hp > 1e3 then
return string.format("%.1fK", hp / 1e3)
else
return hp
end
end
---@param unit string
---@return string?
local function NotifySpotted(unit)
print(unit)
local name = UnitName(unit)
local race = UnitRace(unit)
local hp = UnitHealth(unit)
local maxHp = UnitHealthMax(unit)
if not name then return string.format("Could not find name for unit %s", tostring(unit)) end
if not race then return string.format("Could not find race for unit %s", tostring(unit)) end
if not hp then return string.format("Could not find hp for unit %s", tostring(unit)) end
if not maxHp then return string.format("Could not find maxHp for unit %s", tostring(unit)) end
local msg = string.format("%s (%s) - %s/%s", name, race, FormatHP(hp), FormatHP(maxHp))
print(msg)
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
frame:RegisterEvent("TARGET_UNIT_CHANGED")
frame:SetScript("OnEvent", function(self, event, unit)
local name = UnitName(unit)
if name and UnitIsPlayer(unit) then
local race = UnitRace(unit)
local doNotify = true
if data.config.spotter.allyOnly then
doNotify = false
if data.raceMap[race] == "Alliance" then
doNotify = true
end
end
-- Stinkies overwrite allyOnly
if data.config.spotter.stinkyOnly then
doNotify = false
if data.stinkies[name] then
doNotify = true
end
end
if doNotify then
NotifySpotted(unit)
end
end
end)