WoWInterface SVN NoThreat

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 8 to Rev 9
    Reverse comparison

Rev 8 → Rev 9

branches/core-v1.2.lua
1,25 → 1,36
-- NoThreat, Version 1.1
-- Code by Rakzul, modified and appended by Echoback
-- NoThreat, Version 1.2
-- Code by Rakzul and Echoback (Kaeldra, Rexxar-US)
 
-- Configuration --------------------------------------------------------------
local updateTime = 0.250 -- Update threshold
 
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 font = UNIT_NAME_FONT -- What font to use
local threatSize = 24 -- Font size of 'threat' display
local infoSize = 12 -- Font size of 'info' display
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 colorThreat = true -- Color 'threat' based on how close you are to taking or losing 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 showInfo = true -- Show 'info' display underneath 'threat'
local colorInfo = true -- Color 'info' based on status. No effect if 'infoIsTank' is true
local infoIsTank = false -- Display tank name in 'info'. This will override the default behavior of 'info'
 
local locked = true -- Lock the display, set to false for "demo" information
 
local showSolo = false
local showWithPet = true
local showInParty = true
local showInRaid = true
local hideIfTanking = false
 
local threatYellowThreshold = 80
local threatRedThreshold = 100
-------------------------------------------------------------------------------
 
local timeSinceLastUpdate = 0
 
-- Initialize 'frame' Frame
local frame = CreateFrame("Button", "NoThreat", UIParent)
frame:SetPoint("CENTER", UIParent, "CENTER", xPos, yPos)
44,10 → 55,10
threat:SetShadowOffset(1, -1)
end
 
-- Initialize 'tank' FontString
local tank = frame:CreateFontString(nil, "OVERLAY")
tank:SetPoint("TOP", frame, "CENTER")
tank:SetTextColor(1, 1, 1)
-- Initialize 'info' FontString
local info = frame:CreateFontString(nil, "OVERLAY")
info:SetPoint("TOP", frame, "CENTER")
info:SetTextColor(1, 1, 1)
if (outline) then
tank:SetFont(font, tankSize, "OUTLINE")
else
58,74 → 69,92
tank:SetShadowOffset(1, -1)
end
 
-- Initialize show/hide handler coroutine
local displayHandler = coroutine.create(function()
local show = false
-- Group-based handlers
if (showSolo and not (UnitExists("pet") or GetRealNumPartyMembers() or GetRealNumRaidMembers())) then show = true end
if (showWithPet and UnitExists("pet")) then show = true end
if (showInParty and GetRealNumPartyMembers()) then show = true end
if (showInRaid and GetRealNumRaidMembers()) then show = true end
-- Aggro handler
if (hideIfTanking and playerInfo.tanking) then show = false end
-- Locked handler
if (not locked) then show = true end
 
if (show) then frame:Show else frame:Hide end
if (showPercent) then
if (showTank) then tank:Show() else tank:Hide() end
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
local player, tank, ToT = {}, {}, {}
 
-- Only run if we have an NPC target with a target (or 'locked' is false), otherwise don't waste the cycles
if (not UnitExists("target") or not UnitExists("targettarget") or UnitIsPlayer("target") or locked) then return end
 
-- Don't update too quickly
if (timeSinceLastUpdate == nil) then timeSinceLastUpdate = 0 end
timeSinceLastUpdate = timeSinceLastUpdate + elapsed
if (timeSinceLastUpdate < updateTime) then
return
else
timeSinceLastUpdate = 0
if (timeSinceLastUpdate >= updateTime) then timeSinceLastUpdate = 0
else return
end
 
-- For configuring the anchor
if (not locked) then
threat:SetText("50%")
if (showTank) then
tank:SetText("SomeTank")
else
tank:SetText("")
coroutine.resume(displayHandler) -- Runs the displayHandler coroutine in parallel, since it doesn't affect the following code
 
-- Get threat values and determine tank status
player.tanking, player.status, _, _, player.threat = UnitDetailedThreatSituation("player", "target")
ToT.name = UnitName("targettarget")
if (tank.name and ToT.name == tank.name) then -- Check to see if ToT is actually our tank so we can display the correct data
_, _, _, _, tank.threat = UnitDetailedThreatSituation("targettarget", "target")
elseif (tank.name) then
_, _, _, _, ToT.threat = UnitDetailedThreatSituation(ToT.name, "target")
_, _, _, _, tank.threat = UnitDetailedThreatSituation(tank.name, "target")
if (ToT.threat > tank.threat) then -- We aren't using 'ToT.tanking' because it's faster to just assume ToT is tanking until the target actually starts attacking its tank
tank.name = ToT.name
tank.threat = ToT.threat
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
tank.name = ToT.name
_, _, _, _, tank.threat = UnitDetailedThreatSituation(tank.name, "target")
end
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
 
-- Color threat font
if (showColor) then
if (threatPercent >= 100) then
-- Set 'threat' display
-- Color 'threat' font
if (colorThreat) then
if (threatPercent >= threatRedThreshold) then
threat:SetTextColor(1, 0, 0)
elseif (threatPercent >= 80) then
elseif (threatPercent >= threatYellowThreshold) then
threat:SetTextColor(1, 1, 0)
else
threat:SetTextColor(0, 1, 0)
end
end
threat:SetText(threatPercent:floor() .. "%")
 
-- 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) .. "%")
-- Set 'info' display
-- Color 'info' font
if (colorInfo) then
if (threatPercent >= threatRedThreshold) then
threat:SetTextColor(1, 0, 0)
elseif (threatPercent >= threatYellowThreshold) then
threat:SetTextColor(1, 1, 0)
else
threat:SetTextColor(0, 1, 0)
end
end
tank:SetText(UnitName("targettarget"))
if (infoIsTank) then
info:SetText(UnitName("targettarget"))
elseif (player.status == 3) then
info:SetText("Strongly Tanking")
elseif (player.status == 2) then
info:SetText("Weakly Tanking")
elseif (player.status == 1) then
info:SetText("Threat High")
elseif (player.status == 0) then
info:SetText("Threat Low")
end
end)
\ No newline at end of file
branches/readme-v1.2.txt
3,15 → 3,24
- Use a SavedVariables file
- Make GUI-based config frame for InterfaceOptions_AddCategory()
- Get 'threatDiff' working
- Save tankThreat and compare when target switches targets to determine if tank actually changed
 
Changelog
Version 1.2
- Added tanking functionality: threat color changes based on above-aggro threat, 'info' display
- Added "sticky" tank checking. If the target changes targets NoThreat will compare threat levels to determine if the tank actually changed
- Changed many config option names
- Changed names of some important variables:
FontString 'threat' is now 'info'
local 'playerThreat' is now 'player.threat'
local 'tankThreat' is now 'tank.threat'
local 'isTanking' is now 'player.tanking'
- Added new show/hide handling section (*NOW* 'hideIfAggro' works properly)
 
Version 1.1
Significant changes:
- 'threatDiff' is now 'threatPercent' ('threatDiff' will become a raw threat value difference)
- 'threatPercent' and 'tankName' are displayed in two FontStrings, 'threat' and 'tank', respectively
Working features added:
- 'threatPercent' and 'tankName' are now two separate FontStrings, so each can be modified and styled independently
- 'threatPercent' gets colored based on threat level
- Fonts can now be outlined as well as shadowed
- 'hideIfAggro' is now correctly handled
\ No newline at end of file +- 'hideIfAggro' is now correctly handled