move.inc - simple moving and object avoidance routines

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

Terramantian
a ghoul
a ghoul
Posts: 120
Joined: Thu May 13, 2004 6:20 pm

move.inc - simple moving and object avoidance routines

Post by Terramantian » Thu May 13, 2004 6:50 pm

UPDATED 8/28: Updated it to EQBot_man's version, for anyone who needs it for the next macro I'm posting.

I started writing my own macros for the first time just a few days ago, and one of the most common things I had to do was run my character to a location or a spawn.

I realize advpath can do everything this does and much more, and can probably do it better, but for my purposes I just wanted something simpler.

This little .inc I pieced together works well (for everything I've tried it with); It's mainly a conversion of beatnik007's post in the Pre-Data Forum, but I've added a little more. Anything else I have to say about it is commented in.

Code: Select all

| 
|   move.inc 
| 
|Advanced moving and object-avoidance routines 
| 
|Originally by beatnik007 (Who credits Mckorr) 
| 
|Revised and converted to MQ2Data by Terramantian 
| 
|Signifagant and on-going Improvments by EQBot_Man   8.9.04 
|   Added /call MoveToSpawnName 
|      This will take a partial name and a distance and reliably target and move 
|      to the nearest spawn of that name 
|   Added code to get you to stop a lot closer than 10 units.  You should stop almost 
|      right at the location you want when using MoveToLoc 
|   Sometimes you would get stuck at a door and if you were macroing unattended 
|      you would continue to strafe for hours making it obvious you were 
|      macroing.  Added code that if the strafe function is called more 
|      than 10 times in 60 sec to /quit you out 
|   Have added lots of little checks including NULL targets and corpse checks and a lot 
|      of little things that I can't remember now but I needed to add due to rare 
|      circumstances of the subroutines failing to do what they were desigend to do. 
| 
|  Subroutines: 
|   Sub MoveToLoc 
|      Moves you to a specified xy loc 
|   Sub MoveToSpawn 
|      Moved you to a specified ID number(pretty pointless) 
|   Sub MoveToSpawnName 
|      Moves you to the nearest spawn given a partial or full name 
| 
|===================================================| 


| Sub MoveToLoc                                     | 
|---------------------------------------------------| 
|This simply moves the player to within 1 unit of | 
|the requested location, while avoiding obstacles   | 
|                                                   | 
|This is beatnik007's original sub, with a few minor| 
|changes and rewritten in MQ2Data format            | 
|                                                   | 
|SYNTAX: /call MoveToLoc Y X                        | 


Sub MoveToLoc(MoveToY, MoveToX) 
    /echo Moving to Location: ${MoveToY}, ${MoveToX}. 
    /echo Distance: ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]} 
    /declare FailureTimer timer local 0 
    /declare StrafeFailure int local 
    /declare running int local 
    /declare MaxSpeed int local 
    /declare StopDistance int local 
    /declare distanceNow float local 
    /declare distanceBefore float local 
    /declare distanceModifier int local 
    /varset running 0 
    /declare distanceTimer timer 15 
    /varset distanceBefore ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]} 
    /varset distanceModifier 1 
    /varset MaxSpeed 0 
    :moveToLocation 

   /if (${Me.Speed}>=${MaxSpeed}) /varset MaxSpeed ${Me.Speed} 
   /if (${MaxSpeed}<=166) { 
      /varset StopDistance 3 
   } else { 
      /varset StopDistance 10 
   } 

    /face fast nolook loc ${MoveToY},${MoveToX} 

    /if (${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}<${StopDistance}) { 
        /keypress forward 
        /return 
    } 

    /if (${distanceTimer}==0) { 
        /if (${Me.Sneaking}) { 
            /varset distanceModifier 2 
        } else { 
            /varset distanceModifier 1 
       } 

        /varset distanceNow ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]} 
        /if (${Math.Calc[${distanceBefore}-${distanceNow}]}<${Math.Calc[10/${distanceModifier}]}) { 
           /if (${FailureTimer}==0) { 
              /varset StrafeFailure 0 
              /varset FailureTimer 600 
           } 
           /if (${FailureTimer}>0) { 
              /varset StrafeFailure ${Math.Calc[${StrafeFailure} + 1]} 
           } 
      /if (${StrafeFailure}>=10 && ${FailureTimer}>0) { 
             /keypress forward 
             /keypress back hold 
             /delay 5 
                 /keypress back 
         /afk Be back later, leave a message 
         /echo Your movement failed more than 10 times in 30 seconds and most likely looked macroed.  Ending macro. . . 
         /endmacro 
         /quit 
      } 
            /call strafePastObstacle ${StrafeFailure} 
        } 

        /varset distanceBefore ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]} 
        /varset distanceTimer 15 
    } 

    /if (${running}==0) { 
        /keypress forward 
        /if (${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}>${StopDistance}) { 
            /varset running 1 
            /keypress forward hold 
        } 
    } else { 
        /if (${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}<${StopDistance}) { 
            /varset running 0 
            /keypress forward 
        } 
    } 
    /goto :moveToLocation 
