autofight.inc

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot. MQ2Data format only!

Moderator: MacroQuest Developers

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

autofight.inc

Post by Mckorr » Thu Apr 29, 2004 12:49 pm

My melee routine, updated to the new system. Still working out some bugs with it, but in general it does what it's supposed to do.

Edit: 4th Version. Changes in red fix error messages (and Lax cursing at you). MoveToMob and obstacle avoidance routine are still not working correctly.

Code: Select all

#Event Casting "You begin casting" 
#Event Enraged "has become ENRAGED" 
#Event Offrage "is no longer enraged" 
#Event Gate "Gates" 

sub Attack 

  /declare MyXLOC float outer 
  /declare MyYLOC float outer
  /declare ObstacleCount int outer

  /echo Fighting a level ${Target.Level} ${Target.Name} 
  /face fast nolook 
  /call MoveToMob 

  :CloserAF 
    /if (!${Target.ID}) /goto :EndAF 
    /doevents 
    [color=red]/if (${Target.ID})[/color] /call AttackRoutine 
    /goto :CloserAF 

  :EndAF 
    /attack off 
    /popup TARGET DEAD
    /keypress forward 
    /keypress back 
/return

sub AttackRoutine 
    /attack on
    /doevents 
    /if (${Target.Distance}>10) { 
         /keypress forward hold 
         /timed 1 /keypress forward 
    } 
    /if (${Target.Distance}<10) { 
         /keypress back hold 
         /timed 1 /keypress back 
    } 
    /if (${Target.Distance}>15) /call MoveToMob 
    [color=red]/if (${Target.ID})[/color] /face nolook fast 
    /doevents 
    /if ((${Target.Distance}<11)&&(${Me.AbilityReady["Bash"]})) /doability "Bash" 
    /if ((${Target.Distance}<11)&&(${Me.AbilityReady["Kick"]})) /doability "Kick" 
    /if ((${Target.Distance}<11)&&(${Me.AbilityReady["Disarm"]})) /doability "Disarm" 
/return 

sub MoveToMob 

  /attack off

  /varset MyXLOC ${Me.X} 
  /varset MyYLOC ${Me.Y} 
  /varset ObstacleCount 0 

  /doevents 
  /keypress forward hold 

  :Movementloop 
    /varcalc ObstacleCount ${ObstacleCount}+1 
    /if (${Target.ID}) { 
       /face nolook 
       /if (${Target.Distance}<=15) { 
         /face nolook 
         /keypress forward 
         /return 
       } 
       /if (${ObstacleCount}>=10) { 
          /call CheckObstacle 
          /goto :Movementloop 
       } 
       /if (${Target.Distance}>15) /goto :MovementLoop 
    } 
/return 

sub CheckObstacle 
  /if ((${MyXLOC}==${Me.X})&&(${MyYLOC}==${Me.Y})) /call HitObstacle 
  /varset MyXLOC ${Me.X} 
  /varset MyYLOC ${Me.Y} 
  /varset ObstacleCount 0 
/return 

sub HitObstacle 
  /keypress forward 
  /keypress back hold 
  /delay 3 
  /keypress back 
  /if (${Math.Rand[2]}) { 
    /keypress strafe_right hold 
  } else { 
    /keypress strafe_left hold 
  } 
  /delay 5 
  /keypress strafe_right 
  /keypress strafe_left 
  /keypress forward hold 
/return 

sub Event_Enraged 
    /if (${Target.ID}) { 
        :EnrageDelay 
        /if (${Target.CurrentHPs}<11) { 
            /attack off
            /doevents 
            /goto :EnrageDelay 
        } 
    } 
/return 

sub Event_Offrage 
    /if (${Target.ID}&&(${Target.CurrentHPs}<11)) { 
        /attack on 
    } 
/return 

sub Event_Casting 
   :checkcast 
    /delay 1 
    /if (${Me.Casting.ID}) /goto :checkcast 
/return 

sub Event_Gate 
    /keypress forward 
    /keypress back 
    /attack off 
    /popup GATED!
    /endmacro 
/return
Last edited by Mckorr on Fri Apr 30, 2004 10:28 am, edited 2 times in total.

User avatar
Pax
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Dec 19, 2003 11:04 am
Location: Denmark

Post by Pax » Thu Apr 29, 2004 6:56 pm

Code: Select all

  :Movementloop
    /varadd ObstacleCount 1
    /if (${Target.ID}) {
       /face nolook
       /if (${Target.Distance}<=15) {
         /face nolook
         /keypress forward
         /return
       }
       /if (${ObstacleCount}>=10) {
          /call CheckObstacle
          /goto :Movementloop
       }
       /if (${Target.Distance}>15) /goto :MovementLoop
    }
/return 
should be

Code: Select all

sub MoveToMob

  /attack off

  /varset MyXLOC ${Me.X}
  /varset MyYLOC ${Me.Y}
  /varset ObstacleCount 0

  /doevents
  /keypress forward hold

  :Movementloop
[color=red]   /varcalc ObstacleCount ${ObstacleCount}+1[/color]
    /if (${Target.ID}) {
       /face nolook
       /if (${Target.Distance}<=15) {
         /face nolook
         /keypress forward
         /return
       }
       /if (${ObstacleCount}>=10) {
          /call CheckObstacle
          /goto :Movementloop
       }
       /if (${Target.Distance}>15) /goto :MovementLoop
    }
/return
oh and lax keeps flaming me when stuff dies :( something about no any in zone or something to that effect
//Fuck waiting for us to cleanly exit... we're being unloaded!

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

Post by Mckorr » Fri Apr 30, 2004 10:01 am

Yah, I fixed the /varadd error.

And I get the same result when stuff dies, not sure where that is occuring yet.

Also, MovementLoop causes CheckObstacle to be called a LOT, and that almost always results in a strafe movement. I'll have to come up with a better obstacle avoidance routine. My guess is the problem comes from the macro executing so fast that

Code: Select all

/if ((${MyXLOC}==${Me.X})&&(${MyYLOC}==${Me.Y})) /call HitObstacle 
is always true. Adding a one second delay in there might fix things.

User avatar
aChallenged1
a grimling bloodguard
a grimling bloodguard
Posts: 1804
Joined: Mon Jun 28, 2004 10:12 pm

Post by aChallenged1 » Tue Jul 06, 2004 2:45 pm

Where would I add in the 1 second delay?
I am assuming the line for the pause would be

Code: Select all

/delay 1s 
I have other questions, but I'll stop with this one for now.

Looking through, using the above post as a guide, and the time of the edit of the first post, it looks like there may already be a delay, but I'm pretty sure it is in a different subroutine. Would I still need the delay in question that is mentioned above, or would the delay that I see in the next subroutine take care of it?

I'm thinking the answer is that the delay would need to be added to the specific routine.