My old hunter script no works! Need help

Macro depository for macros written before the user variable changes that broke all of them.

Moderator: MacroQuest Developers

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

My old hunter script no works! Need help

Post by Mutter » Tue Sep 09, 2003 10:57 am

When I run it..it kinda just go nuts for a sec and then bombs out. Used to work but has been quite awhile! (this script is very sweet btw when works)
Is a modification of the original hunter script, with a lot of work from myself and others. It does camps etc, it always returns home, it can pull mobs to a spot before attacking, and it has some VERY primitive caster/pet commands(about %30) done on that...
If anyone could spot where i screwed up I'd preciate it.

Code: Select all

| Hunter.mac
|
| The ultimate melee class.zone farming script
|
#turbo
#include routines.mac
#include spellsub.mac
#define LootTotal v50
#define KSRadius v51
#define NoLOS v38
#define TooFarAway v39
#define MyTarget v40
#define MyHeading v41
#define TargetHeading v42
#define HeadingDelta v43
#define TargetDead v44
#define MyXLoc v46
#define MyYLoc v47
#define KSCheck v49
#define TargetLooted v52
#define LootSlot v54
#define CheckLoot v55
#define AttackedMe v56
#define BackHome v57
#define HomeY v58
#define HomeX v59
#define Attacker v60
#define myrandom v61
#define startlevel v64
#define endlevel v65
#define mobname v66
#define mobid v67
#define bandagedone v68
#define MobLevel v69
#define Realtarget v70
#define CastTimer v71
#define OutRange v72
#define ShieldGone v73
#define spCost v74
#define kRadius v75
#define ipulled v76

#event CannotSee "You cannot see your target"
#event TooFar "Your target is too far away"
#event HitsYou "YOU for"
#event Zoneing "LOADING"
#event Bandagedone "The bandaging is complete"
#event Bandagefail "bandage has failed"
#event Bandageout "buy some"
#event NoBandages "You can't bandage without bandages, go buy some."
#event Bandage50 "cannot bandage your target"
#Event ClarityGone "Your mind returns to normal."
#event OutofRange "Your target is out of range"
#event Buffoff "Your shielding fades" |for my chanter :)
#Event CorpseTime "This corpse will decay in 0"
#Event Looted "--You have looted a "


sub Main
   /zapvars
   /mqlog Hunter script v 20021007a started
   | Set up List of Loot to keep
   | Set KS radius below. The script will not target a mob if a PC is within this radius of it.
   /varset KSRadius 500
   | Set Loot nodrop
   /lootn never
   /loc
   /varset HomeX $char(x)
   /varset HomeY $char(y)
   /varset kRadius $int($p0)
   /delay 5
   /alert clear 4
   /mqlog Home Point is $HomeX, $HomeY
   /press esc
   /press esc
   /press esc
   /press esc
   /press alt
   /press shift
   /press ctrl
   /doevents
   /varset ShieldGone 1
| Start of main Loop
|
        /stand
        /delay 2
        /if n $kRadius==0 /varset kRadius 500
        :Start
           /call makernum 5
           /if n $target(id)==$char(id) /endmacro
           /call getstart $p1
           /doevents
           | RestUp
           /if n $target(id)==0 /call RestUp
           /if n $target(id)==0 /call SetAlerts
           | Aquire nearest target to attack
           /if "$combat"=="TRUE" /stand
           /call GetTarget
           | Advance
           /call Advance
           /delay 5
           |/call AutoLoot
           /press esc
           /doevents
           /if n $distance($HomeY,$HomeX)>500 {
           	/varset HomeX $char(x)
   		/varset HomeY $char(y)
           }
           /if n $target(id)==0 /call HomeBase
           /doevents
           /if n $target(id)==0 /delay $myrandom
        /goto :Start

/return