/return 


| Sub MoveToSpawn                                   | 
|---------------------------------------------------| 
|This moves the player to within a provided distance| 
|of the provided spawn, while avoiding obstacles    | 
|                                                   | 
|I "wrote" this, but as you can see, it's the same  | 
|as MoveToLoc with a few variable replacements.     | 
|                                                   | 
|The second parameter, Distance, allows for the     | 
|player to stop short of the target by a certain    | 
|amount, to provide for different aggro radii, etc. | 
|                                                   | 
|SYNTAX: /call MoveToSpawn ID Distance              | 

Sub MoveToSpawn(MoveToID, StopDistance) 


    /if (!(${Defined[MoveToID]})||(${Spawn[MoveToID].ID})) { 
        /echo Spawn ID not found or no ID provided. Aborting... 
        /return 
    } 
    /if (!(${Defined[StopDistance]})) { 
   /echo Stopping point not defined, using default distance of 70 
        /declare StopDistance int local 
        /varset StopDistance 70 
    } 
    /echo Moving to Spawn: ${MoveToID} (${Spawn[${MoveToID}].CleanName}). 
    /echo Current Location: ${Spawn[${MoveToID}].Y}, ${Spawn[${MoveToID}].X} 
    /echo Current Distance: ${Spawn[${MoveToID}].Distance} 
    /declare FailureTimer timer local 0 
    /declare StrafeFailure int local 
    /declare running int local 
    /declare distanceNow float local 
    /declare distanceBefore float local 
    /declare distanceModifier int local 
    /varset running 0 
    /declare distanceTimer timer 15 
    /varset distanceBefore ${Spawn[${MoveToID}].Distance} 
    /varset distanceModifier 1 

    :moveToSpawn 

    /squelch /face fast nolook id ${MoveToID} 

    /if (${Spawn[${MoveToID}].Distance}<${StopDistance}) { 
        /keypress forward 
        /return 
    } 

    /if (${distanceTimer}==0) { 
        /if (${Me.Sneaking}) { 
            /varset distanceModifier 2 
        } else { 
            /varset distanceModifier 1 
        } 

        /varset distanceNow ${Spawn[${MoveToID}].Distance} 
        /if (${Math.Calc[${distanceBefore}-${distanceNow}]}<${Math.Calc[10/${distanceModifier}]}) { 
           /if (${FailureTimer}==0) { 
                   /varset StrafeFailure 0 
                   /varset FailureTimer 600 
                } 
                /if (${FailureTimer}>0) { 
                   /varset StrafeFailure ${Math.Calc[${StrafeFailure} + 1]} 
                } 
           /if (${StrafeFailure}>=10 && ${FailureTimer}>0) { 
                  /keypress forward 
                  /keypress back hold 
                  /delay 5 
                      /keypress back 
                      /sit 
              /afk Be back later, leave a message 
              /echo Your movement failed more than 10 times in 30 seconds and most likely looked macroed.  Ending macro. . . 
              /endmacro 
         /quit 
           } 
            /call strafePastObstacle ${StrafeFailure} 
        } 
        /varset distanceBefore ${Spawn[${MoveToID}].Distance} 
        /varset distanceTimer 15 
    } 

    /if (${running}==0) { 
        /keypress forward 
        /if (${Spawn[${MoveToID}].Distance}>=${StopDistance}) { 
            /varset running 1 
            /keypress forward hold 
        } 
    } else { 
        /if (${Spawn[${MoveToID}].Distance}<${StopDistance}) { 
            /varset running 0 
            /keypress forward 
        } 
    } 
    /goto :moveToSpawn 
/return 


| Sub MoveToSpawnName                               | 
|---------------------------------------------------| 
|This moves the player to within a provided distance| 
|of the provided spawn, while avoiding obstacles    | 
|                                                   | 
|I "wrote" this, but as you can see, it's the same  | 
|as MoveToLoc with a few variable replacements.     | 
|                                                   | 
|The second parameter, Distance, allows for the     | 
|player to stop short of the target by a certain    | 
|amount, to provide for different aggro radii, or to| 
|attack.                                            | 
|                      | 
|SYNTAX: /call MoveToSpawnName Name Distance        | 
|   Does take partial names:          | 
|   /call MoveToSpawnName skel 9          | 
|      to move you to the nearest skeleton | 
|                      | 
|  I use this for farming bone chips and silks       | 

Sub MoveToSpawnName(Name, StopDistance) 
/keypress esc 
/target ${Name} npc 
/delay 2 
/if (${String[${Target}].Find["NULL"]}) /return 
/if (${String[${Target}].Find["corpse"]}) /return 
    /if (!${Target.ID}) { 
        /echo Name not found or no name provided. Aborting... 
        /return 
    } 
    /if (!(${Defined[StopDistance]})) { 
      /echo Stopping point not defined, using default distance of 70 
        /declare StopDistance int local 
        /varset StopDistance 70 
    } 
    /echo Moving to Spawn: ${Target.CleanName}. 
    /declare FailureTimer timer local 0 
    /declare StrafeFailure int local 
    /declare running int local 
    /declare distanceNow float local 
    /declare distanceBefore float local 
    /declare distanceModifier int local 
    /varset running 0 
    /declare distanceTimer timer 15 
    /varset distanceBefore ${Target.Distance} 
    /varset distanceModifier 1 

    :moveToSpawn 
   /if (${String[${Target}].Find["NULL"]}) /return 
    /face fast predict 

    /if (${Target.Distance}<${StopDistance}) { 
        /keypress forward 
        /return 
    } 

    /if (${distanceTimer}==0) { 
        /if (${Me.Sneaking}) { 
            /varset distanceModifier 2 
        } else { 
            /varset distanceModifier 1 
        } 

        /varset distanceNow ${Target.Distance} 
        /if (${Math.Calc[${distanceBefore}-${distanceNow}]}<${Math.Calc[10/${distanceModifier}]}) { 
           /if (${FailureTimer}==0) { 
                   /varset StrafeFailure 0 
                   /varset FailureTimer 600 
                } 
                /if (${FailureTimer}>0) { 
                   /varset StrafeFailure ${Math.Calc[${StrafeFailure} + 1]} 
                } 
           /if (${StrafeFailure}>=10 && ${FailureTimer}>0) { 
                  /keypress forward 
                  /keypress back hold 
                  /delay 5 
                      /keypress back 
                      /sit 
              /afk Be back later, leave a message 
              /echo Your movement failed more than 10 times in 30 seconds and most likely looked macroed.  Ending macro. . . 
              /endmacro 
         /quit 
           } 
            /call strafePastObstacle ${StrafeFailure} 
        } 
        /varset distanceBefore ${Target.Distance} 
        /varset distanceTimer 15 
    } 

    /if (${running}==0) { 
        /keypress forward 
        /if (${Target.Distance}>=${StopDistance}) { 
            /varset running 1 
            /keypress forward hold 
        } 
    } else { 
        /if (${Target.Distance}<${StopDistance}) { 
            /varset running 0 
            /keypress forward 
        } 
    } 
    /goto :moveToSpawn 
