Food and Drink

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

Moderator: MacroQuest Developers

User avatar
stateful
orc pawn
orc pawn
Posts: 15
Joined: Tue Mar 23, 2004 1:24 am

Food and Drink

Post by stateful » Fri Mar 26, 2004 12:03 pm

To create food and water... If someone has already written something like this, cool, I was just playing around, this is my first macro.
Comments are greatly appreciated.

Code: Select all

||||||||||||||||||||||||||||||||||||||||||
|                                        |
|         Food and Drink Macro           |
|                                        |
|     Set FoodSpell and Waterspell       |
|   To the respective spells you want    |
|                to cast                 |
|    The stuff between the "-" lines     |
|                                        |
|      Execute: /macro fnd <total>       |
|     <total> is the amount of each      |
|               to create                |
|     Default is 20 if not specified     |
|                                        |
||||||||||||||||||||||||||||||||||||||||||

#turbo  | cause everyone else does it

#Event Fizzle "Your spell fizzles!"
#Event Recovered "You haven't recovered yet..."
#Event Interrupt "Your spell is interrupted."
#Event NoMana "Insufficient Mana to cast this spell"
#Event Distracted "You are too distracted to cast a spell now!"
#Event Stunned "You can't cast spells while stunned!"


sub main
/declare recast global		|try recast if fizzle, not recovered
/declare killmac global		|exit macro if interrupted, no mana, distracted, stunned
/declare Total local 		|total pieces of each to create
/declare Spell global 		|var for current spell, disregard
/declare i local 		|iteration count in loop
/declare CT local 		|spell cast time
/declare RT local 		|spell recovery time
/declare FoodSpell local 	|name of food spell
/declare WaterSpell local	|name of water spell
/declare Slot local		|slot number of memed spell

|--------------------------------
/varset FoodSpell "Summon Food" | Set to food spell
/varset WaterSpell "Summon Drink" | Set to water spell
|--------------------------------

/varset Total 20 	| Default total
/if $defined(Param0)!=FALSE { 
  /varset Total @Param0 
} 

/echo Creating @Total Food and Drink

| Mem Spells
|Food
/varset Slot $char(gem,"@FoodSpell")
/if n @Slot==0 {
/windowstate spellbook open
/memspell 7 "@FoodSpell"
/delay 50
/cleanup
}
/varset Slot $char(gem,"@WaterSpell")
/if n @Slot==0 {
/memspell 8 "@WaterSpell"
/delay 50
/cleanup
}

| Stand up
/if $char(state)==SIT { 
      /stand 
} 

| Open Inventory to drop new food and water after creation
/windowstate inventory open

|
| Food Creation
|
/echo Beginning Food Summoning
/varset Spell "@FoodSpell"
/varset CT $spell("@Spell",casttime)s
/varset RT $spell("@Spell",recoverytime)s
/varset i 1

  :foodloop
  /varset recast 0
  /if n @i<=@Total {
    /cast "@Spell"
    /delay 5
    /delay @RT
    /doevents
    /if n @recast==1 /goto :foodloop
    /if n @killmac==1 /return
    /delay @CT
    /delay 15 | more delay, takes too long
    /click left auto
    /varadd i 1
    /goto :foodloop
  }

|
| Drink Creation
|
/echo Beginning Water Summoning
/varset Spell "@WaterSpell"
/varset CT $spell("@Spell",casttime)s
/varset RT $spell("@Spell",recoverytime)s
/varset i 1

  :waterloop
  /varset recast 0
  /if n @i<=@Total {
    /cast "@Spell"
    /delay 5
    /delay @RT
    /doevents
    /if n @recast==1 /goto :waterloop
    /if n @killmac==1 /return
    /delay @CT
    /delay 15 | more delay, takes too long
    /click left auto
    /varadd i 1
    /goto :waterloop
  }

/cleanup
/return

sub Event_Fizzle
  /delay 10
  /echo @Spell Fizzled, recasting
  /varset recast 1
/return

sub Event_Recovered 
  /delay 10
  /echo Didn't wait long enough, retrying...
  /varset recast 1
/return

sub Event_Interrupt
  /delay 4
  /echo @Spell Interrupted, stop moving or getting hit, killing macro
  /varset killmac 1
/return

sub Event_NoMana 
  /delay 4
  /echo No mana to cast, killing macro
  /varset killmac 1
/return

sub Event_Distracted 
  /delay 4
  /echo You are distracted, killing macro
  /varset killmac 1
/return

sub Event_Stunned 
  /delay 4
  /echo You are stunned and probably shouldn't be running this now, killing macro
  /varset killmac 1
/return

User avatar
Bad Karma
a snow griffon
a snow griffon
Posts: 346
Joined: Sat Nov 22, 2003 9:34 pm
Contact:

