Moderator: MacroQuest Developers

dont_know_at_all wrote:Gee, if only there was a way to correctly report a crash...
Code: Select all
| tribute.mac v0.2
|
| Author: I made it myself =P (zoobish)
| Updated: theseans
| =======
|
| Function: Searches bazaar for tribute items worth buying.
| ========= You set the RATIO you like, i.e. 10 means 100pp
| for 1000 tribute. You may set the RATIO via the
| first argument when calling this.
| e.g. /mac tribute 15
| You can also set the MaxPrice with the second
| argument if you wish.
| e.g. /mac tribute 15 3000
| I find 3000 to be ample.
| It will alert you when it finds something.
|
#turbo
| This is the trigger for restarting the search after yah buy the current item.
| You can change it to whatever you want I suppose...
#event gogogo "#*#i need more TRIB now#*#"
#event notForSale "#*#That item is no longer for sale in the bazaar#*#"
Sub Main
| SET THESE IF YOU WISH, overridden by calling arguments.
|Setting the iniSupport at 0 will pause the macro at each find for you to purchase it, and won't resume till you /echo i need more TRIB now
|otherwise it will do a complete scan and write all the finds to the tribute.ini
/declare iniSupport int outer 1
| 1 for beeping on item find, 0 for it just to run silently
/declare iniBeep int outer 1
/declare RATIO int outer 10
/declare MaxPrice int local 3000
/declare reStartFlag bool outer
/declare I int local
/declare J int local
/declare cPrice int local
/declare cTrib int local
/declare forSale bool outer
/declare aSlotNum[17] int local
/varset aSlotNum[1] 3
/varset aSlotNum[2] 4
/varset aSlotNum[3] 6
/varset aSlotNum[4] 7
/varset aSlotNum[5] 8
/varset aSlotNum[6] 9
/varset aSlotNum[7] 10
/varset aSlotNum[8] 11
/varset aSlotNum[9] 12
/varset aSlotNum[10] 13
/varset aSlotNum[11] 14
/varset aSlotNum[12] 16
/varset aSlotNum[13] 18
/varset aSlotNum[14] 19
/varset aSlotNum[15] 20
/varset aSlotNum[16] 21
/varset aSlotNum[17] 22
/declare iniItemName string outer
/declare iniItemTribute int outer
/declare iniItemPrice int outer
/echo Starting Bazaar Tribute Search...
| Check if a ratio and price were entered when called...
/if (${Defined[Param0]}) {
/echo RATIO set to ${Param0}
/varset RATIO ${Param0}
}
/if (${Defined[Param1]}) {
/echo MaxPrice set to ${Param1}
/varset MaxPrice ${Param1}
}
| *** Open the Bazaar window.
/baz
/delay 5s (${Window[BazaarSearchWnd].Open})
/if ( !${Window[BazaarSearchWnd].Open} ) {
/echo FATAL ERROR: Bazaar window could not be found or opened.
/echo ABORTING...
/endm
}
| *** Reset the Bazaar Search form.
/notify BazaarSearchWnd BZR_Default leftmouseup
| *** Key in monetary values
/call SetTextBox BazaarSearchWnd BZR_MaxPriceInput ${MaxPrice}
| *** Loop using Search by Slot.
/for I 1 to 17
/call selectSlotAndSearch ${aSlotNum[${I}]}
| *** Fix for activating "Inspect Item" button.
/notify BazaarSearchWnd BZR_ItemList leftmouseup
| *** Open each item and check stats
/for J 1 to 200
/varset cPrice NULL
/varset cTrib NULL
| *** Get the price of the item
/call getPriceAndSelect ${J}
/varset cPrice ${Macro.Return}
| *** If end of list, get next slot.
/if ( ${cPrice} == NULL ) /next I
| *** Get the tribute value, if any...
/call getSelectedTributeValue
/varset cTrib ${Macro.Return}
| *** If no tribute value, get next item via looking ahead.
/if ( ${cTrib} == NULL ) {
/call lookAhead ${J}
/varset J ${Macro.Return}
/next J
}
| *** Check ahead for the same item, and compare, alert if good.
/call checkAheadCompareAlert ${J} ${cPrice} ${cTrib}
| *** Set J to the position of the last item of the "copies"
/varset J ${Macro.Return}
/if ( ${Window[ItemDisplayWindow].Open} ) /keypress esc
/next J
| *** End item loop
/next I
| *** End Slot loop
/echo DONE.
/return
|==============================================================================
| Returns the position of the last occurrance of the item.
Sub lookAhead(int itemNum)
/declare lastOccur int local ${itemNum}
/declare iName string local
/declare K int local
/call getItemName ${itemNum}
/varset iName ${Macro.Return}
/for K 1 to 2
/varcalc lastOccur ${lastOccur} + 1
| Check if named the same...
/if ( ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[${lastOccur},1].Find[${iName}]} ) {
/varset K 1
} else {
/varset K 2
}
/next K
/varcalc lastOccur ${lastOccur} - 1
/return ${lastOccur}
|==============================================================================
| Returns the name of the item, without the (number) bit...
Sub getItemName(int itemNum)
/declare iName string local NULL
/declare len int local
/varset iName ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[${itemNum},1]}
/varset len ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[${itemNum},1].Find[(]}
/varcalc len ${len} - 1
/return ${iName.Mid[1,${len}]}
|==============================================================================
| I suppose v0.1 of this was crap, it opened every item to find tribute value.
| This was slow, especially when there is usually a few of the same item for
| sale. This just looks at the first occurrence of an item for the tribute,
| then looks ahead at the prices to find the cheapest, without re-opening an
| item window(cause of much time waste). Returns the position of the last
| occurrence.
Sub checkAheadCompareAlert(int itemNum, int tPrice, int tTrib)
/declare lastOccur int local ${itemNum}
/declare lowPos int local ${itemNum}
/declare lowPrice int local ${tPrice}
/declare iName string local
/declare K int local
/call getItemName ${itemNum}
/varset iName ${Macro.Return}
/for K 1 to 2
/varcalc lastOccur ${lastOccur} + 1
| Check if named the same...
/if ( ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[${lastOccur},1].Find[${iName}]} ) {
/varset K 1
| Get the price...
/call getPriceAndSelect ${lastOccur}
/if ( ${Macro.Return} < ${lowPrice} ) {
/varset lowPrice ${Macro.Return}
/varset lowPos ${lastOccur}
}
} else {
/varset K 2
}
/next K
/varcalc lastOccur ${lastOccur} - 1
| Chek if item meets value requirements. If good, alert and wait.
/varset iniItemPrice ${lowPrice}
/varcalc lowPrice ${lowPrice} * ${RATIO}
/if ( ${lowPrice} < ${tTrib} ) {
/varset iniItemTribute ${tTrib}
/call getPriceAndSelect ${lowPos}
/call alertAndWait "${iName}"
}
/return ${lastOccur}
|==============================================================================
| Alerts, beeps, and waits for continue text...
Sub alertAndWait(string itemName)
/if (${iniSupport} == 0) {
/declare K int local
/if ( ${Window[ActionsWindow].Child[AMP_EndFindButton].Open} ) {
| end find...
/notify ActionsWindow AMP_FindButton leftmouseup
/delay 1
}
/popup GOOD ITEM FOUND: >>> ${itemName} <<<
/notify BazaarSearchWnd BZR_FindTraderButton leftmouseup
/for K 1 to 5
/beep
/delay 2
/next K
/popup GOOD ITEM FOUND: >>> ${itemName} <<<
/varset reStartFlag FALSE
/call waitForGo
/return
}
/ini "Tribute-${Time.Month}-${Time.Day}.ini" "${iniItemName}" "${iniItemPrice}" "${iniItemTribute}"
/varset reStartFlag TRUE
/echo ${iniItemName} found for ${iniItemPrice} plat - worth ${iniItemTribute} tribute
/if ( ${iniBeep} == 1) {
/beep
}
/call waitForGo
/return
|==============================================================================
| Returns the tribute value of an item. Does this by opening its item view and
| extracting the text.
Sub getSelectedTributeValue
/declare K int local
/declare tTrib int local NULL
/declare tInfo string local
/declare tPos int local NULL
/if ( ${Window[ItemDisplayWindow].Open} ) /keypress esc
| Open the item window
/notify BazaarSearchWnd BZR_RequestItemButton leftmouseup
/delay 6s (${Window[ItemDisplayWindow].Open})
/if (!${Window[ItemDisplayWindow].Open}) {
/varset forSale TRUE
/doevents
/if ( ${forSale} ) {
/echo Done
/endmacro
/return ${tTrib}
}
}
| Get the text, check for tribute...
/varset tInfo ${Window[ItemDisplayWindow].Child[IDW_ItemDescription].Text}
/varset tPos ${tInfo.Find[<BR>Tribute Value:]}
/if ( ${tPos} == NULL ) {
/return ${tTrib}
}
| Parse the tribute value
/varcalc tPos ${tPos} + 19
/varset tTrib 0
/for K ${tPos} to 10000
/if ( ${tInfo.Mid[${K},1].Compare[<]} != 0 ) {
/varcalc tTrib ${tTrib} * 10
/varcalc tTrib ${tTrib} + ${tInfo.Mid[${K},1]}
} else {
/varset K 10000
}
/next K
/return ${tTrib}
|==============================================================================
| Gets the price of an item in the bazaar search list, also selects it in list.
Sub getPriceAndSelect(int itemNum)
/declare tPrice int local NULL
/notify BazaarSearchWnd BZR_ItemList listselect ${itemNum}
/delay 1
/varset tPrice ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[${itemNum},4]}
/varset iniItemName ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[${itemNum},2]}
/return ${tPrice}
|==============================================================================
| Selects the Item Slot and does search. Waits Max 10s for results.
Sub selectSlotAndSearch(int slotNum)
/declare gotText string local
/declare count int local 0
/declare tt int local NULL
/notify BazaarSearchWnd BZR_ItemSlotCombobox listselect ${slotNum}
/notify BazaarSearchWnd BZR_ItemTypeCombobox listselect 10
/if (${slotNum} == 16 || ${slotNum} == 16 || ${slotNum} == 18) {
/notify BazaarSearchWnd BZR_ItemTypeCombobox listselect 1
}
/notify BazaarSearchWnd BZR_QueryButton leftmouseup
:WAIT_RESULT
/delay 5
/varset gotText ${Window[BazaarSearchWnd].Child[BZR_ItemList].List[1,1]}
/varset tt ${gotText.Find[(]}
/if ( ${tt} != NULL ) /goto :WAIT_END
/varcalc count ${count} + 1
/if ( ${count} > 20 ) {
/return
}
/goto :WAIT_RESULT
:WAIT_END
/delay 5
/return
|==============================================================================
| This waits for the user to buy the found item, user then keys a phrase,
| and search restarts.
Sub waitForGo
:WAIT
/doevents
/if ( ${reStartFlag} ) /return
/delay 1s
/goto :WAIT
/return
|==============================================================================
|This is the event handler for when the user has keyed the restart phrase
Sub Event_gogogo
/varset reStartFlag TRUE
/return
|==============================================================================
|This is the event handler for when the item is no longer for sale
Sub Event_notForSale
/varset forSale FALSE
/return
|==============================================================================
| This sets the text in a text box control. Does not affect sliders. There is
| different code for that.
Sub SetTextBox(string Wnd, string Ctrl, string Inp)
/declare I int local
| Clear the text box
/notify ${Wnd} ${Ctrl} leftmouseup
/for I 1 to 2
/notify ${Wnd} ${Ctrl} leftmouseup
/if ( ${Window[${Wnd}].Child[${Ctrl}].Text.Length} > 0 ) {
/keypress backspace chat
/varset I 1
} else {
/varset I 2
}
/next I
| Fill the box...
/for I 1 to ${Inp.Length}
/keypress ${Inp.Mid[${I},1]} chat
/next I
/return
|===========================================================================end