/return 

| Only to be used by the previous functions - It's obvious what it does. | 

sub strafePastObstacle(Number) 
    /keypress forward 
    /keypress back hold 
    /delay ${Math.Calc[${Number}*3/2+4]} 
    /keypress back 
    /if (!${Me.State.Equal["STAND"]}) /stand 
    /if (${Math.Rand[99]}>50) { 
        /keypress strafe_right hold 
    } else { 
        /keypress strafe_left hold 
    } 
    /delay ${Math.Calc[${Number}*4+5]} 
    /keypress strafe_right 
    /keypress strafe_left 
    /keypress forward hold 
/return 

Sub Turn(THeadingY,THeadingX) 
   /declare PHeading outer 0 
   /declare THeading outer 0 
   /declare Bearing outer 0 
   /declare IsTurning outer 0 
   /declare TurnKey outer NULL 

:TurnLoop 
   /delay 0 
   /if (${Me.Sitting}) /sit off 
   /varset PHeading ${Me.Heading.Degrees} 
   /if (${Defined[THeadingX]}) { 
      /varset THeading ${Heading[${THeadingY},${THeadingX}].Degrees} 
   } else { 
      /varset THeading ${Target.HeadingTo.Degrees} 
   } 

   /varset Bearing ${Math.Calc[(${PHeading}-${THeading}+540)%360-180]} 

   /if (${Bearing}>=-7 && ${Bearing}<=7) { 
      /if (${String[${TurnKey}].NotEqual[NULL]}) /keypress ${TurnKey} 
      /face heading ${Heading[${THeading}].Degrees} nolook 
      /return 
   } else /if (${Bearing}>=-180 && ${Bearing}>=7) { 
      /if (${String[${TurnKey}].NotEqual[LEFT]}) /varset TurnKey LEFT 
   } else /if (${Bearing}<=180 && ${Bearing}<=7) { 
      /if (${String[${TurnKey}].NotEqual[RIGHT]}) /varset TurnKey RIGHT 
   } 

   /if (!${IsTurning}) { 
      /keypress ${TurnKey} hold 
      /varset IsTurning 1 
   } 
   /goto :TurnLoop 

/return 

Please tell me any errors you see / any way to improve it.
Last edited by Terramantian on Sat Aug 28, 2004 1:10 pm, edited 3 times in total.

Drumstix42
a grimling bloodguard
a grimling bloodguard
Posts: 808
Joined: Mon May 03, 2004 4:25 pm

Post by Drumstix42 » Fri May 14, 2004 5:40 pm

Sounds good. Simple is always good, especially if that's all you need. This interestes me much. I'll definately try it out for ya :)

Glasscoin
a lesser mummy
a lesser mummy
Posts: 55
Joined: Mon Jan 13, 2003 8:57 am

Beautiful!

Post by Glasscoin » Fri May 14, 2004 10:13 pm

Thank you for this macro -- simple, clean, and it complimented my hunting macro perfectly. Kudos!

User avatar
MSBoy1
a lesser mummy
a lesser mummy
Posts: 57
Joined: Mon May 19, 2003 3:42 pm
Location: Mississippi

Post by MSBoy1 » Sat May 15, 2004 11:31 pm

Nice little include. Exactly what I am looking for. Thanks for posting it.

amml
a lesser mummy
a lesser mummy
Posts: 68
Joined: Thu Apr 22, 2004 4:55 pm

Post by amml » Mon May 17, 2004 7:51 am

Tahnks a lot for thisone, people asked me to implement something like that into my fishing macro so it makes fishing in plane of water etc even nicer hehe

Pugs
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue May 11, 2004 11:38 pm

Post by Pugs » Sat Jun 12, 2004 2:09 am

:cool: Very good job that is just what i need for my PoS hunting script.



Thank you.

eqjoe
a grimling bloodguard
a grimling bloodguard
Posts: 984
Joined: Sat Sep 28, 2002 12:26 pm

Post by eqjoe » Sun Jun 20, 2004 10:37 pm

I always have problems with advpath. Sometimes simpler is better.


Nice job.


-j

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:04 pm

Terramantian, could you update this so that the < and > are showing correctly, please? BBCode change messed up a bunch of scripts/macros/etc. which had those signs in them. They all were replaced with < and > respectively.


Now, for my question, how would I, or could I, go about using this in conjunction with an INI file to get it to goto the locations I want it? Or would Advpath be how I should go about it?

I'll be digging around MHB macro to see if I can learn something from it for movement.

Terramantian
a ghoul
a ghoul
Posts: 120
Joined: Thu May 13, 2004 6:20 pm

Post by Terramantian » Fri Jul 09, 2004 10:08 am

yeah sorry, fixed that. Hadn't looked at this in ages lol. I'd say you want advpath for that. Unless they're just a few locs and you can move in a straight line to get to them with few obstacles/aggro problems. This inc was made (for my purposes anyway) mostly to run to new targets, or run to a camp spot, in zones like the overthere, eastern wastes, dreadlands, etc. For more precise moving you'll want advpath... never used it myself but looks great hehe, thinking about writing one with it today.

EQBot_man
a ghoul
a ghoul
Posts: 111
Joined: Mon May 17, 2004 6:35 pm

Made Substantial Improvements 8.9.2004

Post by EQBot_man » Tue Jul 20, 2004 2:04 am

Added a shiload including a new subroutine: MoveToSpawnName for moving to the nearest spawn, given a partial/full name and a distance

/call MoveToSpawnName <Partial|Full Name> <Distance to Stop>
Useful for farming bone chips and silks or many other small items


Code: Select all

|
|	move.inc
|
|Advanced moving and object-avoidance routines
|
|Originally by beatnik007 (Who credits Mckorr)
|
|Revised and converted to MQ2Data by Terramantian
|
|Signifagant and on-going Improvments by EQBot_Man   8.9.04
|	Added /call MoveToSpawnName
|		This will take a partial name and a distance and reliably target and move
|		to the nearest spawn of that name
|	Added code to get you to stop a lot closer than 10 units.  You should stop almost
|		right at the location you want when using MoveToLoc
|	Sometimes you would get stuck at a door and if you were macroing unattended
|		you would continue to strafe for hours making it obvious you were
|		macroing.  Added code that if the strafe function is called more
|		than 10 times in 60 sec to /quit you out
|	Have added lots of little checks including NULL targets and corpse checks and a lot
|		of little things that I can't remember now but I needed to add due to rare
|		circumstances of the subroutines failing to do what they were desigend to do.
|
|  Subroutines:
|	Sub MoveToLoc
|		Moves you to a specified xy loc
|	Sub MoveToSpawn
|		Moved you to a specified ID number(pretty pointless)
|	Sub MoveToSpawnName
|		Moves you to the nearest spawn given a partial or full name
|
|===================================================|


| Sub MoveToLoc                                     |
|---------------------------------------------------|
|This simply moves the player to within 1 unit of |
|the requested location, while avoiding obstacles   |
|                                                   |
|This is beatnik007's original sub, with a few minor|
|changes and rewritten in MQ2Data format            |
|                                                   |
|SYNTAX: /call MoveToLoc Y X                        |


