API IsSpellInRange

From Wowpedia
Jump to: navigation, search

Returns whether a given spell is in range.

inRange = IsSpellInRange("spellName", "target")
inRange = IsSpellInRange(index, "bookType", "target")

Arguments

index 
Number - spell book slot index, ascending from 1.
bookType 
String - one of BOOKTYPE_SPELL ("spell") or BOOKTYPE_PET ("pet") specifying which spellbook to index.
spellName 
String - spell name to check the range of. The player must know the spell.
target 
String - unit to use as a target for the spell.

Returns

inRange 
Flag - 1 if the target is in range of the spell, 0 if the target is not in range of the spell, nil if the provided arguments were invalid or inapplicable.

Example

local inRange, unit = 0, "party1"
if UnitExists(unit) and UnitIsVisible(unit) and UnitIsFriend(unit) then
   inRange = IsSpellInRange("Heal", unit)
end
if inRange==1 then
   print("party1 is in healing range!")
else
   print("Cannot heal party1")
end

Details

  • This takes into account talents, and can be used to determine the approximate distance to your raid members.
  • The function returns nil if:
    • The spell cannot be cast on the unit. i.e. [Frostbolt] on a friendly unit, or [Heal] on an hostile unit (such as a mind-controlled raid member)
    • If the unit is not 'visible' (per UnitIsVisible) or does not exist (per UnitExists)
    • The current player does not know this spell (so you cannot use 'Heal' to test 40 yard range for anyone other than a priest)
    • The spell can only be cast on the player (i.e. a self-buff such as [Mage Armor] or [Barkskin])