Page 1 of 1

Tradeskill macro

Posted: Fri Apr 06, 2007 3:03 pm
by jacensolo
After looking at Override's tradeskill macros, I decided that, while they were highly effective for specific combines, they just weren't flexible enough for the combine I needed to do. Specifically, I wanted a macro which could do all the buying, combining, and selling required to make Misty Thicket Picnics, when provided only with cash, tradeskill containers, and a supply of the non-vendor-sold components. Rather than create a macro for that, only to make another when I wanted to work on another combine, I made a macro which will load from an INI file all the information required for any recipe. It will go to the vendors, buy the materials, do the subcombines, do the final combines, sell the finished product if the user sets it to, then repeats the loop until the desired skill is reached or the user runs out of money.

ts.mac:

Code: Select all

|----------------------------------------------------------------------------------
|----------------------------------------------------------------------------------
|----------------------------------------------------------------------------------
|
| ts.mac
|
| Tradeskill Autocombiner
| With recognition to Override for bits and pieces of his buying, selling, and combining codes.
|
| To use this, make an ini file based on "ts_template.ini", then while in the game, type
| "/mac ts name", where "name" is the name of the ini file. Also, if you wish to skip 
| directly to the combines, type "/mac ts name 1". To skip directly to selling, type
| "/mac ts name 2". This macro requires that tradeskill containers be set to open on 
| ctrl-right-click, and that all bags are closed to begin, with the inventory open.
| Warning: In order to let the macro open doors, it spams the U key while moving, so it may
| spam your chat window with consider messages. This should not negatively impact the macro.
|
|----------------------------------------------------------------------------------
|----------------------------------------------------------------------------------
|----------------------------------------------------------------------------------

|()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()
|
| Events
|
|()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()

#event Comp "#*#you are missing#*#"
#event skillup "You have become better at #*#! (#1#)"
#event failure "You lacked the skill#*#"
#event ContInUse "#*#someone else is using#*#"
#event Broke "#*#you cannot afford#*#" 
#event Broke "#*#you can't afford#*#" 

|()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()
|
| Main Script
|
|()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()

Sub Main(iniset,int skipmark)
   /declare z int 1   
   /echo Running Tradeskill Macro
   /declare ts_inifile outer ${iniset}.ini
   /echo Beginning combine loop for ${iniset}

|<<< If the user has specified a skip point, this code will jump to it

   /if (${skipmark}==1) /goto :skippointone
   /if (${skipmark}==2) /goto :skippointtwo

   :startpoint
   /call firstrun
   :skippointone

|<<< Runs to or opens the required tradeskill container for each combine

   /for z 1 to ${Int[${Ini[${ts_inifile},Recipelist,Parts]}]}
      /if (${Int[${Ini[${ts_inifile},${Ini[${ts_inifile},${Ini[${ts_inifile},Recipelist,Part${z}]},Cont]},Steps]}]}==1) {
         /ctrlkey /itemnotify ${FindItem[${Ini[${ts_inifile},${Ini[${ts_inifile},Recipelist,Part${z}]},Cont]}].InvSlot} rightmouseup
      } else {
         /call Go "${Ini[${ts_inifile},${Ini[${ts_inifile},Recipelist,Part${z}]},Cont]}"
         /delay 10
         /itemtarget
         /click left item
      }

|<<< Combines each piece, then returns to the start point

      /call Combine ${z}
      /if (${Window[TradeskillWnd].Open}) /notify TradeskillWnd CloseButton leftmouseup
      /call Return "${Ini[${ts_inifile},${Ini[${ts_inifile},Recipelist,Part${z}]},Cont]}"
   /next z
   :skippointtwo

|<<< If the user has set the INI file to sell successes, it does so

   /if (${Int[${Ini[${ts_inifile},Main,Sell]}]}==1) /call Sell

|<<< Checks to see if your skill is at the desired level, if it is, this ends the macro

   /if (${Me.Skill[${Ini[${ts_inifile},Main,Skillname]}]}==${Int[${Ini[${ininame},Main,StopPoint]}]}) {
      /beep
      /beep
      /beep
      /beep
      /echo Desired skill reached. Ending Macro.
      /endmacro
   }
   /goto :startpoint
/return

