autofight.inc Auto Melee script with obstacle avoidance

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

Moderator: MacroQuest Developers

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

autofight.inc Auto Melee script with obstacle avoidance

Post by Mckorr » Tue Oct 07, 2003 6:54 pm

This script is adapted from L124RD's original script for MacroKit, and is updated to use the new variable format. It is designed to be used as an include in other scripts. The script has rudimentary obstacle avoidance: if you get stuck you back up a bit and strafe left or right.

Code: Select all

#turbo

sub Attack

  /declare MyXLOC global
  /declare MyYLOC global
  /declare ObstacleCount global
  /declare targetarray array
  
  /varset targetarray(0) "$target(name,clean)"
  /varset targetarray(1) $target(level)
  /varset targetarray(2) $target(name)
  /varset targetarray(3) $target(id)

  /echo Fighting a level @targetarray(1) @targetarray(0)
  /face look
  /call MovetoMob

  :CloserAF
    /if "$target(id)"!=@targetarray(3) /goto :EndAF
    /if n $target(distance,nopredict)>10 /press up
    /if n $target(distance,nopredict)<10 /press down
    /if n $target(distance,nopredict)<15 /attack on
    /if n $target(distance,nopredict)>15 /attack off
    /if n $target(distance,nopredict)>15 /call MovetoMob
    /face fast nopredict look
    /if n $target(distance,nopredict)<11 /if n $char(ability,"Bash")>0 /doability "Bash"
    /if n $target(distance,nopredict)<11 /if n $char(ability,"Kick")>0 /doability "Kick"
    /if n $target(distance,nopredict)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm"
    /goto :CloserAF

  :EndAF
    /echo The level @targetarray(1) @targetarray(0) is dead...
    /sendkey up up
    /sendkey up down
    /attack off
    /varset targetarray(3) 0
    /press Num_5
/return

sub MoveToMob

  /varset MyXLOC $char(x)
  /varset MyYLOC $char(y)
  /varset ObstacleCount 0

  /if n $target(distance,nopredict)<=15 {
    /face look
    /return
  }
  /sendkey down up

  :Movementloop
    /varadd ObstacleCount 1
    /if $target()=="FALSE" /return
    /face look
    /if n $target(distance,nopredict)<=10 {
      /face look
      /sendkey up up
      /return
    }
    /if @ObstacleCount>=3 {
      /call CheckObstacle
      /goto :Movementloop
    }
    /if n $target(distance,nopredict)>10 /goto :MovementLoop
/return

sub CheckObstacle
  /if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle
  /varset MyXLOC $char(x)
  /varset MyYLOC $char(y)
  /varset ObstacleCount 0
/return

sub HitObstacle
  /sendkey up up
  /sendkey down down
  /delay 3
  /sendkey up down
  /sendkey down ctrl
  /if n $rand(99)>50 {
    /sendkey down right
  } else {
    /sendkey down left
  }
  /delay 5
  /sendkey up right
  /sendkey up left
  /sendkey up ctrl
  /sendkey down up
/return
MQ2: Think of it as Evolution in action.

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

LOVE it

Post by Mutter » Wed Oct 29, 2003 4:10 pm

Nice! ABout time it was an include file! Will make my scripts MUCH cleaner.

Losingteam
a lesser mummy
a lesser mummy
Posts: 75
Joined: Wed May 21, 2003 8:52 pm
Location: Chicago,Illinois

Fixed

Post by Losingteam » Thu Oct 30, 2003 9:51 am

Updated this to work with the new /face . No longer does nopredict have to be used.

Code: Select all

#turbo 

sub Attack

  /declare MyXLOC global 
  /declare MyYLOC global 
  /declare ObstacleCount global 
  /declare targetarray array 
  
  /varset targetarray(0) "$target(name,clean)" 
  /varset targetarray(1) $target(level) 
  /varset targetarray(2) $target(name) 
  /varset targetarray(3) $target(id) 

  /echo Fighting a level @targetarray(1) @targetarray(0) 
  /face  
  /call MovetoMob 

  :CloserAF 
    /if "$target(id)"!=@targetarray(3) /goto :EndAF 
    /if n $target(distance)>10 /press up 
    /if n $target(distance)<10 /press down 
    /if n $target(distance)<15 /attack on 
    /if n $target(distance)>15 /attack off 
    /if n $target(distance)>15 /call MovetoMob 
    /face fast
    /if n $target(distance)<11 /if n $char(ability,"Bash")>0 /doability "Bash" 
    /if n $target(distance)<11 /if n $char(ability,"Kick")>0 /doability "Kick" 
    /if n $target(distance)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm" 
    /goto :CloserAF 

  :EndAF 
    /echo The level @targetarray(1) @targetarray(0) is dead... 
    /sendkey up up 
    /sendkey up down 
    /attack off 
    /varset targetarray(3) 0  
/return 

