yaf.mac - Yet another forage.mac

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

Moderator: MacroQuest Developers

felidae
decaying skeleton
decaying skeleton
Posts: 1
Joined: Sun Jan 11, 2004 1:45 pm

yaf.mac - Yet another forage.mac

Post by felidae » Sun Jan 11, 2004 1:54 pm

Mostly this was just a refactoring.

Code: Select all

| 
| This is an obvious child of the forage.mac.
|
| There are only a couple functional enhancements:
|
|	- This uses no keyboard based commands so it can run without mouse focus.
|	- Some basic detection avoidence is added, based only on second hand information.
|
| The weak points are:
|
|	- Less configurable
|	- less stats maintained.
|

#define INIFile "forage.ini"

#chat tell
#turbo

Sub Main
  /zapvars
  /declare Attempts global
  /declare Stats array2
  /declare Forage timer
  /declare Break timer

  /cleanup

  /call StatsInit
  /varset Forage 1
  /varset Break 35m

  :Continue
  	/if "$gm"=="TRUE" {
		/mqlog GM!
		/call CampOut
  	}
	/doevents
	/delay 1s

  /goto :Continue

/return

|
| Deal with our two timers
|
Sub Event_Timer(Timer,OrigValue)
	/if "@Timer"=="Forage" /call Forage
	/if "@Timer"=="Break" /call Break
/return

|
| Deal with tells

|
Sub Event_Chat(ChatType,Sender,ChatText) 
	/mqlog Tell @Sender says @ChatText 
	/delay 10s
	/tell "@Sender" think I doozed off foraging I'm gonna log.
	/call CampOut
/return

|
| Forage sub that gets called when timer even expired
|
Sub Forage
	/varset Forage 101s 		| Reset timer
	/varadd Forage $rand(20) 	| Add in some randomness might help avoid detection

  	/if "$char(state)"=="SIT" /sit 
	/varadd Attempts 1
	/echo Foraging, attempt: $int(@Attempts)
	/doability Forage
	/delay 15
	/if "$cursor(name)"=="NULL" {
		/echo Nothing found.
	} else {
                /echo Got a $cursor(name)!
		/call StatsUpdate "$cursor(name)" @Attempts
		/call KeepTest "$cursor(name)"
		/if n $return==1 {
		   /echo Keeping it.
		   /beep 
		   /autoinv
		} else {
		   /echo Destroying it.
		   /destroy
		}
	}
/return

|
| Take a break at least one an hour to avoid hour limit SOE supposedly watches
|
Sub Break
	/varset Break 40m 		| Reset timer
	/varadd Break $rand(10)m  	| Add in some randomness might help avoid detection
	/varadd Forage 5m 		| Stop foraging for a bit  might help avoid detection
	/echo take a brief break
	/sit 
/return

| 
| Look in the ini file to see if we keep a foraged item
|
Sub KeepTest(Item)
	/declare entry local
	/varset entry $ini("INIFile","$zone","@Item")
	/if "@entry"=="NOTFOUND" {
		/echo @Item is a new item!
		/varset entry 1
		/ini "INIFile" "$zone" "@Item" @entry
	}
/return @entry

| 
| Initialize the stats array. The first row of the matrix stores meta data
|
Sub StatsInit
	/varset Stats(0,0) "NULL" 	| A value that wont match any foraged item
	/varset Stats(0,1) 0		| Number of unigue items with rows in matrix
	/varset Stats(0,2) 0		| Number of successful forages
/return

|
| Update the statistics
|
Sub StatsUpdate(Item, Attempts)
	/declare x local
	/declare found local

	/varadd Stats(0,2) 1

	/echo Forage Success Rate: $int(@Stats(0,2)/@Attempts*100)%

	/varset found 0
	/for x 0 to @Stats(0,1)
		/if "@Stats(@x,0)"=="@Item" {
			/varset found 1
			/varadd Stats(@x,1) 1
		}
	/next x

	/if n @found==0 {
		/varadd Stats(0,1) 1
		/varset Stats(@Stats(0,1),0) "@Item"
		/varset Stats(@Stats(0,1),1) 1
	}

	/echo ====================================
	/for x 1 to @Stats(0,1)
		/echo @Stats(@x,0): $int(@Stats(@x,1)) [$int($calc(@Stats(@x,1)/@Stats(0,2)*100))%]
	/next x
	/echo ====================================
/return

| 
| Camp out
|
Sub CampOut 
   /if "$char(state)"=="STAND" /sit 
   /camp desktop 
   /endmacro
/return