|()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()
|
| Subroutines
|
|()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Goes to the merchants and buys 1 batch's set of supplies
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub firstrun
   /declare currentitem int
   /declare currentmerc int
   /declare y int local
   /for currentmerc 1 to ${Int[${Ini[${ts_inifile},Main,Mercs]}]}
      /call Go "${Ini[${ts_inifile},Main,Merc${currentmerc}]}"
      /delay 3
      /target ${Ini[${ts_inifile},Main,Merc${currentmerc}]}
      /delay 3
      /click right target
      /delay 3
      /for currentitem 1 to ${Ini[${ts_inifile},${Ini[${ts_inifile},Main,Merc${currentmerc}]},Items]}
         /call Buy "${Ini[${ts_inifile},${Ini[${ts_inifile},Main,Merc${currentmerc}]},Item${currentitem}]}" "${Ini[${ts_inifile},${Ini[${ts_inifile},${Ini[${ts_inifile},Main,Merc${currentmerc}]},Item${currentitem}]},Amount]}"
         /delay 20
      /next currentitem
      /call Return "${Ini[${ts_inifile},Main,Merc${currentmerc}]}"
      /delay 20
   /next currentmerc
/return

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Buy items
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub Buy(item ItemToBuy, int amount)
   /declare QTY int Inner
   /declare l2 local int
   /varset QTY ${Math.Calc[${amount}-${FindItemCount[=${ItemToBuy}]}]}
   /delay 20
   /if (${FindItemCount[=${ItemToBuy}]}>= ${amount}) /return  
   /varset l2 ${Window[MerchantWnd].Child[ItemList].List[${ItemToBuy},2]}
   /if (!${l2}) {
      /echo couldn't find ${ItemToBuy}
      /endm
   } else {
      /notify MerchantWnd ItemList listselect ${l2}
      /notify MerchantWnd ItemList leftmouse ${l2}
   /delay 2         
   } 
   :Loop
   /if (${QTY}>19) {
      /buyitem 20
      /delay 1s
      /doevents
      /varset QTY ${Math.Calc[${amount}-${FindItemCount[=${ItemToBuy}]}]}
      /goto :Loop
   } ELSE {
      /if (${QTY}>0 && ${QTY}<20) {
         /buyitem ${QTY}
         /delay 1s
         /varset QTY ${Math.Calc[${amount}-${FindItemCount[=${ItemToBuy}]}]}
   }
   }
   /if (${QTY}==0) {
      /return
   }
   /goto :Loop
/return 

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Sells Successes
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub Sell
   /call Go "${Ini[${ts_inifile},Main,Sellto]}"
   /target ${Ini[${ts_inifile},Main,Sellto]}
   /click right target
   /declare z int
   /cleanup
   /keypress i
   /delay 20
   /for z 1 to 8
      /itemnotify pack${z} rightmouseup
      /delay 5
   /next z
   /declare sellvar int
   /declare OldMoney int Inner    
   /declare NewMoney int Inner
   /declare ItemToSell
   /varset ItemToSell ${Ini[${ts_inifile},Main,Final]}
   /autoinv 
   /if (${ItemToSell.Equal[NULL]}) {
     /return
   }
   :Finding 
   /if (${FindItemCount[=${ItemToSell}]}==0) /goto :Done 
   /nomodkey /itemnotify ${FindItem[=${ItemToSell}].InvSlot} leftmouseup 
   :WaitFind 
   /if (${Bool[${SelectedItem}]}==FALSE) /goto :WaitFind 
   :Selling
   /delay 1s 
   /varset OldMoney ${Me.Cash} 
   /nomodkey /shift /notify MerchantWnd MW_Sell_Button leftmouseup 
   :WaitSell 
   /varset NewMoney $(Me.Cash} 
   /if (${NewMoney}==${OldMoney}) /goto :WaitSell 
   /goto :Finding 
   :Done      
   /cleanup
   /keypress i
   :returnpoint
