merch_check.mac - Check for certain item, and purchase it

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

Moderator: MacroQuest Developers

Onezero
a ghoul
a ghoul
Posts: 95
Joined: Thu Jan 01, 2004 1:19 pm
Location: Normal, IL
Contact:

merch_check.mac - Check for certain item, and purchase it

Post by Onezero » Sun Jan 25, 2004 1:51 am

Hi again everyone.

I was scowering merchants all over PoK and PoTranquility for Blue Diamonds tonight and got tired of scrolling through the window manually, so I wrote a little macro. When you start it, you specify an Item Name to look for and you can also define an optional limit to stop at. If no limit is defined, it will continue buying the item until the merchant has no more.

Tell me what you think.

- Update: 1/25/04 -
-----------------------
The macro now has an option to make it search through all of the merchants in the zone. However, if merchants are inside buildings it will propably not work at all, so if anyone would volunteer to fix up the code to account for this that would be great.

Code: Select all

| - merch_check.mac -
| By: Onezero
| Version: 0.0.2
|
| This macro goes through the list of merchants in the zone and checks
| them all for a user-specified item.  If Search = 1 the macro will
| check all merchants in the zone once, then end.  If Search = 0 the
| macro will only check the nearest merchant. User can also specify a
| limit to tell the macro when to stop buying the item.
|
| NOTE: This macro does NOT work well right now unless the zone you are
|   in has very few buildings/obstructions.  If anyone could fix that
|   part up for me I would be most grateful, until then, it sucks :)
|
| Usage: /mac merch_check.mac <item name> <search (Default=1)> <limit>
|
| Example: /mac merch_check.mac "Blue Diamond" 1 5
|          (Goes to all merchants and buys up to 5 Blue Diamond from each)
|
|          /mac merch_check.mac "Water Flask" 0 20
|          (Goes to nearest merchant and buys 20 Water Flask)


#turbo

#event nocash "You cannot afford "

Sub Main(ItemName,Search,Limit)

    /zapvars

    /declare count local
    /varset count 0

    /declare counter local

    /declare curID local
    /varset curID 0

    /declare retry local
    /varset retry -1

    /declare ids array2

    /declare idcount local
    /varset idcount 0

    /echo Looking for @ItemName
    /if $defined(ItemName)==FALSE /endmacro
    /if $defined(Search)==FALSE {
        /echo Searching all merchants.
    } else {
        /if n @Search==1 /echo Searching all merchants.
        /if n @Search!=1 /echo Only checking nearest merchant.
    }
    /if $defined(Limit)==TRUE {
        /echo Buy Limit: @Limit
    } else {
        /echo No buy limit defined!
    }

    :MainLoop

    /if n @retry>=@idcount {
        /echo All merchants have been searched.  Ending macro.
        /endmacro
    }


    /if n @Search==1 {
        /if n @curID==0 {
            /varset curID $searchspawn(npc,class:merchant)
            /varadd idcount 1
        } else {
            /varset curID $searchspawn(npc,id:@curID,class:merchant,next)
            /varadd idcount 1
        }
    } else {
        /target npc class merchant
        /varset curID $target(id)
    }

    /echo Heading to $spawn(@curID,name,clean)

    /for counter 0 to @idcount
        /if n @curID==@ids(0,@counter) {
            /varadd retry 1
            /if n @Search==1 {
                /goto :MainLoop
            } else {
                /goto :MacDone
            }
        }
    /next counter

    /varset ids(0,@idcount) @curID

    /target npc id @curID

    /call movetoloc $target(y),$target(x)

    /click right target
    /delay 15

    /if $merchant(open)==FALSE {
        /echo Could not open merchant window for $spawn(@curID,name,clean).
        /if n @Search==1 {
            /echo Moving on...
            /goto :MainLoop
        } else {
            /goto :MacDone
        }
    }

    /if $merchant(has,"@ItemName")==FALSE {
        /echo Couldn't find @ItemName on $spawn(@curID,name,clean).
        /click left merchant done

        /if n @Search==1 {
            /echo Moving on...
            /goto :MainLoop
        } else {
            /goto :MacDone
        }
    } else {
        :BuyLoop

        /doevents

        /if $merchant(has,"@ItemName")==TRUE {

            /selectitem "@ItemName" merchant

            /if $defined(Limit)==TRUE {
                /if n @count<@Limit {
                    /call BuyItem @ItemName @Limit
                    /varadd count 1
                    /goto :BuyLoop
                }
            } else {
                /call BuyItem @ItemName @Limit
                /varadd count 1
                /goto :BuyLoop
            }
        }
        /click left merchant done

        /echo Bought $int(@count) @ItemName from $spawn(@curID,name,clean).

        /if n @Search==1 {
            /echo Moving on...
            /goto :MainLoop
        } else {
            /goto :MacDone
        }
    }
    :MacDone

    /sendkey up ctrl
    /sendkey up shift
    /sendkey up alt
