SRL Archive - SRL Suggestions

Walking with angle.


Main

2011-02-11 16:10:06

Instead of looking for colour, if you know the angle of the object with respect to your character, why not use that to walk towards or away from the object?

Function one will give you the angle between a coordinate and the north, regardless of your current compass.
The variable z is a dummy angle, which you can use to pick your own reference point, just make sure to set the custom to true.


Function two will walk you towards or away from a angle (The angle is the angle away from north) regardless of your current compass.

Example of use:

{This script will in theory keep you at the same location, but randomness in WalkAngle will make it slightly off}

begin
Setupsrl;
repeat
If Findcolor(X, Y, Flagcolor, MMX1, MMY1, MMX2, MMY2) then
Begin
WalkAngle(AngleToNorth(X, Y, 0, false), true);
While flagpresent do Wait(1);
End;
Until false
end.


Here are the two codes:
{*****************************************************************
Function AngleToNorth(X, Y, Z: Integer; Custom: Boolean): Integer;
By: Main Ftw
Descript: Give the angle between a point and the north compass. The
north compass can be replaced by any other compass degrees.
*****************************************************************}
Function AngleToNorth(X, Y, Z: Integer; Custom: Boolean): Integer;
var
N: Tpoint;
C, H: Integer;
Begin
X:=X - MMCX;
Y:=Y - MMCY;
H:=Round(Hypot(X, Y));
X:=76 * X / H;
Y:=76 * Y / H;
If Custom then C:=Z
else
C:=round(RS_GetCompassAngleDegrees);
N:=Inttopoint(Round(-1000 * Sin(Radians(C))),Round(-1000 * Cos(Radians(C))));
H:=Round(Hypot(N.x, N.y));
N:=Inttopoint(76 * N.x / H, 76 * N.y / H);
Result:=Round(Degrees(ArcCos((N.x * X + N.y * Y)/(Hypot(X, Y) * Hypot(N.x, N.y)))));
If Result > 0 then
Begin
If C < 180 then
Begin
If ((X < 0) and (Y < N.y)) or ((X > 0) and (Y < -1 * N.y)) then Result:=360 - Result;
End else
If ((X < 0) and (Y > -1 * N.y)) or ((X > 0) and (Y > N.y)) then Result:=360 - Result;
End;
Writeln(Inttostr(Result));
End;

{*******************************************************************************
Procedure WalkAngle(Z, H: Integer; Back, Custom: Boolean);
By: Main Ftw
Description: Walk to a position with angle z away from the north. With a bonus
feature of walk to the opposite direction or a custom distance.
*******************************************************************************}
Procedure WalkAngle(Z, H: Integer; Back, Custom: Boolean);
var
P: Tpoint;
R, C: Integer;

Begin
If back then Z:=Z+180;
C:=round(RS_GetCompassAngleDegrees);
P.x:=Round(-100 * Sin(Radians(C + Z)));
P.y:=Round(-100 * Cos(Radians(C + Z)));
If Not Custom then H:=Round(Hypot(P.x, P.y));
R:=randomrange(20,70);
P.x:=MMCX + R * P.x / H;
P.y:=MMCY + R * P.y / H;
Mouse(P.x, P.y, 0, 0, true);
End;



EDIT: This does not require color, so you can avoid using long findcolor high tolerance in placese like dung he.

Wizzup?

2011-02-11 16:14:34

I think this technique has been used several times, perhaps radialwalk even applies it. I think I did have a radialwalk that applied it, anyway.

Main

2011-02-11 16:23:48

I found this in map walk.
  if (Direction < 50) then
SD := ((Direction + 360) - 50)
else
SD := (Direction - 50);

But mine does it without color or change of compass :p.
My thing was made to get player unstuck from fire cave or any other locations where monster or scripts can get the player away from a location. I fixed the old code and added the feature to walk towards a angle aswell. I just thought it was a good idea.

Wanted

2011-02-12 01:33:54

This isn't any more accurate than offsetting a coordinate using simple subtraction/addition i.e.

Ladder.X - 15, Ladder.Y + 6

Now, if you wanted to apply compass angles to that.. no need to even apply trig.. just use a simple rotate point or ToPolar.

Sir R. M8gic1an

2011-02-12 08:07:13

So what points would I use to walk in ur picture?

x=Altar and y=road and z = 0 (North?)

or where do I put the angles?

I just don't get how to use ur func :p

~RM

Naum

2011-02-12 08:58:31

[php]function RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod, Tol: Integer): Boolean;[/php]

Couldn't this be achieved by using RadialWalkEx with high tolerance?

So to walk 65 pixels with a bearing of roughly 090 degrees:

RadialWalkTolerance(ClBlack, 89, 91, 65, 0, 0, 300{});

Main

2011-02-13 11:31:31

From: IceFire908
This isn't any more accurate than offsetting a coordinate using simple subtraction/addition i.e.
Ladder.X - 15, Ladder.Y + 6
Now, if you wanted to apply compass angles to that.. no need to even apply trig.. just use a simple rotate point or ToPolar.


I am not sure what your talking about in offset, but I never knew about rotate point or topolar, and that could definitely work.


From: Sir R. M8gic1an
So what points would I use to walk in ur picture?
I just don't get how to use ur func :p
~RM


The altar and the other symbol are representing coordinates (X Y) which you enter to AngleToNorth Function, the angle shows the result of the function.

If you look at the example script, it records the coordinate of the flag, put it in the equation with z=0 (dummy), and walks back to the original position with those coordinate (back=true).

The Z is only used for if you were to refer the object's angle to a different object. It can be best used for monsters, but its useless for objects that are stationary.


From: Naum
[php]function RadialWalkTolerance(TheColor, StartRadial, EndRadial, Radius, Xmod, Ymod, Tol: Integer): Boolean;[/php]

Couldn't this be achieved by using RadialWalkEx with high tolerance?
RadialWalkTolerance(ClBlack, 89, 91, 65, 0, 0, 300{});


I guess but mine care about the northern compass, unless you can do rotate point or to polar thing that ice fire mentioned.



In my opinion, I think my functions are easier to use and it does what it does well hehe, if other options of getting players "un-lost" did exist, why didn't any one use them in willow cutters or hy's fc runner?