Maybe play with this?
sub buy ; <vendorid/s> <itemtype> <maxprice> <popup option#> <# of items>
{
set %vendor_empty #false
NAMESPACE PUSH
NAMESPACE LOCAL buy
set !_vendors %1
set !_itemtype %2
set !_maxprice %3
set !_popup_option %4
set !_amount %5
set !_popup_y !_popup_option * 20
set ! !_lastitemtype
finditem !_itemtype C_ , #backpackid
set !_item_bp_stack #findstack
set !_item_bp_cnt #findcnt
sub_buy_again:
finditem !_vendors G_8
if #findkind <> -1
{
open_context:
set !_vendor #findid
exevent popup !_vendor
wait 10
click 20 !_popup_y
set %maxwait #scnt + 60
while #contname <> bill_gump || #contsize <> 283_248
{
wait 5
if #scnt >= %maxwait
goto open_context
}
wait 20
scroll_one_down:
gosub pause
getshopinfo
if #shopitemtype <> !_itemtype
{
if !_lastitemtype <> #shopitemtype
set !_lastitemtype #shopitemtype
else
{
set !_x #contposx + 73
set !_y #contposy - 16
click !_x !_y r
NAMESPACE POP
NAMESPACE CLEAR
return #false
}
sleep 0
set !_x #contposx + 73
set !_y #contposy - 16
click !_x !_y
sleep 0
goto scroll_one_down
}
if #shopitemprice <= !_maxprice
{
wait 20
set !_x #contposx - 33
set !_y #contposy - 128
click !_x !_y
wait 10
click !_x !_y x 3
wait 10
click !_x !_y x 3
wait 5
if !_amount > #shopitemmax
{
set !_amount #shopitemmax
set %vendor_empty #true
}
setshopitem #shopitemid !_amount
wait 5
set !_x !_x + 75
set !_y !_y + 335
click !_x !_y
wait 2s
finditem !_itemtype C_ , #backpackid
if #findstack = !_item_bp_stack && #findcnt = !_item_bp_cnt
goto sub_buy_again
NAMESPACE POP
NAMESPACE CLEAR
return #true
}
else
}
click !_x !_y r
NAMESPACE POP
NAMESPACE CLEAR
return #false
}
Maybe give you ideas about stepping down the list.