Page 1 of 3

Brewing Macro from 1 to 248 (Version 2.5) 8/3/04

Posted: Tue Aug 03, 2004 7:51 pm
by Override
Well, I have decided to start releasing some of my Tradeskills Macros. I have them for pretty much for all tradeskills, but I want to work out a few bugs on some before I release a few. Here is a Link that has all the updated macros:

http://www.soc-music.com/mq2/

Below is the Brewing one I have made. This is to be used in the Abysmal Sea and you can go from 1 to 248 in brewing. Plus BE SURE to place the .inc files into the common directory in your macros directory (if there isn't one.....create it).

brewing.mac

Code: Select all

 | 
| brewing.mac
| Takes you from 1 to 248 in Brewing
| Version 2.5
| Date: August 3, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| Before are the settings you need to change for you.
| This Macro can take you up to 248 in brewing. 
| SkillMaxWanted can be change to what skill you want to stop at.
| MerchantNameA is which merchant has the brewing components.
| MerchantNameB is which merchant has the water and short beer components.
|
| This Macro works best in the Abysmal Sea since all the components are there.
| You WILL need to be between both merchants to be able to use this macro.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| This macro may not work any other place then the Abysmal Sea.
| 

#event CombineError "#*#There was no place to put that#*#" 
#event CombineError "#*#You cannot combine these items in this container type!#*#" 
#event CombineError "#*#did not accept these items#*#" 
#event ContUsed "#*#Someone else is using that. Try again later.#*#"
#include common/sell.inc
#include common/buy.inc
#include common/packs.inc

Sub Main
    /declare OldSkill int outer
    /declare SkillMaxWanted int outer
    /declare PackCode string outer 
    /declare Component[10] string outer 
    /declare i int outer
    /declare MerchantNameA string Outer
    /declare MerchantNameB string Outer
    /declare CompA item outer
    /declare CompB item outer
    /declare CompC item outer
    /declare CompD item outer
    /declare CompE item outer
    /declare CombItemName string outer
    /declare ItemToA string outer
    /declare ItemToB string outer
    /declare ItemToC string outer
    /declare EndingVar int outer
    /declare Levelname int outer
    /varset OldSkill ${Me.Skill[Brewing]}

| ************************************************
| *   Change these settings to what you want.    *
| ************************************************
  
    /varset MerchantNameA "Galidnus Corkpopper"
    /varset MerchantNameB "Dray Cuves"
    /varset SkillMaxWanted 248

| ************************************************
| ************************************************

    :start
    /echo Brewing is at ${Me.Skill[Brewing]}

    /if (${Me.Skill[Brewing]}>=${SkillMaxWanted}) {
      /echo Brewing is at ${SkillMaxWanted}. Quiting!
      /endmacro
    }

    /if (${Me.Skill[Brewing]}<${SkillMaxWanted}) {
      /varset CompA "cask"
      /varset CompB "malt"
      /varset CompC "short beer"
      /varset CompD "water flask"
      /varset CompE "yeast"
      /varset CombItemName "MHB"
      /varset ItemToA "Minotaur Hero's Brew"
      /varset ItemToB "bottle"
      /varset ItemToC "cask"
    }


    /varset EndingVar 1
    /call GoToMerchant
    /delay 1s
    /target ${MerchantNameA}
    /face
    /delay 1s
    /click right target
    /delay 1s
    /call Buy ${CompA} 40
    /delay 1s
    /call Buy ${CompB} 120
    /delay 1s
    /call Buy ${CompE} 40
    /delay 1s
    /notify MerchantWnd DoneButton leftmouseup

    /delay 2s
    /target ${MerchantNameB}
    /face
    /delay 1s
    /click right target
    /delay 1s
    /call Buy ${CompC} 80
    /delay 1s
    /call Buy ${CompD} 100
    /delay 1s
    /notify MerchantWnd DoneButton leftmouseup
    /delay 1s

    /call GoToBarrel
    /look
    /delay 1s
    /click left item
    /delay 2s
    /doevents
    /delay 1s
    /notify TradeskillWnd ExperimentButton leftmousehold
    /notify TradeskillWnd ExperimentButton leftmouseup
    /delay 2s
    /call OpenPacks

    /call readIni "${CombItemName}" 
    :Begin 
       /if (${EndingVar}==1) /call ClearCursor 
       /for i 1 to 10 
             /if (${EndingVar}==1) /call AddComp "${Component[${i}]}" ${i} 
       /next i 
       /if (${EndingVar}==1) /call DoCombine 
       /if (${EndingVar}==1) /goto :Begin
 
    /delay 1s
    /call ClosePacks
    /keypress esc
    /keypress esc

    /call GoToMerchant
    /delay 1s
    /target ${MerchantNameA}
    /face
    /delay 1s
    /click right target
    /delay 1s
    /call OpenPacks
    /delay 2s
    /call Sell ${ItemToA}
    /delay 1s
    /call Sell ${ItemToB}
    /delay 1s
    /call Sell ${ItemToC}
    /delay 1s
    /call ClosePacks
    /keypress esc
    /keypress esc

    /goto :start

    /return

Sub readIni(RecipeName) 
    /declare Container string 

    /echo Running ${RecipeName} recipe, which makes ${ItemToA}.

   /if (${Ini["brewing.ini","${RecipeName}",-1,"NOTFOUND"].Equal["NOTFOUND"]}) { 
        /echo Recipe ${RecipeName} not found 
        /endmacro 
    } 

   /varset Container ${Ini[brewing.ini,${RecipeName},Cont,Enviro]} 

   /if (${Container.Equal[Enviro]}) { 
        /varset PackCode Enviro 
   } else { 
        /varset PackCode ${FindItem[=${Container}].InvSlot} 
       
      /if (${PackCode.Equal[NULL]}) { 
         /echo Could not find container ${Container} 
         /varset EndingVar 2
         /return
      } 
      | pack1 = 22, ... , pack8 = 29 
      /varset PackCode pack${Math.Calc[${PackCode}-21].Int} 
   }  

    /for i 1 to 10 
        /varset Component[${i}] ${Ini[brewing.ini,${RecipeName},Comp${Math.Calc[${i}-1].Int},NOTFOUND]} 
    /next i 
    /return 

sub ClearCursor 
    :Loop 
      /if (!${Cursor.ID}) /return 
      /autoinv 
|      /destroy	
      /delay 5 
      /doevents 
      /goto :Loop 
    /return 

sub DoCombine 
    :Loop 
      /combine ${PackCode} 
      /delay 1s 
      /if (${PackCode.Equal[Enviro]}) /delay 1s 
       /doevents 
      /if (${InvSlot[${PackCode}].Item.Items}) /goto :Loop 
      /delay 5 
      /if (${Me.Skill[Brewing]}>${OldSkill}) {
        /echo Your Brewing Went Up!! It's now ${Me.Skill[Brewing]}!
        /varset OldSkill ${Me.Skill[Brewing]}
      }
    /return 

sub AddComp(CompName, PackSlot) 
   /if (${CompName.Equal[NOTFOUND]}) /return 

   /if (!${FindItem[=${CompName}].ID}) { 
      /echo Could not find ${CompName} in inventory 
      /beep 
      /varset EndingVar 2
      /return 
    } 

   :Loop 
      /ctrl /itemnotify ${FindItem[=${CompName}].InvSlot} leftmouseup 

      /if (!${Cursor.ID}) { 
         /delay 1 
         /goto :Loop 
      } 

   /if (${PackCode.Equal[Enviro]}) { 
      /itemnotify ${InvSlot[enviro${PackSlot}]} leftmouseup 
   } else { 
      /itemnotify in ${PackCode} ${PackSlot} leftmouseup 
   }    
   /return 

Sub Event_CombineError 
    /varset EndingVar 2
/return

Sub Event_ContUsed
    /echo Container in use. Waiting 30 seconds and trying again.
    /delay 30s
    /itemtarget "Brew Barrel"
    /delay 1s
    /click left item
    /delay 2s
    /doevents
/return 


Sub GoToMerchant
  /echo Going to Merchants.
  :PullMoveLoop
  /if (${Me.State.Equal[SIT]}) /stand 
  /face nolook loc -165.30,178.83
  /if (${Math.Distance[-165.30,178.83]}>2) /keypress forward hold 
  /if (${Math.Distance[-165.30,178.83]}<=2) {
    /keypress forward
    /return
  }
  /goto :PullMoveLoop 
/return 

Sub GoToBarrel
  /echo Going to Brewing Barrel.
  /itemtarget "Brew Barrel"
  :PullMoveLoop
  /if (${Me.State.Equal[SIT]}) /stand
  /face
  /if (${Target.Distance}>10) /keypress forward hold 
  /if (${Target.Distance}<=10) {
    /keypress forward
    /return
  }
  /goto :PullMoveLoop 
/return 
brewing.ini

Code: Select all

[MHB]
Cont=Enviro
Comp0=yeast
Comp1=malt
Comp2=malt
Comp3=malt
Comp4=short beer
Comp5=short beer
Comp6=water flask
Comp7=water flask
Comp8=cask
buy.inc

Code: Select all

| 
| buy.inc
| Buy Include File needed for macros
| Version 1.3
| Date: August 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| These file MUST be in the common directory in your macros directory.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 


#event Broke "#*#can't afford to buy them#*#" 

Sub Buy(item ItemToBuy, int amount)

/echo Buying ${ItemToBuy}

/declare TotalMItems int Inner
/varset TotalMItems ${Merchant.Items}
/declare x int Inner
/declare ItemSlotNum int Inner
/varset ItemSlotNum 0

/for x 1 to ${TotalMItems}
  /if (${ItemToBuy.Equal[${Merchant.Item[${x}]}]}) {
    /varset ItemSlotNum ${x}
  }
/next x

/if (${ItemSlotNum}==0) {
  /echo Not on Merchant
  /return
}

/itemnotify merchant${ItemSlotNum} leftmouseup


:Buy 
   /if (${FindItemCount[=${SelectedItem}]}>=${amount}) {
     /echo Done!
     /return
   }        

:StackLoop 
   /if (${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]}<=20) /goto :RegLoop 
   /buyitem ${If[${SelectedItem.Stackable},20,1]} 
   /delay 5 
   /doevents 
   /goto :StackLoop 

