SRL Archive - OSR Help

ATPA is innaccurate/ not looping through a repeat


rj

2013-05-01 17:23:35

So I am using a ATPA to find clay rocks, sometimes it has to go through a few to find them, and I AM sorting them from the center of the screen. Secondly, when ever the script clicks the rock it waits 2-3 seconds and clicks it again? It's supposed to wait 6-8 seconds or until the inventory count is added


function MineClay: Boolean;
var
j, CTS, Timeout, OreCount, MineCount, T: Integer;
TPA_Rock, TPA_Vein, TPA_Clay: TPointArray;
Clay_ATPA: T2DPointArray;
g: TPoint;
begin
if (not loggedin) then exit;

OreCount := InvCount + 1
if (IsUpTextMultiCustom(['lay', 'Clay'])) then
begin
update_state('Found clay uptext clicking');
case random(109) of
0..60: Wait(RandomRange(50, 300));
61..91: Wait(RandomRange(100, 400));
92..100: Wait(RandomRange(200, 900));
101..108: Wait(RandomRange(400, 1400));
end;
clickmouse2(mouse_left)
tries := 0;
MarkTime(MineCount);
repeat
update_state('Mining');
Wait(RandomRange(100, 300));
until (TimeFromMark(MineCount) > 3500) or (InvCount = OreCount);
if (InvCount = OreCount) then Inc(OresMined);
exit;
end;

Result := False;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
Timeout := RandomRange(6000, 8000);

begin
SetColorSpeed2Modifiers(0.05, 0.20);
FindColorsTolerance(TPA_ROCK, 4094608, MSX1, MSY1, MSX2, MSY2, 4);
SetColorSpeed2Modifiers(0.01, 2.26);
FindColorsTolerance(TPA_VEIN, 6400982, MSX1, MSY1, MSX2, MSY2, 17);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);
CombineTPAWrap(TPA_Rock, TPA_Vein, TPA_clay);
SplitTPAWrap(TPA_Clay, 5, Clay_ATPA);
SortATPAFromFirstPoint(Clay_ATPA, Point(MSCX, MSCY));
end;

MarkTime(T);
if Length(TPA_clay) < 1 then Exit;
//smart_debugATPA(true,Clay_ATPA);
for j := 0 to High(Clay_ATPA) do
begin
if (Length(Clay_ATPA[j]) < 12) then Continue;
update_state('Starting to loop through atpas');
g := MiddleTPA(Clay_ATPA[j]);
MMouse(g.x, g.y, RandomRange( - 5, 5), RandomRange( - 5, 5));
Wait(RandomRange(100, 250));
if IsUpTextMultiCustom(['lay', 'Clay']) then
begin
Result := True;
update_state('Found the uptext');
clickmouse2(mouse_left);
Flag;
tries := 0;
Wait(RandomRange(100, 700));
repeat
Wait(RandomRange(15, 200));
update_state('Mining');
until (TimeFromMark(MineCount) > TimeOut) or (InvCount = OreCount);
if (InvCount = OreCount) then Inc(OresMined);
break;
exit;
end;
end;
if (not result) then WalkMine;
end;

westkevin12

2013-05-01 21:36:59

i don't know for sure if this is the problem but i had a simmilar problem and adding begin after repeat and end after what it was supposed to repeat fixed it. also the pixelshift function is pretty cool for waiting until your done mining to click the next ore.

Flight

2013-05-01 21:55:52

Your first issue can be solved simply with more advanced object-finding technique. If I were to make a mining script I would, without a doubt, use a dual-color finding method; first finding the standard rock color (whether it has an ore in it or not) and split force that TPA into an array of TPAs with the exact size of 1 standard rock. Next, within the boundaries of each of those TPAs (now considered rocks, with or without ores) I'd search for the actual ore color (clay, in your case). If you wanted to go further than you could count the second color (ore color) inside each of the original TPAs[] and make sure it's within a specific range. That would be much, much more accurate than simply search for the ore color only.

Your second issue. You say it's suppose to wait 6 to 8 seconds after clicking a clay rock, or until the inventory count changes. Looking through your code I see that it only waits 3 and a half seconds:

