-
-
Notifications
You must be signed in to change notification settings - Fork 319
Useful Snippets
- Limit the # of clones in a TSU
- Easy iteration through group members
- Get a spell's cost
- Range checking
- Get WeakAuras to help you track CDs
- Acquiring the region of a WeakAuras clone
- GCD Lookup
- Change the colour of the CD "sweep"
- Getting Boss Units (e.g on council fights)
- Getting dynamic info from non-active triggers
- Useful reference info on the Global table
This will also allow a parent dynamic group to sort them by order of creation.
function(allstates, ...)
--do some stuff
--maybe decision trees or whatever
local newState = {
--state info goes here
show = true,
index = 0, --this bit is important
}
tinsert(allstates, newState)
--this functions as a queue; the oldest clones will be deleted first
for _,v in pairs(allstates) do
v.index = v.index + 1
v.changed = true
if v.index > cloneLimit then --where cloneLimit is some number > 0
v.show = false
end
end
return true
end
for unit in WA_IterateGroupMembers() do
<block>
end
GetSpellPowerCost(spellid)
returns a table.
Cost is found at:
GetSpellPowerCost(spellid)[1].cost
An example of how this could be used would be a custom function that you can call by sending the spellID and get the cost returned:
aura_env.GetCost = function(spellID, powerType)
if not spellID then return end
powerType = powerType or UnitPowerType("player")
local cost = 0
local costTable = GetSpellPowerCost(spellID);
for _, costInfo in pairs(costTable) do
if costInfo.type == powerType then
return costInfo.cost;
end
end
end
aura_env.GetCost(spellID [, powerType])
WeakAuras has a default trigger status - Range Check
that allows for range checks to specified units.
For auras based on proximity with group or nameplates you can use the global Range Check
condition.
If you do need to do some range checking in custom functions then you can also use the WeakAuras functions to simplify things:
WeakAuras.IsSpellInRange(spellId | spellName, unit)
This is very similar to the regular Blizzard function but allows the use of spellIDs or spell names. Returns a single value of nil, 0, or 1 for invalid target, out of range, in range respectively.
WeakAuras.GetRange(unit)
Since there's no way to get precise range info this is as close as it gets. Returns two number values for min and max possible distance from the given unit.
WeakAuras.CheckRange(unit, range, operator)
Allows to check if in or out of a given distance from the target. Give a unit, range number and either ">=" or "<=". Returns boolean.
With precise Unit positions being locked in meaningful content we're limited in the functions we can use to check ranges. The main options are IsItemInRange()
and IsSpellInRange()
. Although they seem very similar IsSpellInRange requires a spell name and a unit, while IsItemInRange will accept an item name, ID or Link, along with the unit. Also while IsItemInRange returns a simple boolean, IsSpellInRange returns a 1/0/nil for true/false/invalid.
A simple spell range check would look like:
function()
return IsSpellInRange((GetSpellInfo(203782)), "target") == 1
end
While a simple item range check would be:
function()
return IsItemInRange(33278, "target")
end
Say you want a trigger to check if there are 3 or more nameplates in range:
function()
if not aura_env.last or aura_env.last < GetTime() - 0.3 then
aura_env.last = GetTime()
local count = 0
for i = 1, 40 do
local unit = "nameplate"..i
if UnitCanAttack("player", unit)
and WeakAuras.CheckRange(unit, 8, "<=")
then
count = count + 1
end
end
aura_env.count = count
end
return aura_env.count and aura_env.count >= 3
end
https://wago.io/SimpleRangeChecker - An example Aura using the above function.
Honourable mentions for range checking go to:
• UnitInRange("unit")
which checks a generic distance for group members only (generally, are people close enough to be healed?)
• CheckInteractDistance("unit", distIndex)
which can be used to check some set distances like within range to trade/follow etc.
WeakAuras.WatchSpellCooldown(id)
-- Once initialised, will fire "events" for the spell on:
SPELL_COOLDOWN_READY:id -- Used for the cooldown ready trigger
SPELL_COOLDOWN_CHANGED:id -- Used for the cooldown progress (spell) trigger
These events all carry the spellID of the CD that's changing as their first arg.
NOTE - aura_env.region
now returns the correct region for clones as well as normal Auras. this makes the following much less frequently needed.
Especially useful for TSU auras.
WeakAuras.GetRegion(auraID, cloneID)
If this is being used within a code block that's specific to the clone (i.e. Custom Text, Custom Animations, On Show/Hide) then you can simply use WeakAuras.GetRegion(aura_env.id, aura_env.cloneId)
Specifically this is for checking against a spell's CD to ensure that it is on CD and not just showing the global.
NOTE - For Era and BCC the spellID 29515
must be used to track the GCD. 5019
can be used to track Shoot.
local gcdSTART, gcdDUR = GetSpellCooldown(61304) -- GCD
local GCD_expirationTime = gcdSTART + gcdDUR
if spell_expirationTime == GCD_expirationTime then
--we are NOT on CD
elseif spell_expirationTime > GCD_expirationTime then
--we ARE on CD.
end
This can also be done with the assistance of a couple of WeakAuras functions. Putting WeakAuras.WatchGCD()
in an Aura's "On Init" gives access to:
local start, duration = GetSpellCooldown(spellId)
if duration > 0 and duration ~= WeakAuras.gcdDuration() then
--We ARE on CD
else
--We ARE NOT on CD
end
Paste the following into Actions - On Init - Custom
and adjust the 4 values in brackets for the required colour and opacity - (red, green, blue, alpha)
aura_env.region.cooldown:SetSwipeTexture([[Interface\AddOns\WeakAuras\Media\Textures\Square_White]])
aura_env.region.cooldown:SetSwipeColor(0.17,0,0,0.8)
Put this into Actions - On Init - custom
local aura_env = aura_env
local GetBossInfo = function()
aura_env.bossUnit = {}
for i = 1,5 do
local unit = "boss"..i
if UnitExists(unit) then
local GUID = UnitGUID(unit)
local NPCID = select(6, strsplit("-", GUID))
aura_env.bossUnit[tonumber(NPCID)] = unit
end
end
end
local spawnChecker = CreateFrame("Frame")
spawnChecker:RegisterEvent("INSTANCE_ENCOUNTER_ENGAGE_UNIT")
spawnChecker:SetScript("OnEvent", GetBossInfo)
This will give you a table of Boss unit IDs accessible via their NPC ID throughout your Aura, e.g. UnitIsUnit("player", aura_env.bossUnit[123456].."target")
.
If you ever need to get dynamic info from a trigger and aura_env.states
isn't an option:
local states = WeakAuras.GetTriggerStateForTrigger(AuraId, triggernum)
This will provide a table containing all the clone states carried by the specified trigger. For a regular non-cloning trigger the single state will have an empty string for its key.
Use /dump VAR_NAME
in game to check their contents.
-
ICON_LIST
: Raid target marker texture paths -
RAID_CLASS_COLORS
: Default colour info for classes -
COMBATLOG_DEFAULT_COLORS.schoolColoring
: Default colour info for damage schools
- Home
- API Documentation
- Getting Involved
- Setting up a Lua Dev Environment
- Deprecations
- Useful Snippets
- Aura Types
- Trigger Types
- Triggers and Untriggers
- Aura Activation
- Dynamic Information
- Text Replacements