GetUnitAura
The GetUnitAura function retrieves detailed information about a specified aura on a given unit or object in the game world. This function is useful for determining the presence and properties of buffs or debuffs, which can be critical for managing rotations, cooldowns, and other gameplay mechanics.
Parameters
unit: The unit identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) for which to check the aura.spellID: The identifier of the aura to check for.isPlayerAura(optional): A boolean value indicating whether to check for a player-applied aura. Iftrue, the function checks for a player-applied aura. Iffalseor not specified, it checks for any unit's aura.
Returns
auraInfo: A table containing detailed information about the aura, including:duration: The duration of the aura.startTime: The start time of the aura.endTime: The end time of the aura.count: The number of applications (stacks) of the aura.- Other relevant information as provided by the game's API.
Example Usage in Lua
Here is a detailed example of how to use the GetUnitAura function in Lua:
local api = ...
-- Function to print detailed information about a specific aura on the player
function PrintPlayerAuraInfo(spellID)
local player = "player"
local auraInfo = api.GetUnitAura(player, spellID)
if auraInfo then
print("Aura with ID " .. spellID .. " on player:")
print("Duration: " .. auraInfo.duration)
print("Start Time: " .. auraInfo.startTime)
print("End Time: " .. auraInfo.endTime)
print("Count: " .. auraInfo.count)
else
print("Aura with ID " .. spellID .. " does not exist on the player.")
end
end
-- Function to print detailed information about a player-applied aura on the target
function PrintPlayerAppliedAuraInfoOnTarget(spellID)
local target = "target"
local auraInfo = api.GetUnitAura(target, spellID, true)
if auraInfo then
print("Player-applied aura with ID " .. spellID .. " on target:")
print("Duration: " .. auraInfo.duration)
print("Start Time: " .. auraInfo.startTime)
print("End Time: " .. auraInfo.endTime)
print("Count: " .. auraInfo.count)
else
print("Player-applied aura with ID " .. spellID .. " does not exist on the target.")
end
end
-- Function to print detailed information about a specific aura on a unit by GUID
function PrintAuraInfoOnUnitByGUID(unitGUID, spellID)
local auraInfo = api.GetUnitAura(unitGUID, spellID)
if auraInfo then
print("Aura with ID " .. spellID .. " on unit with GUID " .. unitGUID .. ":")
print("Duration: " .. auraInfo.duration)
print("Start Time: " .. auraInfo.startTime)
print("End Time: " .. auraInfo.endTime)
print("Count: " .. auraInfo.count)
else
print("Aura with ID " .. spellID .. " does not exist on the unit with GUID " .. unitGUID .. ".")
end
end
-- Call the functions with example spell IDs
local exampleSpellID = 12345
PrintPlayerAuraInfo(exampleSpellID)
PrintPlayerAppliedAuraInfoOnTarget(exampleSpellID)
-- Example unit GUID (replace with an actual GUID in your game)
local exampleUnitGUID = "1234-5678-9012-3456"
PrintAuraInfoOnUnitByGUID(exampleUnitGUID, exampleSpellID)