MarkTime(MineCount);
repeat
update_state('Mining');
Wait(RandomRange(100, 300));
until (TimeFromMark(MineCount) > 3500) or (InvCount = OreCount);

So change 3500 to 6000 for 6 seconds or 8000 for 8 seconds.

rj

2013-05-01 22:02:55

From: Flight
Your first issue can be solved simply with more advanced object-finding technique. If I were to make a mining script I would, without a doubt, use a dual-color finding method; first finding the standard rock color (whether it has an ore in it or not) and split force that TPA into an array of TPAs with the exact size of 1 standard rock. Next, within the boundaries of each of those TPAs (now considered rocks, with or without ores) I'd search for the actual ore color (clay, in your case). If you wanted to go further than you could count the second color (ore color) inside each of the original TPAs[] and make sure it's within a specific range. That would be much, much more accurate than simply search for the ore color only.

Your second issue. You say it's suppose to wait 6 to 8 seconds after clicking a clay rock, or until the inventory count changes. Looking through your code I see that it only waits 3 and a half seconds:

MarkTime(MineCount);
repeat
update_state('Mining');
Wait(RandomRange(100, 300));
until (TimeFromMark(MineCount) > 3500) or (InvCount = OreCount);

So change 3500 to 6000 for 6 seconds or 8000 for 8 seconds.


Can you give me an example of it looking through each TPA? I already use 2 colors

I fixed the other problem though

Flight

2013-05-01 22:32:19

Sure. Here's the FindRock function from my old GranitePro script. It has an explanation on every step within the function.


Function FindRock(Var X,Y: Integer): Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
Hmod,Smod: Extended;
i,Tol,CTS,Col: Integer;
ATPA: T2DPointArray;
begin
Result := False;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(3);
{Search the base rock color}
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 9095162, MSX1, MSY1, MSX2, MSY2, 3);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

{No rocks round}
if (Length(TPA) < 1) then
Exit;

{Of our rock color TPA let's split each section into 30x30 boxes}
ATPA := TPAToATPAEx(TPA, 30, 30);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

{'i' will represent which rock we're observing, so start from 0 to the max # of boxes}
for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]); //This isn't really needed, but it's my own style...

with B do //Within this specific box do whatever
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hmod, SMod);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, OreColor, B.X1, B.Y1, B.X2, B.Y2, Tol);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then //An ore color is found within the rock we're searching
begin
MiddleTPAEx(ATPA[i], X, Y);
Result := True;
HumanMMouse(X, Y, 5, 5);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end else
Result := False;
end;

end;
end;
end;

westkevin12

2013-05-01 23:08:24

From: Flight
Sure. Here's the FindRock function from my old GranitePro script. It has an explanation on every step within the function.


Function FindRock(Var X,Y: Integer): Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
Hmod,Smod: Extended;
i,Tol,CTS,Col: Integer;
ATPA: T2DPointArray;
begin
Result := False;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(3);
{Search the base rock color}
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 9095162, MSX1, MSY1, MSX2, MSY2, 3);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

{No rocks round}
if (Length(TPA) < 1) then
Exit;

{Of our rock color TPA let's split each section into 30x30 boxes}
ATPA := TPAToATPAEx(TPA, 30, 30);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

{'i' will represent which rock we're observing, so start from 0 to the max # of boxes}
for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]); //This isn't really needed, but it's my own style...

with B do //Within this specific box do whatever
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hmod, SMod);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, OreColor, B.X1, B.Y1, B.X2, B.Y2, Tol);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then //An ore color is found within the rock we're searching
begin
MiddleTPAEx(ATPA[i], X, Y);
Result := True;
HumanMMouse(X, Y, 5, 5);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end else
Result := False;
end;

end;
end;
end;


^ genious, so would you say tpatoatpa is better than splittpa for mining?

Flight

2013-05-01 23:51:21

From: westkevin12
^ genious, so would you say tpatoatpa is better than splittpa for mining?


It depends heavily on what you're trying to find. What matters the most is the spacing between the objects. If they're close together and you want to find them separately I'd suggest using TPAtoATPAEx, although personally I would use my ForceATPA function (you'll find that in my Herb-farmer script) which is better because you have the best of both SplitTPA & TPAtoATPA; TPAs are split into exact height x width size with no overlapping. It's useful for objects close together. If there's a bit of space between the objects you're searching for it's better you use SplitTPA.

