SRL Archive - SRL Archives

FindColorsToleranceMM / FindColorToleranceMM / FindColorsMM / FindColorMM


Shuttleu

2009-05-31 22:43:36


function FindColorsToleranceMM(var Points: TPointArray; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
begin
if (not(LoggedIn)) then exit;
if FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol) then
begin
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
Result := Length(TPA) > 0;
if Result then
Points := TPA;
end;
end;

function FindColorsMM(var Points: TPointArray; Color: Integer): Boolean;
begin
Result := FindColorsToleranceMM(Points, Color, 0);
end;

function FindColorMM(var x, y: Integer; Color: Integer): Boolean;
begin
if (not(LoggedIn)) then exit;
Result := FindColorCircle(x, y, Color, MMCX, MMCY, 76);
end;

function FindColorToleranceMM(var x, y: Integer; Color, Tol: Integer): Boolean;
begin
if (not(LoggedIn)) then exit;
Result := FindColorCircleTolerance(x, y, Color, MMCX, MMCY, 76, Tol);
end;
it searches for a color on the MM then uses InCircle to make sure it is on the MM and not in one of the corners around the edges of the MM

~shut

mixster

2009-05-31 22:47:54

FilterPointsPie would remove the need for the InCircle check loop, though you could use rs_OnMinimap as well for the check to see if it is in a valid place.

Naum

2009-05-31 22:58:09

function FindColorsMM(var Points: TPointArray; Color: Integer): Boolean;
var
TPA: TPointArray;
begin
if FindColorsToleranceMM(TPA, Color, 0) then
begin
Points:= TPA;
Result:= True;
end;
end;

function FindColorMM(var x, y: Integer; Color: Integer): Boolean;
var
TPA: TPointArray;
begin
if FindColorsToleranceMM(TPA, Color, 0) then
begin
x:= TPA[0].x;
y:= TPA[0].y;
Result:= True;
end;
end;

function FindColorToleranceMM(var x, y: Integer; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
begin
if FindColorsToleranceMM(TPA, Color, Tol) then
begin
x:= TPA[0].x;
y:= TPA[0].y;
Result:= True;
end;
end;

Shortened to:

function FindColorsMM(var Points: TPointArray; Color: Integer): Boolean;
var
TPA: TPointArray;
begin
Result := FindColorsToleranceMM(TPA, Color, 0);
If Result Then
Points:= TPA;
end;

function FindColorMM(var x, y: Integer; Color: Integer): Boolean;
var
TPA: TPointArray;
begin
Result := FindColorsToleranceMM(TPA, Color, 0);
If Result Then
begin
x:= TPA[0].x;
y:= TPA[0].y;
end;
end;

function FindColorToleranceMM(var x, y: Integer; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
begin
Result := FindColorsToleranceMM(TPA, Color, Tol);
If Result Then
begin
x:= TPA[0].x;
y:= TPA[0].y;
end;
end;

Good work, son :)

A small edit for your first function, to make sure the result is actually correct also removed one variable ;)

function FindColorsToleranceMM(var Points: TPointArray; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
i, ArrayLength: Integer;
begin
if (not(LoggedIn)) then exit;
if FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2, MSY2, Tol) then
begin
for i:=0 to GetArrayLength(TPA)-1 do
if InCircle(TPA[i].x, TPA[i].y, MMCX, MMCY, 76) then
begin
ArrayLength:= GetArrayLength(Points);
SetArrayLength(Points, ArrayLength+1);
Points[ArrayLength]:= TPA[i];
Result:= (High(TPA) > 0) ; //Added this - incase no points.
end;
end;
end;

Rep'ed

Shuttleu

2009-05-31 23:01:01

so would i use it as
FilterPointsPie(TPA, 0, 360, 0, 76, MMCX, MMCY);
?

~shut

Naum

2009-05-31 23:09:14

@Shut you'd need to have an extra parameter to specify the Radials if you did that :/, at least I think.

Shuttleu

2009-05-31 23:11:24

From: NaumanAkhlaQ
@Shut you'd need to have an extra parameter to specify the Radials if you did that :/, at least I think.

FilterPointsPie(TPA, 0{SD}, 360{ED}, 0{SR}, 76{ER}, MMCX, MMCY);
~shut

Naum

2009-05-31 23:12:29

From: Shuttleu
FilterPointsPie(TPA, 0{SD}, 360{ED}, 0{SR}, 76{ER}, MMCX, MMCY);
~shut


