Forager.mac - A forage macro with ini support *MQ2DataTypes*

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

Moderator: MacroQuest Developers

NotHere
a lesser mummy
a lesser mummy
Posts: 40
Joined: Fri Jan 09, 2004 5:59 am

Forager.mac - A forage macro with ini support *MQ2DataTypes*

Post by NotHere » Mon Apr 26, 2004 1:19 am

Heya.

EvilB no longer seems to be around (his login to the board no longer exists), I have taken the liberty of updating his excellent foraging script to support MQ2DataTypes.

This is a line-by-line conversion of the original at http://macroquest2.com/phpBB2/viewtopic.php?t=3272, with a few changes. I modified it to use /destroy, so no need to have Fast Item Destroy enabled in EQ, and I fiddled abit with the columns in the statistics.

If you have any problems with the script, or perhaps ideas for improvement, please post below and I'll try and help as best I can.

Code: Select all

| ---------------------------- 
| FORAGER.MAC
| Forager with ini file support and statistic gathering and reporting 
| Version 2.2
| 
| Originally posted by EvilB
| Updated to MQ2DataTypes by NotHere
|
| 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.
#define IniFile "Forager.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 1            | 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 

  /echo Forager.mac running    
:Continue 
  /doevents 
  /varset Index 0 
  /if (${Me.Sitting}) { 
      /stand 
      /delay 3 
  } 
  /if (${Me.AbilityReady[Forage]}) { 
     /doability Forage 
     /varadd ForageAttempts 1 
     /delay 15 
     /if (${Cursor.ID}) { 
       /varadd ForageSuccess 1 
       /call CheckItem 
       /call HandleItem 
|       /beep 
     } else { 
       /varadd ForageFailure 1 
     } 
  } 
  /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 (${String[@IniList].Find[|]}) { 
      /varset IniPosition 0 
      :CheckGlobalForage 
         /varadd IniPosition 1 
         /varadd NumItem 1 
         /varset ItemArray(0,@NumItem) "${String[@IniList].Arg[@IniPosition,|]}"
         /varset ItemArray(1,@NumItem) ${Ini[IniFile,Global,@ItemArray(0,@NumItem)]} 
         /varset ItemArray(2,@NumItem) 0 
      /if (${String[@IniList].Arg[${Math.Calc[@IniPosition+1].Int},|].Length}>0) /goto :CheckGlobalForage 
   } 
   /varset IniList "${Ini[IniFile,${Zone.Name}]}"
   /if (${String[@IniList].Find[|]}) { 
      /varset IniPosition 0 
      :CheckZoneForage 
         /varadd IniPosition 1 
         /varadd NumItem 1 
         /varset ItemArray(0,@NumItem) "${String[@IniList].Arg[@IniPosition,|]}"
         /varset ItemArray(1,@NumItem) ${Ini[IniFile,${Zone.Name},@ItemArray(0,@NumItem)]} 
         /varset ItemArray(2,@NumItem) 0 
      /if (${String[@IniList].Arg[${Math.Calc[@IniPosition+1].Int},|].Length}>0) /goto :CheckZoneForage 
   } 
/return 

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

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