Olly

2013-05-01 23:59:06

From: Flight
I would use my ForceATPA function (you'll find that in my Herb-farmer script) which is better because you have the best of both SplitTPA & TPAtoATPA; TPAs are split into exact height x width size with no overlapping. It's useful for objects close together.


Herb-farmer is members + only right? Won't be much good for him :/

Flight

2013-05-02 00:09:34

From: Ollybest
Herb-farmer is members + only right? Won't be much good for him :/


Oh right lol…


//Sort TPAs into 2D TPAs through deduction based on size
Function ForceATPA(arr: TPointArray; wSize, hSize: Integer): T2DPointArray;
var
i: Integer;
aBox,bBox: TBox;
fPnts: TPointArray;
t2DArr: T2DPointArray;
begin
Repeat
SortTPAFrom(arr, Point(MSX1,MSY1));
fPnts := [];
t2DArr := [];
aBox := IntToBox(0,0,0,0);
TPAtoATPAExWrap(arr, wSize, hSize, t2DArr);

if (Length(t2DArr) < 1) then
Exit;

aBox := GetTPABounds(t2DArr[0]);

with aBox do
begin
if ((aBox.X2 - aBox.X1) > wSize) then
aBox.X2 := aBox.X1 + wSize;
if ((aBox.Y2 - aBox.Y1) > hSize) then
aBox.Y2 := aBox.Y1 + hSize;
if ((aBox.X2 - aBox.X1) < wSize) then
aBox.X2 := aBox.X1 + wSize;
if ((aBox.Y2 - aBox.Y1) < hSize) then
aBox.Y2 := aBox.Y1 + hSize;
end;

for i:=0 to high(arr) do
begin
if PointInBox(arr[i], aBox) then
begin
SetArrayLength(fPnts, Length(fPnts)+1);
fPnts[High(fPnts)] := arr[i];
end;
end;

bBox := GetTPABounds(fPnts);

with bBox do
begin
if ((bBox.X2 - bBox.X1) > wSize) then
bBox.X2 := bBox.X1 + wSize;
if ((bBox.Y2 - bBox.Y1) > hSize) then
bBox.Y2 := bBox.Y1 + hSize;
if ((bBox.X2 - bBox.X1) < wSize) then
bBox.X2 := bBox.X1 + wSize;
if ((bBox.Y2 - bBox.Y1) < hSize) then
bBox.Y2 := bBox.Y1 + hSize;

SetArrayLength(Result, Length(Result)+1);
Result[High(Result)] := fPnts;
ClearTPAFromTPAWrap(arr, fPnts, arr);
end;

Until(Length(arr) < 1)
end;

There ya go!

Edit:
Give me a minute and I'll make a visual example of the difference between TPAtoATPAEx, SplitTPAEx and my ForceATPA.

Edit2:
Apparently I need to do some work on ForceATPA as there is still overlapping. :/

Edit3:
Fixed it and updated the above function. Here's a visual example of searching for 34x34 size grey rocks very near with each other:


You can see with ForceTPA that there is no overlapping and all points are counted. Because in this version of ForceATPA I've removed the MinCount, so all points will be added to the end result.

westkevin12

2013-05-02 06:41:08

From: Flight
Oh right lol…


//Sort TPAs into 2D TPAs through deduction based on size
Function ForceATPA(arr: TPointArray; wSize, hSize: Integer): T2DPointArray;
var
i: Integer;
aBox,bBox: TBox;
fPnts: TPointArray;
t2DArr: T2DPointArray;
begin
Repeat
SortTPAFrom(arr, Point(MSX1,MSY1));
fPnts := [];
t2DArr := [];
aBox := IntToBox(0,0,0,0);
TPAtoATPAExWrap(arr, wSize, hSize, t2DArr);

if (Length(t2DArr) < 1) then
Exit;

aBox := GetTPABounds(t2DArr[0]);

with aBox do
begin
if ((aBox.X2 - aBox.X1) > wSize) then
aBox.X2 := aBox.X1 + wSize;
if ((aBox.Y2 - aBox.Y1) > hSize) then
aBox.Y2 := aBox.Y1 + hSize;
if ((aBox.X2 - aBox.X1) < wSize) then
aBox.X2 := aBox.X1 + wSize;
if ((aBox.Y2 - aBox.Y1) < hSize) then
aBox.Y2 := aBox.Y1 + hSize;
end;

for i:=0 to high(arr) do
begin
if PointInBox(arr[i], aBox) then
begin
SetArrayLength(fPnts, Length(fPnts)+1);
fPnts[High(fPnts)] := arr[i];
end;
end;

bBox := GetTPABounds(fPnts);

with bBox do
begin
if ((bBox.X2 - bBox.X1) > wSize) then
bBox.X2 := bBox.X1 + wSize;
if ((bBox.Y2 - bBox.Y1) > hSize) then
bBox.Y2 := bBox.Y1 + hSize;
if ((bBox.X2 - bBox.X1) < wSize) then
bBox.X2 := bBox.X1 + wSize;
if ((bBox.Y2 - bBox.Y1) < hSize) then
bBox.Y2 := bBox.Y1 + hSize;

SetArrayLength(Result, Length(Result)+1);
Result[High(Result)] := fPnts;
ClearTPAFromTPAWrap(arr, fPnts, arr);
end;

Until(Length(arr) < 1)
end;

There ya go!

Edit:
Give me a minute and I'll make a visual example of the difference between TPAtoATPAEx, SplitTPAEx and my ForceATPA.

Edit2:
Apparently I need to do some work on ForceATPA as there is still overlapping. :/

Edit3:
Fixed it and updated the above function. Here's a visual example of searching for 34x34 size grey rocks very near with each other:


You can see with ForceTPA that there is no overlapping and all points are counted. Because in this version of ForceATPA I've removed the MinCount, so all points will be added to the end result.

woah! that's awesome forceATPA is like a million times more accurate!

t4q

2013-05-02 06:57:14

Hmm.. I don't seem to have ForceATPA in Simba's functionlist :/

Flight

2013-05-02 10:31:18

From: t4q
Hmm.. I don't seem to have ForceATPA in Simba's functionlist :/


Oh it's not, it's a function I made for Herb-Farmer.

Sjoe

2013-05-02 10:39:19

From: Flight
Oh it's not, it's a function I made for Herb-Farmer.


Looks sexy :p Will definitely try it out.

rj

2013-05-02 16:19:17

From: Flight
Sure. Here's the FindRock function from my old GranitePro script. It has an explanation on every step within the function.


Function FindRock(Var X,Y: Integer): Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
Hmod,Smod: Extended;
i,Tol,CTS,Col: Integer;
ATPA: T2DPointArray;
begin
Result := False;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(3);
{Search the base rock color}
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 9095162, MSX1, MSY1, MSX2, MSY2, 3);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

