-- NoThreat, Version 1.1 |
-- Code by Rakzul, modified and appended by Echoback |
|
-- Configuration -------------------------------------------------------------- |
local xPos = 0 -- X offset for center of 'frame' |
local yPos = -120 -- Y offset for center of 'frame' |
local threatSize = 24 -- Font size of 'threat' |
local tankSize = 12 -- Font size of 'tank' |
local shadow = false -- Font shadow |
local outline = true -- Font outline |
local updateTime = 0.250 -- Update threshold |
local showTank = true -- Display tank name |
local hideIfAggro = false -- Hide display if we get aggro |
local showColor = true -- Color 'threat' based on how close you are to taking aggro |
local showPercent = true -- Show threat percentage value |
local showRaw = false -- (No function yet) Show raw threat value. Displays the amount of threat until you will pull aggro |
local locked = true -- Lock the display, set to false for configuring |
local font = UNIT_NAME_FONT -- What font to use |
------------------------------------------------------------------------------- |
|
local timeSinceLastUpdate = 0 |
|
-- Initialize 'frame' Frame |
local frame = CreateFrame("Button", "NoThreat", UIParent) |
frame:SetPoint("CENTER", UIParent, "CENTER", xPos, yPos) |
frame:SetHeight(threatSize) |
frame:SetWidth(threatSize) |
|
-- Initialize 'threat' FontString |
local threat = frame:CreateFontString(nil, "OVERLAY") |
if (showTank) then |
threat:SetPoint("BOTTOM", frame, "CENTER") |
else |
threat:SetPoint("CENTER", frame, "CENTER") |
end |
threat:SetTextColor(1, 1, 1) |
if (outline) then |
threat:SetFont(font, threatSize, "OUTLINE") |
else |
threat:SetFont(font, threatSize, "NONE") |
end |
if (shadow) then |
threat:SetShadowColor(0, 0, 0, 1) |
threat:SetShadowOffset(1, -1) |
end |
|
-- Initialize 'tank' FontString |
local tank = frame:CreateFontString(nil, "OVERLAY") |
tank:SetPoint("TOP", frame, "CENTER") |
tank:SetTextColor(1, 1, 1) |
if (outline) then |
tank:SetFont(font, tankSize, "OUTLINE") |
else |
tank:SetFont(font, tankSize, "NONE") |
end |
if (shadow) then |
tank:SetShadowColor(0, 0, 0, 1) |
tank:SetShadowOffset(1, -1) |
end |
|
-- Update handler |
frame:SetScript("OnUpdate", function(self, elapsed) |
local isTanking, playerThreat, threatPercent, tankThreat, threatDiff |
|
-- Don't update too quickly. New handler using OnUpdate's built-in elapsed time variable to eliminate a GetTime call |
timeSinceLastUpdate = timeSinceLastUpdate + elapsed |
if (timeSinceLastUpdate < updateTime) then |
return |
else |
timeSinceLastUpdate = 0 |
end |
|
-- For configuring the anchor |
if (not locked) then |
threat:SetText("50%") |
if (showTank) then |
tank:SetText("SomeTank") |
else |
tank:SetText("") |
end |
return |
end |
|
-- Clear display if no target |
if (not UnitExists("target") or not UnitExists("targettarget")) then |
threat:SetText("") |
tank:SetText("") |
return |
end |
|
-- Don't update if we don't have a pet, are not in a party or raid |
if (not UnitExists("pet")) and (not UnitExists("Party1")) and (not UnitExists("Raid1")) then |
threat:SetText("") |
tank:SetText("") |
return |
end |
|
-- Get threat values |
_, _, _, threatPercent, playerThreat = UnitDetailedThreatSituation("player", "target") |
_, _, _, _, tankThreat = UnitDetailedThreatSituation("targettarget", "target") |
if (playerThreat and playerThreat > 0 and tankThreat and tankThreat > 0) then |
threatPercent = (playerThreat / tankThreat) * 100 -- 'threatPercent' gets reset, even after being set to a value, because it isn't handled correctly in the script, yet |
threatDiff = playerThreat - tankThreat -- Pre-seed for "threat until aggro" display |
else |
return -- Drop out if any tests are false. Players don't get threat against players, so the script will throw an error if we don't drop out here |
end |
|
-- Color threat font |
if (showColor) then |
if (threatPercent >= 100) then |
threat:SetTextColor(1, 0, 0) |
elseif (threatPercent >= 80) then |
threat:SetTextColor(1, 1, 0) |
else |
threat:SetTextColor(0, 1, 0) |
end |
end |
|
-- Display values |
if (threatPercent > 130 and hideIfAggro) then |
-- We got aggro for sure, don't display anything unless 'hideIfAggro' is false |
threat:SetText("") |
elseif (threatPercent >= 100) then |
threat:SetText(tostring(threatPercent):sub(1,3) .. "%") |
elseif (threatPercent >= 10) then |
threat:SetText(tostring(threatPercent):sub(1,2) .. "%") |
else |
threat:SetText(tostring(threatPercent):sub(1,1) .. "%") |
end |
tank:SetText(UnitName("targettarget")) |
end) |