Skip to content

UnitHasAura

The UnitHasAura function checks whether a specified aura exists on a given unit or object in the game world. This function can be used to determine if a particular buff or debuff is present on a unit, regardless of whether it is helpful or harmful (no more buff or debuff).

Parameters

  • unit: The unit identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) for which to check the aura.
  • auraID: The identifier of the aura to check for.
  • isPlayerAura (optional): A boolean value indicating whether to check for a player-applied aura. If true, the function checks for a player-applied aura. If false or not specified, it checks for any unit's aura.

Returns

  • exists: A boolean value indicating whether the specified aura exists on the unit (true if the aura exists, false otherwise).

Example Usage in Lua

Here is a detailed example of how to use the UnitHasAura function in Lua:

local api = ...

-- Function to check if a specific aura exists on the player
function CheckPlayerAura(auraID)
    local player = "player"
    local exists = api.UnitHasAura(player, auraID)
    if exists then
        print("Aura with ID " .. auraID .. " exists on the player.")
    else
        print("Aura with ID " .. auraID .. " does not exist on the player.")
    end
end

-- Function to check if a specific player-applied aura exists on the target
function CheckPlayerAppliedAuraOnTarget(auraID)
    local target = "target"
    local exists = api.UnitHasAura(target, auraID, true)
    if exists then
        print("Player-applied aura with ID " .. auraID .. " exists on the target.")
    else
        print("Player-applied aura with ID " .. auraID .. " does not exist on the target.")
    end
end

-- Function to check if a specific aura exists on a unit by GUID
function CheckAuraOnUnitByGUID(unitGUID, auraID)
    local exists = api.UnitHasAura(unitGUID, auraID)
    if exists then
        print("Aura with ID " .. auraID .. " exists on the unit with GUID " .. unitGUID .. ".")
    else
        print("Aura with ID " .. auraID .. " does not exist on the unit with GUID " .. unitGUID .. ".")
    end
end

-- Call the functions with example aura IDs
local exampleAuraID = 12345

CheckPlayerAura(exampleAuraID)
CheckPlayerAppliedAuraOnTarget(exampleAuraID)

-- Example unit GUID (replace with an actual GUID in your game)
local exampleUnitGUID = "1234-5678-9012-3456"
CheckAuraOnUnitByGUID(exampleUnitGUID, exampleAuraID)