SRL Archive - OSR Help

Help with ATPA please


Slashed

2012-12-14 21:02:47

So, I've been all day coding a simple rock finder using ATPA, should be done in 10 minutes or less but instead is error after error when everything seems correct.

It compiles fine but the behave it has is very different.

I defined the TPA and the ATPA, created a MS region for the findcolorstolerance, divided even in that space in small boxes 10 w 10 h and used splitTPAEx.

What it does is loop through the ATPA as if nothing was found and just loops and loops even with a break there.

I know it's hard to but please, try to ignore the messy standards. ( Doesn't do the proper standards in a QUOTE statement)

I leave here the parts that are giving me trouble:

Function FindTin: Boolean;
var
tmpCTS, i, x, y: Integer;
RockTPA: TPointArray;
RockATPA: T2DPointArray;

begin


tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.06,0.87);

FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19)

SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02,0.02);

RockATPA := SplitTPAEx(RockTPA, 10, 10);
SortATPASize(RockATPA, True);

for i :=0 to high(RockATPA) do
begin
MiddleTPAEx(RockATPA,x,y);
MMouse(x, y, 5, 5);
if WaitUptext('ocks', 400)then
begin
Result := True;
Exit;
end;
end;
end;

Procedure MineTin;

begin
if FindTin then
begin
case random(100) of

0..75:begin
wait(RandomRange(50,150));
FastClick(mouse_left);
repeat
wait(1000 + random(100));
until not PlayerIsMining;
end;
76..100:begin
wait(RandomRange(50,150));
FastClick(mouse_right);
wait(100+Random(100));
ChooseOption('Tin');
repeat
wait(1000 + random(100));
until not PlayerIsMining;
end;
end;
end;
end;

Nebula

2012-12-14 21:06:54

Use MSX1, MSY1, MSX2, MSY2 instead of the hand-picked coordinates you have. I think you didn't set the client before grabbing the coordinates, so they're all off, making the object never found.

Slashed

2012-12-14 21:08:29

Oh, I forgot to mention that I restricted that because it was doing the same thing. Before, I had MSX1,MSY1, MSX2, MSY2 in the FindColorsTolerance and it still did the same thing. So I guess it's not from that.

Any idea mate? Thanks for the reply :biggrin:

DannyRS

2012-12-14 21:16:59

Try looking for isup "mine" "ine" not rocks?

Dont think it looks that far for text

That first repeat wait until notmining, looks a bit sketchy, if thats not working, theres no way to break?

Slashed

2012-12-14 21:23:01

From: DannyRS
Try looking for isup "mine" "ine" not rocks?

Dont think it looks that far for text


Nope, still doesn't work :confused:

DannyRS

2012-12-14 21:26:23

From: Slashed
Nope, still doesn't work :confused:


Just call the TPA, not any of the other loop, and add this to just after the size sort

DebugATPABounds(ATPA);

Will print out the ATPA on screen

Brandon

2012-12-14 21:39:54

What is PlayerIsMining?

I see nothing wrong with it.. I fixed the standards and added a length check :l


function FindTin: Boolean;
var
tmpCTS, i, x, y: Integer;
RockTPA: TPointArray;
RockATPA: T2DPointArray;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.06, 0.87);
FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19);
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

If (Length(RockTPA) < 1) Then Exit;

RockATPA := SplitTPAEx(RockTPA, 10, 10);
SortATPASize(RockATPA, True);

for i := 0 to high(RockATPA) do
begin
MiddleTPAEx(RockATPA[i], x, y);
MMouse(x, y, 5, 5);
if WaitUptext('ock', 600) then
begin
Result := True;
Exit;
end;
end;
end;

