Skip to content

Instantly share code, notes, and snippets.

@Choonster
Created January 6, 2015 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Choonster/0e0cd96463e5baf776bb to your computer and use it in GitHub Desktop.
Save Choonster/0e0cd96463e5baf776bb to your computer and use it in GitHub Desktop.
Example WoW AddOn code for displaying range warnings for Imperator Mar'gok's Branded debuff
local BRANDED_IDS = { 164004, 164005, 164006 } -- The spellIDs of each Branded debuff (Displacement, Fortification, Replication)
local NUM_BRANDED_DEBUFFS = #BRANDED_IDS
local BRANDED_NAMES = {}
for i = 1, NUM_BRANDED_DEBUFFS do
local name = GetSpellInfo(BRANDED_IDS[i]) -- Get the localised spell name from the ID
BRANDED_NAMES[i] = name -- Store it in the BRANDED_NAMES table
end
-- Display a Branded warning for the specified unit with the specified stacks of Branded
local function DisplayBrandedWarning(unit, stacks)
local rangeNeeded = 100 * 0.5 ^ (stacks - 1) -- Each stack halves the range needed; i.e. 100, 50, 25, ...
local distanceSquared, checkedDistance = UnitDistanceSquared(unit) -- Get the distance between the player and the unit
local displayText = ("%s %d yards - Current %d yards"):format(UnitName(unit), rangeNeeded, distanceSquared ^ 0.5) -- Build the string to display
-- Display the text in some way here
end
-- Call this function to iterate through each raid member and check if they have a Branded debuff
local function UpdateBrandedStatus()
for i = 1, 40 do -- For each raid member
local unit = "raid" .. i
if UnitExists(unit) and not UnitIsUnit(unit, "player") then -- If this raid member exists and isn't the player
for i = 1, NUM_BRANDED_DEBUFFS do -- For each Branded debuff
local name, _, _, count = UnitDebuff(unit) -- Check if the unit has the debuff
if name then -- If they do
DisplayBrandedWarning(name, count) -- Display a Branded warning
break -- Exit this loop
end
end
end
end
end
-- This version of the code only displays a warning for a single raid member with a Branded debuff
local BRANDED_IDS = { 164004, 164005, 164006 } -- The spellIDs of each Branded debuff (Displacement, Fortification, Replication)
local NUM_BRANDED_DEBUFFS = #BRANDED_IDS
local BRANDED_NAMES = {}
for i = 1, NUM_BRANDED_DEBUFFS do
local name = GetSpellInfo(BRANDED_IDS[i]) -- Get the localised spell name from the ID
BRANDED_NAMES[i] = name -- Store it in the BRANDED_NAMES table
end
-- Display a Branded warning for the specified unit with the specified stacks of Branded
local function DisplayBrandedWarning(unit, stacks)
local rangeNeeded = 100 * 0.5 ^ (stacks - 1) -- Each stack halves the range needed; i.e. 100, 50, 25, ...
local distanceSquared, checkedDistance = UnitDistanceSquared(unit) -- Get the distance between the player and the unit
local displayText = ("%s %d yards - Current %d yards"):format(UnitName(unit), rangeNeeded, distanceSquared ^ 0.5) -- Build the string to display
-- Display the text in some way here
end
-- Call this function to iterate through each raid member and check if they have a Branded debuff
local function UpdateBrandedStatus()
for i = 1, 40 do -- For each raid member
local unit = "raid" .. i
if UnitExists(unit) and not UnitIsUnit(unit, "player") then -- If this raid member exists and isn't the player
local brandedFound = false -- Does this unit have a Branded debuff?
for i = 1, NUM_BRANDED_DEBUFFS do -- For each Branded debuff
local name, _, _, count = UnitDebuff(unit) -- Check if the unit has the debuff
if name then -- If they do
DisplayBrandedWarning(name, count) -- Display a Branded warning
brandedFound = true -- We found someone with a Branded debuff
break -- Exit this loop
end
end
if brandedFound then -- If this unit has a Branded debuff
break -- Exit the outer loop
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment