ForageINI.mac a forage macro with ini support

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
grimmace
decaying skeleton
decaying skeleton
Posts: 1
Joined: Mon Mar 29, 2004 1:09 pm

Post by grimmace » Mon Mar 29, 2004 1:13 pm

I've written a fairly similar forage macro myself, and one of the early pitfalls I encountered was the per-zone item lists. I did away with the per-zone listings for a couple reasons:

1) It doesnt matter what zone you are in, if you want to keep an item, you want to keep it.
2) Many items appear in multiple zones

I wound up loading 2 arrays when the macro kicks off: a Save list and a Destroy list. When an item is foraged, it first checks the Save list - if the item is found, it is /autoinventoried. If the item is NOT found, it checks the Destroy list - if the item is there, it is /destroyed. If the item is not found on EITHER list, it is /autoinventoried for safety reasons.

Dont have the code with me ATM but I think its a superior way to go. Other than that, this macro looks great and gave me a few nice ideas.

Oskar
orc pawn
orc pawn
Posts: 12
Joined: Sun Nov 30, 2003 2:01 pm

Post by Oskar » Mon Apr 05, 2004 9:51 pm

This macro is pretty cool but it doesn't seem to destroy items that have a 0 in the INI file. In GoD, a lot of items have spaces in their names. Could it have something to do with that?

Calon
decaying skeleton
decaying skeleton
Posts: 4
Joined: Tue Apr 13, 2004 12:22 pm

Post by Calon » Tue Apr 13, 2004 12:51 pm

Hi all, I've just got started on here. And I am lost, from what I can tell for this macro is:

original code
someone's mod snippet
ditto
someone's personal mod referencing personal/notlisted Subs (aka useless)
comments
re-code
comments
snippets
re-code to read from ini
corrections
comments
corrections
GD streamlined v2.2
etc etc

But can someone tell me in macro-for-dummy terms which one works? Like for example:
-GD's 2.2 Mar 13, 2004 3:05 pm post +
-snippet A from Apr 12, 2003 3:05 pm post +
-correction B from Dec 4, 2003 2:05 pm post + etc.

So I can put it all together and it will work type of instructions?

The other confusing thing is I have tried to put this together myself, and I can swear I got it to work once or twice, but then without changing the code, on a different day or different zone, it would not read from the INI file. Or more correctly, it would know which items to delete (based on the output echo) but simply not destroy any of those items and just keep collecting everything regardless.

Heeeelllp?


PS Grimmace I agree with you, post your CODE :)
Thanks

firedancer
decaying skeleton
decaying skeleton
Posts: 5
Joined: Wed Apr 14, 2004 4:00 pm

Post by firedancer » Wed Apr 14, 2004 4:04 pm

This is the forage macro as I use it... I love it.
To activate it... in the mq2chatwnd i type...

/macro forage

To end the macro I type...

/endmacro

I usually end the macro and restart it after zoning if I want the stats to be reset.

Also, I posted my ini file below as well.

Code: Select all

|----------------------------
| Forager with ini file support and
| statistic gathering and reporting
| version 2.1

| Set this define to the desired .ini file
| Requires a blank .ini file to start. The marco will
| populate the .ini file automatically for any zone
| and default to keeping the item. Then just change
| the values in the .ini file to 0 for an item to be
| automatically destroyed (requires FastItemDestroy
| be turned on in the options window)

#define IniFile "forage.ini"
#Event ZoneChange "Loading please wait"
#turbo

Sub Main
  /declare ForageDelay global
  /declare EnableShowStats global
  /declare EnableWriteLog global
  /declare EnableClear global

| ##### User set variables #####
  /varset ForageDelay 1010         | The delay between forage attempts
  /varset EnableShowStats 1        | Set to 1 to show foraging statistics
  /varset EnableWriteLog 1         | Set to 1 to write statistics to MQLog
  /varset EnableClear 0            | Set to 1 to clear before writing stats

| ##### User set variables #####

  /declare ForageAttempts global
  /declare ForageSuccess global
  /declare ForageFailure global
  /declare ForageKeeps global
  /declare ForageDestroys global
  /declare NumItem global
  /declare Index global
  /declare ItemArray array2

  /varset ForageAttempts 0
  /varset ForageSuccess 0
  /varset ForageFailure 0
  /varset ForageKeeps 0
  /varset ForageDestroys 0
  /varset NumItem 0
  /call LoadFromIni

:Continue
  /doevents
  /varset Index 0
  /if $char(state)==SIT {
      /stand
      /delay 3
  }
  /if n $char(ability,"Forage")>0 {
     /doability Forage
     /varadd ForageAttempts 1
     /delay 15
     /if "$cursor(name)"=="NULL" {
       /varadd ForageFailure 1
     } else {
       /varadd ForageSuccess 1
       /call CheckItem
       /call HandleItem
|       /beep
     }
  }
  /if @EnableWriteLog==1 /call LogStats
  /if @EnableShowStats==1 /call ShowStats
  /delay @ForageDelay
  /goto :Continue

/return

| ########## Subroutines ##########
Sub Event_ZOneChange
   /delay 1m
   /call LoadFromIni
/return

Sub LoadFromIni
   /varset NumItem 0
   /declare IniPosition local
   /declare IniList local
   /declare tmpItem local
   /varset IniList $ini(IniFile,"Global")
   /if "@IniList"!="NOTFOUND||" {
      /varset IniPosition 0
      :CheckGlobalForage
         /varadd IniPosition 1
         /varadd NumItem 1
         /varset ItemArray(0,@NumItem) "$arg($int(@IniPosition),"@IniList",|)"
         /varset ItemArray(1,@NumItem) $ini(IniFile,"Global","@ItemArray(0,@NumItem)")
|  Setting the second column to 0 in the array at zoneout/in.  Originally wasn't getting set and would cause stats to bail.
         /varset ItemArray(2,@NumItem) 0
      /if "$arg($int($calc(@IniPosition+1)),"@IniList",|)"!="" /goto :CheckGlobalForage
   }
   /varset IniList "$ini(IniFile,"$zone")"
   /if "@IniList"!="NOTFOUND||" {
      /varset IniPosition 0
      :CheckZoneForage
         /varadd IniPosition 1
         /varadd NumItem 1
         /varset ItemArray(0,@NumItem) "$arg($int(@IniPosition),"@IniList",|)"
         /varset ItemArray(1,@NumItem) $ini(IniFile,"$zone","@ItemArray(0,@NumItem)")
         /varset ItemArray(2,@NumItem) 0
      /if "$arg($int($calc(@IniPosition+1)),"@IniList",|)"!="" /goto :CheckZoneForage
   }
/return

Sub LogStats
  /declare xy local
  /if @EnableClear==1 /mqlog clear
  /mqlog #############################################
  /mqlog For Zone: $zone
  /mqlog Attempts = $int(@ForageAttempts)
  /mqlog Success  = $int(@ForageSuccess)  [$int($calc(@ForageSuccess/@ForageAttempts*100))%]
  /mqlog Failures = $int(@ForageFailure)  [$int($calc(@ForageFailure/@ForageAttempts*100))%]
  /mqlog Keeps    = $int(@ForageKeeps)    [$int($calc(@ForageKeeps/@ForageAttempts*100))%]
  /mqlog Destroys = $int(@ForageDestroys) [$int($calc(@ForageDestroys/@ForageAttempts*100))%]
  /mqlog [Idx] [Item] [Keep] [Qty] [%]
  /mqlog -------------------------------------------
  /if n @NumItem>0 {
    /for xy 1 to @NumItem
       /mqlog [$int(@xy)] [@ItemArray(0,@xy)] [$int(@ItemArray(1,@xy))] [$int(@ItemArray(2,@xy))] [$int($calc(@ItemArray(2,@xy)/@ForageAttempts*100))%]
    /next xy
  }