procedure MineTin;
begin
if FindTin then
begin
case random(100) of
0..75:
begin
wait(RandomRange(50, 150));
FastClick(mouse_left);
repeat
wait(1000 + random(100));
until not PlayerIsMining;
end;
76..100:
begin
wait(RandomRange(50, 150));
FastClick(mouse_right);
wait(100 + Random(100));
ChooseOption('Tin');
repeat
wait(1000 + random(100));
until not PlayerIsMining;
end;
end;
end;
end;

Slashed

2012-12-14 21:42:19

From: Brandon
What is PlayerIsMining?

I see nothing wrong with it.. I fixed the standards and added a length check :l


function FindTin: Boolean;
var
tmpCTS, i, x, y: Integer;
RockTPA: TPointArray;
RockATPA: T2DPointArray;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.06, 0.87);
FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19);
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

If (Length(RockTPA) < 1) Then Exit;

RockATPA := SplitTPAEx(RockTPA, 10, 10);
SortATPASize(RockATPA, True);

for i := 0 to high(RockATPA) do
begin
MiddleTPAEx(RockATPA[i], x, y);
MMouse(x, y, 5, 5);
if WaitUptext('ock', 600) then
begin
Result := True;
Exit;
end;
end;
end;

procedure MineTin;
begin
if FindTin then
begin
case random(100) of
0..75:
begin
wait(RandomRange(50, 150));
FastClick(mouse_left);
repeat
wait(1000 + random(100));
until not PlayerIsMining;
end;
76..100:
begin
wait(RandomRange(50, 150));
FastClick(mouse_right);
wait(100 + Random(100));
ChooseOption('Tin');
repeat
wait(1000 + random(100));
until not PlayerIsMining;
end;
end;
end;
end;


PlayerIsMining is an AveragePixelShift check.


//Thanks to Flight for the pixelshift Tutorial
Function PlayerIsMining: Boolean;
var
playerBox: TBox;
begin
PlayerBox := IntToBox(245, 130, 285, 195);
Result := (AveragePixelShift(playerBox, 250, 500) > 400);
end;

Looking now with other eyes, it seems the problem may be on the definition of the result. Any ideas?

Justin

2012-12-14 21:43:51

From: Slashed
PlayerIsMining is an AveragePixelShift check.


That should be a function : boolean returning true\false if the AveragePixelShift is reached

Brandon

2012-12-14 21:47:24

From: Slashed
PlayerIsMining is an AveragePixelShift check.


//Thanks to Flight for the pixelshift Tutorial
Function PlayerIsMining: Boolean;
var
playerBox: TBox;
begin
PlayerBox := IntToBox(245, 130, 285, 195);
Result := (AveragePixelShift(playerBox, 250, 500) > 400);
end;

Looking now with other eyes, it seems the problem may be on the definition of the result. Any ideas?


Looks about right.. Where did you get FastClick from? I see no such function in Simba's includes :l

Change fast click to something like:

ClickMouse2(MOUSE_LEFT);

Also your animation function might be giving false positives. Run it in a test loop and see if it detects you mining all the time or not.

Slashed

2012-12-14 21:55:21

From: [J]ustin
That should be a function : boolean returning true\false if the AveragePixelShift is reached


I thought about that, but if I say that the result in the PlayerIsMining is the AveragePixelShift(something), AveragePixelShift is a boolean itself, it detects if the the pixels change a lot and return true or false and assigns that to the result.

Brandon, FastClick is a mouse procedure by Flight, I tried with clickmouse2 before and it still did a loop. It gets stuck somewhere in the beginning.

Will try what DannyRS and you suggested. Will report soon. Thanks for the replies guys!

Flight

2012-12-14 21:56:54

From: Brandon
Looks about right.. Where did you get FastClick from? I see no such function in Simba's includes :l

Change fast click to something like:

ClickMouse2(MOUSE_LEFT);

Also your animation function might be giving false positives. Run it in a test loop and see if it detects you mining all the time or not.


FastClick is one of mine. Also, adding on to this, I'd also recommend adjusting your "PlayerIsMining" function. Try getting your player's average pixel shift facing all 4 directions.

