PHP Code:
-- Courtesy of Wopak - [url]http://www.ownedcore.com/forums/members/309249-wopak.html[/url]
-- This function doesn't require any PLUA unlocker or any other kind of hack
-- ARGUMENTS
---- name - Name of a spell (string)
---- unit - A unit to target with the spell (string, [url=http://wowprogramming.com/docs/api_types#unitID]API Meta-Types - World of Warcraft Programming: A Guide and Reference for Creating WoW Addons[/url])
---- unit will default to target if left empty
-- RETURN VALUES
---- 1 if the player is near enough to cast the spell on the unit; 0 if not in range; nil if the unit is not a valid target for the spell (1nil)
function fawIsSpellInRange(spell, unit)
if spell == nil then return nil; end
if unit == nil then unit = "target"; end
-- Using WoW's standard API first, because Tricks of the Trade is bugged when passing it's spell index
-- So only going further down the function the spell's that returns nil
-- I this returns nil is if the unit is not a valid target for the spell (or you have no target selected)
local inRange = IsSpellInRange(spell, unit);
-- Collecting the Spell GLOBAL SpellID, not to be confused with the SpellID
-- Matching the Spell Name and the GLOBAL SpellID will give us the Spellbook index of the Spell
-- With the Spellbook index, we can then proceed to do a proper IsSpellInRange with the index.
if inRange == nil then
local myIndex = nil;
local name, texture, offset, numSpells, isGuild = GetSpellTabInfo(2);
local booktype = "spell";
for index = offset+1, numSpells+offset do
-- Get the Global Spell ID from the Player's spellbook
local spellID = select(2, GetSpellBookItemInfo(index, booktype));
if spellID and spell == GetSpellBookItemName(index, booktype) then
myIndex = index;
break; -- Breaking out of the for/do loop, because we have a match
end
end
-- If the Spell wasn't found, we're checking if we have a Pet Spellbook
-- If a Pet Spellbook is found, do the same as above and try to get an Index on the Spell
local numPetSpells = HasPetSpells();
if myIndex == 0 and numPetSpells then
booktype = "pet";
for index = 1, numPetSpells do
-- Get the Global Spell ID from the Pet's spellbook
local spellID = select(2, GetSpellBookItemInfo(index, booktype));
if spellID and spell == GetSpellBookItemName(index, booktype) then
myIndex = index;
break; -- Breaking out of the for/do loop, because we have a match
end
end
end
if myIndex then
return IsSpellInRange(myIndex, booktype, unit);
end
return inRange;
end
return inRange;
end