sub MoveToMob 

  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 
  /varset ObstacleCount 0 

  /if n $target(distance)<=15 { 
    /face 
    /return 
  } 
  /sendkey down up 

  :Movementloop 
    /varadd ObstacleCount 1 
    /if $target()=="FALSE" /return 
    /face  
    /if n $target(distance)<=10 { 
      /face
      /sendkey up up 
      /return 
    } 
    /if @ObstacleCount>=3 { 
      /call CheckObstacle 
      /goto :Movementloop 
    } 
    /if n $target(distance)>10 /goto :MovementLoop 
/return 

sub CheckObstacle 
  /if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle 
  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 
  /varset ObstacleCount 0 
/return 

sub HitObstacle 
  /sendkey up up 
  /sendkey down down 
  /delay 3 
  /sendkey up down 
  /sendkey down ctrl 
  /if n $rand(99)>50 { 
    /sendkey down right 
  } else { 
    /sendkey down left 
  } 
  /delay 5 
  /sendkey up right 
  /sendkey up left 
  /sendkey up ctrl 
  /sendkey down up 
/return 
EDIT: Forgot to delete some of the Nopredicts

Losingteam
a lesser mummy
a lesser mummy
Posts: 75
Joined: Wed May 21, 2003 8:52 pm
Location: Chicago,Illinois

Idea

Post by Losingteam » Thu Oct 30, 2003 10:16 am

I decided to try and edit the existing macro to auto assist. I posted my idea here untested because I am at school and have no way to test it right now. I am almost positive it doesn't work, so don't try it yet. I just needed somewhere to put it, so I wouldn't lose it before I got home.

Code: Select all

|Use of this macro would be /macro assist.mac tankname
|The assist would automatically occur when the tank comes within the
|range of 75. Until then it will remain paused.

#turbo 
[color=red]
Sub Main
  /declare tankname  global
  /varset tankname “@Param0”
  /if n tankname(distance)>=75;
      /call Wait
  /if n tankname(distance)<=75;
      /call Attack
  /return

Sub Wait
  /pause 5
  /return
[/color]
sub Attack 

  /declare MyXLOC global 
  /declare MyYLOC global 
  /declare ObstacleCount global 
  /declare targetarray array 
  
  /varset targetarray(0) "$target(name,clean)" 
  /varset targetarray(1) $target(level) 
  /varset targetarray(2) $target(name) 
  /varset targetarray(3) $target(id) 

  /echo Fighting a level @targetarray(1) @targetarray(0) 
  /face  
  /call MovetoMob 

  :CloserAF 
    /if "$target(id)"!=@targetarray(3) /goto :EndAF 
    /if n $target(distance)>10 /press up 
    /if n $target(distance)<10 /press down 
    /if n $target(distance)<15 /attack on 
    /if n $target(distance)>15 /attack off 
    /if n $target(distance)>15 /call MovetoMob 
    /face fast 
    /if n $target(distance)<11 /if n $char(ability,"Bash")>0 /doability "Bash" 
    /if n $target(distance)<11 /if n $char(ability,"Kick")>0 /doability "Kick" 
    /if n $target(distance)<11 /if n $char(ability,"Disarm")>0 /doability "Disarm" 
    /goto :CloserAF 

  :EndAF 
    /echo The level @targetarray(1) @targetarray(0) is dead... 
    /sendkey up up 
    /sendkey up down 
    /attack off 
    /varset targetarray(3) 0  
/return 

Sub MoveToMob 

  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 
  /varset ObstacleCount 0 

  /if n $target(distance)<=15 { 
    /face 
    /return 
  } 
  /sendkey down up 

  :Movementloop 
    /varadd ObstacleCount 1 
    /if $target()=="FALSE" /return 
    /face  
    /if n $target(distance)<=10 { 
      /face 
      /sendkey up up 
      /return 
    } 
    /if @ObstacleCount>=3 { 
      /call CheckObstacle 
      /goto :Movementloop 
    } 
    /if n $target(distance)>10 /goto :MovementLoop 
/return 

Sub CheckObstacle 
  /if n @MyXLOC==$char(x) /if n @MyYLOC==$char(y) /call HitObstacle 
  /varset MyXLOC $char(x) 
  /varset MyYLOC $char(y) 
  /varset ObstacleCount 0 
/return 

Sub HitObstacle 
  /sendkey up up 
  /sendkey down down 
  /delay 3 
  /sendkey up down 
  /sendkey down ctrl 
  /if n $rand(99)>50 { 
    /sendkey down right 
  } else { 
    /sendkey down left 
  } 
  /delay 5 
  /sendkey up right 
  /sendkey up left 
  /sendkey up ctrl 
  /sendkey down up 
/return 

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

good idea

Post by Mutter » Thu Oct 30, 2003 2:13 pm

I have a sub called gohome i'll post in my hunter script. I'll try to link it here.

but basically what I do is set home point as where i first run the script. Then if any member of my group is fighting and they are close, I run out beat crap outta mob, then come back to home, and sit(if no further fighting needed)