/return 

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Does combine
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub Combine(recipe)
   /declare combvar int
   /declare need int
   /declare have int
   /declare current
   /delay 10
   /if (${FindItemCount["${Ini[${ts_inifile},Recipelist,Part${recipe}]}"]}>=${Ini[${ts_inifile},${Ini[${ts_inifile},Recipelist,Part${recipe}]},Make]}) /return
   /notify TradeskillWnd RecipeList listselect ${Window[TradeskillWnd].Child[RecipeList].List["${Ini[${ts_inifile},Recipelist,Part${recipe}]}"]}
   /delay 5
   /notify TradeskillWnd RecipeList leftmouse ${Window[TradeskillWnd].Child[RecipeList].List["${Ini[${ts_inifile},Recipelist,Part${recipe}]}"]}
   :combloop
   /doevents Comp
   /if (${Macro.Return.Equal[SKIP]}) /return
   /notify TradeskillWnd CombineButton leftmouseup
   /delay 15 ${Cursor.ID}
   :CursorLoop
   /if (${Cursor.ID}) {
      /autoinventory
      /delay 5
      /goto :CursorLoop
   }
   /echo Current: ${FindItemCount["${Ini[${ts_inifile},Recipelist,Part${recipe}]}"]}
   /delay 15
   /if (${FindItemCount["${Ini[${ts_inifile},Recipelist,Part${recipe}]}"]}<${Ini[${ts_inifile},${Ini[${ts_inifile},Recipelist,Part${recipe}]},Make]}) /goto :combloop
/return RESET

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pauses when a container is in use
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub event_ContInUse
   /echo Container in use. Pausing Macro
   /beep
   /beep
   /call Waiting
/return

Sub Waiting
   :Waitloop
   /delay 1m
   /itemtarget ${container}
   /click left item
   /delay 1s
   /if (!${Window[TradeskillWnd].Open]}) /goto :Waitloop
/return

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Travels from the startpoint to the specified endpoint
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub Go(where)
   /declare movevar int local
   /for movevar 1 to ${Int[${Ini[${ts_inifile},${where},Steps]}]}
      :MoveLoop
      /keypress u
      /if (${Ini[${ts_inifile},${where},Step${movevar}].Equal[Door]}) {
         /goto :next
      }
      /squelch /face nolook loc ${Ini[${ts_inifile},${where},Step${movevar}]}
      /if (${Math.Distance[${Ini[${ts_inifile},${where},Step${movevar}]}]}>3) {
         /nomodkey /keypress forward hold
         /face nolook loc ${Ini[${ts_inifile},${where},Step${movevar}]}
      }
      /if (${Math.Distance[${Ini[${ts_inifile},${where},Step${movevar}]}]}<=3) {
         /nomodkey /keypress forward
         /goto :next
      }
      /goto :Moveloop
      :next
   /next movevar
/return

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Travels from an endpoint to the startpoint
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub Return(where)
   /declare movevar int local
   /for movevar ${Int[${Ini[${ts_inifile},${where},Steps]}]} downto 1
      :MoveLoop
      /keypress u
      /if (${Ini[${ts_inifile},${where},Step${movevar}].Equal[Door]}) {
         /goto :next
      }
      /squelch /face nolook loc ${Ini[${ts_inifile},${where},Step${movevar}]}
      /if (${Math.Distance[${Ini[${ts_inifile},${where},Step${movevar}]}]}>3) {
         /nomodkey /keypress forward hold
         /face nolook loc ${Ini[${ts_inifile},${where},Step${movevar}]}
      }
      /if (${Math.Distance[${Ini[${ts_inifile},${where},Step${movevar}]}]}<=3) {
         /nomodkey /keypress forward
         /goto :next
      }
      /goto :Moveloop
      :next
   /next movevar
/return

Sub Event_Comp
/return SKIP

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| If you run out of money, this will end the macro
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Sub event_broke
   /echo You are broke. Ending macro.
   /beep
   /beep
   /beep
   /endmacro
/return
ts_template.ini:

Code: Select all

[Main]
Sell=(1 to sell final combine successes, 0 to keep them)
Skillname=(Name of skill of final combine)
Final=(Name of final combine)
StopPoint=(Desired skill level)
Sellto=(Name of closest vendor)
Mercs=(Number of merchants)
Merc1=(Names of merchants)

[(Merchant name)]
Steps=(Number of steps)
Step1=(Locs to merchant)
Items=(Number of items sold by merchant)
Item1=(Names of items sold by merchant)

[(Tradeskill container)]
Steps=(Number of steps)
Step1=(Locs to container)

[(Name of merchant sold item)]
Amount=(Amount to buy per batch)

[(Name of playermade item)]
Make=(Number needed per batch)
Cont=(Container used for combine)

[Recipelist]
Parts=(Number of playermade items in recipe)
Part1=(Names of playermade items)