Version 1.2 Changes
:: added the ability to update the INI file on the fly using the /echo command (greets to ml2517 for the inadvertant INI tutorial)
:: removed some extraneous code
Version 1.1 Changes
:: added code to differentiate between stackable and non-stackable items
:: changed inventory full check to something cleaner
Code: Select all
|=-=-=-=-=-=-=-=-= ISEARCH.MAC :: MERCHANT SEARCH MACRO =-=-=-=-=-=-=-=-=
|
| To Start: /mac isearch
| To Add or Remove an item from the INI File: /echo update ItemName
| Example: "/echo update Puppy Feet" adds Puppy Feet to the INI file
| if it is not there, or removes it if it already exists.
|
| To Reload INI File: /echo reload
|
| Usage: Add items that you want to buy in bulk from a merchant
| to the INI file. Run the macro. It will wait until you
| open a merchant window to begin searching. The macro
| will cycle through all of your specified items, purchasing
| EVERY one that the merchant has.
|
| Example: If you have Wolf Meat specified in your INI file, and the
| merchant has 182 Wolf Meats for sale, you will buy all of
| them until either his supply is exhausted or you run out
| of money.
|
| Info: Once the macro has cycled through all of the items in your
| INI file, it will close the merchant window and wait for
| another merchant window to open, whereupon it will begin
| its search anew. If you wish, the INI file can be edited
| while the macro is running, and reloaded by simply /echo-ing
| "reload" into the MQ2 window. Running out of money, or having
| a full inventory will cause the macro to end.
|
| INI File Syntax
|
| [Items]
| 0=Wolf Meat
| 1=Snake Egg
| 2=Mammoth Meat
| 3=Centi Toes
| ..and so on
|
|=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=
#event NOMONEY "but you can't afford to buy them."
#event FULLBAGS "You have no more room."
#event RELOAD "[MQ2] reload"
#event UPDATE "[MQ2] update"
Sub Main
/zapvars
/declare ItemArraySize global
/declare Temp0 global
/declare ItemArray array
/call LoadItems
/echo Waiting for a merchant.
:MainLoop
/doevents
/if $merchant(open)==TRUE /call ItemCheck
/goto :MainLoop
/return
Sub ItemCheck
/for Temp0 0 to @ItemArraySize
/if "@ItemArray(@Temp0)"=="Empty" {
/if @Temp0==@ItemArraySize {
/echo Search complete. Waiting for next merchant.
/click left button merchant_done
/return
}
/next Temp0
}
:MerchantCheck
/if $freeinv(space)==0 {
/echo Your inventory is full. Exiting.
/endmacro
}
/echo Searching for [ @ItemArray(@Temp0) ]
/if $merchant(has,"@ItemArray(@Temp0)")==FALSE {
/if @Temp0==@ItemArraySize {
/echo Search complete. Waiting for next merchant.
/click left button merchant_done
/return
}
/next Temp0
}
/selectitem "@ItemArray(@Temp0)" merchant
/if "$selecteditem(count)"=="NOT_STACKABLE" {
/buyitem 1
/goto :MerchantCheck
}
/delay 2s
/buyitem 20
/delay 2s
/goto :MerchantCheck
/next Temp0
/return
Sub Event_NOMONEY
/echo You are out of money.
/endmacro
/return
Sub Event_FULLBAGS
/echo Your inventory is full.
/endmacro
/return
Sub Event_RELOAD
/echo Reloading Items from INI file.
/call LoadItems
/echo Items reloaded. Waiting for a merchant.
/return
Sub LoadItems
/declare Temp1 local
/declare TempList local
/declare Empties local
/varset Empties 0
/varset Temp1 0
:ClearList
/varset TempList "$ini("isearch.ini","Items","$int(@Temp1)")"
/if "@TempList"=="NOTFOUND" /goto :ClearComplete
/varset ItemArray(@Temp1) "Empty"
/varadd Temp1 1
/goto :ClearList
:ClearComplete
/varset Temp1 0
:LoadList
/varset ItemArray(@Temp1) "$ini("isearch.ini","Items","$int(@Temp1)")"
/if "@ItemArray(@Temp1)"=="NOTFOUND" {
/varset ItemArraySize $int(@Temp1)
/varsub ItemArraySize 1
/varset ItemArraySize $int(@ItemArraySize)
/return
}
/varadd Temp1 1
/goto :LoadList
/return
Sub Event_UPDATE(EvtText)
/declare TempItem local
/declare Temp2 local
/declare Temp3 local
/varset Temp2 0
/varset EvtText "$mid(13,$calc($strlen("@EvtText")-13),"@EvtText")"
/if "@EvtText"!="" {
:ItemSearch
/varset TempItem "$ini("isearch.ini","Items","$int(@Temp2)")"
/if "@TempItem"=="NOTFOUND" /goto :AddItem
/if "@TempItem"=="@EvtText" {
/echo [ @EvtText ] Deleted from INI file.
/ini "isearch.ini" "Items" "$int(@Temp2)" "Empty"
/goto :DoneItem
}
/varadd Temp2 1
/goto :ItemSearch
:AddItem
/varset Temp2 0
:AddItemLoop
/varset TempItem "$ini("isearch.ini","Items","$int(@Temp2)")"
/if "@TempItem"=="Empty" /goto :FoundItemSlot
/if "@TempItem"=="NOTFOUND" /goto :FoundItemSlot
/varadd Temp2 1
/goto :AddItemLoop
:FoundItemSlot
/echo [ @EvtText ] Added to INI file.
/ini "isearch.ini" "Items" "$int(@Temp2)" "@EvtText"
} else {
/varset Temp3 0
/echo =-= Current Items =-=
:ItemList
/varset TempItem "$ini("isearch.ini","Items","$int(@Temp2)")"
/if "@TempItem"=="NOTFOUND" /goto :DoneItemList
/varadd Temp2 1
/if "@TempItem"!="Empty" {
/varadd Temp3 1
/echo Item $int(@Temp3) [ @TempItem ]
}
/goto :ItemList
:DoneItemList
/if n @Temp3==0 /echo No Items found.
}
:DoneItem
/call LoadItems
/return