:RegLoop 
   /if (${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]}<=0) {
     /echo Done!
     /return
   }        
   /buyitem ${If[${SelectedItem.Stackable},${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]},1]} 
   /delay 5 
   /doevents 
   /goto :RegLoop 

/return

Sub Event_Broke 
   /echo Error: You are out of money! 
   /beep
   /endmacro
/return 
packs.inc

Code: Select all

| 
| packs.inc
| Open and Close Packs Include File needed for macros
| Version 1.1
| Date: August 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| These file MUST be in the common directory in your macros directory.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 

Sub OpenPacks 
   /declare bag int local 0 

   /newif (!${Window[InventoryWindow].Open}) /keypress inventory 
   /delay 1 
   /for bag 1 to 8 step 1 
      /newif (!${Window[pack${bag}].Open}) /itemnotify pack${bag} rightmouseup 
   /next bag 
   /delay 1 
/return 

Sub ClosePacks 
   /declare bag int local 0 
|   /newif (!${Window[InventoryWindow].Open}} /keypress inventory 
   /delay 1 
   /for bag 1 to 8 step 1 
      /newif (${Window[pack${bag}].Open}) /itemnotify pack${bag} rightmouseup 
   /next bag 
   /delay 1 
/return 
sell.inc

Code: Select all

| 
| sell.inc
| Selling Include File needed for macros
| Version 1.2
| Date: August 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| These file MUST be in the common directory in your macros directory.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 


