The part about this that is unique is the code for pulling with a bow and the return to home point code. I would like if some folks could take a look and see if they have any suggestions or find any errors.
Also, I have not yet installed Macroquest. I wanted to play with the language and see if it was something I could like.
Code: Select all
| Factiongrind.mac
|
#include routines.mac
#define LootTotal v50
#define KSRadius v51
#define FactionHit v35
#define CannotHit v36
#define TooClose v37
#define CannotSee v38
#define TooFar v39
#define MyTarget v40
#define MyHeading v41
#define TargetHeading v42
#define HeadingDelta v43
#define TargetDead v44
#define MyXLoc v46
#define MyYLoc v47
#define StuckCount v48
#define TargetLooted v52
#define LootSlot v54
#define CheckLoot v55
#define HomepointX v60
#define HomepointY v61
#define Factioncount v62
#event CannotSee "cannot see"
#event TooFar "too far away"
#event TooClose "too close"
#event CannotHit "can not hit your target from here"
#event FactionHit "Sarnak Collective has increased"
sub Main
/zapvars
/varset HomepointX $char(x)
/varset HomepointY $char(y)
/varset FactionCount 0
/filter zrange 30
/alert clear 1
/alert add 1 npc class cleric
/alert add 1 npc class shaman
/alert add 1 npc class necromancer
/alert add 1 npc class wizard
/alert clear 2
/alert add 2 npc
/alert clear 3
/alert add 3 npc corpse
/alert clear 4
/alert add 4 npc angry
| Set up list of items to loot in this array
/varset a(1,0) "salt"
/varset a(1,1) "goblin skin"
| Put number of items in list here.
/varset LootTotal 2
| 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
| Aquire nearest target to attack
/call GetTarget
| Volley!
/call Archery
| Start combat
/call Melee
| Loot
/call Loot
| Home
/if n $distance($HomepointY, $HomepointX)>75 /call Homebase
| future place for heal, buff and med routines
/goto :Start
| Acquire Target subroutine
sub GetTarget
:Acquire
/press ESC
/press F8
/if n $target(id)!=0 {
/if n $target(distance)<550 /return
}
/face heading 0
/press F8
/if n $target(id)!=0 {
/if n $target(distance)<550 /return
}
/face heading 90
/press F8
/if n $target(id)!=0 {
/if n $target(distance)<550 /return
}
/face heading 180
/press F8
/if n $target(id)!=0 {
/if n $target(distance)<550 /return
}
/face heading 270
/press F8
/if n $target(id)!=0 {
/if n $target(distance)<550 /return
}
/if "$alert(1)"=="TRUE" {
/target npc alert 1 noalert 4
} else /if "alert(2)"=="TRUE" {
/target npc alert 2 noalert 4
} else {
/target npc alert 3 noalert 4
}
/varset MyTarget $target(id)
/varset TargetDead 0
/doevents
/if n $target(id)==0 /goto :Acquire
/mqlog Target Selected $target(id) $target(name) Range $target(distance)
/return
| Archery until within range subroutine
sub Archery
/mqlog bow pulling
:DrawBow
/doevents flush
/face fast
/if n $target(distance)>450 /sendkey up down
/delay 1
/sendkey up up
/mouseto hotkey 6
/click left
/click left
/click left
/click left
/doevents
/if n $CannotHit==1 {
/mqlog Cant hit
/sendkey down shift
/sendkey down left
/delay 2
/sendkey up left
/sendkey up shift
/face fast
/varset CannotHit 0
/goto :DrawBow
}
/if n $TooClose==1 {
/mqlog Mob closing, switch to weapons.
/call Melee
}
| Check if target is a corpse or not
/if n $target(id)==0 /varset TargetDead 1
| If target is still alive keep at it
/if n $TargetDead!=1 /goto :DrawBow
/return
| Melee with mob subroutine
sub Melee
/if n $TargetDead==1 /return
/mqlog Started melee
/attack on
:Combat
| Check events
/doevents flush
| Make sure were staring the critter out
/face
| If we are too far away close in
/if n $target(distance)>12 /call autorun 1
| If we are in melee range stop running
/if n $target(distance)<15 /call autorun 0
| If we are to close backup a little
|/if n $target(distance)<10 {
| /sendkey down down
| /delay 1
| /sendkey down up
|}
/doevents
| If we cannot see the target backup and face it again.
/if n $CannotSee==1 {
/mqlog Cannot see
/sendkey down shift
/sendkey down down
/sendkey down right
/delay 1
/sendkey down up
/sendkey up right
/sendkey up shift
/face fast
/varset CannotSee 0
}
| Check if target is a corpse or not
|/if "$target(name)"~~"corpse" /varset TargetDead 1
/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
/return
| Loot mobs
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 autorun 0
/loot
/goto :AtTarget
}
| If we are not within range then make sure we are on autorun
/if n $target(distance)>12 /call autorun 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
/goto :Approach
:AtTarget
|Begin Looting
/mqlog starting to loot
/delay 10
| Cycle through each loot slot
/varset LootSlot 0
:LootLoop
/delay 1
/mqlog Checking slot $LootSlot
/click left corpse $LootSlot
/delay 3
/mqlog Picked $cursor(name)
/if "$cursor()"!="TRUE" /goto :NoLoot
| Scan list of loot to keep and auto drop it if we are keeping it.
/varset CheckLoot 0
:GetLoot
/mqlog Comparing $cursor(name) to $a(1,$CheckLoot)
/if "$cursor(name)"~~"$a(1,$CheckLoot)" {
/mqlog Looted $cursor(name)
/click left auto
/goto :Looted
}
/varadd CheckLoot 1
/if n $CheckLoot<$LootTotal /goto :GetLoot
| 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
/goto :LootLoop
:NoLoot
/delay 3
/press esc
/delay 2
/return
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 Homebase
| return to starting point after killing and cleaning up corpses
/press ESC
/press ESC
/delay 1
:HomeLoop
/delay 0
/if n $target(id)!=0 /call Melee
/face nopredict fast loc $HomepointY, $HomepointX
/if n $distance($HomepointY, HomepointX)>40 /call autorun 1
/varset MyXLoc $char(x)
/varset MyYLoc $char(y)
/delay 1
/if n $MyXLoc==$char(x) /if $MyYLoc==$char(y) /call Obstacle
/if n $distance($HomepointY, HomepointX)<20 {
/call autorun 0
/return
}
/goto :HomeLoop
/return
sub Event_TooFar
/mqlog $p0 TooFar Event Fired
/varset TooFar 1
/return
sub Event_CannotSee
/mqlog $p0 CannotSee Event Fired
/varset CannotSee 1
/return
sub Event_TooClose
/mqlog $p0 TooClose Event Fired
/varset TooFar 1
/return
sub Event_CannotHit
/mqlog $p0 CannotHit Event Fired
/varset CannotHit 1
/return
sub Event_FactionHit
/mqlog $p0 FactionHit Event Fired
/varset FactionHit 1
/varadd FactionCount 1
/echo $FactionCount
/return
