Yet Another Forage Macro - yafm

Post your completed (working) macros here. Only for macros using MQ2Data syntax!

Moderator: MacroQuest Developers

sparky13
decaying skeleton
decaying skeleton
Posts: 5
Joined: Thu Jan 12, 2006 10:26 am

Post by sparky13 » Sat Nov 18, 2006 3:32 pm

I've been searching through some different forage macs, and I still currently use yafm.

The nice thing about it is that it creates and appends to its own .ini file. It is also set to KEEP any item !=0 on the list, and not destroy it. When new items are encountered, they're defaulted to =1 (which means keep).

What this does, is if you happen to brain fart, and forget it's running, and pick up your epic... there's no OH FUK! there goes my epic. It in turn adds that item to the .ini file, and sets it to =1, and drops it into your inventory. No harm, no foul.

What I was wondering is this, since I hate all the lil forage turds I leave because I use the foraged water/fruit/veggies to save on my stat food/drink while foraging, can you add a section routine that you could define a # of items to keep, and if that number was not defined, and the setting was keep, it would keep an infinite amount?

Basically I'd like it to keep say 2 stacks of water and roots/fruit, and destroy anything over 40, and not drop them.

Was just wondering. This probably belongs under the YAFM section, so I'll go copy it there, but this seemed a lively discussion at one point =)

***EDIT***

Hrm, just went back through this entire thread, and I'm thinking I got ahold of a mod'd version, because my .mac looks nothing like the full version here. I'm thinking I'll copy this and make a yafm2.mac and see how that works.

Code: Select all


|yafm.mac 
| 
|Yet Another Forage Macro 
| 
|Ini File: yafm.ini 
| 
| 0 = destroy 
| 1 = keep 
| 
|New foraged items are added to the ini file automatically and are kept by default. 


|||||||||||||||||||| 
| Main 
|||||||||||||||||||| 
sub Main 

   /cleanup 

   | Verify that we have the ability to forage. 
   /if (${Me.Skill[Forage]}==0) { 
      /echo You cannot forage, silly person! 
      /goto :Exit 
   } 

   :Forage 

   | Stand up.  Can't forage while sitting. 
   /if (${Me.State.NotEqual[STAND]}) { 
      /stand 
      /delay 5 
   } 

   /delay 1s 

   | If we can forage then do so. 
   /if (${Me.AbilityReady[Forage]}) { 
      /doability forage 
   } 

   | If we successfully foraged something then take care of it. 
   /if (${Cursor.ID}) { 
      /call HandleItem 
   } 

   /goto :Forage 

:Exit 
/return 

|||||||||||||||||||| 
| HandleItem 
|||||||||||||||||||| 
sub HandleItem 

   /declare ItemSetting int local 
   /declare NotFound int local 

   /varset NotFound -1 

   | Look up this item in yafm.ini 
   /varset ItemSetting ${Ini[yafm.ini,ForageList,${Cursor.Name},${NotFound}]} 

   /delay 5 

   | If the item isn't in the .ini file then add it. 
   /if (${ItemSetting}==${NotFound}) { 

      /ini "yafm.ini" "ForageList" "${Cursor.Name}" "1" 

      /varset ItemSetting 1 

   } 

   | If we're keeping this item then stash it in our bags. 
   | Otherwise, just destroy it. 
   /if (${ItemSetting}==1) { 

      :LootIt 
      /autoinventory 
      /delay 5 
      /if (${Cursor.ID}) /goto :LootIt 

   } else { 

      /destroy 

   } 

/return  

jimbo123
a ghoul
a ghoul
Posts: 87
Joined: Wed Dec 21, 2005 9:46 pm

Post by jimbo123 » Sun Nov 19, 2006 8:27 am

I've been using this one for a long time. It works great and does not destroy stuff when you pick it up out of your inventory. I don't know hwo to credit with putting it together.

Code: Select all

|Forage.mac 
|Based off code from Preocts(thanks!) and code from various other forage macros. 
|In the forage.ini file use -1 to keep all, 0 to destroy all and any other number to keep just that many. 
|New foraged items are added to the ini file automatically. 