/return

Sub ShowStats
  /declare xy local
  /if @EnableClear==1 /clear
  /echo #############################################
  /echo For Zone: $zone
  /echo Attempts = $int(@ForageAttempts)
  /echo Success  = $int(@ForageSuccess)  [$int($calc(@ForageSuccess/@ForageAttempts*100))%]
  /echo Failures = $int(@ForageFailure)  [$int($calc(@ForageFailure/@ForageAttempts*100))%]
  /echo Keeps    = $int(@ForageKeeps)    [$int($calc(@ForageKeeps/@ForageAttempts*100))%]
  /echo Destroys = $int(@ForageDestroys) [$int($calc(@ForageDestroys/@ForageAttempts*100))%]
  /echo [Idx] [Item] [Keep] [Qty] [%]
  /echo -------------------------------------------
  /if n @NumItem>0 {
    /for xy 1 to @NumItem
      /echo [$int(@xy)] [@ItemArray(0,@xy)] [$int(@ItemArray(1,@xy))] [$int(@ItemArray(2,@xy))] [$int($calc(@ItemArray(2,@xy)/@ForageAttempts*100))%]
    /next xy
  }
/return


Sub CheckItem
  /declare xy local
  /if @NumItem==0 {
    /varset NumItem 1
    /call AddToArray
    /varset Index 1
  } else {
    /for xy 1 to @NumItem
      /if "@ItemArray(0,@xy)"=="$cursor(name)" /varset Index @xy
    /next xy
    /if @Index==0 {
      /varadd NumItem 1
      /call AddToArray
    } else {
      /varadd ItemArray(2,@Index) 1
    }
  }
/return

Sub AddToArray
    /varset ItemArray(0,@NumItem) "$cursor(name)"
    /varset ItemArray(1,@NumItem) $ini("IniFile","$zone","$cursor(name)")
    /if "@ItemArray(1,@NumItem)"=="NOTFOUND" {
      /varset ItemArray(1,@NumItem) 1
      /ini "IniFile" "$zone" "$cursor(name)" 1
    }
    /varset ItemArray(2,@NumItem) 1
/return

Sub HandleItem
  /if @ItemArray(1,@Index)==0 {
    /varadd ForageDestroys 1
    /echo $cursor(name) should be destroyed.
    /destroy
  } else {
    /varadd ForageKeeps 1
    /autoinv
  }
/return
Edited this post and removed the ini file due to length of the post...
The ini file is created in the release/macros/ folder... just put a 1 for things you want to keep and put a 0 for things you want destroyed... and remember to turn on "fast item destroy" in your EQ options.

squishypoo
decaying skeleton
decaying skeleton
Posts: 1
Joined: Fri Apr 16, 2004 6:15 am

forageini causing anyone else to crash to desktop?

Post by squishypoo » Fri Apr 16, 2004 6:19 am

as of the new EQ patches on or just before Apr 15, I now crash to desktop when I run forageini. anyone else having this problem? seems like I forage successfully and then attempt to auto-inventory what I've foraged and then crash...

Also, anyone attempting to make a new forage macro that will be compatable with the upcomming changes to MQ?

forageini has ruled for me so far. I look forward to continuing to use it =)

-SquishyPoo

Calon
decaying skeleton
decaying skeleton
Posts: 4
Joined: Tue Apr 13, 2004 12:22 pm

Post by Calon » Fri Apr 16, 2004 7:04 am

yes I am crashing also. I believe that's why the code wasn't working for me in my previous post. It was actually MQ changing.

Someone with more coding skill than me should attempt this conversion to the new MQ

LordGiddion
a snow griffon
a snow griffon
Posts: 352
Joined: Sat Sep 13, 2003 6:12 pm
Contact:

