SRL Archive - OSR Help

TPA, how to ignore character when finding color?


jannemus

2012-07-14 03:40:40

Hello!

I'm tried to make a TPA for my character and then make it not to search in that area. Becourse if you have same color on your armor it should not klick on it. So the area is the one in middle while standing still.
The thing is, im getting errors when i try to run it :(

Exception: Range check error at line 20
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap


Line 20: TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));


It should right click and attack Barbarians and ignore to search in the middle part of the screen.

Maybe there is an easier way to do this?

program new;
{$i SRL/srl.simba}

Function FindSomething : Boolean;
Var
CTS, x, y, I, h : Integer;
TPAYou, TPA: TPointArray;
ATPA: Array of TPointArray;
CPA: T2DPointArray;
mid: TPoint;
Begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(3.49, 5.27);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3041353, MSX1, MSY1, MSX2, MSY2, 7);
ColorToleranceSpeed(CTS)
ATPA := TPAToATPAEx(TPA, 25, 25);
For I := 0 to High(ATPA) do
Begin
TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));

CPA := SplitTPA(TPA, 0);

h := High(CPA);
for i := 0 to h do
begin
if(GetArrayLength(CPA[i]) >= 2) then
begin
mid := MiddleTPA(CPA[i]);
if((mid.x > 5) AND (mid.y > 2)) then
begin
if((NOT PointInTPA(mid, TPAYou))) then
begin
MMouse(mid.x, mid.y, 0, 0);
begin
MiddleTPAEx(ATPA[i], x, y);
Mouse(x, y, 2, 2,False);
If (ChooseOption('ttack')) Then
Begin
Wait(1000);
Result := True;
Exit;
End;
End;
End;
End;
End;
End;
End;
Result := False;

End;

begin
SetupSRL;
FindSomething;
end.

Thanks!

Dear // Jannemus!

Flight

2012-07-14 03:53:55

A couple things I noticed. First off, 'IntToBox' has the parameters in this order: X1, Y1, X2, Y2. You have:

TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));
According to this your box's Y1 is > than the Y2 value… So… are you sure that's correct? :/

Another thing is you're actually never removing the 'box area' around your player from your found colour's TPA. You should do this instead:

program new;
{$i SRL/srl.simba}

function FindSomething: Boolean;
var
CTS, x, y, I, h: Integer;
TPAYou, TPA: TPointArray;
ATPA: array of TPointArray;
CPA: T2DPointArray;
mid: TPoint;
begin
TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250)); //You'll want to fix these parameters in the X1,Y1,X2,Y2 format
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(3.49, 5.27);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3041353, MSX1, MSY1, MSX2, MSY2, 7);
SetColorSpeed2Modifiers(0.2, 0.2); //Also added this in
ColorToleranceSpeed(CTS);
TPA := ClearTPAFromTPA(TPA, TPAYou); //Here's where you actually remove any of the TPA that's included in your box
ATPA := TPAToATPAEx(TPA, 25, 25);
for I := 0 to High(ATPA) do
begin
CPA := SplitTPA(TPA, 0); //Why? :/
h := High(CPA);
for i := 0 to h do
begin
if (GetArrayLength(CPA[i]) >= 2) then
begin
mid := MiddleTPA(CPA[i]);
if ((mid.x > 5) and (mid.y > 2)) then
begin
if ((not PointInTPA(mid, TPAYou))) then
begin
MMouse(mid.x, mid.y, 0, 0);
begin
MiddleTPAEx(ATPA[i], x, y);
Mouse(x, y, 2, 2, False);
if (ChooseOption('ttack')) then
begin
Wait(1000);
Result := True;
Exit;
end;
end;
end;
end;
end;
end;
end;
Result := False;
end;

begin
SetupSRL;
FindSomething;
end.

I used Simba's handy little 'Format Script' button to clean up your code. :p

Shatterhand

2012-07-14 04:26:58

I use this in my functions.
    
SortTPAFrom(TPA,Point(MSCX,MSCY));
InvertTPA(TPA);
for i:=0 to High(TPA) do
if (Abs(TPA[i].x - MSCX) < 25) and (Abs(TPA[i].y - MSCY) < 25) then
Break;
SetArrayLength(TPA,i);
This will exclude points in the TPA which are in the 25 distant box from the (MSCX,MSCY).
NOTE: your function should handle the case when it sets the array lenght to 0. (it breaks when i = 0)

jannemus

2012-07-14 17:21:23

From: Flight
A couple things I noticed. First off, 'IntToBox' has the parameters in this order: X1, Y1, X2, Y2. You have:

TPAYou := TPAFromBox(IntToBox(205, 263, 291, 250));
According to this your box's Y1 is > than the Y2 value… So… are you sure that's correct? :/

Another thing is you're actually never removing the 'box area' around your player from your found colour's TPA. You should do this instead


I used Simba's handy little 'Format Script' button to clean up your code. :p


Thanks for all help!

Changed TPA now in the script you sent me.
TPAYou := TPAFromBox(IntToBox(226, 292, 133, 254));

I thought it was x1,x2,y1,y2. hehe.

But i get the same error, but now at line 23

if (GetArrayLength(CPA[i]) >= 2) then 

Error: Out Of Range at line 23
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap]


Thanks again!

Dear // Jannemus!

Sin

2012-07-14 17:29:26

I did this a while back, Im not sure how it goes (lost the code in the crash).
I basically made 4 different boxes
box[1] := IntToBox(50,50,100,100);
box[2] := IntToBox(150,150,200,200);
box[3] := IntToBox(250,250,300,300);
box[4] := IntToBox(350,350,400,400);

Then looped it via a for..to..do loop like this


for i := 1 to 4 do
begin
if FindColorsTolerance(Box.x1[i],Box.y1[i],Box.x2[i],Box.y2[i],col,tol) then
yadayadadaa
end;

That'll basically ignore the character, and search in boxes around it.

Nebula

2012-07-15 16:25:14

Lol.

RemoveDistTPointArray.

Olly

2012-07-19 15:06:38

Cant you do cleartpafromtpa? or something like that

Sex

2012-07-19 15:25:49

Wasn't there a FindColorsSkipBox function?