Sub MoveToLoc(MoveToY, MoveToX)
    /echo Moving to Location: ${MoveToY}, ${MoveToX}.
    /echo Distance: ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}
    /declare FailureTimer timer local 0
    /declare StrafeFailure int local
    /declare running int local
    /declare MaxSpeed int local
    /declare StopDistance int local
    /declare distanceNow float local
    /declare distanceBefore float local
    /declare distanceModifier int local
    /varset running 0
    /declare distanceTimer timer 15
    /varset distanceBefore ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}
    /varset distanceModifier 1
    /varset MaxSpeed 0
    :moveToLocation

	/if (${Me.Speed}>=${MaxSpeed}) /varset MaxSpeed ${Me.Speed}
	/if (${MaxSpeed}<=166) {
		/varset StopDistance 3
	} else {
		/varset StopDistance 10
	}

    /face fast nolook loc ${MoveToY},${MoveToX}

    /if (${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}<${StopDistance}) {
        /keypress forward
        /return
    }

    /if (${distanceTimer}==0) {
        /if (${Me.Sneaking}) {
            /varset distanceModifier 2
        } else {
            /varset distanceModifier 1
    	}

        /varset distanceNow ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}
        /if (${Math.Calc[${distanceBefore}-${distanceNow}]}<${Math.Calc[10/${distanceModifier}]}) {
        	/if (${FailureTimer}==0) {
        		/varset StrafeFailure 0
        		/varset FailureTimer 600
        	}
        	/if (${FailureTimer}>0) {
        		/varset StrafeFailure ${Math.Calc[${StrafeFailure} + 1]}
        	}
		/if (${StrafeFailure}>=10 && ${FailureTimer}>0) {
			    /keypress forward
			    /keypress back hold
			    /delay 5
    			    /keypress back
			/afk Be back later, leave a message
			/echo Your movement failed more than 10 times in 30 seconds and most likely looked macroed.  Ending macro. . .
			/endmacro
			/quit
		}
      		/call strafePastObstacle ${StrafeFailure}
        }

        /varset distanceBefore ${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}
        /varset distanceTimer 15
    }

    /if (${running}==0) {
        /keypress forward
        /if (${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}>${StopDistance}) {
            /varset running 1
            /keypress forward hold
        }
    } else {
        /if (${Math.Distance[${Me.Y},${Me.X}:${MoveToY},${MoveToX}]}<${StopDistance}) {
            /varset running 0
            /keypress forward
        }
    }
    /goto :moveToLocation
/return


| Sub MoveToSpawn                                   |
|---------------------------------------------------|
|This moves the player to within a provided distance|
|of the provided spawn, while avoiding obstacles    |
|                                                   |
|I "wrote" this, but as you can see, it's the same  |
|as MoveToLoc with a few variable replacements.     |
|                                                   |
|The second parameter, Distance, allows for the     |
|player to stop short of the target by a certain    |
|amount, to provide for different aggro radii, etc. |
|                                                   |
|SYNTAX: /call MoveToSpawn ID Distance              |

