Page 1 of 1
Turn.inc - Human style turning (Data/DataVars Compatible)
Posted: Sun May 02, 2004 5:51 am
by GD
Code: Select all
| Turn.inc - Created by GD
|
| MQ2Data mod by Icehouse33
| 26 April 2004
|
| MQ2DataVars mod by GD
| 2 May 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 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
Posted: Sun May 09, 2004 6:26 pm
by blueninja
Shouldn't those variable definitions be like this:
Code: Select all
/declare PHeading int local 0
/declare THeading int local 0
/declare Bearing int local 0
/declare IsTurning bool local 0
/declare TurnKey local NULL
Probably don't have to assign null as the default value but I guess it won't hurt :) .
EDIT: Bah typo..
EDIT2: Looks like you do need to assign NULL to TurnKey after all..
Posted: Sat May 15, 2004 9:26 am
by mpmq
Been playing with this in one of my macros, and once in a while it will spin me 360 once or twice before turning me to the proper heading. I'm using it with the "turn to target" style call. Last time it messed up, the target in question was nearly standing next to me (not moving). Not sure if that has anything to do with it, since I didn't bother to try and check where the targets were when it happened before.
Posted: Sun May 23, 2004 8:21 am
by sumdumgeek
I suspect that the reason you sometimes do 360s is that the pressed key never gets released until your target is in the -7..7 range. If you overshoot, it'll press the other arrow, but it doesn't release the first one. What I did to the non-Datavars version was in the else /if sections, where it's setting TurnKey, was to make it /keypress the old key before setting the new one if they were different.
It's probably not a big deal in terms of wasted cycles, but the tests against -180 and 180 in the else /if blocks are redundant. If Bearing is >= 7, it's >-180. (I also set these to be testing for >0 and <0, to make it more obvious that it's a left/right check. It won't get there if the "in front of me" test passes anyway.)