sub Main 
  /cleanup 
  :Forage 
    /if (${Me.State.NotEqual[STAND]}) { 
      /stand 
      /delay 5 
    } 
    /delay 1s 
    /if (${Me.Skill[Forage]} > 0) /doability forage 
  } 
  /if (${Cursor.ID}) /call ItemSort 
    /goto :Forage 
  :loop 
/return 

sub ItemSort 
  /delay 5 

  /if (!${Ini[forage.ini,ForageList,${Cursor.Name}].Length}) { 
    /ini "Forage.ini" "ForageList" "${Cursor.Name}" "-1" 
  } else { 
    /if (${Ini[forage.ini,ForageList,${Cursor.Name}]}) { 
      /if (${FindItemCount["=${Cursor.Name}"]}>=${Ini[forage.ini,ForageList,${Cursor.Name}]} && ${Ini[forage.ini,ForageList,${Cursor.Name}]}!=-1) /goto :Destroy 
    } else { 
      :Destroy 
      /echo Destroying ${Cursor.Name} 
      /destroy
      /return 
    } 
  } 
  :LootIt 
    /echo Keeping ${Cursor.Name} 
    /autoinventory 
    /delay 5 
    /if (${Cursor.ID}) /goto :LootIt 
/return 

sparky13
decaying skeleton
decaying skeleton
Posts: 5
Joined: Thu Jan 12, 2006 10:26 am

Post by sparky13 » Tue Nov 28, 2006 12:16 pm

Thanks Jimbo. Could you post a snippet of your forage.ini file so I can take a look at it?

I've got 4 that I'm looking at right now and not sure which one I need to be using.

I understand the -1 for all, 0 for destroy, and other # for keep that many, just need to see the format.

Also, is there a default/null=-1 setting for anything not on the list?

jimbo123
a ghoul
a ghoul
Posts: 87
Joined: Wed Dec 21, 2005 9:46 pm

Post by jimbo123 » Tue Nov 28, 2006 1:57 pm

Sure thing, sparky. Stuff gets added to it automatically with a "keep all" option, so when you pick something up while it is running, it doesn't get auto-deleted for not being in the ini :) You can see in the ini that i picked up a Rallic Pack while this was running, so it will keep every Rallic Pack I manage to forage. It will destroy all fishing grubs, and it will keep up to 20 roots.

Save this starter ini file as forage.ini in your macro folder.

Code: Select all

[ForageList]
Roots=20
Rallic Pack=-1
Mushroom=-1
Wild Blueberries=-1
Bloodshrub Thorns=-1
Fishing Grubs=0
Glob of Slush Water=20
--jimbo

sparky13
decaying skeleton
decaying skeleton
Posts: 5
Joined: Thu Jan 12, 2006 10:26 am

Post by sparky13 » Tue Jan 02, 2007 12:41 pm

Sorry Jimbo, realized I never thanked you for this =)

Happy New Year

rok1303
orc pawn
orc pawn
Posts: 11
Joined: Sat Jul 03, 2004 5:27 am

Post by rok1303 » Wed Feb 21, 2007 4:55 pm

The line:

Code: Select all

/if (${Cursor.ID}) /goto :LootIt
in the code Jimbo posted was causing double forages to automatically inventory the second item (regardless of the quantity you had already).

I commented it out and it has been working perfectly ever since... It takes a little longer since the routine has to cycle through the whole sorting algorithm again, but it does it properly.

Thanks a bunch Jimbo :)

dumdum
a lesser mummy
a lesser mummy
Posts: 36
Joined: Sun Mar 02, 2008 4:40 pm
Location: Milky Way

Silly question

Post by dumdum » Mon Mar 10, 2008 12:00 pm

Instead of commenting out the :

/if (${Cursor.ID}) /goto :LootIt

You change it to:

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

That way it place it back at the beginning of the loop to sort out the items, until your cursor is empty. Once your cursor empties out you start at the beginnning of the macro once again. This works I have tested it.

Dumdum

kronfu
a lesser mummy
a lesser mummy
Posts: 37
Joined: Wed Feb 27, 2008 11:20 am

Post by kronfu » Thu Mar 13, 2008 6:11 pm

I tried running this macro and nothing happends. I created the yafm.mac file and use

