Generic Buy Macro

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. MQ2Data format only!

Moderator: MacroQuest Developers

BrainDeath
a ghoul
a ghoul
Posts: 86
Joined: Sun Mar 07, 2004 5:00 pm

Generic Buy Macro

Post by BrainDeath » Fri Apr 30, 2004 5:06 pm

Edit: Updated to work with new event format and handle full inventory condition

I use this to make sure I have a specified amount of an item in my inventory when tradeskilling.

For example, if you need to make sure you have 96 water flasks, you open the merchant window, select the water flask and type /macro buy 96.

Of course I have an alias set up for /buy=/macro buy.

Again, the macro does not buy the specified number, but buys until you have the specified number in your inventory.

This can easily be modifed to an include file if you wish.

Code: Select all

| buy.mac
| This macro will buy the selected item from a merchant until your
| inventory contains the specified amount of the item.
| Requires that the merchant window be open and the item selected.
| Usage: /macro buy amount

#turbo
#event Broke "#*#can't afford to buy them#*#"
#event Full "#*#no more room#*#"

Sub Main(int amount) 

    /if (!${Defined[amount]}) /endmacro

   :Buy 
      /if (${FindItemCount[=${SelectedItem}]}>=${amount}) /endmacro
      
   :StackLoop 
      /if (${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]}<=20) /goto :RegLoop 
      /buyitem ${If[${SelectedItem.Stackable},20,1]}
      /delay 5
      /doevents
      /goto :StackLoop 
      
   :RegLoop 
      /if (${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]}<=0) /endmacro
      /buyitem ${If[${SelectedItem.Stackable},${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]},1]}
      /delay 5
      /doevents
      /goto :RegLoop 
      
/return 

Sub Event_Broke
   /echo Error: You are out of money!
   /beep
   /endmacro
/return

Sub Event_Full
   /echo Error: Your inventory is full!
   /beep
   /endmacro
/return
Of course this is modified from someone else's macro. I don't remember who's code I used though so I can't give them credit. :(

FrankJScott
naggy
naggy
Posts: 2128
Joined: Sun Feb 19, 2023 7:11 am

Recommended Product Guide

Post by FrankJScott » Mon Oct 16, 2023 9:49 pm

Please try Google for Excellent Product Info 1b86b3c