| RestUp
sub RestUp
   /varset AttackedMe 0
   /doevents
   |if fighting get the F out of rest mode
   /if "$combat"=="TRUE" /goto :NoRest
   /if n $target(id)!=0  /goto :NoRest
   /doevents
   /varset bandagedone 1
   /if n $target(id)==0 {
   /sit on |sit when we are not doing anything
   /if n $char(hp,pct)>65 /goto :Healthy
   :Rest
        | Check if something has aggroed and attack it if it has.
        /if n $AttackedMe==1 {
                 /mqlog aggroed whilst sitting
                 /stand
                 /goto :NoRest
        }
        /doevents
        |if fighting get the F out of rest mode
        /if "$combat"=="TRUE" /goto :NoRest
        /if n $target(id)!=0  /goto :NoRest
        /if n $int(bandagedone)<2 {
	        /if n $int($char(hp,pct))<45 { |Changed from 49, waste of bandages for 1 percent
	        		/if $char(ability,"Bind Wound")>0 {
					/target myself
					/doability "Bind Wound"
					:waitband
					/doevents
					/delay 2
					/if n bandagedone!=1 /goto :waitband
					/stand
					/press esc
				}
		/doevents
				
	        }
	}
        /doevents
	/if n $char(hp,pct)<65 /goto :Rest
        /mqlog Hps at $char(hp,pct) Off hunting again
        /stand
}
:Healthy
/sit on
:NoRest
/doevents
/stand
/return

sub GetTarget
      :Acquire
      /doevents
      /if AttackedMe==1 {
         /mqlog Targeted "$v13" who jumped me
         /target "$v13"
         /varset AttackedMe 0
      } else /if "$alert(1)"=="TRUE" {
         /target npc alert 1 notnearalert 4 nopcnear $KSRadius
         /mqlog Targeted $target(name) range $target(distance) on alert list 1
      } else /if "$alert(2)"=="TRUE" {
         /target npc alert 2 notnearalert 4 nopcnear $KSRadius
         /mqlog Targeted $target(name) range $target(distance) on alert list 2
      } else /if "$alert(3)"=="TRUE" {
         /target npc alert 3 notnearalert 4 nopcnear $KSRadius
         /mqlog Targeted $target(name) range $target(distance) on alert list 2
      } else {
        /target npc radius $kRadius range $startlevel $endlevel notnearalert 4 nopcnear $KSRadius
        /doevents
        /delay 5
      }
      /varset MyTarget $target(id)
      /varset TargetDead 0
      /doevents
      /delay 0
      /if n $target(id)==0 /goto :Acquire
      /face nopredict
/return


| Advance to mob subroutine
sub Advance

	:Engage
		/doevents
		|Work on sense heading skill
		/if $char(ability,"Sense Heading")>0 /doability "Sense Heading"
		| Turn towards target
		/face | nopredict
		| If we are not within melee range then make sure we are on autorun
		/if n $target(distance)>15 /call autorun2 1
		| If we are still a distance away from target search for a closer one
		/if n $target(distance)>200 {
			/call GetTarget
		}
		/if n $target(distance)>15 {
			| Save our current x,y loc
			/varset MyXLoc $char(x)
			/varset MyYLoc $char(y)
			| Wait a then check loc again if we are on same spot call the obstacle routine to try and get around it
			/delay 1
			/if n $MyXLoc==$char(x) /if $MyYLoc==$char(y) /call Obstacle
		}
		| If we are within melee range stop running check Target again for other players engaged and attack if all OK.
		/if n $target(distance)<=15 {
			/mqlog In melee range
			/call autorun2 0
			/varset KSCheck $target(id)
			/if AttackedMe!=1 {
				/call GetTarget
				/if n $KSCheck==$MyTarget /call kickass |removed old combat loop was redundant.
			}
			/if AttackedMe==1 /call kickass |screw KS, if it hits us we kill it.
			/delay 0
		}
		/doevents
		/delay 5
		/if n $target(id)==0 /varset TargetDead 1
		/if n $TargetDead!=1 /goto :Engage
		/mqlog Target is dead
		/varset ipulled 0
/return

