WoW API < IsSpellInRange
inRange = IsSpellInRange(spellID, spellType, unit)
inRange = IsSpellInRange(spellName, unit)

Parameters Edit


(spellID, spellType, unit) OR (spellName, unit)
Number , the number of the spell in the spell book
String, "spell" or "pet" to identify the spellbook the spell refers to
String, Alternative (since 2.0), just give the spell name with no rank (e.g. "Heal")
String, the unitID of the target


'0' if out of range, '1' if in range, or 'nil' if the unit is invalid.

Example Edit

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


This takes into account talents etc. but watch out for the 'nil' return.

You will get a 'nil' if:

  1. The spell cannot be cast on the unit. i.e. attempting to check range using 'Frostbolt' on a party member will always return 'nil', similarly testing 'Heal' against an enemy target will also return nil.
  2. If the unit is not 'visible' (see API UnitIsVisible) then you will get a nil, and not a '0' as you might expect.
  3. The unit doesnt exist (e.g. 'target' when you have nothing targetted)
  4. The current player does not know this spell (so you cannot use 'Heal' to test 40 yard range for anyone other than a priest)

It can be used for scanning raid members distances, but just take care what spell you use. For example scanning heal range will start throwing out 'nil' if a raid member is mind controlled.