Code:
-------------------------------------------------------------------------------------------
------------------------------------ Holy Nova Radar --------------------------------------
-------------------------------------------------------------------------------------------
------------------------------------- Version 1.0.1 ---------------------------------------
-------------------------------------------------------------------------------------------
-- This code was created and developed by the priest community of MMO-Champion.com, with
-- special thanks to Dessi, who wrote most of the working script, and to Atonement who had
-- an idea, some good intentions and access to Google.
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
-- Disclaimer:
-- This code was written using elements of the DBM-RangeChecker.lua code which
-- was written and copyrighted by:
-- * Paul Emmerich (Tandanu @ EU-Aegwynn) (DBM-Core)
-- * Martin Verges (Nitram @ EU-Azshara) (DBM-GUI)
-- however HNR and its creators are by no means endorsed by DBM or its authors
--
-- In compliance with the copyright specifications outlined by the DBM authors
-- on which this work is based, you are free:
-- * to Share to copy, distribute, display, and perform the work
-- * to Remix to make derivative works
-- Under the following conditions:
-- * Attribution. You must attribute the work in the manner specified by the author or
-- licensor (but not in any way that suggests that they endorse you or your use of the
-- work).
-- * Noncommercial. You may not use this work for commercial purposes.
-- * Share Alike. If you alter, transform, or build upon this work, you may distribute
-- the resulting work only under the same or similar license to this one.
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
---------------------
------ Globals ------
---------------------
HNR = {}
---------------------
------ Options ------
---------------------
---------------------
--- Slash Command ---
---------------------
SLASH_HNR1 = '/HNR'
function SlashCmdList.HNR(input, editbox)
if input == "" then
if HNRFrame:IsShown() then
HNRFrame:Hide()
else
HNRFrame:Show()
end
end
end
----------------------
---- Create Frame ----
----------------------
local HNR
HNR = CreateFrame("Frame","HNRFrame",UIParent)
HNR:SetMovable(true)
HNR:EnableMouse(true)
HNR:RegisterForDrag("LeftButton")
HNR:SetScript("OnDragStart", HNR.StartMoving)
HNR:SetScript("OnDragStop", HNR.StopMovingOrSizing)
HNR:SetPoint("CENTER");
HNR:SetWidth(64);
HNR:SetHeight(64);
HNR:SetUserPlaced(true) -- tells blizz to care about saving the position
local tex = HNR:CreateTexture("ARTWORK"); -- holy nova texture
tex:SetAllPoints();
tex:SetTexture("Interface\\Icons\\Spell_Holy_HolyNova.blp")
local topMost = CreateFrame("Frame", nil, HNR)
topMost:SetWidth(HNR:GetWidth());
topMost:SetHeight(HNR:GetHeight());
topMost:SetPoint("CENTER");
local texGreen = topMost:CreateTexture("ARTWORK"); -- texture green transparent overlay
texGreen:SetAllPoints();
texGreen:SetTexture(0, 1, 0);
texGreen:SetAlpha(0.2);
local texRed = topMost:CreateTexture("ARTWORK"); -- texture green transparent overlay
texRed:SetAllPoints();
texRed:SetTexture(1, 0, 0);
texRed:SetAlpha(0.2);
texRed:Hide();
local text = topMost:CreateFontString();
text:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE, MONOCHROME")
text:SetText(0)
text:SetTextColor(1,1,1)
text:SetPoint("CENTER",topMost,"CENTER",0,0)
------------------------
------- Map Sizes ------
------------------------
HNR.MapSizes = {}
function HNR:RegisterMapSize(zone, ...)
if not HNR.MapSizes[zone] then
HNR.MapSizes[zone] = {}
end
local zone = HNR.MapSizes[zone]
for i = 1, select("#", ...), 3 do
local level, width, height = select(i, ...)
zone[level] = {width, height}
end
end
function HNR:UpdateMapSizes()
-- try custom map size first
SetMapToCurrentZone()
local mapName = GetMapInfo()
local floor, a1, b1, c1, d1 = GetCurrentMapDungeonLevel()
local dims = HNR.MapSizes[mapName] and HNR.MapSizes[mapName][floor]
if dims then
currentSizes = dims
return
end
-- failed, try Blizzard's map size
if not (a1 and b1 and c1 and d1) then
local zoneIndex, a2, b2, c2, d2 = GetCurrentMapZone()
a1, b1, c1, d1 = a2, b2, c2, d2
end
if not (a1 and b1 and c1 and d1) then return end
currentSizes = {abs(c1-a1), abs(d1-b1)}
end
function HNR:GetMapSizes()
if not currentSizes then
HNR:UpdateMapSizes()
end
return currentSizes
end
-----------------------
---- Range Checker ----
-----------------------
function HNR:updateHNR()
SetMapToCurrentZone()
local activeRange = 12; -- HN range 12 yrds
local numPlayers = GetNumGroupMembers()
local player = GetUnitName("player")
local prefix = "raid"
local playerThreshold = 5000 -- TODO calc HN Heal value
local dims = HNR:GetMapSizes()
local playerX, playerY = GetPlayerMapPosition("player")
if playerX == 0 and playerY == 0 then return end -- Somehow we can't get the correct position?
if not IsInRaid() then
prefix = "party"
numPlayers = numPlayers - 1
end
local playersInRange = 0 -- anzahl spieler in range mit health defizit
-- add yourself as a potential healing target
if not UnitIsDeadOrGhost("player") then
local healthDeficit = UnitHealthMax("player") - UnitHealth("player")
if healthDeficit > playerThreshold then
playersInRange = playersInRange + 1
end
end
for i = 1, numPlayers do
local unit = prefix..i
if not UnitIsUnit(unit, "player") and not UnitIsDeadOrGhost(unit) then
local x, y = GetPlayerMapPosition(unit)
if x ~= 0 and y ~= 0 then
local cx = (x - playerX) * dims[1]
local cy = (y - playerY) * dims[2]
local range = (cx * cx + cy * cy) ^ 0.5
if range <= (activeRange * 1.1) then-- add 10% because of map data inaccuracies
-- player is in nova range
--determine if player has a health deficit
local healthDeficit = UnitHealthMax(unit) - UnitHealth(unit)
if healthDeficit > playerThreshold then
playersInRange = playersInRange + 1
end
end
end
end
if playersInRange >= 5 then -- exit loop when 5 viable players were found
break
end
end
text:SetText(playersInRange) -- TODO change texture depending on player count
if playersInRange > 4 then
texRed:Hide()
texGreen:Show()
else
texRed:Show()
texGreen:Hide()
end
return playersInRange
end
----------------------
--- setup onUpdate ---
----------------------
local tickTime = 0.05 --call range checking function ever tickTime seconds
local targetTime = 0
local total = 0
function HNR:onUpdate(elapsed)
total = total + elapsed
if total >= tickTime then
HNR:updateHNR() -- call updateHNR every 0.05secs
total = 0
targetTime = tickTime
end
end
HNR:SetScript("OnUpdate", HNR.onUpdate)
Things we still need to do: