SRL Archive - OSR Help

Color Finding


DeSnob

2010-05-14 17:37:30

In my script, when it looks for a color the mouse goes crazy moving around the screen to check if the uptext is correct. Is there any way to make the color finding precise so that it only moves the mouse over a tree, and clicks the first time it hovers over a pixel?

For example, in Coh3n's willow chopper it moves the mouse directly to the tree and doesn't try to look around the whole screen. How can i modify my script so it does this?

Gu3st...

2010-05-14 17:48:43

Check a tutorial on TPA and ToleranceSpeed :)
Experient with Dimensional TPA's and SplitTPA()

DeSnob

2010-05-14 19:50:00

Did what you told me, went to Naum's tut :P and got a much better tree finding procedure. Although it doesn't meet my standards *yet*, it finds trees much faster! Sometimes even on the first attempt :D

Here's my function:
function IsTreeThere: boolean;
var
TreeTPA: TPointArray;
ATPA: Array of TPointArray;
CTS: integer;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.98, 1.93);


FindColorsSpiralTolerance(MSCX, MSCY, TreeTPA, 3303258, MSX1, MSY1, MSX2, MSY2, 10);
ColorToleranceSpeed(CTS);

SortTPAFrom(TreeTPA, Point(MSCX+50, MSCY+50));
ATPA := TPAToATPAEx(TreeTPA, 50, 50);

SortATPASize(ATPA, True);

For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
wait(200+random(500));
{If (IsUpTextMultiCustom(['hop', 'Tre'])) then
begin
Mouse(x, y, 0, 0, True);
end;}
end;
end;

Please tell me if i'm doing anything wrong, as I'm still a TPA nooby xD

Gu3st...

2010-05-15 03:35:58

I think you're doing great! That procedure is close to perfect :)
Keep on experimenting and trying out different stuff and you'll fully understand this in no time :)

DeSnob

2010-05-15 07:20:17

Thanks!

Right now I'm trying to learn tpa walking.. which is complicated! Wish me luck :)

Awkwardsaw

2010-05-15 09:44:10

i do beleive you need to change ColorToleranceSpeed(1); to ColorToleranceSpeed(2);

:)

NCDS

2010-05-15 10:05:13

Just lower the tolerance a little bit and try to use a more unique color of the tree that has few other occurrences on the screen.

Once you do that you should be good to go.

DeSnob

2010-05-15 10:10:20

From: NCDS
Just lower the tolerance a little bit and try to use a more unique color of the tree that has few other occurrences on the screen.

Once you do that you should be good to go.


Alright, and about the unique color, it's hard to find in a forest with green and brown floors xD

NCDS

2010-05-15 10:15:51

From: DeSnob
Alright, and about the unique color, it's hard to find in a forest with green and brown floors xD


Yeah I know what your saying. Try using the brightest/darkest colors of green on the tree. You should really lower the tolerance though. Try it at 5, that should be plenty.

DeSnob

2010-05-15 10:49:03

I tried the brightest color i could find, and switched up how the atpas were sorted and have an even better function :p!

function FindTree: boolean;
var
TreeTPA: TPointArray;
ATPA: Array of TPointArray;
CTS: integer;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.98, 1.93);

repeat
FindColorsSpiralTolerance(MSCX, MSCY, TreeTPA, 6264456, MSX1, MSY1, MSX2, MSY2, 5);
ColorToleranceSpeed(CTS);

if (Length(TreeTPA) = 0) then Result := False;

SortTPAFrom(TreeTPA, Point(MSCX+50, MSCY+50));
ATPA := TPAToATPAEx(TreeTPA, 50, 50);

SortATPASize(ATPA, False);

For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 2);
FindNormalRandoms;
wait(200+random(500));
if IsUptext('ak') or IsUptext('ew') then exit;
If (IsUpTextMultiCustom(['hop', 'Tre'])) then
begin
Mouse(x, y, 0, 0, True);
repeat
wait(20);
until(not(IsMoving))
end;
end;
until((InvFull) or (not(LoggedIn)))
end;

Naum

2010-05-15 10:54:43

ColorToleranceSpeed(1);
Should be:
ColorToleranceSpeed(2);

;)
Looks good, nonetheless.

NCDS

2010-05-15 11:08:44

A little confused here:

SortTPAFrom(TreeTPA, Point(MSCX+50, MSCY+50));
Why do yo sort it 50 px from you?


Your FindNormalRandoms is called in kind of a silly spot.
Perhaps pluck it in here:

repeat
wait(20);
until(not(IsMoving))
That way, it will be called while your chopping the tree, not in the middle of clicking it.

Last thing,

if IsUptext('ak') or IsUptext('ew') then exit;
Could just be:

if IsUptext('ak') or IsUptext('ew') then Continue;
That way, it will just continue looping through the ATPA instead of exiting the function and making you continually call it.

Overall looks good, Just some pointers ;)

DeSnob

2010-05-15 11:14:45

From: NCDS
A little confused here:

SortTPAFrom(TreeTPA, Point(MSCX+50, MSCY+50));
Why do yo sort it 50 px from you?


Your FindNormalRandoms is called in kind of a silly spot.
Perhaps pluck it in here:

repeat
wait(20);
until(not(IsMoving))
That way, it will be called while your chopping the tree, not in the middle of clicking it.

Last thing,

if IsUptext('ak') or IsUptext('ew') then exit;
Could just be:

if IsUptext('ak') or IsUptext('ew') then Continue;
That way, it will just continue looping through the ATPA instead of exiting the function and making you continually call it.

Overall looks good, Just some pointers ;)


I sort it 50 px away from the center, so that it starts looking for the TPAs/ATPAs that aren't where the player is (Trees aren't found under a player) That way, it looks a little further and usually clicks the tree closest to the character ;o)

About the Isuptext, thanks! It actually fixed a little problem i was having :D

From: Naum
ColorToleranceSpeed(1);
Should be:
ColorToleranceSpeed(2);

;)
Looks good, nonetheless.


Alright, switched. Thank you! :)