Bazaar Buying macro

Post your completed (working) macros here. Only for macros using MQ2Data syntax!

Moderator: MacroQuest Developers

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Bazaar Buying macro

Post by Override » Wed Sep 01, 2004 3:10 am

Well, a lot of people wanted me to post my bazaar buying function so they could add it to there macros or just use it. With this, I could see a lot of differnet macros that are able to be made, such as AFK buying for tradeskills. I know I hate it when I search for an item and its not there too. Not you can make a quick macro with this and let it buy it for you when someone decides to sell it. Anyways, here it is:

Code: Select all

| 
| baztest.inc
| This is to Test the BazaarBuy Function
| Version 1.0
| Date: September 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/
|
| This is to show and test the bazzarbuy function that I have made. 
| You MUST go to the website above and download the common.zip out of
| the tradeskill macro section and put them into a common directory in 
| your macro directory. If you don't have one, make it. All you have 
| to tell it is what you want. The max you will pay for it. And how many
| you want total. This macro will look to see how many you have first and subtract 
| that away by how many you want total. Just change the variables below and let it
| go. You WILL need to be in front of Caerlyna in the bazaar (The lady you turn in
| your bag tokens to) once you start it up. This macro was its own pathing too. Also,
| ever once in a while you get a merchant you can't find, it is designed to skip that
| merchant in the array and go to the next one. Also, when you enter in the max price,
| if you enter 10000, that means 10pp 0g 0s 0c.
|
| When including these into your own macro, be sure to include the buy.inc and the 
| gogetitem.inc too.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 




#include common/bazaarbuy.inc
#include common/buy.inc
#include common/gogetitem.inc

Sub Main 

   /declare ItemToBuy string inner
   /declare HighestPriceToPay int inner
   /declare TotalYouWant int inner

   /varset ItemToBuy "Spider Silk"
   /varset HighestPriceToPay 10000
   /varset TotalYouWant 40

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

/return
Be sure to get the newest common.zip from the website to make sure you have the newest version.
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

SlimFastForYou
a hill giant
a hill giant
Posts: 174
Joined: Sat Jan 24, 2004 1:38 am

Post by SlimFastForYou » Thu Sep 02, 2004 4:23 am

I've been messing with this code.

I have to say it looks good overall but for me it bombs after a few searches.

For the purposes of reporting a possible bug, I have replaced all /echo commands in the common files with /mqlog (easier to note the increase of time it takes to process).

The macro I am trying to integrate this into is much more complex, but this is a nice easy way to reproduce the problem:

Code: Select all

#include common/bazaarbuy.inc
#include common/buy.inc
#include common/gogetitem.inc

Sub Main
	/mqlog BazaarBuy bug test macro started
	/call BazaarBuy "essence of sunlight" 200 20
	/delay 5s
	/call BazaarBuy "ornate silk turban" 150000 2
	/delay 4s
	/call BazaarBuy "windblade" 16000000 1
	/delay 3s
	/call BazaarBuy "bracelet of comprehension" 4000000 2
/return
The output looks something like this (note the time):
[09/02/2004 01:10:49] BazaarBuy bug test macro started
[09/02/2004 01:10:50] Searching Bazaar for essence of sunlight
[09/02/2004 01:10:50] Setting Size of Trader Array
[09/02/2004 01:10:50] Building Trader List Array
[09/02/2004 01:10:50] There are none for sell at that price, try to higher you max price.
[09/02/2004 01:10:55] Searching Bazaar for ornate silk turban
[09/02/2004 01:10:56] Setting Size of Trader Array
[09/02/2004 01:11:07] Building Trader List Array
[09/02/2004 01:11:17] There are none for sell at that price, try to higher you max price.
[09/02/2004 01:11:21] Searching Bazaar for windblade
[09/02/2004 01:11:22] Setting Size of Trader Array
[09/02/2004 01:13:43] /endmacro

Note: At the time of testing, none of these items are available for the price I am willing to pay.


Essence of sunlight doesn't take long to finish at all.

Ornate silk turban seems to take a little longer than it should to finish.

Windblade gets stuck. Maybe it would finish if I gave it an hour, but when the first one finishes in 5 seconds and this one is still running at 2 minutes I simply /endmacro =).

I am looking into the problem. My wild guess would be some variable isn't being destructed somewhere, and interfering with subsequent BazaarBuy calls (if you /endmacro and restart it doesn't start terribly slow). If I find a fix before you, I'll post it.

Again, this looks great. I had just finished the planning process for a somewhat more complicated bazaar buy macro (determines the path to take based on loc coordinates), but yours saved me a little time =).

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Thu Sep 02, 2004 5:31 am

I updated it so it doesn't take as long, I havent uploaded it yet, but I will later tonight, I'm not sure why it ended on you, but I will post the fix for that tonight.
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

SlimFastForYou
a hill giant
a hill giant
Posts: 174
Joined: Sat Jan 24, 2004 1:38 am

Post by SlimFastForYou » Thu Sep 02, 2004 10:40 am

Thanks!

It didn't actually end on me - I killed it myself because it was taking way too long. The first search took 2 seconds. The second over 20. The third search was over 2 minutes before I said forget it and did an /endmacro.

SlimFastForYou
a hill giant
a hill giant
Posts: 174
Joined: Sat Jan 24, 2004 1:38 am