Slashed

2012-12-14 22:01:52

From: Flight
FastClick is one of mine. Also, adding on to this, I'd also recommend adjusting your "PlayerIsMining" function. Try getting your player's average pixel shift facing all 4 directions.


Oh, that makes sense. Will try tomorrow ( 3 am here). Will report progress on this tomorrow. Thanks for the insight Flight! :biggrin:

Slashed

2012-12-15 13:14:06

EDIT: Sorry for the double post! Didn't notice.

Reporting in,

So after tweaking a LOT to no avail, I tried a different approach and it worked! I'm so happy! :biggrin:

I tweaked the PlayerIsMining function after debugging my pixels and lowered the condition for the AveragePixelShift to return true. I deleted the repeat and replaced with a while. After that I only did an IF THEN check for the uptext, if it found it, it would break out of the loop and set the result to true.



I leave here the code to the curious ones:

Ignore the case statement as I deleted the right mouse clicking case for testing purposes.


function FindTin: Boolean;
var
tmpCTS, i, x, y: Integer;
RockTPA: TPointArray;
RockATPA: T2DPointArray;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.06, 0.87);
FindColorsTolerance(RockTPA, 10790596, 185, 175, 327, 258, 19);
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);

If (Length(RockTPA) < 1) Then Exit;

RockATPA := SplitTPAEx(RockTPA, 10, 10);
SortATPASize(RockATPA, True);


for i := 0 to high(RockATPA) do
begin
MiddleTPAEx(RockATPA[i], x, y);
MMouse(x, y, 5, 5);
if WaitUpTextMulti(['ine', 'in', 're', 'ore', ' ock'], 600) then
Break
else Writeln('We didnt find the rock');
end;
Result :=True;
end;

procedure MineTin;
begin
if FindTin then
begin
case random(100) of
0..100:
begin
wait(RandomRange(50, 150));
FastClick(mouse_left);
while PlayerIsMining do
wait(1000 + random(100));
end;
end;
end;
end;

Thanks a lot to everyone who lost 5 minutes of their time to help me! Really appreciated!

Wardancer

2012-12-15 16:41:13

From what I can see, your function will still result as true if you don't find any ore if it goes through the ATPA to no avail. You might want to add some Exit with your writeln to avoid this.

Flight

2012-12-15 19:35:35

From: Wardancer
From what I can see, your function will still result as true if you don't find any ore if it goes through the ATPA to no avail. You might want to add some Exit with your writeln to avoid this.


Ah yeah you're right Wardancer. Take a look at where you placed "Result := True;" in your findTin function, Slashed. Here's what I would recommend using instead for your for…to…do loop:


for i := 0 to high(RockATPA) do
begin
MiddleTPAEx(RockATPA[i], x, y);
MMouse(x, y, 5, 5);
if WaitUpTextMulti(['ine', 'in', 're', 'ore', ' ock'], 600) then
begin
Result :=True;
Exit;
end else
Writeln('We didnt find the rock');
end;

Notice the placement of Result := True and how it exits the functions immediately following successfully finding the tin rock.

Slashed

2012-12-15 22:15:45

From: Flight
Ah yeah you're right Wardancer. Take a look at where you placed "Result := True;" in your findTin function, Slashed. Here's what I would recommend using instead for your for…to…do loop:


for i := 0 to high(RockATPA) do
begin
MiddleTPAEx(RockATPA[i], x, y);
MMouse(x, y, 5, 5);
if WaitUpTextMulti(['ine', 'in', 're', 'ore', ' ock'], 600) then
begin
Result :=True;
Exit;
end else
Writeln('We didnt find the rock');
end;

Notice the placement of Result := True and how it exits the functions immediately following successfully finding the tin rock.



Well, that was stupid on my part :redface: I had the result inside the loop before but when tweaking I must have left the result outside the loop. My bad!

Thanks Wardancer and Flight!