Sub MoveToSpawn(MoveToID, StopDistance)


    /if (!(${Defined[MoveToID]})||(${Spawn[MoveToID].ID})) {
        /echo Spawn ID not found or no ID provided. Aborting...
        /return
    }
    /if (!(${Defined[StopDistance]})) {
   /echo Stopping point not defined, using default distance of 70
        /declare StopDistance int local
        /varset StopDistance 70
    }
    /echo Moving to Spawn: ${MoveToID} (${Spawn[${MoveToID}].CleanName}).
    /echo Current Location: ${Spawn[${MoveToID}].Y}, ${Spawn[${MoveToID}].X}
    /echo Current Distance: ${Spawn[${MoveToID}].Distance}
    /declare FailureTimer timer local 0
    /declare StrafeFailure int local
    /declare running int local
    /declare distanceNow float local
    /declare distanceBefore float local
    /declare distanceModifier int local
    /varset running 0
    /declare distanceTimer timer 15
    /varset distanceBefore ${Spawn[${MoveToID}].Distance}
    /varset distanceModifier 1

    :moveToSpawn

    /squelch /face fast nolook id ${MoveToID}

    /if (${Spawn[${MoveToID}].Distance}<${StopDistance}) {
        /keypress forward
        /return
    }

    /if (${distanceTimer}==0) {
        /if (${Me.Sneaking}) {
            /varset distanceModifier 2
        } else {
            /varset distanceModifier 1
        }

        /varset distanceNow ${Spawn[${MoveToID}].Distance}
        /if (${Math.Calc[${distanceBefore}-${distanceNow}]}<${Math.Calc[10/${distanceModifier}]}) {
     		/if (${FailureTimer}==0) {
             		/varset StrafeFailure 0
             		/varset FailureTimer 600
             	}
             	/if (${FailureTimer}>0) {
             		/varset StrafeFailure ${Math.Calc[${StrafeFailure} + 1]}
             	}
     		/if (${StrafeFailure}>=10 && ${FailureTimer}>0) {
     			    /keypress forward
     			    /keypress back hold
     			    /delay 5
         			    /keypress back
         			    /sit
     			/afk Be back later, leave a message
     			/echo Your movement failed more than 10 times in 30 seconds and most likely looked macroed.  Ending macro. . .
     			/endmacro
			/quit
     		}
      		/call strafePastObstacle ${StrafeFailure}
        }
        /varset distanceBefore ${Spawn[${MoveToID}].Distance}
        /varset distanceTimer 15
    }

    /if (${running}==0) {
        /keypress forward
        /if (${Spawn[${MoveToID}].Distance}>=${StopDistance}) {
            /varset running 1
            /keypress forward hold
        }
    } else {
        /if (${Spawn[${MoveToID}].Distance}<${StopDistance}) {
            /varset running 0
            /keypress forward
        }
    }
    /goto :moveToSpawn
/return


| Sub MoveToSpawnName                               |
|---------------------------------------------------|
|This moves the player to within a provided distance|
|of the provided spawn, while avoiding obstacles    |
|                                                   |
|I "wrote" this, but as you can see, it's the same  |
|as MoveToLoc with a few variable replacements.     |
|                                                   |
|The second parameter, Distance, allows for the     |
|player to stop short of the target by a certain    |
|amount, to provide for different aggro radii, or to|
|attack.                                            |
|						    |
|SYNTAX: /call MoveToSpawnName Name Distance        |
|	Does take partial names:		    |
|	/call MoveToSpawnName skel 9		    |
|		to move you to the nearest skeleton |
|						    |
|  I use this for farming bone chips and silks	    |

Sub MoveToSpawnName(Name, StopDistance)
/keypress esc
/target ${Name} npc
/delay 2
/if (${String[${Target}].Find["NULL"]}) /return
/if (${String[${Target}].Find["corpse"]}) /return
    /if (!${Target.ID}) {
        /echo Name not found or no name provided. Aborting...
        /return
    }
    /if (!(${Defined[StopDistance]})) {
   	/echo Stopping point not defined, using default distance of 70
        /declare StopDistance int local
        /varset StopDistance 70
    }
    /echo Moving to Spawn: ${Target.CleanName}.
    /declare FailureTimer timer local 0
    /declare StrafeFailure int local
    /declare running int local
    /declare distanceNow float local
    /declare distanceBefore float local
    /declare distanceModifier int local
    /varset running 0
    /declare distanceTimer timer 15
    /varset distanceBefore ${Target.Distance}
    /varset distanceModifier 1

    :moveToSpawn
	/if (${String[${Target}].Find["NULL"]}) /return
    /face fast predict

    /if (${Target.Distance}<${StopDistance}) {
        /keypress forward
        /return
    }

    /if (${distanceTimer}==0) {
        /if (${Me.Sneaking}) {
            /varset distanceModifier 2
        } else {
            /varset distanceModifier 1
        }

        /varset distanceNow ${Target.Distance}
        /if (${Math.Calc[${distanceBefore}-${distanceNow}]}<${Math.Calc[10/${distanceModifier}]}) {
     		/if (${FailureTimer}==0) {
             		/varset StrafeFailure 0
             		/varset FailureTimer 600
             	}
             	/if (${FailureTimer}>0) {
             		/varset StrafeFailure ${Math.Calc[${StrafeFailure} + 1]}
             	}
     		/if (${StrafeFailure}>=10 && ${FailureTimer}>0) {
     			    /keypress forward
     			    /keypress back hold
     			    /delay 5
         			    /keypress back
         			    /sit
     			/afk Be back later, leave a message
     			/echo Your movement failed more than 10 times in 30 seconds and most likely looked macroed.  Ending macro. . .
     			/endmacro
			/quit
     		}
      		/call strafePastObstacle ${StrafeFailure}
        }
        /varset distanceBefore ${Target.Distance}
        /varset distanceTimer 15
    }

    /if (${running}==0) {
        /keypress forward
        /if (${Target.Distance}>=${StopDistance}) {
            /varset running 1
            /keypress forward hold
        }
    } else {
        /if (${Target.Distance}<${StopDistance}) {
            /varset running 0
            /keypress forward
        }
    }
    /goto :moveToSpawn
