hunter.mac simple hunt macro with loot capability.

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

Moderator: MacroQuest Developers

bardwithbadwrists
decaying skeleton
decaying skeleton
Posts: 6
Joined: Tue Jul 22, 2003 2:49 pm

Post by bardwithbadwrists » Mon Feb 23, 2004 2:25 pm

I noticed that the loot loop tends to destroy the 2nd item looted a few times per hour regardless of what it is... any idea why?

code4food
orc pawn
orc pawn
Posts: 24
Joined: Fri Feb 20, 2004 12:31 pm

Post by code4food » Mon Feb 23, 2004 2:41 pm

here's my tweaked version, roaming radial hunter w/ priority.

Code: Select all

| hunter.mac
| v3.1.c4f (adapted from grimjack's)
| Hunt script with loot for new loot parser.
| As always much of this script is inspired or taken directly from
| pieces of macro's found at macroquest2.com's macro depot
| Thank you to all the people who have donated their scripts which
| made this possible.  And thank you to the MQ developers.
|
| Edit  /varset Loot(0) "silk" and /varset Loot(1) "skin"
| Also edit /varset Mob(0) "widow" and /varset Mob(1) "wolf"
| You can also make these arrays bigger.  If you want to search for
| wolfs, widows and orcs you would have this
| /varset Mob(0) "widow"
| /varset Mob(1) "wolf"
| /varset Mob(2) "orc"
|
| What type of loot you want can be expanded in a similar way to
| the mobs you want to hunt.  
|
| C4F Modifications:
| -tweaked search pattern (and as a bonus has 'priority' as a side effect) to
|  look in ever increasing radius til it finds a suitable target
| -changed/added special attacks during combat sub
| -added respawn timeout wait timer, so if nothings found, it'll wait a bit
|  before searching again
| -paranoia random delay after each kill
| -automatic array size calculation
| -kill nearby, hostile "adds" (seems to work, let me know)
| -/autoinventory for keepers, and drops items on the ground otherwise.
| -NOTE: cause i'm paranoid about my hard earned gear, this script won't farm 
|  NO-DROP items for ya (yet, i might get around to tweaking the code to do so)

#turbo 90
#event AFKTell "AFK Message:"
#event InvFull "no room to put that!"
#event Died "you have entered"
#event Hostile "scowls at you, ready to attack"

Sub Main
   /echo $time() Starting $macro
   /declare MobToHunt global
   /declare Loot array
   /declare Mob array
   /declare MyXLOC global
   /declare MyYLOC global
   /declare KSRadius global
   /declare NotSee global
   /declare TooFar global
   /declare MyTarget global
   /declare TargetDead global
   /declare HasTarget global
   /declare ObstCount global
   /declare LootSlot global
   /declare CheckLoot global
   /declare LootTotal global
   /declare MobArraySize global
   /declare RangeMax global
   /declare RangeMin global
   /declare FastRange global

   /declare FailMax global
   /declare FailCounter global
   /declare RandomDelay global
   /declare CurrentTarget global
   /declare TargetSub global
   /declare CurrentRadius global
   /declare MaxRadius global
   /declare CombatClickie global
   /declare HostileNPC global

   /press esc
   /press esc
   /press esc
   /press esc
   /press alt
   /press shift
   /press ctrl

   /alert add 1 npc radius 20

   /varset FailMax 3
   /varset FailCounter 0
|set the max radius to hunt per cycle
   /varset MaxRadius 3000
| if you have a combat clickie you'd like to use, put the item name here
   /varset CombatClickie "Celestial Fists"

   /varset RangeMax 9
   /varset RangeMin 2
   /varset FastRange 11
   /varset LootSlot 0
   /varset CheckLoot 0

| Items to Loot
   /varset Loot(0) "silk"
   /varset Loot(1) "quality"
   /varset Loot(2) "snake egg"
|  /varset Loot(3) ""
|  /varset Loot(4) ""
|  /varset Loot(5) ""
|  /varset Loot(6) ""
|  /varset Loot(7) ""
|  /varset Loot(8) ""
|  /varset Loot(9) ""
|  /varset Loot(10) ""
|
| Targets to hunt - the lower subscript, the higher priority
   /varset Mob(0) "widow"
   /varset Mob(1) "wolf"
   /varset Mob(2) "spider"
   /varset Mob(3) "moccasin"
   /varset Mob(4) "tiger"
   /varset Mob(5) "leopard"
   /varset Mob(6) "snake"
   /varset Mob(7) "hopper"
   /varset Mob(8) "lion"
|  /varset Mob(9) ""
|  /varset Mob(10) ""

   /varset KSRadius 60
   /varset HasTarget 0
   /varset ObstCount 0
| finding size of Loot array
   /call ArraySize Loot
   /varset LootTotal $return
   /if LootTotal<0 {
    /echo Nothing specified to loot! Just hunting specified mobs.
   }
   /echo Loot pool size $calc(@LootTotal+1)

| finding size of mob array
   /call ArraySize Mob
   /varset MobArraySize $return
   /if MobArraySize<0 {
    /echo Nothing specified to hunt! (you do know what this script is supposed to do, right?)
    /endmacro
   }
   /echo Mob list has $calc(@MobArraySize+1) entries

   :Start
   /doevents
   /call GetTarget

:KillAdds
   /if @HasTarget=="1" /call MoveToMob
   /if @HasTarget=="1" /call CombatSub
   /if @HasTarget=="1" /call MoveToMob
   /if (@HasTarget=="1" && @LootTotal>=0) /call LootMob
   /call ResetSub

   /if $alert(1)==TRUE {
    /echo Looks like we have adds...
    /target npc radius 20
    /if $target(type)=="npc" {
     /varset MyTarget $target(id)
     /varset TargetDead 0
     /varset HasTarget 1
     /varset MobToHunt $target(name)
     /consider
     /delay 2
     /doevents
     /if @HostileNPC=="TRUE" {
      /echo time to die $target(name,clean)
      /goto :KillAdds 
     } else {
      /echo False Alarm 
      /call ResetSub
     }
    }    
   }
| Random wait after kill (up to 5 seconds)
   /varset RandomDelay $rand(5)
   /varcat RandomDelay "s"
   /echo Paranoia - Waiting @RandomDelay before resuming
   /delay @RandomDelay

   /goto :Start
/return



sub GetTarget
   :Acquire
   /for CurrentRadius 100 to @MaxRadius step 100 {
    /for TargetSub 0 to @MobArraySize {
     /target radius @CurrentRadius nopcnear @KSRadius npc "@Mob(@TargetSub)"
     /varset MyTarget $target(id)
     /varset TargetDead 0
     /if n $target(id)!=0 {
      /varset HasTarget 1
      /varset MobToHunt $target(name)
      /echo Acquired $target(name,clean) at range $target(distance) heading $target(direction)
      /return
     }
     /next TargetSub
    }
   /delay 2
   /next CurrentRadius
   }

   /if n $target(id)==0 {
    /delay 2s
    /varadd FailCounter 1
    /echo Failed to Acquire Target in range @MaxRadius @FailCounter times
    /if n @FailCounter>=@FailMax {
     /echo waiting for respawns, resetting failure count.
     /delay 60s
     /varset FailCounter 0
     }
    /goto :Acquire
   }
   /varset HasTarget 1
   /varset MobToHunt $target(name)
/return


Sub MoveToMob
   /face fast
   /if n $target(distance)>=@FastRange /call Fastmove
   /if n $target(distance)>@RangeMax {
      /press up
   }
   /if n $target(distance)<@RangeMin {
      /press down
   }
/return


Sub Fastmove
   /varset MyXLOC $char(x)
   /varset MyYLOC $char(y)
   /varset ObstCount 0
   :fastmoveloop
   /if $target()=="FALSE" {
      /sendkey up up
      /if $combat=="TRUE" {
         /attack off
         /return
      }
   }
   /face fast
   /if n $target(distance)>@FastRange {
      /sendkey down up
   }
   /if n $target(distance)<=@FastRange {
      /sendkey up up
      /return
   }
   /varadd ObstCount 1
   /if n @ObstCount>=3 {
      /call CheckObst
   }
   /goto :fastmoveloop
/return


sub CombatSub
   /if $target()=="FALSE" {
      /varset HasTarget 0
      /return
   }
   /attack on
   :combatloop
   /face fast
   /call SpecialIt
   /call MoveToMob
   /face fast
   /if n $target(id)==0 /varset TargetDead 1
   /if n @TargetDead!=1 /goto :combatloop
   /sendkey up up
   /delay 1s
   /target corpse
/return


sub LootMob
   /fastdrop on
   /lootn always
   /delay 2s
   /loot
   /look 128
   /delay 2s
| check and see if corpse is empty
   /if $corpse(empty)=="TRUE" { /echo empty corpse /goto :doneloot }
   :lootloop
   /if n @LootSlot>=9 /goto :doneloot
   /click left corpse @LootSlot
   /delay 1s
   /if "$cursor()"!="TRUE" /goto :doneloot
   :lootChecker
   /if "$cursor(name)"~~"@Loot(@CheckLoot)" {
      /delay 1s
      /echo Saving "$cursor(name)"
      /autoinventory
      /delay 1s
      /varadd LootSlot 1
      /goto :lootloop
   }
   /varadd CheckLoot 1
   /if "$cursor()"=="TRUE" {
      /if n @CheckLoot<=@LootTotal /goto :lootchecker
   }
   /if "$cursor()"=="TRUE" {
      /delay 1s
      /echo Attempting to Drop "$cursor(name)"
      /click left 0 0
      /delay 1s
      /if "$cursor()"=="TRUE" {
       /beep
       /echo could not drop "$cursor(name)" putting into inventory
       /autoinventory
      }
   }
   /varadd LootSlot 1
   /varset CheckLoot 0
   /goto :lootloop
   :doneloot
   /fastdrop off
   /look 0
   /varset LootSlot 0
| check for adds
   /target npc radius 10
   /if $target(type)=="npc" :goto KillAdds
/return


sub ResetSub
   /sendkey up up
   /press esc
   /press esc
   /press esc
   /press esc
   /press alt
   /press shift
   /press ctrl
   /varset CheckLoot 0
   /varset HasTarget 0
   /varset ObstCount 0
   /varset HostileNPC FALSE
   /delay 1s
/return


sub CheckObst
   /if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObst 5
   /varset MyXLOC $char(x)
   /varset MyYLOC $char(y)
   /varset ObstCount 0
/return


sub HitObst 
   /sendkey up up
   /sendkey down down
   /if n $rand(99)>50 {
      /delay 1s
      /sendkey up down
      /sendkey down Right
      /delay @Param0
      /sendkey up Right
      /sendkey down up
      /delay 2s
      /sendkey up up
   } else {
      /delay 1s
      /sendkey up down
      /sendkey down left
      /delay @Param0
      /sendkey up left
      /sendkey down up
      /delay 2s
      /sendkey up up       
   }
   /sendkey up down
   /sendkey up Right
   /sendkey up Left
   /sendkey down up
/return


Sub SpecialIt 
   /if ($char(class)==Rogue && n $char(ability,"Backstab")>0) {
      /if $target()=="TRUE" {
         /face fast
         /doability "Backstab"
      }
   }
   /if ($char(class)==Monk && n $char(ability,"Flying Kick")>0) {
      /if $target()=="TRUE" {
         /face fast
         /doability "Flying Kick"
      }
   }
   /if "@CombatClickie"!="" {
      /cast item "@CombatClickie"
   }
/return



| returns the last valid subscript of an array, returns -1 for failure or no size

Sub ArraySize(IncArray) 
 /declare ArrSize local
 /declare ArrayCounter local
 /if $defined(IncArray)!=FALSE {
  /varset ArrSize 0
   /for ArrayCounter 0 to 1 step 0 {
    /if "@@IncArray(@ArrSize)"=="UNDEFINED-ARRAY-ELEMENT" {
     /return $calc(@ArrSize-1)
    }
    /varadd ArrSize 1
   /next ArrayCounter
   }
 }
 /return -1



Sub Event_AFKTell 
/beep /delay 1s /beep 
/return



Sub Event_InvFull 
/beep /delay 1s
/beep /delay 2s
/beep /delay 1s
/beep 
/endmacro
/return

Sub Event_Hostile
/varset HostileNPC "TRUE"
/return

Sub Event_Died 
/declare BeepCounter local
/for BeepCounter 0 to 10 {
 /beep /delay 3
/next BeepCounter
}
/endmacro
/return 
edit: stupid smilies, and fix a small error in the loot subscript references.
edit2: no longer destroys items you're not looking for, just drops them on the ground.
edit3: editted kill adds stuff, should only attack nearby hostile creatures (let me know), and the empty corpse code doesn't work (but its more of a proper thing than a necessary for functional thing)
edit4: more tweaks, kill adds should work properly now. still can't be run AFK, no gm checking, and rarely you'll get a weird targetting race condition after you kill something but before you loot it when you have adds on you. /shrug. i'll work on it more tomorrow. let me know.

Wuwu
decaying skeleton
decaying skeleton
Posts: 1
Joined: Fri Feb 27, 2004 7:15 am

Post by Wuwu » Fri Feb 27, 2004 7:22 am

Got a small question, how MaxRadius work? Is it the max radius to the target from the character?

If not would it be possible to implemate so you only attack mobs say within 300 feet from you so you dont run all over the zone? How would this be done best?

Wuwu

code4food
orc pawn
orc pawn
Posts: 24
Joined: Fri Feb 20, 2004 12:31 pm

Post by code4food » Fri Feb 27, 2004 6:22 pm

your assumption is correct, maxradius is the max distance from your character that it will search. with the pause for respawn in there, you can also 'drive' over to a fresh spot for it start again in.

oneoneone
a lesser mummy
a lesser mummy
Posts: 30
Joined: Mon Jan 26, 2004 5:52 am

Post by oneoneone » Sat Feb 28, 2004 4:14 pm

Very well written macro. Is there any way someone could add a check to see if there are other corpses of the same type of mob you are hunting around and if there are, move to and loot them? Played around with it a bit and I wasnt able to get it to work. Thanks in advance. I've been using Code4Food's source on page 6.

bigt
decaying skeleton
decaying skeleton
Posts: 3
Joined: Sat Feb 28, 2004 3:02 am

Post by bigt » Sat Feb 28, 2004 9:57 pm

how could we add some thing that detects a gm on and if so /unloads
and if you die it /camp :shock:
eat your cheese

code4food
orc pawn
orc pawn
Posts: 24
Joined: Fri Feb 20, 2004 12:31 pm

Post by code4food » Sun Feb 29, 2004 8:59 pm

i might put in an alert if a GM is in zone, but its not intended for afk hunting, it still has serious issues with pathing and dealing with adds. it should camp out if you die (but i haven't had a chance to test it yet =p).

next revision is gonna be significant changes, different movement code (debating writing my own or using calls to someone else's), and using a stack for kill/adds/loot so it doesn't look as dumb. also gonna try to remove the race conditions that have cropped up in rare situations. might also toss in a destroy this list for items you don't want to be dropped, and a flag so it can hunt for nodrop items. when i have free time + motivation.

edit: and might add .ini support to have a 'generic' target/loot, and zone specific lists of mob/loot to hunt for.

Psychor
decaying skeleton
decaying skeleton
Posts: 1
Joined: Sat Mar 06, 2004 2:51 am

Post by Psychor » Sat Mar 06, 2004 2:54 am

I have been using this macro for a few days now, excellent piece of work.

Only one small mishap that i found out about, while hunting for some tradeskill components, i ran to a mob at range 1500, but meanwhile another player engaged that mob, i arrived and KS'ed him.

Maybe before starting to attack the mob a double PC check?

Zak
orc pawn
orc pawn
Posts: 28
Joined: Fri Mar 05, 2004 9:54 am
Contact:

Hiho!

Post by Zak » Sun Mar 07, 2004 4:15 am

I just started messing with this macro today, however here is what I have found. This macro will continue to run, even after you die lol, but it's not necessarily a bad thing. Just make sure you are bound in the zone you are running this macro in if possible. I do have a few questions / suggestions after running this macro for 5 hours on 2 different characters/classes.
First of all, is it possible to implement a conning system so that if the mob cons tombstone it will ignore it? Secondly, I was finding that more often than not, it was attacking mobs that are not in the list. Is this normal? Is it possible to make it only attack the mobs in the list? I would be tickled pink if I could kill everything But Griffawns in EK to see if it is possible to have every mob in EK be a griffawn.
Other than those 2 things, it is flawless as far as I can tell at this point. To be honest, I was jumping up and down shouting when I got it working, because I am such a newb at this stuff hehe. :oops:
Man without religion is like a fish without a bicycle

code4food
orc pawn
orc pawn
Posts: 24
Joined: Fri Feb 20, 2004 12:31 pm

Post by code4food » Tue Mar 09, 2004 11:03 pm

yup, need a double check in there, i'll toss it on the list of changes.
guess the died event isn't working right, should be camping you out after you die.
and engaging anything is either you being too generic in your mob list, or stuff triggering the add code, i'll check it out.

noober
a lesser mummy
a lesser mummy
Posts: 71
Joined: Mon Mar 08, 2004 4:09 pm

Post by noober » Sat Mar 13, 2004 2:04 am

CTD with this macro just now.

CyberCide
a lesser mummy
a lesser mummy
Posts: 41
Joined: Wed Mar 10, 2004 1:48 pm
Location: Here lurking

Post by CyberCide » Sat Mar 13, 2004 11:58 am

noober wrote:CTD with this macro just now.
What version are you using?

I just ran v3.1.c4f and it works fine.

Mutter
a ghoul
a ghoul
Posts: 105
Joined: Sat Nov 16, 2002 1:09 pm

Yep!

Post by Mutter » Sun Mar 14, 2004 12:16 pm

CTD here too.

inthrall
orc pawn
orc pawn
Posts: 13
Joined: Sun Mar 14, 2004 3:57 pm

Post by inthrall » Sun Mar 14, 2004 4:07 pm

has anyone else attempted to replace /target with /spawn? It seems to fail when attempting to move to the mob unless you actually target it.. and sometimes from across the zone. I'll post the changes ive made on request, but its by NO means pretty.

Also, I have not been able to figure out what the "normal" targeting radius is when its raining. I have been attempting to make this as human like as possible, but I'm not haveing much luck.

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Sun Mar 14, 2004 4:11 pm

inthrall wrote:has anyone else attempted to replace /target with /spawn?
Except for the fact that there is no /spawn command, it should work fine.