BuyItem.inc

A forum for you to dump all the macros you create, allowing users to use, modify, and comment on your work.

Moderator: MacroQuest Developers

User avatar
Kint
a hill giant
a hill giant
Posts: 208
Joined: Thu Mar 13, 2003 3:36 am

BuyItem.inc

Post by Kint » Sun Dec 14, 2003 4:31 am

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 
} 
/return
handy buyitem sub. do /buyitem "name" #. You can specifiy any number and it will buy that number. If you want to buy too many items, it /returns
I'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.
Last edited by Kint on Fri Feb 27, 2004 1:01 am, edited 1 time in total.

User avatar
Kint
a hill giant
a hill giant
Posts: 208
Joined: Thu Mar 13, 2003 3:36 am

Post by Kint » Sun Jan 25, 2004 5:06 am

updated a little to return error msgs and to buy less then a stack of items more reliably. not tested.