SRL Archive - OSR Help

How to choose closest ATPA / tpa?


Peanuts

2013-05-28 10:41:09

How?





Function Findiron:boolean;
var
ironTPA, WoodTPA:TPointArray;
ironATPA:T2DPointArray;
ironBox:TBox;
i, r, counter:integer;
begin
if not(loggedin) then
exit;
SetColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.23, 0.83);
if findcolorstolerance(ironTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then
begin

SortATPASize(ironATPA, True);
for i := 0 to high(ironATPA) do
begin
ironBox := GetTPABounds(ironATPA[i]);
SetColorSpeed2Modifiers(0.04, 0.28);
if findcolorstolerance(ironTPA, 4609378, ironBox.x1, ironbox.Y1, ironbox.X2, ironbox.Y2, 15) then
Break;
if i = high(ironATPA) then
begin
writeln('Colours not finding!');
Terminatescript;
end;
end;
SetColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.02, 0.02);
marktime(counter);
while (not isuptextmulticustom(['ron','iron'])) do
begin
r := random(length(ironTPA));
mmouse(ironTPA[r].x, ironTPA[r].y, 3, 3);
wait(randomrange(200, 500));
if timefrommark(counter) > 5000 then
begin
writeln('No Uptext Found');
Logout;
Terminatescript;
end;
end;
clickmouse2(mouse_right);
if ChooseOption('em') then
begin
Writeln('Mining...');
end;
end;
end;

Peanuts

2013-05-28 10:44:06

I think you are right.. But i need a lil more explanation.. Can't seem to find info on it. Or i suck at google.

EngageTheRage

2013-05-28 10:44:57

you can use:

SortATPAFromMidPoint(yourATPA, yourTPoint)

and then the closest TPA to yourTPoint will be yourATPA[0]

Peanuts

2013-05-28 10:49:01

From: EngageTheRage
you can use:

SortATPAFromMidPoint(yourATPA, yourTPoint)

and then the closest TPA to yourTPoint will be yourATPA[0]


Thanks..
Makes sense. I think.

I'm just confused on what i put into the 'yourTpoint' part..
Which t point.. like.. erg..

EngageTheRage

2013-05-28 10:53:15

From: Peanuts
Thanks..
Makes sense. I think.

I'm just confused on what i put into the 'yourTpoint' part..
Which t point.. like.. erg..


it the point that you want to get the closest TPA to …

eg.

i want to find the closest TPA to a rock, yourTPoint would therefore be the TPoint that is the rocks location. you then sort yourATPA from the rock (yourTPoint) and the first index will be the closest TPA in yourATPA to the rock.

rj

2013-05-28 10:58:52

Like this?

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

That sorts from the middle of the mainscreen

Peanuts

2013-05-28 11:01:53

From: EngageTheRage
it the point that you want to get the closest TPA to …

eg.

i want to find the closest TPA to a rock, yourTPoint would therefore be the TPoint that is the rocks location. you then sort yourATPA from the rock (yourTPoint) and the first index will be the closest TPA in yourATPA to the rock.


Like this?

Simba Code:
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

That sorts from the middle of the mainscreen


Thanks lads!

EDIT: Sorry… but.. I put that in my script and its still picking random rocks.. :|
My first script is almost complete !

Peanuts

2013-05-28 11:20:32

Bump. Not sure if edited response was seen.

Heres the code

 begin

SortATPAFromMidPoint(GemATPA, Point(MSCX, MSCY));
for i := 0 to high(GemATPA) do
begin
GemBox := GetTPABounds(GemATPA[i]);
SetColorSpeed2Modifiers(0.04, 0.28);
if findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15) then
Break;
if i = high(GemATPA) then
begin
writeln('We went through all TPA''s and found no brown! Check your CTS2 Work!');
Terminatescript;
end;
end;
SetColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.02, 0.02);
marktime(counter);
while (not isuptextmulticustom(['em','asd'])) do

EngageTheRage

2013-05-28 12:06:53

what do you mean picking random rocks?

rj

2013-05-28 12:15:11

From: Peanuts
Thanks lads!

EDIT: Sorry… but.. I put that in my script and its still picking random rocks.. :|
My first script is almost complete !


Can you debug the atpa?

smart_debugATPA(true, ATPA);

Peanuts

2013-05-28 12:28:39

From: EngageTheRage
what do you mean picking random rocks?


I want to pick the rock closest to me, like a human would.

From: Officer Barbrady
Can you debug the atpa?

smart_debugATPA(true, ATPA);


I put that in.. is something supposed to happen im meant to paste to you?

EngageTheRage

2013-05-28 12:33:29

From: Peanuts
I want to pick the rock closest to me, like a human would.


yes i get that, but what do you mean by random?

because from what i can see, the ATPA is sorted and then you are iterating through to find whatever color you're looking for, and that seems fine. how do you find the initial ATPA?

rj

2013-05-28 13:34:00

From: Peanuts
I want to pick the rock closest to me, like a human would.



I put that in.. is something supposed to happen im meant to paste to you?


Yes, it is supposed to show the found ATPA's on the screen, if it does not then your colors are probably bad

Kevin

2013-05-28 13:52:44

Just a rough snippet, but should be solid for you. :)

tempCTS := GetColorToleranceSpeed; //save CTS so we can reset it
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hue, sat);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, color, MSX1, MSY1, MSX2, MSY2A, tol);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(tempCTS);
ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.

Peanuts

2013-05-28 14:24:23

From: EngageTheRage
yes i get that, but what do you mean by random?

because from what i can see, the ATPA is sorted and then you are iterating through to find whatever color you're looking for, and that seems fine. how do you find the initial ATPA?


By random i mean.. It will sometimes click the furthest away rock instead of the one next to me. (Which is what i want)
I'm so confused.. Perhaps i should read more tutorials.


From: Officer Barbrady
Yes, it is supposed to show the found ATPA's on the screen, if it does not then your colors are probably bad


It never has an issue finding the colors.. I tested it alone over n over.. n it seemed flawless.

I think perhaps I did something else wrong?



From: Kevin
Just a rough snippet, but should be solid for you. :)

tempCTS := GetColorToleranceSpeed; //save CTS so we can reset it
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hue, sat);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, color, MSX1, MSY1, MSX2, MSY2A, tol);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(tempCTS);
ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.


I am using a findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15)
which appears to have different vars
Should i change to findspiral like in your example?
Will that do the trick?

Sjoe

2013-05-28 14:27:17

From: Peanuts

I am using a findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15)
which appears to have different vars
Should i change to findspiral like in your example?
Will that do the trick?


That's the easiest approach :)

or u use this by flight: http://villavu.com/forum/showthread.php?t=102536&p=1232797#post1232797

Kevin

2013-05-28 14:28:18

From: Peanuts
By random i mean.. It will sometimes click the furthest away rock instead of the one next to me. (Which is what i want)
I'm so confused.. Perhaps i should read more tutorials.

It never has an issue finding the colors.. I tested it alone over n over.. n it seemed flawless.

I think perhaps I did something else wrong?




I am using a findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15)
which appears to have different vars
Should i change to findspiral like in your example?
Will that do the trick?


Changing to findspiral shouldn't be nearly as big a deal for what you want as this portion:

ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.
That will be where the ATPA is created (the separated rocks) as well as the actual sorting of them so the first object in the array will be the closest rock to you.

Peanuts

2013-05-28 14:35:53

From: Kevin
Changing to findspiral shouldn't be nearly as big a deal for what you want as this portion:

ATPA:= SplitTPA(TPA, 5);//This creates the array of tpas.
SortATPAFromMidPoint(ATPA, Point(MSCX, MSCY));//This sorts them so when you use a for loop, the first thing atpa[0], will be closest rock.
That will be where the ATPA is created (the separated rocks) as well as the actual sorting of them so the first object in the array will be the closest rock to you.


When I put that in…