Post by LordGiddion » Fri Apr 16, 2004 9:19 am

The crash was an MQ bug. Should be fixed with the latest zip.

bartab
a grimling bloodguard
a grimling bloodguard
Posts: 715
Joined: Wed Oct 15, 2003 8:12 am

Post by bartab » Wed Apr 21, 2004 11:21 am

tried to make this file compliant with new parms :
good exercise indeed to learn, as I have not tested I cannot say it works, but I did my best.
Sub LogStats and ShowStats need to be updated also, I have been lazy.

every time I changed the code I made :

Code: Select all

| old code here
new code here
so that everyone is able to see what & how I changed .
I will try to test it tonight, in the meantime all comments are welcome : very good training to do that exercise :)

Code: Select all

|---------------------------- 
| Forager with ini file support and 
| statistic gathering and reporting 
| version 2.1 

| Set this define to the desired .ini file 
| Requires a blank .ini file to start. The marco will 
| populate the .ini file automatically for any zone 
| and default to keeping the item. Then just change 
| the values in the .ini file to 0 for an item to be 
| automatically destroyed (requires FastItemDestroy 
| be turned on in the options window) 

#define IniFile "forage.ini" 
#Event ZoneChange "Loading please wait" 
#turbo 

Sub Main 
  /declare ForageDelay global 
  /declare EnableShowStats global 
  /declare EnableWriteLog global 
  /declare EnableClear global 

| ##### User set variables ##### 
  /varset ForageDelay 1010         | The delay between forage attempts 
  /varset EnableShowStats 1        | Set to 1 to show foraging statistics 
  /varset EnableWriteLog 1         | Set to 1 to write statistics to MQLog 
  /varset EnableClear 0            | Set to 1 to clear before writing stats 

| ##### User set variables ##### 

  /declare ForageAttempts global 
  /declare ForageSuccess global 
  /declare ForageFailure global 
  /declare ForageKeeps global 
  /declare ForageDestroys global 
  /declare NumItem global 
  /declare Index global 
  /declare ItemArray array2 

  /varset ForageAttempts 0 
  /varset ForageSuccess 0 
  /varset ForageFailure 0 
  /varset ForageKeeps 0 
  /varset ForageDestroys 0 
  /varset NumItem 0 
  /call LoadFromIni 

