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

EvilB

ForageINI.mac a forage macro with ini support

Post by EvilB » Mon Oct 06, 2003 12:13 am

Yet another foraging macro.

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 "e:\macros\forage.ini"
#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 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
  /varset Index 0
  /call Forage
  /if "$cursor(name)"=="NULL" {
    /varadd ForageFailure 1
  } else {
    /varadd ForageSuccess 1
    /call CheckItem 
    /call HandleItem
    /beep
  }

  /if @EnableShowStats==1 /call ShowStats
  /if @EnableWriteLog==1 /call LogStats
  /delay @ForageDelay
  /goto :Continue

/return

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

Sub Forage
  /doability Forage
  /varadd ForageAttempts 1
  /delay 15
/return

Sub LogStats
  /declare xy local
  /call CalculateRates
  /if @EnableClear==1 /mqlog clear
  /mqlog #############################################
  /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 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
    /click left destroy
  } else {
    /varadd ForageKeeps 1
    /autoinv
  }
/return

sample ini file

Code: Select all

[Plane of Knowledge]
Habanero Pepper=1
Roots=1
Bookworm=1
Pod of Water=0

mekaniak
a hill giant
a hill giant
Posts: 290
Joined: Thu Sep 18, 2003 3:21 pm

Post by mekaniak » Mon Oct 06, 2003 12:52 am

Hey, thats really cool how you said to make just a blank .ini file and it will automatically populate it. Which part of the code writes to the .ini file?

EvilB

Post by EvilB » Mon Oct 06, 2003 1:06 am

Code: Select all

Sub AddToArray
    /varset ItemArray(0,@NumItem) "$cursor(name)" | puts the item on the cursor into the array
    /varset ItemArray(1,@NumItem) $ini("INIFile","$zone","$cursor(name)") | reads the ini file for the item on the cursor (actually looking to see if its a keep or destroy)
    /if "@ItemArray(1,@NumItem)"=="NOTFOUND" { | checks to see if their was a valid entry in the ini file
      /varset ItemArray(1,@NumItem) 1         | if not a valid entry adds the item to the array
      /ini "INIFile" "$zone" "$cursor(name)" 1  | if not a valid entry adds the item to the ini file

    }
    /varset ItemArray(2,@NumItem) 1

adds 1 to the count of the item

/return


mekaniak
a hill giant
a hill giant
Posts: 290
Joined: Thu Sep 18, 2003 3:21 pm

Post by mekaniak » Mon Oct 06, 2003 1:07 pm

thank you so very much.

mackster
a ghoul
a ghoul
Posts: 95
Joined: Mon Sep 09, 2002 3:02 pm

Post by mackster » Mon Oct 06, 2003 6:55 pm

This is pretty cool, I dig it. :D


Nm, I answered my own question :oops:

Jaerin
Developer
Developer
Posts: 133
Joined: Mon Mar 10, 2003 7:37 pm
Contact:

Post by Jaerin » Mon Oct 06, 2003 6:59 pm

Take out the /beep command.

Jaerin

Blade
decaying skeleton
decaying skeleton
Posts: 1
Joined: Tue Oct 07, 2003 8:29 pm

Remove unused code

Post by Blade » Wed Oct 08, 2003 12:54 pm

Remove the "/call CalculateRates" line in the LogStats subroutine as that subroutine does not exist.

Bio_War
a lesser mummy
a lesser mummy
Posts: 36
Joined: Sun Sep 29, 2002 1:03 pm

Logging

Post by Bio_War » Wed Oct 08, 2003 11:50 pm

ok, decided to try the logging for this, however, I find that right after it forages the first thing,, it ends the macro and says: "Ending Macro: Subroutine CalculateRates wasn't found.

if the following sub, it callls for calculateRates, but that sub is not in the macro

-------------------------------------------------------------------------

Code: Select all

Sub LogStats
  /declare xy local
  /call CalculateRates
  /if @EnableClear==1 /mqlog clear
  /mqlog #############################################
  /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
------------------------------------------------------------------------------

Bio_War

edit: Valerian likes code brackets.

AlphaBeta
a ghoul
a ghoul
Posts: 126
Joined: Sat Nov 09, 2002 12:35 am

Post by AlphaBeta » Fri Oct 17, 2003 1:18 pm

I thought I would try this script today and it seems to work well cept two things.

1. Items that are =0 in the .ini file sometimes are not destroyed like they should be.

2. The forage key seems to be on a timer and not looking for the button to refresh.

Also a nice feature in the .ini file would be a global zone to keep/destroy items found in every/most zones. Something like:

[Global]
Pod of Water=1
Roots=1
Vegetables=0
Fruit=0
Fishing Grubs=0
Rabbit Meat=0

[other zones here]
etc...

Lawyer
decaying skeleton
decaying skeleton
Posts: 4
Joined: Thu Oct 16, 2003 7:19 am
Contact:

Post by Lawyer » Fri Oct 17, 2003 1:53 pm

Yes, very nice macro. I ended up modifying the macro so it will work when you are sitting (so I can have this macro running all the time when I am playing). Now if you are sitting, instead of getting an error and fubaring the timer, the script checks to see if you are sitting, and if you are, stands you up-forages-sits you back down. If not, it goes on its normal business. The delay was also changed a minor bit to account for /stand. I dont know if it does make a difference, but it 1 second isnt a huge hit.

Modified code is bolded.

Code: Select all

:Continue 
  /varset Index 0 
  [b]/if "$char(state)"=="SIT" {
    /call SitForage
  } else {
    /call Forage
  }[/b]
  /if "$cursor(name)"=="NULL" { 
    /varadd ForageFailure 1 
  } else { 
    /varadd ForageSuccess 1 
    /call CheckItem 
    /call HandleItem 
    /autoinventory 
  } 
  if @EnableShowStats==1 /call ShowStats 
  /if @EnableWriteLog==1 /call LogStats 
  /delay @ForageDelay 
  /goto :Continue 

/return 

AlphaBeta
a ghoul
a ghoul
Posts: 126
Joined: Sat Nov 09, 2002 12:35 am

Post by AlphaBeta » Fri Oct 17, 2003 3:09 pm

Can anyone tell me why this macro won't distroy some things in the .ini file has set for =0? its driving me crazy :evil:

Ecchi_User
orc pawn
orc pawn
Posts: 18
Joined: Fri Aug 30, 2002 6:34 am

=/

Post by Ecchi_User » Mon Oct 20, 2003 3:55 am

Even with commenting out the CalculateRates, this macro does not distroy any itmes when said item is set to 0 in the ini file. Any items thats at 0, just get overwritten and put back to 1 the next time that foraged item comes back up.

Any ideas?

AzLiving
decaying skeleton
decaying skeleton
Posts: 2
Joined: Tue Oct 21, 2003 6:56 pm

Post by AzLiving » Sat Oct 25, 2003 8:11 am

1-
Last edited by AzLiving on Sun Nov 02, 2003 7:13 pm, edited 1 time in total.

millenium

what i do with this code?

Post by millenium » Mon Oct 27, 2003 5:06 pm

can somebody tell me what i need to do with this code, to makeit work in EQ? i am a very noob in this macro stuff.. thanks

mackster
a ghoul
a ghoul
Posts: 95
Joined: Mon Sep 09, 2002 3:02 pm

Re: what i do with this code?

Post by mackster » Tue Oct 28, 2003 1:38 pm

millenium wrote:can somebody tell me what i need to do with this code, to makeit work in EQ? i am a very noob in this macro stuff.. thanks
Um, have you compiled MacroQuest yet?