SRL Archive - OSR Help

Get Color works once


rj

2013-07-14 19:02:47

so I have a function that checks for login:

function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
CTS, X, Y, i:Integer;
begin
if (not ss_loggedin) then exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol) then
begin
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
SetColorSpeed2Modifiers(0.02, 0.02);
end;

Janilabo

2013-07-14 19:06:57

Not sure if this is the problem but.. You seem to only restore CTS when you find the color.

function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
CTS, X, Y, i:Integer;
begin
if (not ss_loggedin) then exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol) then
begin
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS); // Added this here.
end;

rj

2013-07-14 19:09:39

From: Janilabo
Not sure if this is the problem but.. You seem to only restore CTS when you find the color.

function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
CTS, X, Y, i:Integer;
begin
if (not ss_loggedin) then exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol) then
begin
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS); // Added this here.
end;


I had that before, and I just retested it and it still didnt work

Janilabo

2013-07-14 19:13:38

From: Officer Barbrady
I had that before, and I just retested it and it still didnt work
Yeah, like I said, I wasn't sure if that was the problem at all, I just noticed that you were missing it from your code.

So, what exactly is the problem? You really should give some more information here…
Like: Where does it stop working, at which part of the code?
Also, have you been debugging it with WriteLn()'s etc..?

rj

2013-07-14 19:14:39

From: Janilabo
Yeah, like I said, I wasn't sure if that was the problem at all, I just noticed that you were missing it from your code.

So, what exactly is the problem? You really should give some more information here…
Like: Where does it stop working, at which part of the code?
Also, have you been debugging it with WriteLn()'s etc..?

Ok, So before it cuts the tree, it has a login check and it returns true. After it clicks the tree and the tree is chopped down and it goes to find the next tree the login check returns false and therfor it tries to relog in

Janilabo

2013-07-14 19:19:30

From: Officer Barbrady
Ok, So before it cuts the tree, it has a login check and it returns true. After it clicks the tree and the tree is chopped down and it goes to find the next tree the login check returns false and therfor it tries to relog in
Sounds like the problem is with ss_LoggedIn check then? ..or possibly somewhere even deeper.

I recommend you add 1 more thing to this function, to prevent false-positives:

function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
CTS, X, Y, i:Integer;
begin
Result := False; // This here.
if (not ss_loggedin) then exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol) then
begin
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS); // Added this here.
end;

rj

2013-07-14 19:20:56

From: Janilabo
Sounds like the problem is with ss_LoggedIn check then? ..or possibly somewhere even deeper.

I recommend you add 1 more thing to this function, to prevent false-positives:

function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
CTS, X, Y, i:Integer;
begin
Result := False; // This here.
if (not ss_loggedin) then exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
if FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol) then
begin
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then Exit;
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS); // Added this here.
end;

Can't be a problem with that. Because I restart the script and it works

Kasi

2013-07-14 19:21:28

Or better yet…


function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
X, Y, i:Integer;
begin
if (not ss_loggedin) then exit;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol);
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.02, 0.02);
if (Length(TPA) > 0) then
begin
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
end;

rj

2013-07-14 19:27:26

From: Kasi
Or better yet…


function FindObjectCTS(Color, w, h, tol, filter:Integer; hmod, smod:Extended):Boolean;
var
TPA:TPointArray;
ATPA:T2DPointArray;
X, Y, i:Integer;
begin
if (not ss_loggedin) then exit;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol);
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.02, 0.02);
if (Length(TPA) > 0) then
begin
ATPA := TPAToATPAEx(TPA, w, h);
filterTPAsBetween(ATPA, 1, filter);
SortATPAFromFirstpoint(ATPA, Point(ss_MS.x, ss_MS.x));
try
MiddleTPAEx(ATPA[i], X, Y);
mmouse(x, y, 0, 0)
ClickMouse2(Mouse_left);
Result := True;
except
Writeln('*****Out of range*****');
end;
end;
end;

Ok, made them all like thatm still returns false after it clicks a tree

Kasi

2013-07-14 19:30:28

From: Officer Barbrady
Ok, made them all like thatm still returns false after it clicks a tree


Hint: never use try statements when debugging.

Edit: whats i?

rj

2013-07-14 19:44:22

From: Kasi
Hint: never use try statements when debugging. i = ????


Removed all the try's

Still returns false

Kasi

2013-07-14 19:49:26

From: Officer Barbrady
Removed all the try's

Still returns false


can't possibly return false, as again its procedural, if it clicks then it cant possibly fail on Result := true;
try debugging by sticking a Writeln('Clicked'); under that Result := true;?

rj

2013-07-14 19:50:29

From: Kasi
can't possibly return false, as again its procedural, if it clicks then it cant possibly fail on Result := true;
try debugging by sticking a Writeln('Clicked'); under that Result := true;?


No the login check is return false after the tree is clicked

Kasi

2013-07-14 19:51:37

From: Officer Barbrady
No the login check is return false after the tree is clicked


PM Teamviewer details again?

Janilabo

2013-07-14 19:52:15

How about this:

function FindObjectCTS(color, w, h, tol, filter: Integer; hmod, smod: Extended): Boolean;
var
TPA: TPointArray;
ATPA: T2DPointArray;
X, Y, CTS, hm, sm: Integer;
begin
Result := False;
if not ss_LoggedIn then
Exit;
CTS := GetToleranceSpeed;
GetToleranceSpeed2Modifiers(hm, sm);
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(hmod, smod);
FindColorsSpiralTolerance(ss_MS.x, ss_MS.y, TPA, color, ss_MSX1, ss_MSY1, ss_MSX2, ss_MSY2, tol);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(hm, sm);
if (Length(TPA) > 0) then
begin
ATPA := TPAToATPAEx(TPA, w, h);
FilterTPAsBetween(ATPA, 1, filter);
if (Length(ATPA) > 0) then
begin
SortATPAFromFirstPoint(ATPA, Point(ss_MS.x, ss_MS.x));
MiddleTPAEx(ATPA[0], X, Y);
MMouse(X, Y, 0, 0);
ClickMouse2(mouse_Left);
Result := True;
end;
end;
end;

Kasi

2013-07-14 21:50:13

Fixed :P