Skip to content

IsSpellInRange

The IsSpellInRange function checks whether a specified spell can be cast on a given unit based on the spell's range. This function is useful for determining if a target is within the effective range of a spell, which is important for casting spells and managing combat strategies.

Parameters

  • unit: The unit identifier (GUID) or unit identifier (such as "player", "target", "focus", etc.) to check the spell range against.
  • spellID: The identifier of the spell to check.

Returns

  • inRange: A boolean value indicating whether the specified spell can be cast on the unit (true if in range, false otherwise).

Example Usage in Lua

Here is an example of how to use the IsSpellInRange function in Lua:

local api = ...

-- Function to check if a spell is in range for the player's target
function CheckIfSpellInRangeForTarget(spellID)
    local target = "target"
    local inRange = api.IsSpellInRange(target, spellID)
    if inRange then
        print("Spell with ID " .. spellID .. " is in range for the target.")
    else
        print("Spell with ID " .. spellID .. " is not in range for the target.")
    end
end

-- Function to check if a spell is in range for a specific unit by GUID
function CheckIfSpellInRangeForUnit(unitGUID, spellID)
    local inRange = api.IsSpellInRange(unitGUID, spellID)
    if inRange then
        print("Spell with ID " .. spellID .. " is in range for the unit with GUID " .. unitGUID .. ".")
    else
        print("Spell with ID " .. spellID .. " is not in range for the unit with GUID " .. unitGUID .. ".")
    end
end

-- Example usage: Check if a spell is in range for the player's target
local exampleSpellID = 12345
CheckIfSpellInRangeForTarget(exampleSpellID)

-- Example usage: Check if a spell is in range for a specific unit by GUID
local exampleUnitGUID = "1234-5678-9012-3456"
CheckIfSpellInRangeForUnit(exampleUnitGUID, exampleSpellID)