Moving behind a mob w/ strafing - not quite working

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Moving behind a mob w/ strafing - not quite working

Post by ThatOtherGuy » Mon Oct 06, 2003 9:48 am

And I don't know why. Theoretically this should see if you're in the back 80degrees of the target, and if you're not, send you to the loop to mvoe you there. However, ocne you trigger it (in weird places, not what it should be) it just sends you in an endless loop in 1 direction around the target.

Code: Select all

Sub movebehind
	/if $target()==FALSE { 
		/attack off
		/return
	}
/face fast nopredict
/varset MobShouldFace $char(heading)
:moveloop
	/if @Combatstatus=="1" {
		/if $target()==FALSE {
			/return
			/attack off
		}
		/face fast nopredict
		/if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) {
			/goto :right
		} else {
			/if n $target(heading)<=$calc($calc(@MobShouldFace+40)%360) {
				/goto :left
			}
		} else {
			/goto :end
		}
		/sendkey up ctrl
		/face fast nopredict
	}
:right
/if n $target(heading)<=$calc($calc(@MobShouldFace+40)%360) {
	/goto :left
} else /if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) {
	/face fast nopredict
	/sendkey down Ctrl
	/press Left
	/press Left
	/press Left
	/sendkey up ctrl
	/face fast nopredict
	/goto :moveloop
} else {
	/goto :end
}

:left
/if n $target(heading)>=@MobShouldFace {
	/goto :right
} else /if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) {
	/face fast nopredict
	/sendkey down Ctrl
	/press Right
	/press Right
	/press Right
	/sendkey up ctrl
	/face fast nopredict
	/goto :moveloop
} else {
	/goto :end
}

:end
/sendkey up ctrl
/return
-TOG

blacrain
decaying skeleton
decaying skeleton
Posts: 5
Joined: Tue Jul 29, 2003 11:22 pm

Re: Moving behind a mob w/ strafing - not quite working

Post by blacrain » Mon Oct 06, 2003 11:14 am

I haven't installed the new stuff yet, waiting for tradeskills (the only thing i use it fer. /shrug... but anyways.

item #1:
ThatOtherGuy wrote:

Code: Select all

:moveloop
/if @Combatstatus=="1" {
This /if has no /else... If you don't have attack on, it's gonna start making you run in circles!

Item #2:

Code: Select all

:moveloop 
|--update our heading
      /varset MobShouldFace $char(heading) 
   /if @Combatstatus=="1" { 
      /if $target()==FALSE { 
         /return 
         /attack off 
      } 
      /face fast nopredict 
      /if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) { 
         /goto :right 
      } else { 
         /if n $target(heading)<=$calc($calc(@MobShouldFace+40)%360) { 
            /goto :left 
         } 
      } else { 
         /goto :end 
      } 
      /sendkey up ctrl 
      /face fast nopredict 
   }
Don't forget to update the values you use in the math, so it knows what you're facing..

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Post by ThatOtherGuy » Mon Oct 06, 2003 7:08 pm

As i understand it, and if without an else just skips the whole thing. So if @Combatstatus!=1 then it just skips teh whole thing and moves on to the closing }

Now that I see it mentioned, I'm sure that the not-updating-heading thing is the problem :p Thanks - will edit later when I'm home to say if it worked :p
-TOG

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Post by ThatOtherGuy » Mon Oct 06, 2003 8:31 pm

So remembering to update the math so that it doesn't endlessly spin me in circles any more - Now I have a new special l33t uberproblem of doom.

For some reason, this code calulates the place where it should put me as about 45degrees from teh FRONT of the mob(right about 45 on following diagram). If I start in the 180-270 quadrant, the script stops working - but doesn't end or error out.

diagram (0 = front)

Code: Select all

    0
90   270
  180
Heres the code that is doing the calcs

Code: Select all

Sub movebehind
	/if $target()==FALSE { 
		/attack off
		/return
	}
/face fast nopredict
:moveloop
/varset MobShouldFace $char(heading)
	/if @Combatstatus=="1" {
		/if $target()==FALSE {
			/return
			/attack off
		}
		/face fast nopredict
		/if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) {
			/if n $target(heading)<=$calc($calc(@MobShouldFace+180)%360) {
				/goto :right
			}
		}
		/if n $target(heading)<=$calc($calc(@MobShouldFace+40)%360) {
			/if n $target(heading)>=$calc($calc(@MobShouldFace-180)%360) {
				/goto :left
			} else {
				/goto :end
			}
		}
		/face fast nopredict
	} else {
		/goto :end
	}