{No rocks round}
if (Length(TPA) < 1) then
Exit;

{Of our rock color TPA let's split each section into 30x30 boxes}
ATPA := TPAToATPAEx(TPA, 30, 30);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

{'i' will represent which rock we're observing, so start from 0 to the max # of boxes}
for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]); //This isn't really needed, but it's my own style...

with B do //Within this specific box do whatever
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hmod, SMod);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, OreColor, B.X1, B.Y1, B.X2, B.Y2, Tol);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then //An ore color is found within the rock we're searching
begin
MiddleTPAEx(ATPA[i], X, Y);
Result := True;
HumanMMouse(X, Y, 5, 5);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end else
Result := False;
end;

end;
end;
end;


Thanks, It worked extremly fast when i started the script but it takes a while to move on to the next rock?

Function MineClay(): Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
i,CTS, Orecount, MineCount, X, Y, Timeout: Integer;
ATPA: T2DPointArray;
begin
if (not loggedin) then exit;

Result := False;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.05, 0.20);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 4094608, MSX1, MSY1, MSX2, MSY2, 7);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);


if (Length(TPA) < 1) then
Exit;

ATPA := TPAToATPAEx(TPA, 22, 22);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]);

with B do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.01, 2.26);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 6400982, B.X1, B.Y1, B.X2, B.Y2, 17);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then
begin
MiddleTPAEx(ATPA[i], X, Y);
smart_debugATPA(true,ATPA);
Result := True;
HumanMMouse(X, Y, 6, 6);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
update_state('Found the uptext');
clickmouse2(mouse_left);
MarkTime(MineCount);
Timeout := RandomRange(4000, 6000);
repeat
Wait(RandomRange(15, 200));
Antiban;
update_state('Mining');
until (TimeFromMark(MineCount) > TimeOut) or (InvCount = OreCount);
if (InvCount = OreCount) then Inc(OresMined);
Exit;
end else
Result := False;
WalkMine;
end;
end;
end;
end;

