Hello, im trying to make a script for paladin that will check my potion, and my spears.
If i have less pot/spear than i want it will stop atacking and leave cave for refill.

But im having some troubles... sometimes while running bot in cave, my mainbp or the others get closed, and the leave cave with pots and spear, and it don't open de the bp again
And other, after re-opening the backpack the check does not do the order of continue hunting if I have pots/spear and continues leaving cave instead of backing hunt

Check+force
auto(100)
if $wptsection == "FirstFloor" and not $trapped then
if (itemcount("Health Potion") < 2 or itemcount("Spear") < 2 or $cap < 2) then
setsetting('Targeting/Creatures/Rotworm/Setting1/OnlyIfTrapped', 'yes', 'TargetList')
setsetting('Targeting/Creatures/Carrion Rotworm/Setting1/OnlyIfTrapped', 'yes', 'TargetList')
setsetting("Persistent/Scripts/RunPK/Enabled","no")
gotolabel(0,"LeaveCave")
wait(5000)
end
end


CheckAmmo
auto(100)
if $wptsection == "FirstFloor" and not $trapped then
if (itemcount("Health Potion") > 2 or itemcount("Spear") > 2) then
setsetting('Targeting/Creatures/Rotworm/Setting1/OnlyIfTrapped', 'no', 'TargetList')
setsetting('Targeting/Creatures/Carrion Rotworm/Setting1/OnlyIfTrapped', 'no', 'TargetList')
setsetting("Persistent/Scripts/RunPK/Enabled","no")
gotolabel(0,"FirstFloor")
end
end

ReOpenBP
local bpgold = "Shopping Bag"
local bprare = "Purple Backpack"
closewindows()
wait(1000,2000)
openitem($back.id, "back")
wait(1000,2000)
resizewindows()
openitem(bpgold, itemname($back.id), true)
wait(1000,2000)
resizewindows()


Can someone help me?