:right
/if n $target(heading)<=$calc($calc(@MobShouldFace+40)%360) {
	/goto :left
} else /if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) {
	/face fast nopredict
	/sendkey down Ctrl
	/press Left
	/press Left
	/press Left
	/sendkey up ctrl
	/face fast nopredict
	/goto :moveloop
} else {
	/goto :end
}

:left
/if n $target(heading)>=$calc($calc(@MobShouldFace-40)%360) {
	/goto :right
} else /if n $target(heading)<=$calc($calc(@MobShouldFace+40)%360) {
	/face fast nopredict
	/sendkey down Ctrl
	/press Right
	/press Right
	/press Right
	/sendkey up ctrl
	/face fast nopredict
	/goto :moveloop
} else {
	/goto :end
}

:end
/sendkey up ctrl
/return
-TOG

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Mon Oct 06, 2003 9:55 pm

You can't do it this way.

First of all, this algorthm won't work. If you are neither right or left of where you want to be (assuming that you've done the calculations correctly), it ends. Well, maybe you want that but are complaining that it just ends.

Second, you are basing calculations on your heading, which is completely irrelevant to where you want to be. You want to compare your target's heading ($target(heading)) and the relative heading from your target to you (180-$target(headingto)). This is not your problem, though, because you are always faceing the mob.

Third, and most importantly, you are doing zero based calculations. Headings that are greater than 180 are really less than zero and you can't normalize them with modulus.

Put some /echo statements in and you'll soon have this figured out.

Valerian
a grimling bloodguard
a grimling bloodguard
Posts: 709
Joined: Sun Jul 28, 2002 3:29 am

Post by Valerian » Tue Oct 07, 2003 8:34 am

*bows to DKAA's uber mathiness*

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Post by ThatOtherGuy » Tue Oct 07, 2003 11:06 am

mkay, that didn't make much sense, but I guess I'll trash it since you say it can't be done :p
-TOG

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

Post by Mckorr » Tue Oct 07, 2003 11:42 am

Of course it can be done. Not as difficult as it sounds.

You need a loop. While always facing your target, you continually loop the following:

1. adjust your distance to target
2. get your targets heading
3. if your heading is not the same as your target, strafe sideways... maintaining your /face towards the target.

Untested, off the cuff, possibly pseudo code ahead:

Code: Select all

:GetBehindIt
/face fast nopredict
/if n $target(distance,nopredict)>10 /press up
/if n $target(distance,nopredict)<10 /press down
/if n $char(heading)!=n $target(heading) {
  /sendkey down ctrl
  /press left
  /sendkey up ctrl
  /goto :GetBehindIt
}
Something to that effect, no math involved. Tries to keep you at a range of 10, while moving clockwise to put you and your target on the same heading.
MQ2: Think of it as Evolution in action.

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Post by ThatOtherGuy » Tue Oct 07, 2003 4:35 pm