Post by SlimFastForYou » Thu Sep 02, 2004 12:20 pm

Figured out the problem. Don't think it had anything to do with destructing variables:

In bazaarbuy.inc, this line can be found twice

Code: Select all

/for forprice 1 to ${HighPrice} step 1000
Replace both occurances with

Code: Select all

/for forprice ${Math.Calc[${HighPrice}/5]} to ${HighPrice} step ${Math.Calc[${HighPrice}/10]}
It was coincidental that I was searching for a cheap product, then a slightly more expensive one, then a much more expensive one. The problem was the computer was too busy checking all traders, steping one plat, then checking the traders again. For a 16k item the old algorithm would take quite a while.

The way I updated it now, if we use my windblade example, it will try to find the cheapest seller starting at just over 5k (16k/5) (Windblades sell for way more than that anyway). It will then step 1.6k each time (16k/10).

I think that the fractions could be bumped up even more without too much of a performance hit.

Might be a little buggy if people are searching for items not even worth 1 silver, but... sheesh lol =).

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Thu Sep 02, 2004 7:44 pm

Yeah, that is the fix I was going to post kind of, lol, but I was going to have it take the lowest price of the item to the highest set price and search between that. cause if you step too much the array won't be sorted to well. Cause it sorts it by making the lowest ones first in the array and it goes in gets the first ones in the array first till it gets how many you wanted. But I have an idea for it to make it faster and still have a low step :) I'm going to try it tonight and post it
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Thu Sep 02, 2004 10:26 pm

Ok, I updated it on the website with the fix, you can download it there now. It goes a lot faster now. Let me know how it works for you all.
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

Tanaka
decaying skeleton
decaying skeleton
Posts: 3
Joined: Thu Sep 02, 2004 10:56 pm

Post by Tanaka » Thu Sep 02, 2004 11:01 pm

Having a slight issue with this macro. Everything works fine up until the macro attempts to read the zone information. The error message I am getting is:

Attempting to Read Section "The Bazaar" Zone Information from gogetitem.ini...
"The Bazaar" is not a Valid Section for FILE:gogetitem.ini, ending macro...
No Loc Array Created...

Would appreciate any assistance. Thanks in advance.

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Thu Sep 02, 2004 11:19 pm

Be sure the gogetitem.ini is in the common directory in your macro directory. All the files in the common.zip need to be in that directory.
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Fri Sep 03, 2004 12:37 am

Here is an example of something that you can use with it, you can just set this macro up with stuff you are wanting to buy and the max price, then just let it run all day while you are at work or school:

Code: Select all

#include common/bazaarbuy.inc
#include common/buy.inc
#include common/gogetitem.inc

Sub Main 

   /declare ItemToBuy string inner
   /declare HighestPriceToPay int inner
   /declare TotalYouWant int inner


   :start
   /varset ItemToBuy "Coiled Spring"
   /varset HighestPriceToPay 50000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Saltpeter"
   /varset HighestPriceToPay 10000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Pinion"
   /varset HighestPriceToPay 25000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Steel Ball Bearing"
   /varset HighestPriceToPay 30000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Jacinth"
   /varset HighestPriceToPay 500000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Blue Diamond"
   /varset HighestPriceToPay 300000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Branch of Sylvan Oak"
   /varset HighestPriceToPay 30000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /varset ItemToBuy "Black Sapphire"
   /varset HighestPriceToPay 600000
   /varset TotalYouWant 100

   /call BazaarBuy ${ItemToBuy} ${HighestPriceToPay} ${TotalYouWant}

   /delay 600s
   /goto :start

/return
I am a big tinker so I need a lot of tinkering stuff, that is what this one is for. :smile:
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

Tanaka
decaying skeleton
decaying skeleton
Posts: 3
Joined: Thu Sep 02, 2004 10:56 pm

Post by Tanaka » Fri Sep 03, 2004 10:40 am

Be sure the gogetitem.ini is in the common directory in your macro directory. All the files in the common.zip need to be in that directory.
It is, and they are. At first it couldn't find the file, but I fixed that by replacing a forward slash with a backslash where it calls for the include. Now it is finding the file, but returning the error I noted above.
My wife pointed out that I may be having my weekly case of the stupids, but any assistance would be appreciated.

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Fri Sep 03, 2004 9:15 pm

Try this, move all the files to the macro directory and change all the #includes to not have it go to teh common directory.
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

Tanaka
decaying skeleton
decaying skeleton
Posts: 3
Joined: Thu Sep 02, 2004 10:56 pm

Post by Tanaka » Sat Sep 04, 2004 1:33 am

That did the trick Override. Thanks for your assistance, it is much appreciated.

User avatar
Override
a hill giant
a hill giant
Posts: 179
Joined: Sun Dec 29, 2002 9:19 am

Post by Override » Sat Sep 04, 2004 7:45 am

No problem, I am glad it is working for you.
Self Automated Tradeskill Macros at:
[url=http://www.override13.com/mq2/]http://www.override13.com/mq2/[/url]

SlimFastForYou
a hill giant
a hill giant
Posts: 174
Joined: Sat Jan 24, 2004 1:38 am

Post by SlimFastForYou » Sat Sep 04, 2004 5:35 pm

Looks like if someone jacks up the price between the search and the gogetitem the bot will buy the item anyway. It looks like the price is stored in "PriceArray[${nArray}]", might be good to use this for a final price check before buying.