BuyItems.inc

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot.

Moderator: MacroQuest Developers

bob_the_builder
a hill giant
a hill giant
Posts: 275
Joined: Tue Jul 22, 2003 1:22 pm

BuyItems.inc

Post by bob_the_builder » Thu Feb 26, 2004 8:20 pm

Code: Select all

| - BuyItems.inc - 
| Kint 10/14/03
|  
|  
| #include BuyItems
| /call BuyItems "item_name" <number>

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 
} else /if n @count==0 { 
   /if n @Param1>$freeinv(space) /return 
} 

/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 { 
/buyitem @Param1 
} 
} else /if n @count==0 { 
/for loop 1 to @Param1 
  /varset OldMoney $char(cash) 
  :buyloop2 
  /buyitem 1 
  /if n $char(cash)==@OldMoney /goto :buyloop2 
/next loop 
} 
/return
Last edited by bob_the_builder on Fri Feb 27, 2004 1:34 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 » Fri Feb 27, 2004 1:06 am


User avatar
Bad Karma
a snow griffon
a snow griffon
Posts: 346
Joined: Sat Nov 22, 2003 9:34 pm
Contact:

Post by Bad Karma » Mon Mar 01, 2004 6:07 am

Hrmm...
[b]- Bad Karma
________________________________________[/b]

In our own quest for excellence, we should strive to take the time to help those who help themselves.

All others should [b]RTFM[/b]!!!!!!!!!