Sub CheckItem 
  /declare xy local 
  /if (@NumItem==0) {
    /echo FIRST ITEM! 
    /varset NumItem 1 
    /call AddToArray 
    /varset Index 1 
  } else { 
    /for xy 1 to @NumItem 
      /if (${String[@ItemArray(0,@xy)].Equal[${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.Name},${Cursor.Name},-1]}
    /if (@ItemArray(1,@NumItem)<0) { 
      /varset ItemArray(1,@NumItem) 1 
      /ini "IniFile" "${Zone.Name}" "${Cursor.Name}" 1 
    } 
    /varset ItemArray(2,@NumItem) 1 
    /varset Index @NumItem
/return 

Sub HandleItem 
  /if (@ItemArray(1,@Index)==0) { 
    /echo ${Cursor.Name} should be destroyed. 
    /varadd ForageDestroys 1 
    /destroy 
  } else { 
    /echo ${Cursor.Name} should be kept. 
    /varadd ForageKeeps 1 
    /autoinv 
  } 
/return 
Sample Ini:

Code: Select all

[Skyfire Mountains]
Fishing Grubs=1
[The Plane of Water]
Large Brine Shrimp=0
Cluster of Kelp=1
Pod of Water=1
PLEASE NOTE!

If you use this with an existing ini, it seems that MQ2 now returns zone names in a slighty different way. The script will then add a new zone to the bottom of the ini file, and populate that new zone with items. If you want to use your old item data, simply rename the old zone definition to the name of the new zone, and delete the new one.
NotHere
/afk

mukluk123
decaying skeleton
decaying skeleton
Posts: 2
Joined: Sun Feb 15, 2004 10:55 am

doesnt destroy

Post by mukluk123 » Mon Apr 26, 2004 4:39 pm

everything looks good except it doesnt detroy anything on the list. it shows up in the stats as being an item to destoy but it auto inventories everything

NotHere
a lesser mummy
a lesser mummy
Posts: 40
Joined: Fri Jan 09, 2004 5:59 am

Post by NotHere » Tue Apr 27, 2004 12:45 am

That sounds strange.

I left it running for 8 hours straight yesterday, and it destroyed all the items I had configured it to destroy, then kept the rest.

Could you post the part of the .ini that contains the zone you have problems with?
NotHere
/afk

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

tip

Post by Calon » Tue Apr 27, 2004 12:52 pm

Perhaps you should change this:

Code: Select all

#define IniFile "Forager.ini" 

#Event ZoneChange "Loading please wait" 

#turbo 
to

Code: Select all

#define IniFile "Forager.ini" 

#Event ZoneChange [color=red]"LOADING, PLEASE WAIT..."[/color]

#turbo 

ImaNoob
a ghoul
a ghoul
Posts: 89
Joined: Mon Mar 08, 2004 4:37 am

Added hiding

Post by ImaNoob » Tue Apr 27, 2004 4:45 pm

Added hiding and now it looks like this

Code: Select all

| ---------------------------- 
| FORAGER.MAC 
| Forager with ini file support and statistic gathering and reporting 
| Version 2.2 
| 
| Originally posted by EvilB 
| Updated to MQ2DataTypes by NotHere 
| 
| 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. 
#define IniFile "Forager.ini" 

#Event ZoneChange "LOADING, PLEASE WAIT..." 
#Event NotHidden "You stop hiding"
#Event Moved "You have moved and are no longer hidden!!"
#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 1            | 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 

  /echo Forager.mac running
  /if (${Me.AbilityReady[Hide]}) {
	/doability Hide
  }
    
:Continue 
  /doevents 
  /varset Index 0 
  /if (${Me.Sitting}) { 
      /stand 
      /delay 3 
  } 
  
  
  /if (${Me.AbilityReady[Forage]}) { 
     /doability Forage 
     /varadd ForageAttempts 1 
     /delay 15 
     /if (${Cursor.ID}) { 
       /varadd ForageSuccess 1 
       /call CheckItem 
       /call HandleItem 
|       /beep 
     } else { 
       /varadd ForageFailure 1 
     }
     /if (@EnableWriteLog==1) /call LogStats 
     /if (@EnableShowStats==1) /call ShowStats 
  }
  
  
  /goto :Continue 
/return 

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

Sub Event_NotHidden
  /delay 10s
  /if (${Me.AbilityReady[Hide]}) {
	/doability Hide
  }
/return

Sub Event_Moved
  /delay 10s
  /if (${Me.AbilityReady[Hide]}) {
	/doability Hide
  }
/return
 
Sub LoadFromIni 
   /varset NumItem 0 
   /declare IniPosition local 
   /declare IniList local 
   /declare tmpItem local 
   /varset IniList "${Ini[IniFile,Global]}" 
   /if (${String[@IniList].Find[|]}) { 
      /varset IniPosition 0 
      :CheckGlobalForage 
         /varadd IniPosition 1 
         /varadd NumItem 1 
         /varset ItemArray(0,@NumItem) "${String[@IniList].Arg[@IniPosition,|]}" 
         /varset ItemArray(1,@NumItem) ${Ini[IniFile,Global,@ItemArray(0,@NumItem)]} 
         /varset ItemArray(2,@NumItem) 0 
      /if (${String[@IniList].Arg[${Math.Calc[@IniPosition+1].Int},|].Length}>0) /goto :CheckGlobalForage 
   } 
   /varset IniList "${Ini[IniFile,${Zone.Name}]}" 
   /if (${String[@IniList].Find[|]}) { 
      /varset IniPosition 0 
      :CheckZoneForage 
         /varadd IniPosition 1 
         /varadd NumItem 1 
         /varset ItemArray(0,@NumItem) "${String[@IniList].Arg[@IniPosition,|]}" 
         /varset ItemArray(1,@NumItem) ${Ini[IniFile,${Zone.Name},@ItemArray(0,@NumItem)]} 
         /varset ItemArray(2,@NumItem) 0 
      /if (${String[@IniList].Arg[${Math.Calc[@IniPosition+1].Int},|].Length}>0) /goto :CheckZoneForage 
   } 
/return 

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

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


Sub CheckItem 
  /declare xy local 
  /if (@NumItem==0) { 
    /echo FIRST ITEM! 
    /varset NumItem 1 
    /call AddToArray 
    /varset Index 1 
  } else { 
    /for xy 1 to @NumItem 
      /if (${String[@ItemArray(0,@xy)].Equal[${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.Name},${Cursor.Name},-1]} 
    /if (@ItemArray(1,@NumItem)<0) { 
      /varset ItemArray(1,@NumItem) 1 
      /ini "IniFile" "${Zone.Name}" "${Cursor.Name}" 1 
    } 
    /varset ItemArray(2,@NumItem) 1 
    /varset Index @NumItem 
/return 

Sub HandleItem 
  /if (@ItemArray(1,@Index)==0) { 
    /echo ${Cursor.Name} should be destroyed. 
    /varadd ForageDestroys 1 
    /autoinv
  } else { 
    /echo ${Cursor.Name} should be kept. 
    /varadd ForageKeeps 1 
    /autoinv 
  } 
/return 
Probably an easier and cleaner way to stay hidden, but without a proper readme on the new datatypes, I'm a little clueless on how to tell if your hidden or not.

NBarnes
orc pawn
orc pawn
Posts: 19
Joined: Wed Jan 28, 2004 10:46 pm

Post by NBarnes » Sat Jun 12, 2004 5:22 am

When I attempt to run this, I get

/declare 'ForageDelay' failed. Name already in use.
Forager.mac@17 (Main): /declare ForageDelay global

Code: Select all

/declare 'EnableShowStats' failed.  Name already in use.
Forager.mac@18 (Main): /declare EnableShowStats global
[code]/declare EnableWriteLog' failed.  Name already in use.
Forager.mac@19 (Main): /declare EnableWriteLog global
[code]/declare 'EnableClear' failed.  Name already in use.
Forager.mac@20 (Main): /declare EnableClear global

 And then the same again for lines 30 through 36 (but [i]not[/i] 37).  Does anybody know why this would be happening?  It seems very strange to me that this would be failing like this on a macro that other people are using successfully.

Drumstix42
a grimling bloodguard
a grimling bloodguard
Posts: 808
Joined: Mon May 03, 2004 4:25 pm

Post by Drumstix42 » Sat Jun 12, 2004 2:26 pm

Firstly, this is the old Macro Database...

NBarnes
orc pawn
orc pawn
Posts: 19
Joined: Wed Jan 28, 2004 10:46 pm

Post by NBarnes » Sat Jun 12, 2004 8:08 pm

....

Oh. Uh... thanks.

*blush*