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:
Here are the two codes:
EDIT: This does not require color, so you can avoid using long findcolor high tolerance in placese like dung he.
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.