Turn.inc - Reliable human-style turning for the masses

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

Moderator: MacroQuest Developers

GD
a snow griffon
a snow griffon
Posts: 353
Joined: Sat Jun 29, 2002 11:57 pm

Turn.inc - Reliable human-style turning for the masses

Post by GD » Thu Feb 26, 2004 1:03 am

OK, I wrote this because I wanted turning that wasn't so bot-like. Using face, it was somtimes too fast. You could tell it wasn't real because the PC wouldn't move his/her feet like real turning does, it looked more like a pet auto-turning to the nearest mob.

Solution: Get the Bearing to the target or location, figure out which direction it is, press the Left/Right key once as needed, with no repetetive key presses, then do a /face when within a 15 degree arc of it being directly ahead of you.

It's very human like, and works pretty damn well.

Code: Select all

| Turn.inc -  Created by GD
|
| Usage: #Include it into your current macro, then call it as follows:
|
|     To turn towards Target: /call Turn
|     To turn towards Location: /call LocY LocX
|        IE: /call Turn -460 500

#turbo

Sub Turn(THeadingY,THeadingX)
	/declare PHeading local
	/declare THeading local
	/declare Bearing local
	/declare TurnKey local
	/declare IsTurning local

:TurnLoop
	/delay 0
	/if $char(state)=="SIT" /sit off
	/varset PHeading $int($char(heading))
	/if "$defined(THeadingX)"=="TRUE" {
		/varset THeading $int($heading(@THeadingY,@THeadingX))
	} else {
		/varset THeading $int($target(headingto))
	}

	/varset Bearing $int($calc($calc(@PHeading-@THeading+540)%360-180))

	/if (n @Bearing>=-7 && n @Bearing<=7) {
		/if "@TurnKey"!="" /sendkey up @TurnKey
		/face heading @THeading nolook
		/return
	} else /if (n @Bearing>=-180 && n @Bearing>=7) {
		/if "@TurnKey"!="RIGHT" /varset TurnKey RIGHT
	} else /if (n @Bearing<=180 && n @Bearing<=7) {
		/if "@TurnKey"!="LEFT" /varset TurnKey LEFT
	}

	/if n @IsTurning!=1 {
		/sendkey down @TurnKey
		/varset IsTurning 1
	}
	/goto :TurnLoop

/return
I'm not breaking the macro down with comments, so you can use your brain to figure out how it's actually working.
Opinions are like assholes, everyone has one, but most of them stink.

rzmonk76
a hill giant
a hill giant
Posts: 165
Joined: Sat Jan 31, 2004 1:37 pm
Contact:

a few probelems

Post by rzmonk76 » Sun Mar 07, 2004 8:00 am

with lag and distance to mob greater than 75 the pc spins at lesat once before lock on. also i was having trouble with the player runing around the mob because in prev code there was a sendkey up down so i uncluded sendkey up up at the start of your code. how can i fix the 360 degree turning before lock on? would turning up the turbo work?

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Sun Mar 07, 2004 10:46 am

He is currently using #turbo. That uses the maximum possible.

GD
a snow griffon
a snow griffon
Posts: 353
Joined: Sat Jun 29, 2002 11:57 pm

Post by GD » Sun Mar 07, 2004 4:45 pm

This only turns, it doesn't stop running for you, so as you said, you'd have to put that in yourself.

I never had a problem with it spinning, but increasing the angle of the "forward" direction would give it a little more room to work with.

Example, a 20 degree forward arc:

Code: Select all

/if (n @Bearing>=-10 && n @Bearing<=10) { 
      /if "@TurnKey"!="" /sendkey up @TurnKey 
      /face heading @THeading nolook 
      /return 
   } else /if (n @Bearing>=-180 && n @Bearing>=10) { 
      /if "@TurnKey"!="RIGHT" /varset TurnKey RIGHT 
   } else /if (n @Bearing<=180 && n @Bearing<=10) { 
      /if "@TurnKey"!="LEFT" /varset TurnKey LEFT 
   } 
Opinions are like assholes, everyone has one, but most of them stink.

sumdumgeek
decaying skeleton
decaying skeleton
Posts: 4
Joined: Fri Mar 26, 2004 1:09 am

Post by sumdumgeek » Fri Mar 26, 2004 1:11 am

It looks like what's happening is once it decides it needs to turn left, it just keeps going left til it winds up within +- seven degrees.

What it could do instead is, if it's turned left too far and should be turning right now, stop turning left, and similar for the other side.

Also, the test for >-180 && >7 is redundant; if it's >7 it's >-180. At that point you know it's not in the 15 degree front arc, so all you really need is positive or negative. So...

Code: Select all

/if (n @Bearing>=-7 && n @Bearing<=7) { 
	/if "@TurnKey"!="" /sendkey up @TurnKey 
	/face heading @THeading nolook 
	/return 
} else /if n @Bearing>0 {
	/if "@TurnKey"!="RIGHT" {
		/if n @IsTurning==1 {
			/sendkey up @TurnKey
			/varset IsTurning 0
		}
		/varset TurnKey RIGHT
	}
} else {
      	/if "@TurnKey"!="LEFT" {
		/if n @IsTurning==1 {
			/sendkey up @TurnKey
			/varset IsTurning 0
		}
		/varset TurnKey LEFT
	}
} 

gruefood
a lesser mummy
a lesser mummy
Posts: 30
Joined: Sat Mar 27, 2004 6:31 pm

Post by gruefood » Sun Mar 28, 2004 10:13 am

This is actually pretty sweet. I didn't like the botic turning and was trying to do this myself but this one is much better. Thx. 8)

icehouse33
orc pawn
orc pawn
Posts: 12
Joined: Mon Dec 15, 2003 8:34 am

turn.inc MQ2Data ready

Post by icehouse33 » Mon Apr 26, 2004 5:35 pm

Code: Select all

| Turn.inc -  Created by GD 
| 
| MQ2Data mod by Icehouse33
|     26 April 2004
|
| Usage: #Include it into your current macro, then call it as follows: 
| 
|     To turn towards Target: /call Turn 
|     To turn towards Location: /call Turn LocY LocX 
|        IE: /call Turn -460 500 

#turbo 

Sub Turn(THeadingY,THeadingX) 
   /declare PHeading local 
   /declare THeading local 
   /declare Bearing local 
   /declare TurnKey local 
   /declare IsTurning local
   
   /varset IsTurning 0 
   /varset TurnKey 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 
Last edited by icehouse33 on Tue Apr 27, 2004 1:03 am, edited 1 time in total.

gruefood
a lesser mummy
a lesser mummy
Posts: 30
Joined: Sat Mar 27, 2004 6:31 pm

Post by gruefood » Mon Apr 26, 2004 10:46 pm

Thank you icehouse!

This was one a the last things I had to fix in my macros and I kept putting it off.

GF

gruefood
a lesser mummy
a lesser mummy
Posts: 30
Joined: Sat Mar 27, 2004 6:31 pm

Post by gruefood » Mon Apr 26, 2004 11:19 pm

One very minor thing...

If you are already within 7 degrees of facing your desired heading...you'll get an error:

Invalid mappable command or key combo 'UNDEFINED-LOCAL'

But everything still works.

I could see that it's looking for NULL so I just added:

Code: Select all

/varset TurnKey NULL

to the top of the macro.

GF