Le Jingle

2013-05-02 18:02:54

From: Officer Barbrady
Thanks, It worked extremly fast when i started the script but it takes a while to move on to the next rock?


In your nest repeat loop, I think adding a invcount to a variable prior to the repeat loop, and checking with WaitInvCountInc(), may help you break out faster of that nested loop. Thus you should hopefully not wait as long in between rocks, no? Also depending on how you use this function in your script will potentially influence how often ores are mined.

rj

2013-05-02 18:06:36

From: Le Jingle
In your nest repeat loop, I think adding a invcount to a variable prior to the repeat loop, and checking with WaitInvCountInc(), may help you break out faster of that nested loop. Thus you should hopefully not wait as long in between rocks, no? Also depending on how you use this function in your script will potentially influence how often ores are mined.


ahh I see i didn't use OreCount := InvCount + 1 so it was doing the defualt timeout

rj

2013-05-04 21:07:25

@Flight The end else isn't working, sometimes it is out of view of the clay and just sits there and does not walk to mine likes it's supposed to what am i doing wrong?

Function MineClay(): Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
i,CTS, Orecount, MineCount, X, Y, Timeout: Integer;
ATPA: T2DPointArray;
begin
if (not loggedin) then exit;

Result := False;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.05, 0.20);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 4094608, MSX1, MSY1, MSX2, MSY2, 7);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);


if (Length(TPA) < 1) then
Exit;

ATPA := TPAToATPAEx(TPA, 22, 22);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]);

with B do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.01, 2.26);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 6400982, B.X1, B.Y1, B.X2, B.Y2, 10);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then
begin
MiddleTPAEx(ATPA[i], X, Y);
//smart_debugATPA(true,ATPA);
Result := True;
HumanMMouse(X, Y, 6, 6);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
update_state('Found the uptext');
clickmouse2(mouse_left);
MarkTime(MineCount);
Timeout := RandomRange(4000, 6000);
OreCount := InvCount + 1
repeat
Wait(RandomRange(15, 200));
Antiban;
update_state('Mining');
until (TimeFromMark(MineCount) > TimeOut) or (InvCount = OreCount);
if (InvCount = OreCount) then Inc(OresMined);
Exit;
end else
Result := False;
WalkMine;
end;
end;
end;
end;

Flight

2013-05-04 23:14:55

From: Officer Barbrady
@Flight The end else isn't working, sometimes it is out of view of the clay and just sits there and does not walk to mine likes it's supposed to what am i doing wrong?


Eh, the way you're going about this, finding & mining a rock in the same function, I really wouldn't recommend, especially in this case in which you call another procedure/function in the instance that no rocks are found. If it were me I'd separate the FindRock and MineClay functions and use them together like so:


if not FindRock then
begin
WalkMine;
if FindRock then
MineClay;
end else
MineClay;

And here's the FindRock function & MineClay procedure:

Function FindRock: Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
i,CTS,X,Y: Integer;
ATPA: T2DPointArray;
begin
Result := False;
if (not loggedin) then exit;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.05, 0.20);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 4094608, MSX1, MSY1, MSX2, MSY2, 7);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA) < 1) then
Exit;

ATPA := TPAToATPAEx(TPA, 22, 22);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]);

with B do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.01, 2.26);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 6400982, B.X1, B.Y1, B.X2, B.Y2, 10);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then
begin
MiddleTPAEx(ATPA[i], X, Y);
//smart_debugATPA(true,ATPA);
Result := True;
HumanMMouse(X, Y, 6, 6);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
Exit;
end;
end;
end;
end;
end;