Sub kickass
	/echo Fighting $target(name). It is level $target(level).
	/face
	/attack on
	/if "$combat"=="TRUE" {
		/if $int($ipulled)==0 { |Have we pulled this sucker home yet? If not take it to camp
			/call homebase
			/varset ipulled 1
		}
		/call doskills |put all yer kicks punches and other misc skills here
		/if n $int($target(speed)==0{
			/if "$char(class)"=="Enchanter" /call docombatspells |my chanter uses this a bit. madify to suit your need
		}
		/if n $TargetDead==1 /attack off
	/return
	
Sub AutoLoot
	/target id $MyTarget |moved here so if you do NOT want to use looting does not screw you up
	:getcorpse
	/if "$combat"=="TRUE" /return
	/doevents
	/delay 1
	/face
	/if n $target(distance)<11 /goto :LootCorpse
	/sendkey down up
	/if n $target(distance)>11 /goto :getcorpse
	:FaceCorpse
		/delay 0
		/face
	:LootCorpse
		/sendkey up up
		/loot
		/delay 10
		/varset v3 0

	:Looting
		/delay 0
		/varset v5 $v3
		/click left corpse $v3
		/delay 5
		/doevents
		/echo $cursor(name)
		/if $cursor()==TRUE /call DL "$cursor(name)"
		/echo return is $return on $cursor(name)
		/delay 3
		/if n $int($return)==0 /click left destroy
		/delay 3
		/if n $int($return)==1 /click left auto
		/delay 3
		/if n $v3>$v5 /goto :Looting

	:Continue
		/varset v4 0
		/if $cursor()==TRUE /call DL "$cursor(name)"
		/delay 3
		/if n $int($return)==0 /click left destroy
		/if n $int($return)==1 /click left auto
		/delay 10
	:destroy
		/left click auto
		/delay 3
		/if $cursor()==TRUE /goto :destroy
		/press esc
	/target corpse radius $kRadius
	/if n $target(id)!=0 /goto :getcorpse
	/return
	
Sub DL
	/if "$p0"~~"pad" {
	/return 1
	} else /if "$p0"~~"Headdress" {
	/return 0
	} else /if "$p0"~~"Belt" {
	/return 1
	} else /if "$p0"~~"Head" {
	/return 1
	} else /if "$p0"~~"Silk" {
	/return 1
	} else /if "$p0"~~"Velium" {
	/return 1
	} else /if "$p0"~~"Backbone" {
	/return 1
	} else /if "$p0"~~"Stein" {
	/return 1
	} else /if "$p0"~~"Blood" {
	/return 1
	} else /if "$p0"~~"Oxide" {
	/return 1
	} else /if "$p0"~~"Diamond" {
	/return 1
	} else /if "$p0"~~"Ruby" {
	/return 1
	} else /if "$p0"~~"Pearl" {
	/return 1
	} else /if "$p0"~~"Emerald" {
	/return 1
	} else /if "$p0"~~"Meat" {
	/return 1
	} else /if "$p0"~~"Rib" {
	/return 1
	} else /if "$p0"~~"Saphire" {
	/return 1
	} else /if "$p0"~~"Saphire" {
	/return 1
   } else {
      /if n $int($cursor(value)) >999 /return 1
      /return 0
   }
/return

sub HomeBase

   /mqlog Heading Home

   :RunHome

         |Process any events
         /doevents

         |Work on sense heading skill
         /if $char(ability,"Sense Heading")>0 /doability "Sense Heading"

         |Check if we have aggroed something and stop running home if we have
         /if n $AttackedMe==1 {
            /mqlog $v13 Atacked be on the way home
            /return
         }

         | Turn towards target
         /face loc $HomeY,$HomeX

         | If we are not within melee range then make sure we are on autorun
         /if n $distance($HomeY,$HomeX)>15 /call autorun2 1

         | Save our current x,y loc
         /varset MyXLoc $char(x)
         /varset MyYLoc $char(y)

         | Wait a then check loc again if we are on same spot call the obstacle routine to try and get around it
         /delay 1
         /if n $MyXLoc==$char(x) /if $MyYLoc==$char(y) /call Obstacle
         /if n $distance($HomeY,$HomeX)<15 {
            /mqlog Reached Home
            /call autorun2 0
            /varset BackHome 1
            /if n $target(id)==0 /face loc $MyYLoc,$MyXLoc
         }
         /delay 0
        /if n $BackHome!=1 /goto :RunHome
   	/varset BackHome 0

/return 1

sub Obstacle

   | We appear to be stuck so try and backup and strafe sideways
   /mqlog Ouch! ran into something
   /sendkey up up
   /sendkey down down
   /call makernum 5
   /delay $myrandom
   /doevents
   /sendkey up down
   /sendkey down ctrl
   /if n $rand(99)>50 {
      /sendkey down right
   } else {
      /sendkey down left
   }
   /delay $myrandom
   /doevents
   /sendkey up right
   /sendkey up left
   /sendkey up ctrl
   /sendkey down up
/return

sub AvoidLoc
| Pass in 3 numbers first two are the Y and X locs of the point to avoid third one is the distance you want to keep from it.
| This sub will check if you are within the distance specified and turn you away from the loc and run you until you are the correct
| distance away. Too many calls to this sub will slow your main loop down badly so keep the areas large and infrequent for best results.
| i.e. if there are a few huts together set a loc and radius that will cover the whole area rather than each individual hut.

/if n $distance($p0,$p1)>$p2 /goto :OK
    /mqlog close to $p0 $p1
    /if n $calc($heading($p0,$p1)-$char(heading)<0 {
       /face heading $calc($heading($p0,$p1)-95)
    } else {
       /face heading $calc($heading($p0,$p1)+95)
    }
    :RunAway
    /call autorun2 1
    /delay 5
    /if n $distance($p0,$p1)<$p2 /goto :RunAway
:OK

/return

Sub AutoRun2
   /if $p0==1 /sendkey down up
   /if $p0==0 /sendkey up up
/return


| This Sub sets up the alert lists for the mobs we want to hunt

sub SetAlerts
        | Setup Alerts for the most important mobs here (rare)
	/call makefearlist

        /alert clear 1
        /alert add 1 npc radius $int($kRadius) goblin
        /alert add 1 npc radius 500 lion
        /alert add 1 npc radius 500 kodiak
        /alert add 1 npc radius 500 puma
        /alert add 1 npc radius 500 skeleton
        | Setup Alerts for the next most important mobs here (uncommon)

        /alert clear 2
        /alert add 2 npc radius 1000 lion
        /alert add 2 npc radius 1000 kodiak
        /alert add 2 npc radius 1000 puma
        | Setup Alerts for the next most important mobs here (common)

        /alert clear 3
        /alert add 3 npc lion
        /alert add 3 npc kodiak
        /alert add 3 npc puma
/return

sub makernum
        /varset myrandom $calc($rand($int($p0))+1)
/return


sub makefearlist
| Setup Alerts for Scary mobs here
        /alert clear 4
        /varset v1 0
        | Loop to find first valid spawn
        :ValidLoop
        /varset v2 $spawn($v1,next)
        /if n $v2==0 {
           /varadd v1 1
           /goto :ValidLoop
        } else {
           /varset v1 $v2
        }

        | Save off the first valid spawn found
        /varset v3 $v1

        :WalkSpawns
        | Loop through all spawns to find a mach
        /mqlog $v1

        /if n $int($spawn($v1,level))>$int($endlevel) {
                /if n $v1!=$char(id) {
                        /if "$spawn($v1,type)"=="NPC" {
                                /mqlog id $v1 $spawn($v1,name) is too high for us, avoiding $spawn($v1,level)
                                /alert add 4 npc radius 500 $spawn($v1,name[clean])
                        }

                 }
        }
        /varset v1 $spawn($v1,next)
        /doevents
        /if "$spawn($v1,name[clean])"~~"NULL" /goto :donewalkin
        /if n $v1!=$v3 /goto :WalkSpawns
        :donewalkin
        /mqlog finished checking all spawns
        /return

|here we take care of our wounds with bandage skill




sub getstart
      	/if n $p0==0 /varset startlevel $int($calc($int($char(level))-4))
      	/if n $p0!=0 /varset startlevel $int($p0)
      	/varset endlevel $int($calc($int($char(level))-1))
	/return

sub doskills
  	/if $char(ability,"Round Kick")>0 /doability "Round Kick"
  	/if $char(ability,"Taunt")>0 /doability "Taunt"
  	/if $char(ability,"Kick")>0 /doability "Kick"
  	/if $char(ability,"Mend")>0 /doability "Mend"
  	/if $char(ability,"Slam")>0 /doability "Slam"
	/return

sub docombatspells
	/call autorun2 0
	/varset spCost $spell("$char(gem,1)",mana)
	/delay 1
	/face
        /if n $int($spCost)<$int($char(mana,cur)){
        	/if n $target(id)==0 /goto :endnuke
		/call autorun2 0
		/sendkey down up
		/sendkey up up
		/call SpellSub 1 CastTimer
		/delay 10

        }
        :endnuke
	/return

sub Event_CannotSee
	/varset NoLOS 1
	/return

Sub Event_CorpseTime
   	/varset v4 1
	/return

Sub Event_Looted
   	/varadd v3 1
   	/return

sub Event_Bandage50
        /varset $bandagedone 1
        /delay 5
        /return

sub Event_NoBandages
        /varset $bandagedone 2
        /delay 5
        /return

sub Event_Bandageout
        /varset $bandagedone 2
        /delay 5
        /return

sub Event_Bandagefail
        /varset $bandagedone 1
        /delay 5
        /return

sub Event_Bandagedone
        /varset $bandagedone 1
        /delay 5
        /return

sub Event_Zoneing
        /endmacro
        /return

sub Event_TooFar
	/varset TooFarAway 1
	/return

sub Event_CannotSee
	/varset NoLOS 1
	/return


sub Event_HitsYou
	/attack on
	/if "$combat"=="TRUE" /goto :StillEngaged
	/varset ipulled 0
	/varset AttackedMe 1
	/varset v10 "$left($calc($instr("YOU","$p0")-1),"$p0")"
	/varset v11 $strlen("$v10")
	:WalkString
		/if "$mid($v11,1,"$v10")"==" " {
		  /varset v12 $v11
		  /goto :DoneWalkString
		}
		/varsub v11 1
		/delay 0
		/goto :WalkString
	:DoneWalkString
		/varset Attacker "$left($v12,"$v10")"
		/mqlog Being Hit by $Attacker
	:StillEngaged
	/return

Code: Select all

| - SpellSub.mac - 
| Spell Casting Sub routine - Usage "/call SpellSub <gem> <delay *actual cast time plus recast*>" 
| Will return $v99 = 999 if you go oom. 
| 
| Modified by GD to work with the 7-4-2002 Release 
| 
| modified by sempi to include sitting/standing and be more cleric oriented 
| 1. Complete Heal 
| 2. Divine Light 
| 3. Celestial Healing 
| 4. Remedy 
| 5. Symbol of Marzin (?) 
| 6. Heroic Bond 
| 7. Mark of Karn 
| 8. Mark of Retribution 
| 
| Modified by S_B_R to handle more events and relay more information to the person 
| issuing the command. Also removed the auto-sit function to help control aggro. 09-07-02 

#Event CastStart "You begin casting" 
#Event CastFizzle "Your spell fizzles!" 
#Event CastInterrupt "Your spell is interrupted." 
#Event CastNoMana "Insufficient Mana to cast this spell" 
#Event CastTooFar "Your target is out of range, get closer!" 
#Event CastTimer "You haven't recovered yet..." 
#Event CastResist "Your target resisted " 

Sub SpellSub 
   /varset v98 $p0 
   /varset v99 $int($spell("$char(gem,$v98)",casttime))*10
   *10+$spell("$char(gem,$v98)",recoverytime)*10 + 20) 
   :ReCast 
   /sit off 
   /varset v1 2
   /cast $v98
   /echo "$char(gem,$v98)"
   /doevents 
   /if n $v1==0 /goto :ReCast 
   /if n $v1>1 /goto :Failure 
/return 

:Failure 
   /if n $v1==2 { 
      /delay 5 
   } else /if n $v1==3 { 
      /delay 5 
   } else /if n $v1==4 { 
      /delay 100 
      /sit on 
   } else /if n $v1==5 { 
   } else /if n $v1==6 {  
   } 
/return 

Sub Event_CastStart 
   /varset v1 1 
   /delay $int($v99)
/return 

Sub Event_CastFizzle 
   /varset v1 0 
/return 

Sub Event_CastInterrupt 
   /varset v1 0 
/return 

Sub Event_CastTooFar 
   /varset v1 3 
/return 

Sub Event_CastNoMana 
   /varset v1 4 
/return 

Sub Event_CastTimer 
   /varset v1 5 
/return 

Sub Event_CastResist 
   /varset v1 6 
/return