/return

| Only to be used by the previous functions - It's obvious what it does. |

sub strafePastObstacle(Number)
    /keypress forward
    /keypress back hold
    /delay ${Math.Calc[${Number}*3/2+4]}
    /keypress back
    /if (!${Me.State.Equal["STAND"]}) /stand
    /if (${Math.Rand[99]}>50) {
        /keypress strafe_right hold
    } else {
        /keypress strafe_left hold
    }
    /delay ${Math.Calc[${Number}*4+5]}
    /keypress strafe_right
    /keypress strafe_left
    /keypress forward hold
/return

Sub Turn(THeadingY,THeadingX)
   /declare PHeading outer 0
   /declare THeading outer 0
   /declare Bearing outer 0
   /declare IsTurning outer 0
   /declare TurnKey outer NULL

:TurnLoop
   /delay 0
   /if (${Me.Sitting}) /sit off
   /varset PHeading ${Me.Heading.Degrees}
   /if (${Defined[THeadingX]}) {
      /varset THeading ${Heading[${THeadingY},${THeadingX}].Degrees}
   } else {
      /varset THeading ${Target.HeadingTo.Degrees}
   }

   /varset Bearing ${Math.Calc[(${PHeading}-${THeading}+540)%360-180]}

   /if (${Bearing}>=-7 && ${Bearing}<=7) {
      /if (${String[${TurnKey}].NotEqual[NULL]}) /keypress ${TurnKey}
      /face heading ${Heading[${THeading}].Degrees} nolook
      /return
   } else /if (${Bearing}>=-180 && ${Bearing}>=7) {
      /if (${String[${TurnKey}].NotEqual[LEFT]}) /varset TurnKey LEFT
   } else /if (${Bearing}<=180 && ${Bearing}<=7) {
      /if (${String[${TurnKey}].NotEqual[RIGHT]}) /varset TurnKey RIGHT
   }

   /if (!${IsTurning}) {
      /keypress ${TurnKey} hold
      /varset IsTurning 1
   }
   /goto :TurnLoop

/return

aich
decaying skeleton
decaying skeleton
Posts: 1
Joined: Fri Oct 22, 2004 8:09 pm

Where

Post by aich » Fri Oct 22, 2004 8:10 pm

Wundering where you put this, I copy/paste the code, saved as a move.inc in macros folder, but /macro move.inc says missing main.

User avatar
peach
a hill giant
a hill giant
Posts: 156
Joined: Fri Sep 10, 2004 8:20 pm

Post by peach » Fri Oct 22, 2004 9:48 pm

thats because you don't use /macro to use it

move DOT INC not DOT MAC
[img]http://img23.exs.cx/img23/4702/search2.jpg[/img]