:Continue 
  /doevents 
  /varset Index 0 
  
  |/if n $char(ability,"Forage")>0 {
  /newif ${charachter.AbilityReady["Forage"]} { 
     /doability Forage 
     /varadd ForageAttempts 1 
     /delay 15 
     |/if "$cursor(name)"=="NULL" {
     /newif ${Cursor.Name}=="NULL"{ 
       /varadd ForageFailure 1 
     } else { 
       /varadd ForageSuccess 1 
       /call CheckItem 
       /call HandleItem 
|       /beep 
     } 
  } 
  |/if @EnableWriteLog==1 /call LogStats 
  |/if @EnableShowStats==1 /call ShowStats 
  /newif @EnableWriteLog==1 /call LogStats 
  /newif @EnableShowStats==1 /call ShowStats 
  /delay @ForageDelay 
  /goto :Continue 

/return 

| ########## Subroutines ########## 
Sub Event_ZOneChange 
   /delay 1m 
   /call LoadFromIni 
/return 

Sub LoadFromIni 
   /varset NumItem 0 
   /declare IniPosition local 
   /declare IniList local 
   /declare tmpItem local 
   |/varset IniList $ini(IniFile,"Global") 
   /varset IniList ${Ini[IniFile,"Global"]}
   |/if "@IniList"!="NOTFOUND||" {
   /newif "@IniList"!="NOTFOUND||" {
      /varset IniPosition 0 
      :CheckGlobalForage 
         /varadd IniPosition 1 
         /varadd NumItem 1 
         |/varset ItemArray(0,@NumItem) "$arg($int(@IniPosition),"@IniList",|)" 
         /varset ItemArray(0,@NumItem) ${String[@IniList].Arg[${Int[@IniPosition]},|]}
         |/varset ItemArray(1,@NumItem) $ini(IniFile,"Global","@ItemArray(0,@NumItem)")
         /varset ItemArray(1,@NumItem) ${Ini[IniFile,"Global","@ItemArray(0,@NumItem)"]}
|  Setting the second column to 0 in the array at zoneout/in.  Originally wasn't getting set and would cause stats to bail. 
         /varset ItemArray(2,@NumItem) 0 
      |/if "$arg($int($calc(@IniPosition+1)),"@IniList",|)"!="" /goto :CheckGlobalForage
      /newif ${String[@IniList].Arg[${Int[${Calc[@IniPosition+1]}]},|]}!=${String[""]} /goto :CheckGlobalForage
   } 
   |/varset IniList "$ini(IniFile,"$zone")" 
   /varset IniList ${Ini[IniFile,${currentZone.Name}]}
   |/if "@IniList"!="NOTFOUND||" { 
   /newif "@IniList"!="NOTFOUND||" { 
      /varset IniPosition 0 
      :CheckZoneForage 
         /varadd IniPosition 1 
         /varadd NumItem 1 
         |/varset ItemArray(0,@NumItem) "$arg($int(@IniPosition),"@IniList",|)" 
         /varset ItemArray(0,@NumItem) ${String[@IniList].Arg[${Int[@IniPosition]},|]}
         |/varset ItemArray(1,@NumItem) $ini(IniFile,"$zone","@ItemArray(0,@NumItem)") 
         /varset ItemArray(1,@NumItem) ${Ini[IniFile,${currentZone.Name},@ItemArray(0,@NumItem)]}
         /varset ItemArray(2,@NumItem) 0 
      |/if "$arg($int($calc(@IniPosition+1)),"@IniList",|)"!="" /goto :CheckZoneForage 
      /newif ${String[@IniList].Arg[${Int[${Calc[@IniPosition+1]}]},|]}
   } 
/return 

Sub LogStats 
  /declare xy local 
  /if @EnableClear==1 /mqlog clear 
  /mqlog ############################################# 
  /mqlog For Zone: $zone 
  /mqlog Attempts = $int(@ForageAttempts) 
  /mqlog Success  = $int(@ForageSuccess)  [$int($calc(@ForageSuccess/@ForageAttempts*100))%] 
  /mqlog Failures = $int(@ForageFailure)  [$int($calc(@ForageFailure/@ForageAttempts*100))%] 
  /mqlog Keeps    = $int(@ForageKeeps)    [$int($calc(@ForageKeeps/@ForageAttempts*100))%] 
  /mqlog Destroys = $int(@ForageDestroys) [$int($calc(@ForageDestroys/@ForageAttempts*100))%] 
  /mqlog [Idx] [Item] [Keep] [Qty] [%] 
  /mqlog ------------------------------------------- 
  /if n @NumItem>0 { 
    /for xy 1 to @NumItem 
       /mqlog [$int(@xy)] [@ItemArray(0,@xy)] [$int(@ItemArray(1,@xy))] [$int(@ItemArray(2,@xy))] [$int($calc(@ItemArray(2,@xy)/@ForageAttempts*100))%] 
    /next xy 
  } 
/return 

Sub ShowStats 
  /declare xy local 
  /if @EnableClear==1 /clear 
  /echo ############################################# 
  /echo For Zone: $zone 
  /echo Attempts = $int(@ForageAttempts) 
  /echo Success  = $int(@ForageSuccess)  [$int($calc(@ForageSuccess/@ForageAttempts*100))%] 
  /echo Failures = $int(@ForageFailure)  [$int($calc(@ForageFailure/@ForageAttempts*100))%] 
  /echo Keeps    = $int(@ForageKeeps)    [$int($calc(@ForageKeeps/@ForageAttempts*100))%] 
  /echo Destroys = $int(@ForageDestroys) [$int($calc(@ForageDestroys/@ForageAttempts*100))%] 
  /echo [Idx] [Item] [Keep] [Qty] [%] 
  /echo ------------------------------------------- 
  /if n @NumItem>0 { 
    /for xy 1 to @NumItem 
      /echo [$int(@xy)] [@ItemArray(0,@xy)] [$int(@ItemArray(1,@xy))] [$int(@ItemArray(2,@xy))] [$int($calc(@ItemArray(2,@xy)/@ForageAttempts*100))%] 
    /next xy 
  } 
/return 


Sub CheckItem 
  /declare xy local 
  |/if @NumItem==0 {
  /newif @NumItem==0 { 
    /varset NumItem 1 
    /call AddToArray 
    /varset Index 1 
  } else { 
    /for xy 1 to @NumItem 
      |/if "@ItemArray(0,@xy)"=="$cursor(name)" /varset Index @xy
      /newif @ItemArray(0,@xy)==${Cursor.Name} /varset Index @xy
    /next xy 
    /if @Index==0 { 
      /varadd NumItem 1 
      /call AddToArray 
    } else { 
      /varadd ItemArray(2,@Index) 1 
    } 
  } 
/return 

Sub AddToArray 
    /varset ItemArray(0,@NumItem) ${Cursor.Name} 
    |/varset ItemArray(1,@NumItem) $ini("IniFile","$zone","$cursor(name)") 
    /varset ItemArray(1,@NumItem) ${Ini["IniFile",${currentZone.Name},${Cursor.Name}]}
    |/if "@ItemArray(1,@NumItem)"=="NOTFOUND" {
    /newif @ItemArray(1,@NumItem)=="NOTFOUND" {
      /varset ItemArray(1,@NumItem) 1 
      |/ini "IniFile" "$zone" "$cursor(name)" 1
      /ini "IniFile" ${currentZone.Name} ${Cursor.Name} 1
    } 
    /varset ItemArray(2,@NumItem) 1 
/return 

Sub HandleItem
  |/if @ItemArray(1,@Index)==0 {
  /newif @ItemArray(1,@Index)==0 {
    /varadd ForageDestroys 1 
    |/echo $cursor(name) should be destroyed. 
    /echo ${Cursor.Name} should be destroyed. 
    /destroy 
  } else { 
    /varadd ForageKeeps 1 
    /autoinv 
  } 
/return

game_slave
orc pawn
orc pawn
Posts: 18
Joined: Wed Apr 21, 2004 6:50 pm

Not working after today's patch

Post by game_slave » Wed Apr 21, 2004 7:30 pm

Hmmmmm, this wonderful macro has ceased to work for me after today's patch. I get a "Failed to parse /if command" error.

forage.mac@90(LoadFromini):/if"@inilist"!="NOTFOUND||"{
forage.mac@47(Main):/call LoadFromini

I have tried it with the modified code in the message above mine here and the original code that was working before. The line numbers differ but the error is the same.

I am just starting to learn this macro stuff so eventually I will be able to figure it out but was hoping someone with more experience could get this working sooner so I can at least be able to forage while I am learning how to program macros. :)

c52k
decaying skeleton
decaying skeleton
Posts: 6
Joined: Fri Feb 27, 2004 10:48 pm

Post by c52k » Thu Apr 22, 2004 11:59 am

/if no longer exists in the form it used to be. Shouldn't be too hard to update this script. I use it too, but haven't had time to work on it yet.
20 Apr 2004 by Lax:
- /if is now GONE. /if is now the same as what /newif was. /newif is aliased to /if.

Ketamine
orc pawn
orc pawn
Posts: 18
Joined: Thu Feb 26, 2004 4:12 pm

Post by Ketamine » Thu Apr 22, 2004 6:40 pm

Ok, really new to this and trying to figure this out... If I go through the whole macro and change all "/if" to "/newif" should that fix it? or do I need to tell it that everywhere it sees a "/if" to use "/newif". If thats the case how do I do that? Thanks

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Thu Apr 22, 2004 7:22 pm

Ketamine wrote:Ok, really new to this and trying to figure this out... If I go through the whole macro and change all "/if" to "/newif" should that fix it? or do I need to tell it that everywhere it sees a "/if" to use "/newif". If thats the case how do I do that? Thanks
In answer to your direct question, no. /if and /newif do the same damn thing now.
In answer to your I-didn't-try-to-figure-this-out unspoken question:

http://macroquest2.com/phpBB2/viewtopic.php?t=6179
http://macroquest2.com/phpBB2/viewtopic.php?t=6212
http://macroquest2.com/phpBB2/viewtopic.php?t=6022
http://macroquest2.com/phpBB2/viewtopic.php?t=6214

game_slave
orc pawn
orc pawn
Posts: 18
Joined: Wed Apr 21, 2004 6:50 pm

Post by game_slave » Thu Apr 22, 2004 9:01 pm

Ok. I have never seen nor worked with MacroQuest macro code before yesterday. Since I use and love this macro for foraging I have been trying to fix it as best as I can with what little knowledge I have. I didn't write any of this code. I have only tried to "fix" the broken code. I have spent hours searching through the forums and other people's code to try to figure this out. I have been able to get it to the point where it almost sorta works again. It watches the "Forage" button and forages whenever it pops. It seems to write to and read from the .ini file. The statistics sub that displays what you have foraged, destroyed, etc. does not display correctly. There are some array errors it seems as well. If someone wants to try to fix what I haven't been able to that would be great. I am going to keep working on it but at the rate I am going it's going to take days.................or longer. :p

I repeat. This is NOT properly working code yet!

Code: Select all

|----------------------------
| Forager v2.21
|
| Changes in 2.21:
|   
|   Only changes for compatability purposes
|   This macro is NOT working correctyl yet

#define INIFile "Forage.ini"

| Set the above define to the desired .ini file
| Requires a blank .ini file to start. The marco will
| populate the .ini file automatically for any zone
| and default to keeping the item. Then just change
| the values in the .ini file to 0 for an item to be
| automatically destroyed (requires FastItemDestroy
| be turned on in the options window)


Sub Main
   /declare EnableShowStats global
   /declare EnableWriteLog global
   /declare EnableClear global

| ##### User set variables #####
   /varset EnableShowStats 1        | Set to 1 to show foraging statistics
   /varset EnableWriteLog 0         | Set to 1 to write statistics to MQLog
   /varset EnableClear 0            | Set to 1 to clear before writing stats

| ##### User set variables #####
   /declare ForageAttempts global
   /declare ForageSuccess global
   /declare ForageFailure global
   /declare ForageKeeps global
   /declare ForageDestroys global
   /declare NumItem global
   /declare Index global
   /declare ItemArray array2

   /varset ForageAttempts 0
   /varset ForageSuccess 0
   /varset ForageFailure 0
   /varset ForageKeeps 0
   /varset ForageDestroys 0
   /varset NumItem 0

:Continue
   /delay 5
   /varset Index 0
   /if (${Me.State.NotEqual[STAND]}) {
      /stand
      /delay 5
   }

   /if (${Me.AbilityReady[Forage]}) {
      /doability Forage
      /delay 5
      /varadd ForageAttempts 1
      |/if (${cursor}=="NULL") {
      /if (${Cursor.ID}) {
      	/Echo Forage Success!
         /varadd ForageSuccess 1
         /call CheckItem
         /call HandleItem
         		   
     } else {
     		/Echo Forage Failure 
        /varadd ForageFailure 1 
      }   
      }
      /if (@EnableShowStats==1)  {
      	 /call ShowStats
      }	 
      /if (@EnableWriteLog==1) {
      	/call LogStats
   }
   }
   /goto :Continue

/return

| ########## Subroutines ##########

Sub LogStats
   /declare xy local
   /if @EnableClear==1 /mqlog clear
   /mqlog #############################################
   /mqlog Attempts: $int(@ForageAttempts), Success: $int(@ForageSuccess) [$int($calc(@ForageSuccess/@ForageAttempts*100))%]  Failures: $int(@ForageFailure) [$int($calc(@ForageFailure/@ForageAttempts*100))%]
   /mqlog Keeps: $int(@ForageKeeps) [$int($calc(@ForageKeeps/@ForageAttempts*100))%]  Destroys: $int(@ForageDestroys) [$int($calc(@ForageDestroys/@ForageAttempts*100))%]
   /mqlog [Idx] [Item] [Keep] [Qty] [%]
   /mqlog -------------------------------------------
   /if (n @NumItem>0) {
      /for xy 1 to @NumItem
      /mqlog [$int(@xy)] [@ItemArray(0,@xy)] [$int(@ItemArray(1,@xy))] [$int(@ItemArray(2,@xy))] [$int($calc(@ItemArray(2,@xy)/@ForageAttempts*100))%]
      /next xy
   }
/return

Sub ShowStats
   /declare xy local
  | /if (@EnableClear==1) /clear {
  /echo #############################################
  /echo For Zone: ${Zone}
  /echo Attempts = $int(@ForageAttempts)
  /echo Success  = $Int(@ForageSuccess)  [$int($calc(@ForageSuccess/@ForageAttempts*100))%]
  /echo Failures = $int(@ForageFailure)  [$int($calc(@ForageFailure/@ForageAttempts*100))%]
  /echo Keeps    = $int(@ForageKeeps)    [$int($calc(@ForageKeeps/@ForageAttempts*100))%]
  /echo Destroys = $int(@ForageDestroys) [$int($calc(@ForageDestroys/@ForageAttempts*100))%]
  /echo [Idx] [Item] [Keep] [Qty] [%]
  /echo -------------------------------------------
      /for xy 1 to @NumItem
      /echo [$int(@xy)] [@ItemArray(0,@xy)] [$int(@ItemArray(1,@xy))] [$int(@ItemArray(2,@xy))] [$int($calc(@ItemArray(2,@xy)/@ForageAttempts*100))%]
      /next xy
   }
/return

Sub CheckItem
/Echo CheckItem
   /declare xy local
   /if (@NumItem==0) {
      /varset NumItem 1
      /call AddToArray
      /varset Index 1
    } else {
      /for xy 1 to @NumItem
      /if @ItemArray(0,@xy)==${cursor} /varset Index @xy {
      /next xy
      /if @Index==0 {
         /varadd NumItem 1
         /call AddToArray
      } else {
         /varadd ItemArray(2,@Index) 1
      }
      }
   }
   
/return

Sub AddToArray
/Echo AddToArray
	 /varset ItemArray(0,@NumItem) ${Cursor}
	 /echo @NumItem
	 /echo @ItemArray(0,@NumItem)
   /varset ItemArray(1,@NumItem)
   $ini("INIFile","${zone.name}","$(cursor.name)")
   
   |/if (@ItemArray[1,@NumItem]==NOTFOUND)  {
      /newif (!${Ini[forage.ini,${Zone.Name},${Cursor}].Length}) {
      /varset ItemArray(1,@NumItem) 1
      /ini "INIFile" "${Zone.Name}" "${Cursor}" 1
   }
   /varset ItemArray(2,@NumItem) 1
/return

Sub HandleItem
/Echo HandleItem
   /if (@ItemArray(1,@Index)==0) {
      /varadd ForageDestroys 1
      /destroy
   } else {
      /varadd ForageKeeps 1
      /autoinv
   }
/return