Is that a 'your right' or a 'your wrong'?

Shuttleu

2009-05-31 23:15:03

you said i needed to add an extra perameter for the radials
SD is Start Degrees
ED is End Degrees
SR is Start Radius
ER is End Radius

so your wrong (i think)

~shut

Naum

2009-05-31 23:41:58

{procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer);
Description: Removes the points in the TPointArray Points that are not within
the degrees SD (StartDegree) and ED (EndDegree) and the distances
MinR (MinRadius) and MaxR (MaxRadius) from the origin (Mx, My).}

Doesn't that work On radial's though?


{I think) :)

Also whats the points of that, Doesn't In Circle do that anyway?

senrath

2009-05-31 23:55:34

Um, slight error here:

if FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2, MSY2, Tol) then
Shouldn't that be:


if FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol) then

mixster

2009-06-01 00:30:25

FilterPointsPie means that half the function can be put into one place. As far as I know, it does use degrees, hence SD and ED being Start Degree and End Degree. From that line, it looks right, though I thought the radius for the minimap was 72, hence that being the maximum for when you do walking. Oh, and your fix results in redundant code Nauman - first of all because I thought it was not up to SRL to check if the person is logged in first and secondly because you placed "Result:= (High(TPA) > 0);" in the main loop rather than at the end of the function (thought it should also be <> -1 or > -1 or >= 0 as High = -1 when empty, but this way it only allows a TPA of at least 2 to return true).

Shuttleu

2009-06-01 01:54:15

From: senrath
Um, slight error here:

if FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2, MSY2, Tol) then
Shouldn't that be:


if FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol) then

thanks
i typed it up twice but then scar kept crashing
so i didnt really check the third time
once again thanks
From: mixster
FilterPointsPie means that half the function can be put into one place. As far as I know, it does use degrees, hence SD and ED being Start Degree and End Degree. From that line, it looks right, though I thought the radius for the minimap was 72, hence that being the maximum for when you do walking.

oh i thought it was 76 :/
ok i shall change it

~shut

lordsaturn

2009-06-01 04:53:14

Shortened your first procedure abit
function FindColorsToleranceMM(var Points: TPointArray; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
begin
if (not(LoggedIn)) then exit;
if FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol) then
begin
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
Result := Length(TPA) > 0;
if Result then
Points := TPA;
end;
end;

Pointing out a few errors in your code
  1. The line if (TPArrayLength>0) then is redundant. If FindColorsTolerance results true then the length of the TPA is > 0, you don't need to check it again.
  2. The radius of the minimap is 76, not 72.
  3. It is bad coding technique to reset the length of the Points array every iteration of the for loop. To speed up your code dramatically, you should call SetArrayLength(Points, TPArrayLength); before the for loop, add a counter for the logical size within the for loop, and then reset the length after the for loop.

Nava2

2009-06-01 05:15:24

FindColorsPie

?

ZephyrsFury

2009-06-01 08:13:37

It is extremely inefficient to use FindColorsTolerance just to find the coord of one point. It would be better to use FindColorCircle or FindColorCircleTolerance within FindColorMM and FindColorToleranceMM:


function FindColorCircle(var x, y: Integer; color, mx, my, r: Integer): Boolean;
Finds a color in a circular area specified by a set of coordinates for the midpoint (mx, my) and a radius specified by r.

function FindColorCircleTolerance(var x, y: Integer; color, mx, my, r, Tolerance: Integer): Boolean;
Works like the regular FindColorCircle function but with a tolerance parameter for finding any similar color. Tolerance is used to find a color in range of the color you are looking for. The greater color range you want, the higher the tolerance parameter should be.


Shuttleu

2009-06-01 13:18:35

