Here is my solution for getting stuck when you are out of capacity, this disables targeting when less than 100 cap. It's not the best fix seeing as how much loot you might miss out on, you can also change it to your liking but at least you can bot afk without worrying about dying to it. This way your bot will make it to the cap checker in your script and go deposit then re-enable looting once it has over 100 cap again.
Code:
while (true) do
if (Self.Cap() < 100) then
setLooterEnabled(false)
else
setLooterEnabled(true)
end
wait (500,1500)
end