/mac yafm.mac

it appears to run but nothing happens.

Is this still working for anyone?

jacensolo
a snow griffon
a snow griffon
Posts: 427
Joined: Wed Feb 14, 2007 8:51 am
Location: Right behind you

Post by jacensolo » Thu Mar 13, 2008 10:04 pm

What error do you get?

Try /mac yafm

kronfu
a lesser mummy
a lesser mummy
Posts: 37
Joined: Wed Feb 27, 2008 11:20 am

Post by kronfu » Fri Mar 14, 2008 7:57 am

It works, was operator error. You need to set the Forage on your abilities tab first.

ScriptKitty
decaying skeleton
decaying skeleton
Posts: 3
Joined: Tue Feb 09, 2010 2:06 pm

Post by ScriptKitty » Fri Feb 12, 2010 11:37 pm

Edit: Nevermind, new user error ^^;

User avatar
gse7en
a hill giant
a hill giant
Posts: 262
Joined: Mon Oct 17, 2005 8:19 pm
Contact:

Re: Yet Another Forage Macro - yafm

Post by gse7en » Fri Sep 16, 2011 12:59 am

yafm2, line 80 or so:

Change

Code: Select all

/varset ItemsHave ${FindItemCount[=${Cursor.Name}]}
to

Code: Select all

/varset ItemsHave ${FindItemCount[=${Cursor}]}
Version that works:

Code: Select all

|yafm2.mac
|Version 2.01
|
|Yet Another Forage Macro
|
|Ini File: yafm2.ini
|
| 0 = destroy
| x = keep at most x of this item
|
|New foraged items are added to the ini file automatically and are kept by default.


||||||||||||||||||||
| Main
||||||||||||||||||||
sub Main

    /declare DefaultMaxSave int outer

    /varset DefaultMaxSave ${Ini[yafm2.ini,Default,MaxSave,${NotFound}]}
    /if (${DefaultMaxSave}==${NotFound}) {
       /ini "yafm2.ini" "Default" "MaxSave" "100"
        /varset DefaultMaxSave 100
    }

   /cleanup

   | Verify that we have the ability to forage.
   /if (${Me.Skill[Forage]}==0) {
      /echo You cannot forage, silly person!
      /goto :Exit
   }

   :Forage

   | If we can forage then do so.
   /if (${Me.AbilityReady[Forage]}) {
      | Stand up.  Can't forage while sitting.
      /if (${Me.State.NotEqual[STAND]}) {
         /stand
         /delay 5
      }

      /doability forage
   }

   | If we successfully foraged something then take care of it.
   /if (${Cursor.ID}) {
      /call HandleItem
   }

   /goto :Forage

:Exit
/return

||||||||||||||||||||
| HandleItem
||||||||||||||||||||
sub HandleItem

   /declare ItemSetting int local
   /declare NotFound int local
   /declare ItemsHave int local

   /varset NotFound -1

   :LootIt

   | Look up this item in yafm2.ini
   /varset ItemSetting ${Ini[yafm2.ini,ForageList,${Cursor.Name},${NotFound}]}
   /delay 5

   | If the item isn't in the .ini file then add it.
   /if (${ItemSetting}==${NotFound}) {
       /ini "yafm2.ini" "ForageList" "${Cursor.Name}" "${DefaultMaxSave}"
       /varset ItemSetting ${DefaultMaxSave}
   }

   /varset ItemsHave ${FindItemCount[=${Cursor}]} 
   
   | If we're keeping this item then stash it in our bags.
   | Otherwise, just destroy it.
   /if (${ItemSetting}>${ItemsHave}) {
     /autoinventory
   } else {
     /destroy
   }

   /delay 5
   /if (${Cursor.ID}) /goto :LootIt

/return

Deltor
a lesser mummy
a lesser mummy
Posts: 52
Joined: Mon Jan 09, 2006 12:02 pm

Re: Yet Another Forage Macro - yafm

Post by Deltor » Sun Jun 22, 2014 12:12 am

Line #38 $Me.AbilityReady[Forage]

is always false since patch 6/20/14

Deltor
a lesser mummy
a lesser mummy
Posts: 52
Joined: Mon Jan 09, 2006 12:02 pm

