I notice 2 possibilities:
1) maybe you are human and end up with a negative quantity calcualtion on bolts
2) The more likely, your wait timers around drag/dropc is too quick and you are left with 'ghost image' items that are found and produce false positives.
In general, #maxweight is correct for elf and gargoyle races, but you get "strong back" as a human - allowing you to carry an extra 60 stones. It is possible for your #weight to be more than #maxweight if you are human. Then %dragamount can go negative, but you neither check for that situation nor adjust the #maxweight part of the calculation to reflect human.
finditem %bolt C_ , %secure
while #findkind <> -1
{
set %dragamount #maxweight - #weight
set %dragamount %dragamount / 5
set %dragamount %dragamount - 1
if #findstack < %dragamount
set %dragamount #findstack
if %dragamount <> 0
{
exevent drag #findid %dragamount
wait 3
exevent dropc #backpackid
wait 7
}
Dealing with 'ghost image' items. First, slow down your drag/drop operations. You need at least 1 second (wait 20 or other method) between 'exevent dropc' actions. Sometimes you can get an item stuck on your cursor as if you are dragging it, so include a "just in case"
exevent dropc before the
exevent drag. Also on each round open your backpack using
event macro 8 7 in the cycle.
You could streamline it in steps:
find bolts in secure
drag some bolts to backpack
cut the bolts to cloth
find cloth in backpack
cut cloth to bandages
move bandages (which sometimes drop to the ground because of a legacy weight issue when bandages weighed 1 stone each (now weight .1 stone each)) to the secure.
You would save time skipping the extra drag/drop steps of cloth by just cutting to bandages.
I have attached my take on doing this a while ago. I do not have code to look for bandages that dropped to the ground. That would need to add another routine to the logic after dragging bandages from your backpack to the secure... find/drag from ground to secure. It would look something like this:
finditem %bandages G_2
if #findcnt > 0
{
for #findindex 1 #findcnt
{
exevent drag #findid #findstack
wait 10
exevent dropc %secureid
wait 10
}
}
I like your weight calculation for bolts to cloth. It isn't necessary for the cloth to bandages since that is a 1 to 1 in both count and weight (ignoring the age old bug where it drops bandages to the ground in some instances) - which would be a 10:1 ratio rather than a 5:1 ratio if you decided to try to keep that. It would be faster to pull the maximum bolts you can carry, cut to cloth, cut to bandages and move from the ground to secure. Leave the check in for moving bandages from backpack to secure to complete a partial stack of bolts/cloth/bandages at the end.
My routine hard coded drag quantity rather than calculating against my remaining weight. I would just test how many I could hold without it dropping to the ground and set that value in the script hard coded. You will see I had it set to 1 bolt and 1 cloth at a time - which is too slow, but safe and eventually may finish before server restart.
If you married your weight calculation (adjusting for human +60 stones) with my version and added the test for bandages that may drop to the ground, it should chug along nicely.
Gaderian