Procedure MineClay;
var
Orecount,MineCount,Timeout: Integer;
begin
if (not loggedin) then exit;

if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
update_state('Found the uptext');
clickmouse2(mouse_left);
MarkTime(MineCount);
Timeout := RandomRange(4000, 6000);
OreCount := InvCount + 1
repeat
Wait(RandomRange(15, 200));
Antiban;
update_state('Mining');
until (TimeFromMark(MineCount) > TimeOut) or (InvCount = OreCount);
if (InvCount = OreCount) then Inc(OresMined);
Exit;
end;
end;

rj

2013-05-04 23:18:00

From: Flight
Eh, the way you're going about this, finding & mining a rock in the same function, I really wouldn't recommend, especially in this case in which you call another procedure/function in the instance that no rocks are found. If it were me I'd separate the FindRock and MineClay functions and use them together like so:


if not FindRock then
begin
WalkMine;
if FindRock then
MineClay;
end else
MineClay;

And here's the FindRock function & MineClay procedure:

Function FindRock: Boolean;
var
B: TBox;
TPA,TPA2: TPointArray;
i,CTS,X,Y: Integer;
ATPA: T2DPointArray;
begin
Result := False;
if (not loggedin) then exit;
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.05, 0.20);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 4094608, MSX1, MSY1, MSX2, MSY2, 7);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA) < 1) then
Exit;

ATPA := TPAToATPAEx(TPA, 22, 22);
SortATPAFromFirstpoint(ATPA, Point(MSCX, MSCY));

for i := 0 to High(ATPA) do
begin

B := GetTPABounds(ATPA[i]);

with B do
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.01, 2.26);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 6400982, B.X1, B.Y1, B.X2, B.Y2, 10);
SetColorSpeed2Modifiers(0.02, 0.02);
ColorToleranceSpeed(CTS);

if (Length(TPA2) > 0) then
begin
MiddleTPAEx(ATPA[i], X, Y);
//smart_debugATPA(true,ATPA);
Result := True;
HumanMMouse(X, Y, 6, 6);
if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
Result := True;
Exit;
end;
end;
end;
end;
end;

Procedure MineClay;
var
Orecount,MineCount,Timeout: Integer;
begin
if (not loggedin) then exit;

if WaitUpTextMulti(['Mine','Rocks'], 300) then
begin
update_state('Found the uptext');
clickmouse2(mouse_left);
MarkTime(MineCount);
Timeout := RandomRange(4000, 6000);
OreCount := InvCount + 1
repeat
Wait(RandomRange(15, 200));
Antiban;
update_state('Mining');
until (TimeFromMark(MineCount) > TimeOut) or (InvCount = OreCount);
if (InvCount = OreCount) then Inc(OresMined);
Exit;
end;
end;


Ahh I see very nice I was getting 2hr proggy but it would eventually get stuck 10 tiles away from clay :(


Main loop is getting big

begin
SetupSRL;
DeclarePlayers;
Smart_fixspeed := True;
SRL_SIXHOURFIX := TRUE;
InitRocks();
Draw_Smart := true;
LoadClay;
StartTime := GetSystemTime;
MakeCompass('S')
repeat

AddOnTerminate('Free_DTMs');

case Random(100) of
0..1: MakeCompass('S')
end;

GameTab(Tab_inv);

SMART_ClearMS();

B_FindAbNormalRandoms;


if (invfull) then
begin
case (nearBank) of

True:

begin
ClickBox;
StoreAll;
CloseBox;
Exit_dung;
end;


False:

begin
SPS_Bank;
Enter;
ClickBox;
StoreAll;
CloseBox;
Exit_dung;
end;

end;
end;


if not (invfull) then
begin
case (nearBank) of

True:

begin
Exit_dung;
WalkMine;
end;


False:

case (NearEnterance) of

True:

begin
WalkMine;
end;

False:

begin

Case (FindRock) of

True: MineClay;

False: WalkMine;

end;

end;

end;

end;

end;

Until False;

end.

Is there a way I can clean it up I made it as short as possible