Code: Select all
|_______BUY ITEMS SUB_______________________________________________
|Kint 10/14/03
|Usage: /call BuyItems <name of item> <number of items>
Sub BuyItems
/declare OldMoney local
/declare Stacks local
/declare Remainder local
/declare loop local
/declare count local
/autoinventory
/if n @Param1<=0 /return
/if $merchant(has,"@Param0")==FALSE /return
/selectitem "@Param0" merchant
/if "$selecteditem(count)"=="NOT_STACKABLE" {
/varset count 0
} else {
/varset count 1
}
/if n @count==1 {
/if n @Param1>$calc($calc($freeinv(space)*20)+$calc(20-$calc($count("@Param0")%20))) /return NO_ROOM
} else /if n @count==0 {
/if n @Param1>$freeinv(space) /return NO_ROOM
}
/if n @count==1 {
/if n @Param1>20 {
/varset Stacks $int($calc(@Param1/20))
/varset Remainder $calc(@Param1%20)
/buyitem @Remainder
/echo @Remainder @Stacks
/for loop 0 to @Stacks
/varset OldMoney $char(cash)
:buyloop
/buyitem 20
/if n $char(cash)==@OldMoney /goto :buyloop
/next loop
} else /if n @Param1<=20 {
:buyloop2
/varset OldMoney $char(cash)
/buyitem @Param1
/if n $char(cash)==@OldMoney /goto :buyloop2
}
} else /if n @count==0 {
/for loop 1 to @Param1
/varset OldMoney $char(cash)
:buyloop3
/buyitem 1
/if n $char(cash)==@OldMoney /goto :buyloop3
/next loop
}
/returnI've tested this and it works, but I have not done any thurough testing. If you find a bug, please post. Also if you have any suggestions please post.