Re: Yet Another Forage Macro - yafm

Post by Deltor » Sun Jun 22, 2014 11:59 am

Fixed. Change line 38 to

/if (${Me.Skill[Forage]} > 0) {

ToVuNikaMua
decaying skeleton
decaying skeleton
Posts: 5
Joined: Fri Oct 31, 2003 6:21 pm

Re: Yet Another Forage Macro - yafm

Post by ToVuNikaMua » Sun Jan 08, 2017 9:32 pm

I made an updated version for yafm2 that ensures you are holding the item you foraged before taking any dangerous actions (i.e. /destroy). I also added event checking to stop the macro when your inventory is full. With the current macro call structure there is no way to continue the macro when inventory is full, as the cursor will always be occupied, so it just continues to call HandleItems. Also changed the exit routine from a /goto to a /call.

Code: Select all

|yafm2.mac
|Version 2.10
|
|Yet Another Forage Macro
|
|Ini File: yafm2.ini
|
| 0 = destroy
| x = keep at most x of this item
|
|New foraged items are added to the ini file automatically and are kept by default.
|
|Macro automatically ends when inventory is full to prevent infinite calls of HandleItem
|

#Event InventoryFull "#*#There are no open slots for the held item in your inventory.#*#"

||||||||||||||||||||
| Main
||||||||||||||||||||
sub Main
   | Declare our DefaultMaxSave variable
   /declare DefaultMaxSave int outer

   | Set DefaultMaxSave from Ini
   /varset DefaultMaxSave ${Ini[yafm2.ini,Default,MaxSave]}

   | If the DefaultMaxSave is not in Ini, enter it
   /if (${DefaultMaxSave}==${NotFound}) {
     /ini "yafm2.ini" "Default" "MaxSave" "100"
     /varset DefaultMaxSave 100
   }

   /cleanup

   | Verify that we have the ability to forage.
   /if (${Me.Skill[Forage]}==0) {
      /echo You cannot forage, silly person!
      /call Exit
   }

   :Forage

   | If we can forage then do so.
   /if (${Me.AbilityReady[Forage]}) {
      | Stand up.  Can't forage while sitting.
      /if (${Me.State.NotEqual[STAND]}) {
         /stand
         /delay 5
      }

      /doability forage
   }


   | If we successfully foraged something then take care of it.
   /if (${Cursor.ID}) {
      /call HandleItem ${Cursor.ID}
   }
   /goto :Forage
/return

||||||||||||||||||||
| HandleItem
||||||||||||||||||||
sub HandleItem(Item)
   | Declare our variables
   /declare ItemSetting int local
   /declare NotFound int local
   /declare ItemsHave int local

   | Set NotFound to -1 to start
   /varset NotFound -1

   | Look up this item in yafm2.ini
   /if (${Cursor.ID} == ${Item}) {
     /varset ItemSetting ${Ini[yafm2.ini,ForageList,${Cursor.Name},${NotFound}]}
     /delay 5

     | If the item isn't in the .ini file then add it.
     /if (${ItemSetting}==${NotFound}) {
         /ini "yafm2.ini" "ForageList" "${Cursor.Name}" "${DefaultMaxSave}"
         /varset ItemSetting ${DefaultMaxSave}
     }
   }

   /varset ItemsHave ${FindItemCount[=${Cursor}]} 
   
   | If we're keeping this item then stash it in our bags.
   | Otherwise, just destroy it.
   /if (${ItemSetting}>${ItemsHave}) {
      /autoinventory
      | Check to see if our inventory is full
      /doevents
   } else {
      | Make sure item currently on cursor is the one we foraged
      | Ensures we don't delete things we picked up between forages
      /if (${Cursor.ID} == ${Item}) {
         /destroy
      }
   }

   /delay 5
   /if (${Cursor.ID}) /call HandleItem ${Cursor.ID}
/return

||||||||||||||||||||
| Event_InventoryFull
||||||||||||||||||||
Sub Event_InventoryFull
  /echo Inventory Full
  /call Exit
/return

||||||||||||||||||||
| Exit
||||||||||||||||||||
Sub Exit
  /echo Exiting
  /endmacro
/return