Add spotter from weakaura
This commit is contained in:
59
Spotter.lua
Normal file
59
Spotter.lua
Normal 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)
|
||||
Reference in New Issue
Block a user