-- NOTE: Booktypes can be inferred from using a for loop to find the keys of SPELLBOOK_PAGENUMBERS BOOKTYPES = { BOOKTYPE_ABILITY, BOOKTYPE_PET, BOOKTYPE_SPELL }; function FindBookThingyByName(name, booktype) local spellName = "smurf"; local subSpellName = "Rank 5"; -- thanks to Munelear for the nice loop condition :) while spellName do spellName, subSpellName = GetSpellName(index, booktype); if ( ( spellName ~= nil) and ( string.find(spellName, name) ~= nil) ) then return index; end end return nil; end function FindSpellByName(name) return FindBookThingyByName(name, BOOKTYPE_SPELL); end function FindPetByName(name) return FindBookThingy(name, BOOKTYPE_PET); end function FindAbilityByName(name) return FindBookThingyByName(name, BOOKTYPE_ABILITY); end -- will return an index and then a book type. -- if the thingy is not found in any book nil, nil will be returned. function FindInAnyBookType(name) local index = nil; for i, bookType in BOOKTYPES do index = FindBookThingyByName(name, bookType); if (index ~= nil) then return index, bookType; end end return nil, nil; end