Post by Bad Karma » Sat Mar 27, 2004 6:37 am

Not bad for a first macro. Looks like you used some more advanced scripting to accomplish this simple task. It's a good way to learn, and from what I see of it, it looks like you've got a decent grasp of how things run.
Here are some suggestions to help streamline the process, as well as some examples for you to look at:

1. Set #turbo 50

2. Use #include SpellCast.inc, found here.

3.

Code: Select all

| Mem Spells
   /varset Slot $char(gem,"@SpellName")
   /if n @Slot==0 {
      /windowstate spellbook open
      /memspell 7 "@SpellName"
      /delay 50
      /cleanup
   }
can be slimplified by using

Code: Select all

   /if n $char(gem,"@SpellName")==0 /memspell 7 "@SpellName"
   /delay 5
This will return 1-8 if the spell is loaded, then mem it if not. You only need a /delay 5, unless you lag REALLY bad. No need to open the spellbook to mem spells.

4.

Code: Select all

| Stand up
   /if $char(state)==SIT {
      /stand
   }
More reliable method of checking to see if you're standing (accounts for being on a mount):

Code: Select all

   /if $char(mounted)!=TRUE /if $char(state)!="STAND" /stand
5. - The first think I notice with this is all those /delays...took me a moment to see exactly what it was you were trying to accomplish with all that and why...

Code: Select all

| Creation
   /varset Spell "@SpellName"
   /varset CT $spell("@Spell",casttime)s
   /varset RT $spell("@Spell",recoverytime)s
   /varset i 1
:loop
   /varset recast 0
   /if n @i<=@Total {
      /cast "@Spell"
      /delay 5
      /delay @RT
      /doevents
      /if n @recast==1 /goto :loop
      /if n @killmac==1 /return
      /delay @CT
      /delay 15 | more delay, takes too long
      /click left auto
      /varadd i 1
      /goto :loop
   }
- Some summoning spells result in more than one item being summoned (Cleric food/water summoning, for example). Using a :loop that casts the spell a hard 20 times could result in 80 food/water.
- I would use a $count() to determine when to stop casting, in stead....(Also, use < rather than <=, or you will end up actually summoning more than your desired @Total. You can also use >=, if you don't mind having too many...but chances are, you'll want the free inventory slots.)
- The code below checks to see if you are currently casting, or if you are waiting to recover from casting: /if n $char(gem,"@SpellName")<0, then the gem is not ready yet.
- @killmac, as is, will still try to cast. Use /endmacro to actually kill the macro.

Code: Select all

| Creation
:loop
   /if n $count("@ItemName")<@Total {
      /cast "@SpellName"
:WaitCast
      /if ($char(casting)==TRUE || n $char(gem,"@SpellName")<0) {
         /delay 1
         /goto :WaitCast
      }
      /if n @killmac==1 /endmacro
      /if $cursor()==TRUE {
         /autoinventory
         /delay 3
      }
      /goto :loop
   }
- I'd put this in a Sub Summon, and use a var such as @ItemName to pass whether or not it's food or water (/define ItemName "Blackend Bread" or "Pod of Water", for example)...make it generic enough to use one Sub for both items.
- You can also cut this down to nothing by using SpellCast.inc and changing /cast "@SpellName" to /call cast "@SpellName", then delete the :WaitCast loop. SpellCast.inc will handle everything (and more) you have in your #Events.

Code: Select all

| Creation
Sub Summon(ItemName, SpellName)
:loop
   /call cast "@SpellName"
   /if $cursor()==TRUE {
      /autoinventory
      /delay 3
   }
   /if n $count("@ItemName")<@Total /goto :loop
/return
- You could also kill most of you Sub Main (meming the spell) by using SpellCast.inc.
- Doing this also cuts your overall macro size down to nothing, since you're eliminating 2 large chunks of code needed to do the same thing more than once.

Code: Select all

Sub Main
   ...other sutff here...
| Food
   /call Summon @ItemName @SpellName
| Again for Water
   /call Summon @ItemName @SpellName
   ...other stuff here...
/return
Keep up the good work and effort! :D
[b]- Bad Karma
________________________________________[/b]

In our own quest for excellence, we should strive to take the time to help those who help themselves.

All others should [b]RTFM[/b]!!!!!!!!!

User avatar
stateful
orc pawn
orc pawn
Posts: 15
Joined: Tue Mar 23, 2004 1:24 am

Wow, thanks!

Post by stateful » Wed Mar 31, 2004 4:01 am

Bad Karma, Thank you for all of the info, hints, and tips. It's nice to see a good code review.
I'll incorporate the suggestions and post an update, in a bit.

-stateful