Second problem, sometimes I end up chasing them down the hall if the root doesn't hold long enough. I'd like to return to the Home Point if I get too far from it or if there's no target within about 2 or 3 minutes (it's roughly a 6 minute spawn time).
Code follows:
|Wailing.mac
|Collects wailing substance from grimy owlbear cubs in Paludal.
#include routines.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
#event CannotSee "You cannot see your target"
#event TooFar "Your target is too far away"
#event HitsYou "YOU for"
sub Main
/zapvars
/mqlog Wailing script started
| Set up Alert lists
/alert clear 1
/alert add 1 npc radius 200 grimy
| Set Home Point
/varset HomeX -364.00
/varset HomeY -2034.00
| Set KS radius below. The script will not target a mob if a PC is within this radius of it.
/varset KSRadius 60
| Set Loot nodrop
/lootn never
|
| First off put clean up any open windows and make sure modifier keys are reset
/press esc
/press esc
/press esc
/press esc
/press alt
/press shift
/press ctrl
| Start of main Loop
|
:Start
| RestUp
/call RestUp
| Aquire nearest target to attack
/call GetTarget
|Root him so he can't run
/face nopredict
/cast 4
/delay 3s
| Advance
/call Advance
| Loot
/call Loot
/delay 0
/goto :Start
/return
| RestUp
sub RestUp
| Run to Home Base if needed
/if n $char(mana,pct)>80 /goto :NoRest
|Low on HP's running home
/mqlog HPs at $char(hp,pct) heading home
/call HomeBase
| If we didnt make it home we dont want to rest
/if n $return!=1 {
/mqlog Didnt make it home aborting run home
/goto :NoRest
}
| Make sure we are sat down.
/mqlog Reached home base resting
/sit on
:Rest
| Check if something has aggroed and attack it if it has.
/if n $AttackedMe==1 {
/mqlog aggroed whilst sitting
/sit off
/goto :NoRest
}
/delay 5
/if $char(ability,"Mend")>0 /doability "Mend"
/if n $char(mana,pct)<100 /goto :Rest
/mqlog Hps at $char(mana,pct) Off hunting again
}
:NoRest
/stand
/return
| Acquire Target subroutine
sub GetTarget
:Acquire
/if AttackedMe==1 {
/mqlog Targeted "$v13" who jumped me
/target "$v13"
/varset AttackedMe 0
} else /if "$alert(1)"=="TRUE" {
/target npc alert 1 nopcnear $KSRadius
/mqlog Targeted $target(name) range $target(distance) on alert list 1
}
/varset MyTarget $target(id)
/varset TargetDead 0
/doevents
/delay 0
/if n $target(id)==0 /goto :Acquire
/return
| Advance to mob subroutine
sub Advance
:Engage
|Process any events
/doevents
| 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
| 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)
/call GetTarget
/if n $KSCheck==$MyTarget /call Melee
}
/if n $TargetDead!=1 /goto :Engage
/mqlog Target is dead
/target id $MyTarget
/return
| Melee with mob subroutine
sub Melee
/mqlog Started melee
/attack on
:Combat
| Check events
/doevents flush
| Make sure were staring the critter out
/face nopredict
| If we are too far away close in
/if n $target(distance)>15 {
/face nopredict
/delay 2
/call autorun2 1
/mqlog $target(distance,nopredict) from $target(name)
}
| If we are in melee range stop running
/if n $target(distance)<15 {
/call autorun2 0
/delay 2
/face fast nopredict
/mqlog In melee with $target(name) at $target(hp,pct) I am at $char(hp,pct)
}
/doevents
| If we cannot see the target backup and face it again.
/if n $NoLOS==1 {
/mqlog Cannot see
/face nopredict
/sendkey down down
/delay 4
/sendkey up down
/varset NoLOS 0
/delay 3
}
| If we are too far away close in
/if n $TooFarAway==1 {
/face nopredict
/delay 2
/call autorun2 1
/varset TooFarAway 0
}
/if $char(ability,"Round Kick")>0 /doability "Round Kick"
/if $char(ability,"Kick")>0 /doability "Kick"
/if $char(ability,"Mend")>0 /doability "Mend"
/if $char(ability,"Slam")>0 /doability "Slam"
| Check if target is dead or we have lost it
/if n $target(id)==0 /varset TargetDead 1
| If target is still alive keep at it
/if n $TargetDead!=1 /goto :Combat
| Target is dead so stop attacking
/attack off
/varset AttackedMe 0
/return
| Loot mob
sub Loot
/varset TargetLooted 0
:Approach
/mqlog Advancing to corpse
|Process any events
/doevents
| Check we still have a target if not dont try to loot it
/if n $target(id)==0 /goto :Looted
| Turn towards target
/face nopredict
| If we are within range loot corpse
/if n $target(distance)<15 {
/call autorun2 0
/loot
/goto :AtTarget
}
| If we are not within range then make sure we are on autorun
/if n $target(distance)>12 /call autorun2 1
| Save our current x,y loc
/varset MyXLoc $char(x)
/varset MyYLoc $char(y)
| Wait and 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
/delay 0
/goto :Approach
:AtTarget
|Begin Looting
/mqlog starting to loot
/delay 5
| Cycle through each loot slot
/varset LootSlot 0
:LootLoop
/delay 5
/click left corpse $LootSlot
/delay 5
/if "$cursor()"!="TRUE" /goto :NoLoot
| Scan list of loot to keep and auto drop it if we are keeping it.
:GetLoot
/if "$cursor(name)"~~"wailing" {
/mqlog Looted $cursor(name)
/click left auto
/goto :Looted
}
/if "$cursor(name)"~~"feather" {
/mqlog Looted $cursor(name)
/click left auto
/goto :Looted
}
/if "$cursor(name)"~~"pelt" {
/mqlog Looted $cursor(name)
/click left auto
/goto :Looted
}
| Checked list of loot to keep with no matches so destroy (must turn on fast destroy)
/mqlog Destroying $cursor(name)
/click left destroy
:Looted
/varadd LootSlot 1
/delay 5
/goto :LootLoop
:NoLoot
/delay 5
/press esc
/delay 5
/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 we are within melee range stop running check Target again for other players engaged and attack if all OK.
/if n $distance($HomeY,$HomeX)<15 {
/mqlog Reached Home
/call autorun2 0
/varset BackHome 1
}
/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
/delay 2
/doevents
/sendkey up down
/sendkey down ctrl
/if n $rand(99)>50 {
/sendkey down right
} else {
/sendkey down left
}
/delay 3
/doevents
/sendkey up right
/sendkey up left
/sendkey up ctrl
/sendkey down up
/return
Sub AutoRun2
/if $p0==1 /sendkey down up
/if $p0==0 /sendkey up up
/return
sub Event_TooFar
/varset TooFarAway 1
/return
sub Event_CannotSee
/varset NoLOS 1
/return
sub Event_HitsYou
/if "$combat"=="TRUE" /goto :StillEngaged
/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
}
/varsub v11 1
/delay 0
/goto :WalkString
/varset Attacker "$left($v12,"$v10")"
/mqlog Being Hit by $Attacker
:StillEngaged
/return