I should've stated this at the begining :P
this is part of a modified monk fighter script (actually pretty heavily modified - I'd estimate 75-80% code of my own from the original)

I already have the distance held pretty solid.

The biggest problem with that /press left thing is if you're just a teensy bit leftof the back... You strafe 359degrees around it, which looks miiiiighty weird. Also, staying at exactly the same heading as the target is pretty durn difficult - you'd prolly end up just doing endless circles

What I would really want is a way to define a +/- range on an operation - see if @value1 is within the range of @value2(+/-)40

so like

Code: Select all

/if n $target(heading)==$calc($char(heading)(+/-)40) {
     /echo blehblah
}
would check so see if $target(heading)==$char(heading)+40,-40, +39,-39, ect ect ect

in VB6 (last semireal programming language I worked with - I'ma modeler, not a coder ;P) it'd be an AND operator, but I haven't been able to find anything that would work as AND

Code: Select all

/if n $target(heading)<=$calc($char(heading)-40) AND $target(heading)>=$calc($char(heading)+40) {
     /echo omfgyer not behind the mob!
}
Also would be nifty if there was a way to get the targets heading and always call that 0, and base the $char(heading) off that - could subdivide the sides of the mob into 180 arcs and figure out which way to strafe to get to the back the quickest and least goofy looking

Maybe there already is a way to do this and I'm jsut being st00pid :) Save me math coder superdudes~!
-TOG

User avatar
dont_know_at_all
Developer
Developer
Posts: 5450
Joined: Sun Dec 01, 2002 4:15 am
Location: Florida, USA
Contact:

Post by dont_know_at_all » Tue Oct 07, 2003 6:08 pm

The problem is that 1 and 359 are two degrees apart. You have to account for this.

I had some math tricks in a macro but now I can't find them. When I get some free time, I'll try to re-derive them.

peaches
orc pawn
orc pawn
Posts: 10
Joined: Tue Oct 07, 2003 10:24 pm

Post by peaches » Tue Oct 07, 2003 10:25 pm

There's real nice move behind code in the macro depot. Anything wrong with it?

Plazmic
The One
The One
Posts: 800
Joined: Fri Jun 14, 2002 12:31 am
Contact:

Post by Plazmic » Tue Oct 07, 2003 11:14 pm

I do something similar to (pseudo-code)
headingdifference = target headingto - char heading
if (headingdifference < -180) headingdifference += 360
if (headingdifference > 180) headingdifference -= 360

this centers the headingdifference on 0 with a range of -180 to 180
- Plazmic

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Post by ThatOtherGuy » Wed Oct 08, 2003 11:42 am

peaches - It works fine for most stuff, but I ahve an obsession to make a completely automated bot that looks natural :P The movehind in the macro depot points to to a point some units behind the mob , moves you at it, then points you back at the mob... OK for some stuff, but if you wanted to make it look like a human might be at the controls, strafing is way more natural - and strafing to a rear arc allows for mobs being walled on raids and stuff - as I'm in a high end guild, walling a mob happens pretty often.

Plazmic - Would the code to use that look something like this? I wish I was smarter at math :p

Code: Select all

/varset HeadingDiff $calc($target(heading)-$char(heading))
/if n @HeadingDiff>=180 {
	/varcalc HeadingDiff @Headingdiff-360
}
/if n @HeadingDiff<=-180 {
	/varcalc HeadingDiff @HeadingDiff+360
}
Now, if I'm interpretting this right... If char is facing exactly the same as mob, @HeadingDiff==0. If char is 40degrees to the right of the back of the mob, @HeadingDiff==40, and -40 for 40degrees left of back, right?
If thats the case it's pretty simple to write up movement code for it - for this I'll assume a 100degree 'back' of the mob

Code: Select all

:moveloop
	/face fast nopredict
	/varset HeadingDiff $calc($target(heading)-$char(heading))
	/if n @HeadingDiff>=180 {
		/varcalc HeadingDiff @Headingdiff-360
	}
	/if n @HeadingDiff<=-180 {
		/varcalc HeadingDiff @HeadingDiff+360
	}
	/if n @HeadingDiff<=-50 {
		/sendkey down ctrl
		/press left
		/press left
		/press left
		/sendkey up ctrl
		/goto :moveloop
	} else {
		/if n @HeadingDiff>=50 {
			/sendkey down ctrl
			/press right
			/press right
			/press right
			/sendkey up ctrl
			/goto :moveloop
		}
	} else {
		/return
	}
Sound about right? Or am I being a n00b again ^_^

~edited for typos in code
-TOG

ThatOtherGuy
a lesser mummy
a lesser mummy
Posts: 41
Joined: Tue Aug 05, 2003 6:12 pm

Post by ThatOtherGuy » Wed Oct 08, 2003 6:10 pm

Got it working, and it works beautifully! Heres the movebehind code, if you're interested :P I removed to loop so that it would check teh range from mob in between strafes and help not lose DPS that way.

Code: Select all

Sub movebehind
/if $target()==FALSE { 
	/attack off 
	/sendkey up up 
	/return
}
/face fast nopredict
/varset HeadingDiff $calc($target(heading)-$char(heading))
/if n @HeadingDiff>=180 {
	/varcalc HeadingDiff @HeadingDiff-360
}
/if n @HeadingDiff<=-180 {
	/varcalc HeadingDiff @HeadingDiff+360
}
/if n @HeadingDiff<=-60 {
	/sendkey down ctrl
	/press left
	/press left
	/face fast nopredict
	/sendkey up ctrl
} else {
	/if n @HeadingDiff>=60 {
		/sendkey down ctrl
		/press right
		/press right
		/face fast nopredict
		/sendkey up ctrl
	}
} else {
	/return
}
/return
-TOG

Plazmic
The One
The One
Posts: 800
Joined: Fri Jun 14, 2002 12:31 am
Contact:

Post by Plazmic » Wed Oct 08, 2003 9:07 pm

Glad it's working... a little extra parsing time could be removed though:
ThatOtherGuy wrote:

Code: Select all

		/face fast nopredict
		/sendkey up ctrl
	}
[color=red]} else {
	/return[/color]
}
/return
- Plazmic