From: lordsaturn
Shortened your first procedure abit
function FindColorsToleranceMM(var Points: TPointArray; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
begin
if (not(LoggedIn)) then exit;
if FindColorsTolerance(TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol) then
begin
FilterPointsPie(TPA, 0.0, 360.0, 0.0, 76.0, MMCX, MMCY);
Result := Length(TPA) > 0;
if Result then
Points := TPA;
end;
end;

Pointing out a few errors in your code
  1. The line if (TPArrayLength>0) then is redundant. If FindColorsTolerance results true then the length of the TPA is > 0, you don't need to check it again.
  2. The radius of the minimap is 76, not 72.
  3. It is bad coding technique to reset the length of the Points array every iteration of the for loop. To speed up your code dramatically, you should call SetArrayLength(Points, TPArrayLength); before the for loop, add a counter for the logical size within the for loop, and then reset the length after the for loop.

i thought it was 76 but mixster said it was 72 so i changed it to 72
and thankyou for correcting the problems that i had left
From: ZephyrsFury
It is extremely inefficient to use FindColorsTolerance just to find the coord of one point. It would be better to use FindColorCircle or FindColorCircleTolerance within FindColorMM and FindColorToleranceMM:


function FindColorCircle(var x, y: Integer; color, mx, my, r: Integer): Boolean;
Finds a color in a circular area specified by a set of coordinates for the midpoint (mx, my) and a radius specified by r.

function FindColorCircleTolerance(var x, y: Integer; color, mx, my, r, Tolerance: Integer): Boolean;
Works like the regular FindColorCircle function but with a tolerance parameter for finding any similar color. Tolerance is used to find a color in range of the color you are looking for. The greater color range you want, the higher the tolerance parameter should be.


ok i shall add them into the functions then

~shut

EDIT: would this be correct?
function FindColorsToleranceMM(var Points: TPointArray; Color, Tol: Integer): Boolean;
var
TPA: TPointArray;
begin
if (not(LoggedIn)) then exit;
FindColorsPie(TPA, Color, Tol, 0.0, 160.0, 0.0, 76.0, MMX1, MMY1, MMX2, MMY2, MMCX, MMCY);
Result := Length(TPA) > 0;
if Result then
Points := TPA;
end;

ZephyrsFury

2009-06-01 13:45:31


FindColorsPie(TPA, Color, Tol, 0.0, 360.0, 0.0, 76.0, MMX1, mMY1, MMX2, MMY2, MMCX, MMCY);

Change 160.0 to 360.0 for a full circle.

Shuttleu

2009-06-01 13:46:51

From: ZephyrsFury

FindColorsPie(TPA, Color, Tol, 0.0, 360.0, 0.0, 76.0, MMX1, mMY1, MMX2, MMY2, MMCX, MMCY);

Change 160.0 to 360.0 for a full circle.

oh yea i ment 360 -_-'
im in school atm and im very bored and tired

~shut

Naum

2009-06-01 19:46:49

From: mixster
FilterPointsPie means that half the function can be put into one place. As far as I know, it does use degrees, hence SD and ED being Start Degree and End Degree. From that line, it looks right, though I thought the radius for the minimap was 72, hence that being the maximum for when you do walking. Oh, and your fix results in redundant code Nauman - first of all because I thought it was not up to SRL to check if the person is logged in first and secondly because you placed "Result:= (High(TPA) > 0);" in the main loop rather than at the end of the function (thought it should also be <> -1 or > -1 or >= 0 as High = -1 when empty, but this way it only allows a TPA of at least 2 to return true).


because I thought it was not up to SRL to check if the person is logged in first

It was shut's code, I did not touch that line..

Result:= (High(TPA) > 0);" in the main loop rather than at the end of the function


MainLoop?
I kinda agree I should have added an If Result Then Break :)

TPA of at least 2 to return true


program New;

Var X : Integer;

begin
X := 1;
If (High(X) > 0) Then
WriteLn('One works!');
end.

-> 1 works, son. Excuse me if I'm wrong, I did those edits in my school, there should was a quick rush to make sure the teacher did not catch me, which leads to detentions and such ;).

Your -1 point is absolutely correct, so I thank-you :).
Sorry if I am wrong, please correct me if anything these is not right :).

ZephyrsFury

2009-06-01 20:09:00

From: NaumanAkhlaQ
It was shut's code, I did not touch that line..



MainLoop?
I kinda agree I should have added an If Result Then Break :)



program New;

Var X : Integer;

begin
X := 1;
If (High(X) > 0) Then
WriteLn('One works!');
end.

-> 1 works, son. Excuse me if I'm wrong, I did those edits in my school, there should was a quick rush to make sure the teacher did not catch me, which leads to detentions and such ;).

Your -1 point is absolutely correct, so I thank-you :).
Sorry if I am wrong, please correct me if anything these is not right :).


If you're trying to check if a TPA isn't empty then use:


if (Length(TPA) > 0) then

OR

if (High(TPA) > -1) then

Nava2

2009-06-02 02:29:17

You should use RemoveDistTPA its faster ;)