Ok 2 errors in this code
Finditem %Mage_Book C_ , #backpackid
set %spellbook #ltargetID
Finditem %spellbook
set %booktype #findtype
wait 10
Firstly If you want to set %spellbook to a found book you must set it to #findid not #Ltargetid (LAST TARGET) Remember when scripting its the same as doing things manually. When you find something you are not TARGETing it therefor LASTTARGET is not set.
General overview of when you do a finditem it creates and array of items that match the search criteria. This array of item is 0... #findcnt (findcount) For every item found it sets a whole bunch of #find??? vars
EUO WIKI OF FINDITEM Scroll down to related commands to see list of vars set.
Right after you do a finditem the var #findindex is set to 1 if one or more items are found. If you want to look at the 5th spellbook found you set #findindex 5 ... 2nd set #findindex 2 etc. This way you can loop through all the found items eg for #findindex 1 #findcount
Now back to your code... you do a finditem then set the %spellbook to lasttarget (not anything that was found but what ever you happened to target prior to running the script or while running script)... then you find the lasttarget and set booktype to its type. As you can see you will be getting nonesense values .. lets fix it
Finditem %Mage_Book C_ , #backpackid
If #findcnt >0
{
set %spellbook #findid
set %booktype #findtype
wait 10
}
else
{
display ok error no spellbook found fix that and start again
halt
}
(A) set %spellbook to #findid (first item found)
(b) No need to find it again we just did that .. so set %booktype to #findtype without doing another search.
(c) added an if condition incase no spellbooks found