API IsSpellInRange

inRange = IsSpellInRange(spellID, spellType, unit) inRange = IsSpellInRange(spellName, unit)

Parameters
Arguments


 * (spellID, spellType, unit) OR (spellName, unit)


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

Returns


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

Example
local inRange = 0 local unit = "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 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.