You're using the if statement wrong, if any of those statements:
itemcount(MPtype) < MPmin
weaponamount > SpearMin
cap > CapToLeave
return true, then it will go to start hunting again, it won't leave until all of these return false, so what you want to do is use "and" instead of "or":
Edit: Your first comparisong was checking if you had less manas than MPmin, instead of more, so this would also have fucked it (it wouldn't have deposited at all). The code above is repaired.
if itemcount(MPtype) > MPmin and weaponamount > SpearMin and cap > CapToLeave then