if findcolorstolerance(GemTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then
begin
GemATPA:= SplitTPA(GemTPA, 5);//This creates the array of tpas.
SortATPAFromMidPoint(GemATPA, Point(MSCX, MSCY));

for i := 0 to high(GemATPA) do
begin
GemBox := GetTPABounds(GemATPA[i]);
SetColorSpeed2Modif

I get - Error: Out Of Range at line 235.

        begin
r := random(length(GemTPA));
mmouse(GemTPA[r].x, GemTPA[r].y, 3, 3); -----235
wait(randomrange(400, 600));
if timefrommark(counter) > 5000 then
begin

Its to do with the random/[r] thing?

EngageTheRage

2013-05-28 14:48:16

ok from your first post this is the code that i go:


Function Findiron:boolean;
var
ironTPA: TPointArray;
ironATPA: T2DPointArray;
ironBox: TBox;
i: integer;
begin
Result := false;
SetColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.23, 0.83);
if findcolorstolerance(ironTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then // search for color store in ironTPA
begin
ironATPA:= SplitTPAEx(ironTPA, 5, 5); // split ironTPA into 5x5's
SortATPAFromMidpoint(ironATPA, Point(MSCX, MSCY)); // sort ironATPA from the centre of MS

for i := 0 to high(ironATPA) do // iterate through ironATPA and check
begin
ironBox := GetTPABounds(ironATPA[i]);
SetColorSpeed2Modifiers(0.04, 0.28); // for ore color within the rock
if findcolorstolerance(ironTPA, 4609378, ironBox.x1, ironbox.Y1, ironbox.X2, ironbox.Y2, 15) then
begin
//do whatever you need to do here for example:
MMouse((ironBox.x1 + ironBox.x2) /2, (ironBox.y1 + ironBox.y2) /2, 5, 5); // if or found then move mouse to centre of rock
if IsUpTextEx('ron') then // if the uptext is 'ron'
begin // then left click to mine and then break
clickMouse2(true); // out of for loop
Result = true;
Break;
end;
end;
if i = high(ironATPA) then // if you get to the end of ironATPA and
begin // have found no ores then terminate
writeln('No rocks that can be mined found, terminating ...');
Terminatescript;
end;
end;
end;
SetColorToleranceSpeed(1); // reset toleranceSpeed and modifiers at the
SetColorSpeed2Modifiers(0.02, 0.02); // end of your procedure/function
end;

the looks a lot messier on here :/ the comments were on the right hand side and it looked all prettyful :D

EDIT: why if you have just found the index of the rock closest that you can mine, have you then gone and used random to get an index to move the mouse to?

and i believe that by using
 r := random(length(GemTPA));
r can equal length(GemTPA) which is out of bounds, you should use length(GemTPA)-1
EDIT2: or actually, just dont do that.

Peanuts

2013-05-28 15:10:52

From: EngageTheRage
ok from your first post this is the code that i go:

the looks a lot messier on here :/ the comments were on the right hand side and it looked all prettyful :D

EDIT: why if you have just found the index of the rock closest that you can mine, have you then gone and used random to get an index to move the mouse to?

and i believe that by using
 r := random(length(GemTPA));
r can equal length(GemTPA) which is out of bounds, you should use length(GemTPA)-1
EDIT2: or actually, just dont do that.


okay. Copy pasted into simba n i can read it a bit easier now.. Giving it a go.

Peanuts

2013-05-28 15:31:47

From: EngageTheRage
ok from your first post this is the code that i go:



ARGHH…


Why does it still not choose the closest.. I'm guessing im missing some tiny thing -.-


unction FindGems:boolean;
var
GemTPA, WoodTPA:TPointArray;
GemATPA:T2DPointArray;
GemBox:TBox;
i : integer;
begin
Result := False
if not(loggedin) then
exit;
SetColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.23, 0.83);

if findcolorstolerance(GemTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then
begin
GemATPA:= SplitTPAeX(GemTPA, 5, 5);
SortATPAFromMidPoint(GemATPA, Point(MSCX, MSCY));
for i := 0 to high(GemATPA) do
begin
GemBox := GetTPABounds(GemATPA[i]);
SetColorSpeed2Modifiers(0.04, 0.28);
if findcolorstolerance(GemTPA, 4609378, GemBox.x1, Gembox.Y1, Gembox.X2, Gembox.Y2, 15) then
Break;
end;
SetColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.02, 0.02);
while (not isuptextmulticustom(['em','asd'])) do
begin
mmouse((gemBox.x1 + gemBox.x2) /2, (gemBox.y1 + gemBox.y2) /2, 5, 5);
wait(randomrange(400, 600));
ClickMouse2(false);
if ChooseOption('em') then
result := true;
end;
end;
end;

P.S - It seems to be starting from the left side, maybe left bottom corner. Always picks there first

EngageTheRage

2013-05-28 15:53:54

From: Peanuts
ARGHH…


Why does it still not choose the closest.. I'm guessing im missing some tiny thing -.-

P.S - It seems to be starting from the left side, maybe left bottom corner. Always picks there first


first off, that last part doesnt seem great,


while (not isuptextmulticustom(['em','asd'])) do
begin
mmouse((gemBox.x1 + gemBox.x2) /2, (gemBox.y1 + gemBox.y2) /2, 5, 5);
wait(randomrange(400, 600));
ClickMouse2(false);
if ChooseOption('em') then
result := true;
end;
seems destined to continue for eternity …

use

SMART_Debug(GemATPA);

before your for loop to check out what the ATPA looks like after its sorted, then in your for loop, use:

SMART_DrawBoxEx(true, GemBox, 255);

to show you which box it is on. you might have to add a few wait(1000); just so you can see whats going on.

by doing that you will see it iterate through and see the order in which it checks the rocks, and the one on which it breaks.