/return

Sub BuyItem(ItemName,Limit)
    /sendkey down ctrl

    /click left merchant buy
    /delay 1s

    /sendkey up ctrl
/return

Sub Event_nocash
    /echo Not enough money.  Ending macro.
    /click left merchant done
    /endmacro
/return

Sub movetoloc(xloc,yloc)
  /declare MyXLOC local
  /declare MyYLOC local
  /declare ObstCount local

  /varset MyXLOC $char(x)
  /varset MyYLOC $char(y)
  /varset ObstCount 0
  :locloop
  /face nolook loc @xloc
  /if "@yloc"=="u" /Press u
  /call AutoRun 1
  /varadd ObstCount 1
  /if n @ObstCount>=3 {
    /if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) {
        /sendkey up up
        /sendkey down down
        /if n $rand(99)>50 {
          /delay 1s
          /sendkey up down
          /sendkey down Right
          /delay 5
          /sendkey up Right
          /sendkey down up
          /delay 1s
          /sendkey up up
        } else {
          /delay 1s
          /sendkey up down
          /sendkey down left
          /delay 5
          /sendkey up left
          /sendkey down up
          /delay 1s
          /sendkey up up
        }

       /sendkey up down
       /sendkey up Right
       /sendkey up Left
     }
     /varset MyXLOC $char(x)
     /varset MyYLOC $char(y)
     /varset ObstCount 0
    }

  /if n $distance(@xloc)>10 /goto :locloop

  }
  /call autorun 0
/return

Sub AutoRun
   /if @Param0==1 /sendkey down up
   /if @Param0==0 /sendkey up up
/return
Last edited by Onezero on Sun Jan 25, 2004 3:55 pm, edited 4 times in total.
.[b].[/b]:[b]:[/b] Onezero
"[i]Health is merely the slowest rate at which you can die.[/i]"

Drunkensloth
a lesser mummy
a lesser mummy
Posts: 67
Joined: Sat Oct 18, 2003 2:54 am

Post by Drunkensloth » Sun Jan 25, 2004 1:21 pm

make it so it cycles through merchants using
searchspawn

that would make this mac OANAGE :)
And here I was clicking like a sucker!

Onezero
a ghoul
a ghoul
Posts: 95
Joined: Thu Jan 01, 2004 1:19 pm
Location: Normal, IL
Contact:

Post by Onezero » Sun Jan 25, 2004 1:39 pm

Gonna log on now and see if I can do that, thanks for the idea. :)
.[b].[/b]:[b]:[/b] Onezero
"[i]Health is merely the slowest rate at which you can die.[/i]"

Onezero
a ghoul
a ghoul
Posts: 95
Joined: Thu Jan 01, 2004 1:19 pm
Location: Normal, IL
Contact:

Post by Onezero » Sun Jan 25, 2004 3:30 pm

Updated the mac.. read first post above.
.[b].[/b]:[b]:[/b] Onezero
"[i]Health is merely the slowest rate at which you can die.[/i]"

Onezero
a ghoul
a ghoul
Posts: 95
Joined: Thu Jan 01, 2004 1:19 pm
Location: Normal, IL
Contact:

Post by Onezero » Fri Jan 30, 2004 3:15 pm

Anyone use this thing at all? Just wondering...
.[b].[/b]:[b]:[/b] Onezero
"[i]Health is merely the slowest rate at which you can die.[/i]"

User avatar
Slice
a hill giant
a hill giant
Posts: 189
Joined: Wed Oct 30, 2002 2:52 pm

Post by Slice » Fri Jan 30, 2004 3:21 pm

Could you add ini support to pull items to look for from an ini file?
Slice

Scary_Penguin
a lesser mummy
a lesser mummy
Posts: 76
Joined: Sun Nov 16, 2003 11:45 am

Post by Scary_Penguin » Fri Jan 30, 2004 3:36 pm

Tried this in Pok untill it started taking me to class guildmasters...

/hugs his /endmac hotkey

Nice work otherwise, is there any way you can make it record the vendors you have already been to? I had a lot of the same names fly through the MQ window, and it has trouble getting around a lot, maybe add a /press U line in with the obstacle area to open doors.
Scary:.

No, Really.

Onezero
a ghoul
a ghoul
Posts: 95
Joined: Thu Jan 01, 2004 1:19 pm
Location: Normal, IL
Contact:

Post by Onezero » Fri Jan 30, 2004 3:58 pm

If you set the Search flag to 1, when it goes from merchant to merchant it keeps track of the ones it has been to and will not go back to that merchant until you run the mac again.

As far as why it was going to guild masters.. I dont know.. it searches for NPCs whose class is "merchant", and I think GMs are different, but I'm not sure. I'll look into this.

Ini support I will work on now, thanks for the suggestion.
.[b].[/b]:[b]:[/b] Onezero
"[i]Health is merely the slowest rate at which you can die.[/i]"