moveToLoc - accurate, object avoidance

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.

Moderator: MacroQuest Developers

beatnik007
decaying skeleton
decaying skeleton
Posts: 6
Joined: Sun Feb 22, 2004 6:46 am

moveToLoc - accurate, object avoidance

Post by beatnik007 » Sat Apr 10, 2004 10:43 am

After spending 4 hours running behind a tree, I decided to write my own moveToLoc function.

Credits to Mckorr for the object avoidance. It remains the same, but the logic to call it differs.

Please post improvements.


Code: Select all

#turbo 100

Sub Main
    /zapvars
    /declare distanceTimer timer

    /call moveToLoc 2410 7074
    /call moveToLoc 2697 7295
/endmacro

Code: Select all

Sub moveToLoc
    /echo Moving to @Param1, @Param0.

    /declare running local
    /declare distanceNow local
    /declare distanceBefore local
    /declare distanceModifier local
    /varset running 0
    /varset distanceTimer 15
    /varset distanceBefore $distance(@Param1,@Param0)
    /varset distanceModifier 1
    
    :moveToLocation

    /face fast loc @Param1,@Param0

    /if n $distance(@Param1,@Param0)<2 {
        /sendkey up up
        /return
    }
    
    /if n @distanceTimer==0 {
        /if $char(sneaking)==TRUE {
            /varset distanceModifier 2
        } else {
            /varset distanceModifier 1
        }

        /varset distanceNow $distance(@Param1,@Param0)
        /if n $calc(@distanceBefore-@distanceNow)<$calc(10/@distanceModifier) {
            /call strafePastObstacle
        }
        /varset distanceBefore $distance(@Param1,@Param0)
        /varset distanceTimer 15
    }

    /if n @running==0 {
        /press up
        /if n $distance(@Param1,@Param0)>30 {
            /varset running 1
            /sendkey down up
        }
    } else {
        /if n $distance(@Param1,@Param0)<31 {
            /varset running 0
            /sendkey up up
        }
    }
    /goto :moveToLocation
/return

sub strafePastObstacle
    /sendkey up up
    /sendkey down down
    /delay 2
    /sendkey up down
    /sendkey down ctrl
    /if n $rand(99)>50 {
        /sendkey down right
    } else {
        /sendkey down left
    }
    /delay 3
    /sendkey up right
    /sendkey up left
    /sendkey up ctrl
    /sendkey down up
/return

OldNecro
a ghoul
a ghoul
Posts: 136
Joined: Thu Dec 19, 2002 3:09 am

Post by OldNecro » Sat Apr 24, 2004 9:25 am

where is distancetimer being incremented/decrimented?
Saddam Hussein begins to use An Innocent Bystander as a living shield!
An Innocent Bystander ceases protecting Saddam Hussein's corpse.

Preocts
a snow griffon
a snow griffon
Posts: 312
Joined: Thu Jan 29, 2004 1:02 pm

Post by Preocts » Sat Apr 24, 2004 10:32 am

Change Turbo to 20 or just remove it. Turbo only goes to 40 for a max now. :wink:

wassup
Official Guardian and Writer of TFM
Official Guardian and Writer of TFM
Posts: 1487
Joined: Sat Oct 26, 2002 5:15 pm

Post by wassup » Sat Apr 24, 2004 1:04 pm

OldNecro wrote:where is distancetimer being incremented/decrimented?
timers decrement themselves...

This needs to be changed to MQ2Data anyway, which doesn't look like ti would take much work.

Guest

Post by Guest » Sat Apr 24, 2004 5:06 pm

Yes, but DistanceTimer isn't a timer... He didn't even declare it... (however I think this *is* the only problem with it...)

I went ahead and converted this to MQ2Data, but I prolly shouldn't post it here because I customized the hell out of it and it really wouldn't operate independently anyway...

dedw8
decaying skeleton
decaying skeleton
Posts: 6
Joined: Wed Aug 11, 2004 3:10 pm

Post by dedw8 » Wed Aug 11, 2004 3:24 pm

I'm confused, is this MQ2 compatible or not? Sorry, I'm new here.
D

User avatar
Cr4zyb4rd
Plugins Czar
Posts: 1449
Joined: Tue Jul 20, 2004 11:46 am

Post by Cr4zyb4rd » Wed Aug 11, 2004 3:38 pm

No, this won't work as-posted. If you look around a bit, you should be able to find move-to and avoidance routines of all shapes and sizes inside of other macros, many probably based on some variation of the above code.

ChrisCim
a lesser mummy
a lesser mummy
Posts: 77
Joined: Sun Feb 29, 2004 2:45 am

Post by ChrisCim » Sat Nov 27, 2004 3:19 am

..