Sub Sell(string ItemToSell)
   /declare OldMoney int Inner    
   /declare NewMoney int Inner
 
   /autoinv 

   /if (${ItemToSell.Equal[NULL]}) {
     /echo Usage: /macro sell "Item"
     /return
   }

   :Finding 
      /if (${FindItemCount[=${ItemToSell}]}==0) /goto :Done 
      /itemnotify ${FindItem[=${ItemToSell}].InvSlot} leftmouseup 

   :WaitFind 
      /if (${Bool[${SelectedItem}]}==FALSE) /goto :WaitFind 

   :Selling
      /delay 1s 
      /varset OldMoney ${Me.Cash} 
      /shift /notify MerchantWnd MW_Sell_Button leftmouseup 

   :WaitSell 
      /varset NewMoney $(Me.Cash} 
      /if (${NewMoney}==${OldMoney}) /goto :WaitSell 
      /goto :Finding 

   :Done 
      /echo No more ${ItemToSell} to sell!!!      
/return 

Posted: Thu Aug 05, 2004 4:17 am
by Seariz
I know this is a stupid question, but how many bag slots does this macro expect you to have open?

Posted: Thu Aug 05, 2004 12:17 pm
by loadingpleasewait
this macro opens and closes all your bag slots, automagically

Posted: Thu Aug 05, 2004 12:33 pm
by thatguy48
When I run this macro it does nothing but buy casks until my inventory is full, and then buys and drops them on the ground until I end the macro.

