SRL Archive - OSR Help

How to check if a ATPA has a certain number of points?


rj

2013-05-17 12:58:31

I am trying to search for an object inside of a ATPA and i want to filter the ATPA so only ones with a certain number of points inside of them.

if (Length(ATPA[i]) > 2) then Continue;

I tried using this but I'm pretty sure that's checking for the number of ATPA's, not the number of points, how do i check the number of points?

Kevin

2013-05-17 13:14:26

if (Length(ATPAToTPA(ATPA)) > 2) then Continue;

How about that?

rj

2013-05-17 13:16:07

From: Kevin
if (Length(ATPAToTPA(ATPA)) > 2) then Continue;

How about that?


Ok thanks ill check if that works

Olly

2013-05-17 13:16:10

ATPA is a TPA so you are checking for the amount of points.

In SRL-6 i did add this though, should solve your needs.
https://github.com/SRL/SRL-6/blob/master/lib/tmp.simba#L241

rj

2013-05-17 13:22:56

From: Ollybest
ATPA is a TPA so you are checking for the amount of points.

In SRL-6 i did add this though, should solve your needs.
https://github.com/SRL/SRL-6/blob/master/lib/tmp.simba#L241


I get a type mismach on :

insert(atpa[i], c);

Olly

2013-05-17 13:28:51

That isn't in ps (at least in 992)

procedure filterTPAsBetween(var atpa: T2DPointArray; len1, len2: integer);
var
h, l, i: integer;
c: T2DPointArray;
begin
h := high(atpa);

for i := 0 to h do
begin
l := length(atpa[i]);

if (not (inRange(l, len1, len2))) then
begin
setLength(c, length(c) + 1); // could be done way more efficiency but meh.
c[high(c)] := atpa[i];
end;
end;

atpa := c;
end;

rj

2013-05-17 13:33:26

From: Ollybest
That isn't in ps (at least in 992)

procedure filterTPAsBetween(var atpa: T2DPointArray; len1, len2: integer);
var
h, l, i: integer;
c: T2DPointArray;
begin
h := high(atpa);

for i := 0 to h do
begin
l := length(atpa[i]);

if (not (inRange(l, len1, len2))) then
begin
setLength(c, length(c) + 1); // could be done way more efficiency but meh.
c[high(c)] := atpa[i];
end;
end;

atpa := c;
end;


I figured it would be in lape, but there is a problem now, it cannot find the object within the box, but I know the object exists because I have a high tolerance.
{$I SRL-OSR/SRL.Simba}
{$I SRL/SRL/Misc/Debug.simba}

Var
cage: TBox;
ATPA: T2DPointArray;
procedure filterTPAsBetween(var atpa: T2DPointArray; len1, len2: integer);
var
h, l, i: integer;
c: T2DPointArray;
begin
h := high(atpa);

for i := 0 to h do
begin
l := length(atpa[i]);

if (not (inRange(l, len1, len2))) then
begin
setLength(c, length(c) + 1);
c[high(c)] := atpa[i];
end;
end;

atpa := c;
end;
Function FindCage: Boolean;
var
TPA,TPA2: TPointArray;
i,CTS,X,Y: Integer;
begin
Result := False;

CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.00, 0.00);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 594520, 0, 0, 514, 338, 8);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA) < 1) then
Exit;

ATPA := TPAToATPAEx(TPA, 120, 120);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

for i := 0 to High(ATPA) do
begin

filterTPAsBetween(ATPA, 1, 8)

debugATPABounds(ATPA);
cage := GetTPABounds(ATPA[i]);
result := true;

end;
end;
Function FindDemon: Boolean;
var
cage: TBox;
TPA: TPointArray;
i,CTS,X,Y: Integer;
NPC_ATPA: T2DPointArray;
h:TPoint;

begin
Result := False;

CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.15, 1.94);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 662873, cage.x1, cage.y1, cage.x2, cage.y2, 11);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then Exit;

NPC_ATPA := TPAToATPAEx(TPA, 40, 40);

SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

debugATPABounds(NPC_ATPA);

for i := 0 to High(NPC_ATPA) do
begin

filterTPAsBetween(NPC_ATPA, 1, 5)
debugATPABounds(NPC_ATPA);
if WaitUpTextMulti(['', ''], 600) then

begin
MiddleTPAEx(NPC_ATPA[i], X, Y);
Result := true;
end;
end;
end;


begin
SetupSRL;
FindCage;
FindDemon;
end.

I have not added for it to move the mouse to the object yet, just trying to see if it will find it.

Olly

2013-05-17 13:38:44

take filterTPAsBetween(ATPA, 1, 8) out the loop, put it under tpaToATPAEx

and you forgot to set SetColorSpeed2Modifiers(0.00, 0.00);.

rj

2013-05-17 13:42:09

From: Ollybest
take filterTPAsBetween(ATPA, 1, 8) out the loop, put it under tpaToATPAEx

and you forgot to set SetColorSpeed2Modifiers(0.00, 0.00);.


Ok did all that, it was setting it back to what it orginally was, so I did all that.

{$I SRL-OSR/SRL.Simba}
{$I SRL/SRL/Misc/Debug.simba}

Var
cage: TBox;
ATPA: T2DPointArray;
procedure filterTPAsBetween(var atpa: T2DPointArray; len1, len2: integer);
var
h, l, i: integer;
c: T2DPointArray;
begin
h := high(atpa);

for i := 0 to h do
begin
l := length(atpa[i]);

if (not (inRange(l, len1, len2))) then
begin
setLength(c, length(c) + 1);
c[high(c)] := atpa[i];
end;
end;

atpa := c;
end;
Function FindCage: Boolean;
var
TPA,TPA2: TPointArray;
i,X,Y: Integer;
begin
Result := False;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.00, 0.00);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 594520, 0, 0, 514, 338, 2);
SetColorSpeed2Modifiers(0.00, 0.00);

if (Length(TPA) < 1) then
Exit;

ATPA := TPAToATPAEx(TPA, 120, 120);

filterTPAsBetween(ATPA, 1, 120)
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

for i := 0 to High(ATPA) do
begin


debugATPABounds(ATPA);
cage := GetTPABounds(ATPA[i]);
result := true;

end;
end;
Function FindDemon: Boolean;
var
cage: TBox;
TPA: TPointArray;
i,CTS,X,Y: Integer;
NPC_ATPA: T2DPointArray;
h:TPoint;

begin
Result := False;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.07, 1.82);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 1451877, cage.x1, cage.y1, cage.x2, cage.y2, 10);
SetColorSpeed2Modifiers(0.00, 0.00);
if (Length(TPA) < 1) then Exit;

NPC_ATPA := TPAToATPAEx(TPA, 40, 40);

filterTPAsBetween(NPC_ATPA, 1, 5)

SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));


debugATPABounds(NPC_ATPA);


for i := 0 to High(NPC_ATPA) do
begin

debugATPABounds(NPC_ATPA);
if WaitUpTextMulti(['ank', 'eposite'], 600) then

begin
MiddleTPAEx(NPC_ATPA[i], X, Y);

mmouse(x,y,1,1);
Result := true;
end;
end;
end;


begin
SetupSRL;
FindCage;
FindDemon;
end.

It's not moving the mouse I guess it's not finding it somehow

Olly

2013-05-17 13:48:04

do writeln(length(atpa)) after filterTPAsBetween(ATPA, 1, 120) to see if you actually have any atpa's to search in.

rj

2013-05-17 13:56:25

From: Ollybest
do writeln(length(atpa)) after filterTPAsBetween(ATPA, 1, 120) to see if you actually have any atpa's to search in.


Ok I did a little debugging and it does find it, as seen here:

271,81|392,225

But I also did a writeln in the findDemon procedure to get the coords again and the result was:

0,0|0,0

So somehow they are all resetting back to 0 even though cage is global?