The forage code is structured as a subroutine so that it can be inserted into other macro event loops (meditation for example).
Code: Select all
|
| Common.inc (excerpt)
|
#event NoForage "#*#You fail to locate any food nearby#*#"
#event ForagedFood "#*#You have scrounged up some food#*#"
#event ForagedDrink "#*#You have scrounged up some water#*#"
#event ForagedDrink2 "#*#You have scrounged up some drink#*#"
#event ForagedBait "#*#You have scrounged up some fishing grubs#*#"
#event ForagedNonedible "#*#You have scrounged up something that doesn't look edible#*#"
#event StomacheFull "#*#You could not possibly eat any more#*#"
#event BladderFull "#*#You could not possibly drink any more#*#"
#event Consumed2 "#*#Ahhh#*#refreshing#*#"
#event Consumed "#*#Ahhh. That was#*#"
#event InvFull "#*#Inventory full, and item is NODROP#*#"
#event InvFull2 "#*#There was no place to put that!#*#"
/declare ForageDone bool outer
sub Forage
/if (!${Defined[ForageDone]}) /declare ForageDone bool global
/varset ForageDone false
/sit off
/doability Forage
/delay 1s
:WaitForIt
/doevents
/if (!${ForageDone}) /goto :WaitForIt
/return
sub Event_NoForage
/varset ForageDone true
/return
sub Event_ForagedFood
/call Foraged "Food" 1
/return
sub Event_ForagedDrink
/call Foraged "Drink" 2
/return
sub Event_ForagedDrink2
/call Foraged "Drink" 2
/return
sub Event_ForagedBait
/call Foraged "Bait" 0
/return
sub Event_ForagedNonedible
/call Foraged "Non-Edible", 0
/delay 5
/doevents
/varset ForageDone true
/return
sub Foraged(string ItemType,int Edible)
/declare ItemName string local
/declare ItemID int local
/declare Count int local
/declare MaxCount int local
/varset ItemID ${Cursor.ID}
/varset ItemName ${Cursor.Name}
/call CountItem ${ItemID}
/varset Count ${Macro.Return}
/popup Foraged ${ItemName}.
| Check the forage ini file for max item count. -1 indicates "keep none". If there's no entry an unlimited number of items are kept.
/if (${Ini[../Forage.ini,Items,${ItemName}]}) {
/if (${Ini[../Forage.ini,Items,${ItemName}]}==-1) {
/varset MaxCount 0
} else {
/varset MaxCount ${Ini[../Forage.ini,Items,${ItemName}]}
}
} else {
/varset MaxCount -1
}
| If no limit has been spec'd or the current count is less than the limit
/if (${Math.Calc[${MaxCount} == -1 || ${Count} < ${MaxCount}]}) {
/call KeepForagedItem
/varcalc Count ${Count}+1
/echo Foraged ${ItemType} (${ItemName}) have ${Count}
| otherwise, eat/drink it if we can, drop it if we can't
} else {
/echo Already foraged the limit (${MaxCount}) of ${ItemName}. Getting rid of it.
/if (${Edible}) {
/call EatItem "${ItemName}" ${Edible}
} else /if (${Cursor.NoDrop}) {
/echo Destroying ${ItemName}
| /destroy
/beep
/beep
/varset ForageDone true
} else {
/echo Dropping ${ItemName}
/drop
/varset ForageDone true
}
}
/return
sub KeepForagedItem
/notify InventoryWindow IW_CharacterView leftmouseup
/delay 5
/doevents
/varset ForageDone true
/return
sub EatItem
/if (${Param1}==1) {
/echo Eating ${Param0}
} else /if (${Param1}==2) {
/echo Drinking ${Param0}
}
/itemnotify pack8 leftmouseup
/itemnotify pack8 rightmouseup
/itemnotify pack8 leftmouseup
/delay 1s
/doevents
/return
sub Event_StomacheFull
/echo I'm full. Dropping ${Cursor.Name}
/drop
/varset ForageDone true
/return
sub Event_InvFull
/echo Inventory Full. Destroying ${Cursor.Name}
| /destroy
/beep
/beep
/varset ForageDone true
/return
sub Event_InvFull2
/echo Inventory full. ${Cursor.Name} was dropped.
/varset ForageDone true
/return
sub Event_BladderFull
/echo I'm full. Dropping ${Cursor.Name}
/drop
/varset ForageDone true
/echo Debug - Event_BladderFull - ForageDone=${ForageDone}
/return
sub Event_Consumed
/varset ForageDone true
/echo Debug - Event_Consumed - ForageDone=${ForageDone}
/return
sub Event_Consumed2
/varset ForageDone true
/echo Debug - Event_Consumed2 - ForageDone=${ForageDone}
/return
Code: Select all
|
| Forageloop.mac
|
#include Common.inc
Sub Main
:Loop
:WaitForIt
/if (!${Me.AbilityReady[Forage]}) {
/delay 20s
/doevents
/popup Waiting to forage
/goto :WaitForIt
}
/doevents
/echo Foraging
/call Forage
/goto :Loop
/echo Done Foraging
/endmacro