SRL Archive - OSR Help

TPA Help


**BANNED The Man

2010-12-23 21:21:11

Which TPA is best?

Function FindTrees(Var X, Y : Integer; W, H, X1, Y1, X2, Y2 : Integer): Boolean;
Begin
var
x, y, i, h : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
begin
if not LoggedIn then Exit;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.17, 1.87);
begin
FindColorsSpiralTolerance(x, y, TPA, 2904128, MSX1, MSY1, MSX2, MSY2, 6);
SetColorToleranceSpeed(1);
ATPA := SplitTPAEx(TPA, 4, 4);
if (Length(ATPA) = 0) then
Exit;.
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));
h := High(ATPA);
for i := 0 to h do
begin;
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 3, 3);
WaitUpText('illo', 250);
end else
Exit;
end;
Writeln('Found the Willow!');
end;
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(1);
Result := Players[CurrentPlayer].Loc := 'found trees';
End;

program FindObject;
{.include SRL\SRL.scar}

var
x, y: Integer;

function FindObject(var fx, fy: Integer): Boolean;
var
arP, arAP: TPointArray;
arC, arUC: TIntegerArray;
ararP: T2DPointArray;
tmpCTS, i, j, arL, arL2: Integer;
P: TPoint;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.17, 1.87);

if not(FindColorsTolerance(arP, 2904128, MSX1, MSY1, MSX2, MSY2, 6)) then
begin
Writeln('Failed to find the color, no object found.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
arUC := arC;
ClearSameIntegers(arUC);
arL := High(arUC);
arL2 := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 3.31) and (X <= 8.16) and (Y >= 4.21) and (Y <= 10.91) and (Z >= 1.91) and (Z <= 5.93) then
begin
for j := 0 to arL2 do
begin
if (arUC[i] = arC[j]) then
begin
SetLength(arAP, Length(arAP) + 1);
arAP[High(arAP)] := arP[j];
end;
end;
end;
end;

SortTPAFrom(arAP, Point(MSCX, MSCY));
ararP := SplitTPAEx(arAP, 10, 10);
arL := High(ararP);

for i := 0 to arL do
begin
if (Length(ararP[i]) < 10) then Continue;
P := MiddleTPA(ararP[i]);
MMouse(P.x, P.y, 5, 5);
Wait(100 + Random(100));
if (IsUpText('Take')) then
begin;
Result := True;
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
begin
Writeln('FindObject could not find object.');
Exit;
end;

GetMousePos(fx, fy);
end;

begin
SetupSRL;
FindObject(x, y);
end.

Thankyoooo
-Boom

Frement

2010-12-23 21:26:02

The first one should do just fine in my opinion, thats what I use.

**BANNED The Man

2010-12-23 21:37:47

Ok, thank you.

-Boom

Train

2010-12-23 21:42:15

One you made yourself, not using ACA. ;)

**BANNED The Man

2010-12-23 21:45:08

From: Train
One you made yourself, not using ACA. ;)


First one it is then :)

Cheers
-Boom

TomTuff

2010-12-24 01:24:21

From: Dynamite

Function FindTrees(Var X, Y : Integer; W, H, X1, Y1, X2, Y2 : Integer): Boolean;
Begin
var
x, y, i, h : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
begin
if not LoggedIn then Exit;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.17, 1.87);
begin
FindColorsSpiralTolerance(x, y, TPA, 2904128, MSX1, MSY1, MSX2, MSY2, 6);
SetColorToleranceSpeed(1);
ATPA := SplitTPAEx(TPA, 4, 4);
if (Length(ATPA) = 0) then
Exit;.
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));
h := High(ATPA);
for i := 0 to h do
begin;
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 3, 3);
WaitUpText('illo', 250);
end else
Exit;
end;
Writeln('Found the Willow!');
end;
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(1);
Result := Players[CurrentPlayer].Loc := 'found trees';
End;


Just a few notes on efficient code:
Since you have local variables x and y set, they don't need to be in the parameters. Also, the other params are unused, so essentially none of the params are necessary.

Doing FindColorsSpiralTolerance then SortATPAFromFirstPoint is a waste of resources; I would just use FindColorsTolerance then SortATPAFromFirstPoint.

if you want this to be used in another function to cut trees, i would do "Result := WaitUptext('illo', 250)", then following that, do an "if Result then Exit;", however i would simply do it all in one function. To do this, do something like… if the uptext is found, then right click (ClickMouse2 ;)), then Result := WaitOption('whatever option', 600).

The way you use "Result := Players…" will ALWAYS return true, thus defeating the purpose of having it be a function. what you could do, is at the end, call "if Result then Players[CP].Loc := 'found trees', but what would be better (at least by what it looks like what you're trying to do from other threads) to do would be, in the mainloop do "if CutTrees then Players[CP].Loc := 'cut trees';"

Gu3st...

2010-12-24 10:06:15

From: TomTuff
Doing FindColorsSpiralTolerance then SortATPAFromFirstPoint is a waste of resources; I would just use FindColorsTolerance then SortATPAFromFirstPoint.
Actually, it's not a waste of resources. The first point in the FindColorsSpiralTolerance, will be near the middle of the screen, while the other will be near the top left

3Garrett3

2010-12-24 12:12:14

From: Zyt3x
Actually, it's not a waste of resources. The first point in the FindColorsSpiralTolerance, will be near the middle of the screen, while the other will be near the top left


But if you're sorting anyway, wouldn't it just be easier to use FindColorsTolerance? I thought that it was a little faster.

TomTuff

2010-12-24 13:33:18

From: Zyt3x
Actually, it's not a waste of resources. The first point in the FindColorsSpiralTolerance, will be near the middle of the screen, while the other will be near the top left


From: 3Garrett3
But if you're sorting anyway, wouldn't it just be easier to use FindColorsTolerance? I thought that it was a little faster.


This. You sort it twice, waste of resources.

Gu3st...

2010-12-24 18:48:06

From: 3Garrett3
But if you're sorting anyway, wouldn't it just be easier to use FindColorsTolerance? I thought that it was a little faster.

From: TomTuff
This. You sort it twice, waste of resources.
You guys are correct.. Sorry >_<
I though SortATPAFromFirstPoint sorted the ATPA from the first point in the ATPA, as the function name suggests…
I guess it should be renamed SortATPAFromPoint or something like that..

Wizzup?

2010-12-24 18:54:02

The sorting may be a lot faster is they are sorted more or less.

Boreas

2010-12-24 19:35:52

From: Wizzup?
The sorting may be a lot faster is they are sorted more or less.


Good point.

So use FindColorsSpiralTolerance(mmcx, mmcy