I can duplicate this with 2.5 and the latest 2.6 I just grabbed off your site, and I have already viewed and applied the fix listed at.

http://macroquest2.com/phpBB2/viewtopic.php?t=8508

I figured the /Call Buy${CompA} 40 was for 40 casks and not 40 stacks, but even when I've changed the amount to something as low as 10 it still continually buys them until it's out of space.

I can also duplicate the behavior with the JC macro, it just bought 10 stacks of electrum bars before I ended the macro.

Posted: Thu Aug 05, 2004 12:57 pm
by Seariz
The reason I asked, was because I had the exact same problem Thatguy48 had. I was just asking to see if I needed more free bag space instead of trying to fix the problem.

Fix you did

Posted: Thu Aug 05, 2004 3:13 pm
by Axo959
After you edited the eqgame.h (header) file, did you re compile macroquest2 with the edited file? I deleted my current c:\mq2 dir (sans macros, ini's, common, etc), recompiled using the edited offsets in eqgame.h and it worked after that for me.

Posted: Thu Aug 05, 2004 4:43 pm
by loadingpleasewait
aye, the problem you are having is related to the selecteditem offset error, ReApply the fix and recompile. The macro is truly amazing and I see no major errors in it.

Posted: Thu Aug 05, 2004 5:23 pm
by Drumstix42
Started it up to test. Bought stuff from first mechant, started buying from 2nd merchant, then client crashed. /shrug

My structs are correct.

Posted: Thu Aug 05, 2004 5:49 pm
by 3djoker
drum i am having the exact same problem. i narrowed it down to this,,.....

Code: Select all

/itemtarget "brew barrel"
the wierd thing is, i used the exact same compile from this comp on my wifes comp. she has no problems whatsoever.

im not sure what it is that makes the difference, but our computers are almost identical. i can type /itemtarget "brew barrel" on my comp and i CTD, yet i type it on hers and it targets the barrel no probs.

im totally boggled right now. (so now i just run it on her comp lol)

Posted: Thu Aug 05, 2004 6:31 pm
by Drumstix42
Hmm yes you are right, but the really wierd thing is I tried /itemtarget last night and it was fine!

I thought i read somewhere it had to do with /mapfilter but I've triedit on and off and I keep CTD. :?

Posted: Thu Aug 05, 2004 6:41 pm
by Override
I am not sure why you would be CTD. It seems that maybe someone else is having the same problem here:

http://macroquest2.com/phpBB2/viewtopic.php?t=8574

But they do not say how to fix it. It may just be a bug in the lastest release that needs to be fix and may work in the next release.

Posted: Thu Aug 05, 2004 7:17 pm
by thatguy48
I was able to fix my problem (Yes I had remembered to recompile the .h first).

What I ended up doing was taking the .h, and my macro directory and scraping the rest, I redownloaded the source, inserted the fixed .h, ran the Mq2auth and compiled. Then it worked.

I don't know why it didn't like the recompile, but at least it's working now...

Thanks for a great set of scripts! :D

Brewing 148

Posted: Thu Aug 05, 2004 7:35 pm
by Poot Pantaloon
ok, downloaded the latest source, made the change to the .h file as mentioned above...did a recompile...

Now for the goodies...

I decided to see just how much it would cost to take an "average" toon up.

Here are the stats:

Str 134
Sta 138
Agi 69 (due to the amount of cash I carried)
Dex 100
Wis 171 (not a super twink)
int 85
Cha 84

level 26 beastlord cat....

I carried 10098 (yes 10k) into the room

I left with 9787 plat

So getting to 248 on my average char cost me 311 plat and took about 6 hours in total (1 of which I was doing stupid stuff which cost me a little extra - leaving stuff in the barrel, trying to alt tab out and messing it up, etc....

Great Macro!!!!!

Poot Pantaloon

Posted: Thu Aug 05, 2004 8:01 pm
by Drumstix42
that's what I did when I did the struct changes in the .h file. I just started from scrathed, made changes, then compiled (obviously you have to make the changes before compiling). And I swear it worked last night.

couple changes

Posted: Fri Aug 06, 2004 6:07 pm
by showme1
Can thank Rusty~ for this, but I have updated the brewing and include files so that alt tabbing or hitting the shift key wont mess it up. Before if alt tabbing or shifting while buying or combining it would mess the macro up. I added the /nomodkey line where it was needed on the brewing macro and the 3 include files. Something you might want to add to the other macros. These are very well done BTW. Thank you very much for them! Here is the new code...

sell.inc

Code: Select all

| 
| sell.inc
| Selling Include File needed for macros
| Version 1.2
| Date: August 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| These file MUST be in the common directory in your macros directory.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 


Sub Sell(string ItemToSell)
   /declare OldMoney int Inner    
   /declare NewMoney int Inner
 
   /autoinv 

   /if (${ItemToSell.Equal[NULL]}) {
     /echo Usage: /macro sell "Item"
     /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 
      /echo No more ${ItemToSell} to sell!!!      
/return 

buy.inc

Code: Select all

| 
| buy.inc
| Buy Include File needed for macros
| Version 1.3
| Date: August 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| These file MUST be in the common directory in your macros directory.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 


#event Broke "#*#can't afford to buy them#*#" 

Sub Buy(item ItemToBuy, int amount)

/echo Buying ${ItemToBuy}

/declare TotalMItems int Inner
/varset TotalMItems ${Merchant.Items}
/declare x int Inner
/declare ItemSlotNum int Inner
/varset ItemSlotNum 0

/for x 1 to ${TotalMItems}
  /if (${ItemToBuy.Equal[${Merchant.Item[${x}]}]}) {
    /varset ItemSlotNum ${x}
  }
/next x

/if (${ItemSlotNum}==0) {
  /echo Not on Merchant
  /return
}

/nomodkey /itemnotify merchant${ItemSlotNum} leftmouseup


:Buy 
   /if (${FindItemCount[=${SelectedItem}]}>=${amount}) {
     /echo Done!
     /return
   }        

:StackLoop 
   /if (${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]}<=20) /goto :RegLoop 
   /buyitem ${If[${SelectedItem.Stackable},20,1]} 
   /delay 5 
   /doevents 
   /goto :StackLoop 

:RegLoop 
   /if (${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]}<=0) {
     /echo Done!
     /return
   }        
   /buyitem ${If[${SelectedItem.Stackable},${Math.Calc[${amount}-${FindItemCount[=${SelectedItem}]}]},1]} 
   /delay 5 
   /doevents 
   /goto :RegLoop 

/return

Sub Event_Broke 
   /echo Error: You are out of money! 
   /beep
   /endmacro
/return 

packs.inc

Code: Select all

| 
| packs.inc
| Open and Close Packs Include File needed for macros
| Version 1.1
| Date: August 1, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| These file MUST be in the common directory in your macros directory.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| 

Sub OpenPacks 
   /declare bag int local 0 

   /newif (!${Window[InventoryWindow].Open}) /keypress inventory 
   /delay 1 
   /for bag 1 to 8 step 1 
      /newif (!${Window[pack${bag}].Open}) /nomodkey /itemnotify pack${bag} rightmouseup 
   /next bag 
   /delay 1 
/return 

Sub ClosePacks 
   /declare bag int local 0 
|   /newif (!${Window[InventoryWindow].Open}} /keypress inventory 
   /delay 1 
   /for bag 1 to 8 step 1 
      /newif (${Window[pack${bag}].Open}) /nomodkey /itemnotify pack${bag} rightmouseup 
   /next bag 
   /delay 1 
/return 

brewing.mac

Code: Select all

| 
| brewing.mac
| Takes you from 1 to 248 in Brewing
| Version 2.5
| Date: August 3, 2004
|
| Please be sure to get the lastest updates at http://www.soc-music.com/mq2/index.htm
|
| Before are the settings you need to change for you.
| This Macro can take you up to 248 in brewing. 
| SkillMaxWanted can be change to what skill you want to stop at.
| MerchantNameA is which merchant has the brewing components.
| MerchantNameB is which merchant has the water and short beer components.
|
| This Macro works best in the Abysmal Sea since all the components are there.
| You WILL need to be between both merchants to be able to use this macro.
|
| Disclaimer:
| Code was used from other programers also from the MQ Forums.
| This macro may not work any other place then the Abysmal Sea.
| 

#event CombineError "#*#There was no place to put that#*#" 
#event CombineError "#*#You cannot combine these items in this container type!#*#" 
#event CombineError "#*#did not accept these items#*#" 
#event ContUsed "#*#Someone else is using that. Try again later.#*#"
#include common/sell.inc
#include common/buy.inc
#include common/packs.inc

Sub Main
    /declare OldSkill int outer
    /declare SkillMaxWanted int outer
    /declare PackCode string outer 
    /declare Component[10] string outer 
    /declare i int outer
    /declare MerchantNameA string Outer
    /declare MerchantNameB string Outer
    /declare CompA item outer
    /declare CompB item outer
    /declare CompC item outer
    /declare CompD item outer
    /declare CompE item outer
    /declare CombItemName string outer
    /declare ItemToA string outer
    /declare ItemToB string outer
    /declare ItemToC string outer
    /declare EndingVar int outer
    /declare Levelname int outer
    /varset OldSkill ${Me.Skill[Brewing]}

| ************************************************
| *   Change these settings to what you want.    *
| ************************************************
  
    /varset MerchantNameA "Galidnus Corkpopper"
    /varset MerchantNameB "Dray Cuves"
    /varset SkillMaxWanted 248

| ************************************************
| ************************************************

    :start
    /echo Brewing is at ${Me.Skill[Brewing]}

    /if (${Me.Skill[Brewing]}>=${SkillMaxWanted}) {
      /echo Brewing is at ${SkillMaxWanted}. Quiting!
      /endmacro
    }

    /if (${Me.Skill[Brewing]}<${SkillMaxWanted}) {
      /varset CompA "cask"
      /varset CompB "malt"
      /varset CompC "short beer"
      /varset CompD "water flask"
      /varset CompE "yeast"
      /varset CombItemName "MHB"
      /varset ItemToA "Minotaur Hero's Brew"
      /varset ItemToB "bottle"
      /varset ItemToC "cask"
    }


    /varset EndingVar 1
    /call GoToMerchant
    /delay 1s
    /target ${MerchantNameA}
|    /face
    /delay 1s
    /click right target
    /delay 1s
    /call Buy ${CompA} 40
    /delay 1s
    /call Buy ${CompB} 120
    /delay 1s
    /call Buy ${CompE} 40
    /delay 1s
    /nomodkey /notify MerchantWnd DoneButton leftmouseup

    /delay 2s
    /target ${MerchantNameB}
|    /face
    /delay 1s
    /click right target
    /delay 1s
    /call Buy ${CompC} 80
    /delay 1s
    /call Buy ${CompD} 100
    /delay 1s
    /nomodkey /notify MerchantWnd DoneButton leftmouseup
    /delay 1s

    /call GoToBarrel
    /look
    /delay 1s
    /click left item
    /delay 2s
    /doevents
    /delay 1s
    /nomodkey /notify TradeskillWnd ExperimentButton leftmousehold
    /nomodkey /notify TradeskillWnd ExperimentButton leftmouseup
    /delay 2s
    /call OpenPacks

    /call readIni "${CombItemName}" 
    :Begin 
       /if (${EndingVar}==1) /call ClearCursor 
       /for i 1 to 10 
             /if (${EndingVar}==1) /call AddComp "${Component[${i}]}" ${i} 
       /next i 
       /if (${EndingVar}==1) /call DoCombine 
       /if (${EndingVar}==1) /goto :Begin
 
    /delay 1s
    /call ClosePacks
    /keypress esc
    /keypress esc

    /call GoToMerchant
    /delay 1s
    /target ${MerchantNameA}
|    /face
    /delay 1s
    /click right target
    /delay 1s
    /call OpenPacks
    /delay 2s
    /call Sell ${ItemToA}
    /delay 1s
    /call Sell ${ItemToB}
    /delay 1s
    /call Sell ${ItemToC}
    /delay 1s
    /call ClosePacks
    /keypress esc
    /keypress esc

    /goto :start

    /return

Sub readIni(RecipeName) 
    /declare Container string 

    /echo Running ${RecipeName} recipe, which makes ${ItemToA}.

   /if (${Ini["brewing.ini","${RecipeName}",-1,"NOTFOUND"].Equal["NOTFOUND"]}) { 
        /echo Recipe ${RecipeName} not found 
        /endmacro 
    } 

   /varset Container ${Ini[brewing.ini,${RecipeName},Cont,Enviro]} 

   /if (${Container.Equal[Enviro]}) { 
        /varset PackCode Enviro 
   } else { 
        /varset PackCode ${FindItem[=${Container}].InvSlot} 
       
      /if (${PackCode.Equal[NULL]}) { 
         /echo Could not find container ${Container} 
         /varset EndingVar 2
         /return
      } 
      | pack1 = 22, ... , pack8 = 29 
      /varset PackCode pack${Math.Calc[${PackCode}-21].Int} 
   }  

    /for i 1 to 10 
        /varset Component[${i}] ${Ini[brewing.ini,${RecipeName},Comp${Math.Calc[${i}-1].Int},NOTFOUND]} 
    /next i 
    /return 

sub ClearCursor 
    :Loop 
      /if (!${Cursor.ID}) /return 
      /autoinv 
|      /destroy	
      /delay 5 
      /doevents 
      /goto :Loop 
    /return 

sub DoCombine 
    :Loop 
      /combine ${PackCode} 
      /delay 1s 
      /if (${PackCode.Equal[Enviro]}) /delay 1s 
       /doevents 
      /if (${InvSlot[${PackCode}].Item.Items}) /goto :Loop 
      /delay 5 
      /if (${Me.Skill[Brewing]}>${OldSkill}) {
        /echo Your Brewing Went Up!! It's now ${Me.Skill[Brewing]}!
        /varset OldSkill ${Me.Skill[Brewing]}
      }
    /return 

sub AddComp(CompName, PackSlot) 
   /if (${CompName.Equal[NOTFOUND]}) /return 

   /if (!${FindItem[=${CompName}].ID}) { 
      /echo Could not find ${CompName} in inventory 
      /beep 
      /varset EndingVar 2
      /return 
    } 

   :Loop 
      /nomodkey /ctrl /itemnotify ${FindItem[=${CompName}].InvSlot} leftmouseup 

      /if (!${Cursor.ID}) { 
         /delay 1 
         /goto :Loop 
      } 

   /if (${PackCode.Equal[Enviro]}) { 
      /nomodkey /itemnotify ${InvSlot[enviro${PackSlot}]} leftmouseup 
   } else { 
      /nomodkey /itemnotify in ${PackCode} ${PackSlot} leftmouseup 
   }    
   /return 

Sub Event_CombineError 
    /varset EndingVar 2
/return

Sub Event_ContUsed
    /echo Container in use. Waiting 30 seconds and trying again.
    /delay 30s
    /itemtarget "Brew Barrel"
    /delay 1s
    /click left item
    /delay 2s
    /doevents
/return 


Sub GoToMerchant
  /echo Going to Merchants.
  :PullMoveLoop
  /if (${Me.State.Equal[SIT]}) /stand 
  /face nolook loc -165.30,178.83
  /if (${Math.Distance[-165.30,178.83]}>2) /keypress forward hold 
  /if (${Math.Distance[-165.30,178.83]}<=2) {
    /keypress forward
    /return
  }
  /goto :PullMoveLoop 
/return 

Sub GoToBarrel
  /echo Going to Brewing Barrel.
  /itemtarget "Brew Barrel"
  :PullMoveLoop
  /if (${Me.State.Equal[SIT]}) /stand
  /face fast
  /if (${Target.Distance}>10) /keypress forward hold 
  /if (${Target.Distance}<=10) {
    /keypress forward
    /return
  }
  /goto :PullMoveLoop 
/return