SRL Archive - OSR Help

Help with making this procedure more efficient?


rotchy1

2013-06-03 19:03:46

So I made this little procedure that searches for a raw chicken, and then moves mouse over and if uptext is "take" then it right clicks and selects "take chicken" and then waits until player is not moving and repeats until the inv is full. My question is, is there any way for me to have the player right click another raw chicken on the ground and wait to click "take until he is not moving (like after he has already clicked one).

Basically, I want it to look more human like by first clicking take chicken, and then while moving to the chicken it just clicked, it will then find and right click another chicken so that as soon as the player stops moving it is ready to click the next chicken which will add more human like interactions and make the script faster as well?

heres the procedure.

Procedure FindRaw;
var
Raw, i, l, r, T, TimesFailed: integer;
RawTPA: TPointArray;
begin
Raw := GetToleranceSpeed;

SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.20, 0.44);

FindColorsTolerance(RawTPA, 9213099, MSX1, MSY1, MSX2, MSY2, 19);

SetColorToleranceSpeed(Raw);
SetToleranceSpeed2Modifiers(0.02, 0.02);

L := High(RawTPA)
marktime(T);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(RawTPA[r].x, RawTPA[r].y, 2, 2);
if waituptext('ake', 300) then
Break;
if timefrommark(T) > 3000 then
begin
Inc(TimesFailed);
if TimesFailed = 3 then
begin
KillChicken;
AntiBan;
end;
if TimeFromMark(T) > 30000 then
begin
Logout;
TerminateScript;
end
else
end;
end;
clickmouse2(mouse_right);
ChooseOption('hicken');
WaitNotMoving(true);
end;

Kasi

2013-06-03 20:06:40

Raw := GetToleranceSpeed; // dont need that line
SetColorToleranceSpeed(Raw); // can be changed to SetColorToleranceSpeed(1);

its normally good practice to change the CTS back to normal. But usually all scripts using cts 2 have it as 1, temporarily change it to 2, and then change it back to default. by default it is set to 1.

Would also Split the TPA / reduce the amount of points by using SplitTPA(EX) or RAaSTPA(EX) respectfully, this means less points are stored in memory, and as you know, in rs generally chickens are not 1 pixel by 1 pixel therefore there would be no point checking an adjacent pixel to that one. Rather, i would Split the TPA by an area of maybe 5 by 5 or maybe a little bigger and store the middle of that 2d Point Array. SplitTPA splits by area. RAaSTPA splits by distance i think. a Member called Naum has a great tutorial on tpa's (http://villavu.com/forum/showthread.php?t=49067)

When using Waituptext, I would recommend setting the wait option in increments of 600ms, 600ms is one game tick. <–not too sure on this.

if your function finds the "ake" uptext it may left click but might not find a ChooseOption under "hicken", because of this, i would break out of the for loop if the chooseoption is found, rather than if the uptext is found.

also check your standards, i havent compiled your code but i dont know why you need that end else. your standards aren't the worst, but they can be improved.

rotchy1

2013-06-03 20:18:09

From: Kasi
Raw := GetToleranceSpeed; // dont need that line
SetColorToleranceSpeed(Raw); // can be changed to SetColorToleranceSpeed(1);

its normally good practice to change the CTS back to normal. But usually all scripts using cts 2 have it as 1, temporarily change it to 2, and then change it back to default. by default it is set to 1.

Would also Split the TPA / reduce the amount of points by using SplitTPA(EX) or RAaSTPA(EX) respectfully, this means less points are stored in memory, and as you know, in rs generally chickens are not 1 pixel by 1 pixel therefore there would be no point checking an adjacent pixel to that one. Rather, i would Split the TPA by an area of maybe 5 by 5 or maybe a little bigger and store the middle of that 2d Point Array. SplitTPA splits by area. RAaSTPA splits by distance i think. a Member called Naum has a great tutorial on tpa's (http://villavu.com/forum/showthread.php?t=49067)

When using Waituptext, I would recommend setting the wait option in increments of 600ms, 600ms is one game tick. <–not too sure on this.

if your function finds the "ake" uptext it may left click but might not find a ChooseOption under "hicken", because of this, i would break out of the for loop if the chooseoption is found, rather than if the uptext is found.

also check your standards, i havent compiled your code but i dont know why you need that end else. your standards aren't the worst, but they can be improved.


Some very good advice here, thank you very much. And as for the "end else" I originally tried just "end;" however for some reason the script would logout after 30 seconds of searching everytime, so i changed to end else and then it seemed to work fine?

Kasi

2013-06-03 20:32:43

From: rotchy1
Some very good advice here, thank you very much. And as for the "end else" I originally tried just "end;" however for some reason the script would logout after 30 seconds of searching everytime, so i changed to end else and then it seemed to work fine?


Gimme a sec, ill set it up and make some changes.

rotchy1

2013-06-03 20:37:38

From: Kasi
Gimme a sec, ill set it up and make some changes.


Would you like me to post the entire script if that is easier? It compiles and runs semi smoothly

Kasi

2013-06-03 22:44:52

From: rotchy1
Would you like me to post the entire script if that is easier? It compiles and runs semi smoothly


Erm could do, im just trying to teach you a little. Read through that..


program new;
{$DEFINE SMART8}
{$DEFINE CSMART} // if you dont have brandon's smart overhall comment out this line.
{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/SmartGraphics.Simba}

Function FindRaw : Boolean;
var
I, T, TimesFailed : integer;
RawTPA : TPointArray;
Raw2DTPA : T2DPointArray;
TB : TBox;
begin
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.20, 0.44); // pretty much the same as yours
FindColorsTolerance(RawTPA, 9213099, MSX1, MSY1, MSX2, MSY2, 19);
SetColorToleranceSpeed(1);
SetToleranceSpeed2Modifiers(0.02, 0.02);

Writeln('Points = ' + IntToStr(Length(RawTPA))); // debug the amount of points started off with

SplitTPAExWrap(RawTPA, 10, 10, Raw2DTPA); // split the TPA, this also cuts down the amount of points

SetLength(RawTPA, 0); // just a quick way of clearing a TPointArray


// i noticed that in your function it sometimes picked up other smaller items, this checks
// for the individual bounds of the TPA. and removes any that are too big / too small.

for I := 0 to High(Raw2DTPA) do
begin
TB := GetTPABounds(Raw2DTPA[I]);
if ((iAbs(TB.X1 - TB.X2) > 8) and (iAbs(TB.Y1 - TB.Y2) > 8) and
(iAbs(TB.X1 - TB.X2) < 15) and (iAbs(TB.Y1 - TB.Y2) < 15))
then
CombineTPAWrap(RawTPA, [MiddleTPA(Raw2DTPA[I])], RawTPA);
end;


// again just to debug so you have an understanding of how it works.
// the boxes without text have been filtered out.
for I := 0 to High(RawTPA) do
SMART_DrawText(RawTPA[I].x, RawTPA[I].y, 'SmallChars', ToStr(I), 16711680);
for I := 0 to High(Raw2DTPA) do
SMART_DrawBoxEx(False, False, GetTPABounds(Raw2DTPA[I]), 16711680);


// shows how many points are actually left.
Writeln('Points LEFT = ' + IntToStr(Length(RawTPA)));


// sorts the remaining points from the players position to get the closest point / chicken
SortTPAFrom(RawTPA, Point(MSCx, MSCy));

MarkTime(T);

for i := 0 to High(RawTPA) do // loop through our entire array of points.
begin
{ r := random(L); ?? why? this could lead to choosing the same point
more then once, a real rs player would select the closest chicken }

// wait(randomrange(60, 200));
MMouse(RawTPA[I].x, RawTPA[I].y, 2, 2); // changed.
if waituptext('aw ch', 100) and RBoolEx(2) then // if the uptext / top item is the chicken then we have a 50% chance of clicking it
begin
ClickMouse2(mouse_Left);
Result := WaitNotMoving(True);
Break;
end else
begin
if waituptext('ake', 500) then // if we find text, we preform a right click.
begin
ClickMouse2(Mouse_Right);
if WaitOption('hicken', 600) then // and click the chicken option
begin
WaitNotMoving(true);
Result := True;
Break; // break out after we get the chicken
end;
end else
begin
if TimeFromMark(T) > 3000 then
begin
Inc(TimesFailed);
if TimesFailed >= 3 then
begin
//KillChicken; // commented out as i dont have these functions.
//AntiBan;
TimesFailed := 0;
end;
end;
if TimeFromMark(T) > 30000 then
begin
Logout;
TerminateScript;
end;
end;
end;
end;
end;

begin
SetupSRL;
SMART_ClearCanvas();
Repeat
SMART_ClearCanvas();
until(Not(FindRaw) or InvFull);
end.

it should run fine, just go into a crowded world at the chickens, and read my comments whilst running, try to understand how everything is working, you could even edit into your code, the debugging isnt actually nessesary.. ill post a clean version underneath.


Function FindRaw : Boolean;
var
I, T, TimesFailed : integer;
RawTPA : TPointArray;
Raw2DTPA : T2DPointArray;
TB : TBox;
begin
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.20, 0.44);
FindColorsTolerance(RawTPA, 9213099, MSX1, MSY1, MSX2, MSY2, 19);
SetColorToleranceSpeed(1);
SetToleranceSpeed2Modifiers(0.02, 0.02);
SplitTPAExWrap(RawTPA, 10, 10, Raw2DTPA);
SetLength(RawTPA, 0);
for I := 0 to High(Raw2DTPA) do
begin
TB := GetTPABounds(Raw2DTPA[I]);
if ((iAbs(TB.X1 - TB.X2) > 8) and (iAbs(TB.Y1 - TB.Y2) > 8) and
(iAbs(TB.X1 - TB.X2) < 15) and (iAbs(TB.Y1 - TB.Y2) < 15))
then
CombineTPAWrap(RawTPA, [MiddleTPA(Raw2DTPA[I])], RawTPA);
end;
SortTPAFrom(RawTPA, Point(MSCx, MSCy));
MarkTime(T);
for i := 0 to High(RawTPA) do
begin
MMouse(RawTPA[I].x, RawTPA[I].y, 2, 2);
if waituptext('aw ch', 100) and RBoolEx(2) then
begin
ClickMouse2(mouse_Left);
Result := WaitNotMoving(True);
Break;
end else
begin
if waituptext('ake', 500) then
begin
ClickMouse2(Mouse_Right);
if WaitOption('hicken', 600) then
begin
WaitNotMoving(true);
Result := True;
Break;
end;
end else
begin
if TimeFromMark(T) > 3000 then
begin
Inc(TimesFailed);
if TimesFailed >= 3 then
begin
KillChicken;
AntiBan;
TimesFailed := 0;
end;
end;
if TimeFromMark(T) > 30000 then
begin
Logout;
TerminateScript;
end;
end;
end;
end;
end;

rotchy1

2013-06-04 07:48:34

From: Kasi
Erm could do, im just trying to teach you a little. Read through that..


program new;
{$DEFINE SMART8}
{$DEFINE CSMART} // if you dont have brandon's smart overhall comment out this line.
{$I SRL/SRL.Simba}
{$I SRL/SRL/Misc/SmartGraphics.Simba}

Function FindRaw : Boolean;
var
I, T, TimesFailed : integer;
RawTPA : TPointArray;
Raw2DTPA : T2DPointArray;
TB : TBox;
begin
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.20, 0.44); // pretty much the same as yours
FindColorsTolerance(RawTPA, 9213099, MSX1, MSY1, MSX2, MSY2, 19);
SetColorToleranceSpeed(1);
SetToleranceSpeed2Modifiers(0.02, 0.02);

Writeln('Points = ' + IntToStr(Length(RawTPA))); // debug the amount of points started off with

SplitTPAExWrap(RawTPA, 10, 10, Raw2DTPA); // split the TPA, this also cuts down the amount of points

SetLength(RawTPA, 0); // just a quick way of clearing a TPointArray


// i noticed that in your function it sometimes picked up other smaller items, this checks
// for the individual bounds of the TPA. and removes any that are too big / too small.

for I := 0 to High(Raw2DTPA) do
begin
TB := GetTPABounds(Raw2DTPA[I]);
if ((iAbs(TB.X1 - TB.X2) > 8) and (iAbs(TB.Y1 - TB.Y2) > 8) and
(iAbs(TB.X1 - TB.X2) < 15) and (iAbs(TB.Y1 - TB.Y2) < 15))
then
CombineTPAWrap(RawTPA, [MiddleTPA(Raw2DTPA[I])], RawTPA);
end;


// again just to debug so you have an understanding of how it works.
// the boxes without text have been filtered out.
for I := 0 to High(RawTPA) do
SMART_DrawText(RawTPA[I].x, RawTPA[I].y, 'SmallChars', ToStr(I), 16711680);
for I := 0 to High(Raw2DTPA) do
SMART_DrawBoxEx(False, False, GetTPABounds(Raw2DTPA[I]), 16711680);


// shows how many points are actually left.
Writeln('Points LEFT = ' + IntToStr(Length(RawTPA)));


// sorts the remaining points from the players position to get the closest point / chicken
SortTPAFrom(RawTPA, Point(MSCx, MSCy));

MarkTime(T);

for i := 0 to High(RawTPA) do // loop through our entire array of points.
begin
{ r := random(L); ?? why? this could lead to choosing the same point
more then once, a real rs player would select the closest chicken }

// wait(randomrange(60, 200));
MMouse(RawTPA[I].x, RawTPA[I].y, 2, 2); // changed.
if waituptext('aw ch', 100) and RBoolEx(2) then // if the uptext / top item is the chicken then we have a 50% chance of clicking it
begin
ClickMouse2(mouse_Left);
Result := WaitNotMoving(True);
Break;
end else
begin
if waituptext('ake', 500) then // if we find text, we preform a right click.
begin
ClickMouse2(Mouse_Right);
if WaitOption('hicken', 600) then // and click the chicken option
begin
WaitNotMoving(true);
Result := True;
Break; // break out after we get the chicken
end;
end else
begin
if TimeFromMark(T) > 3000 then
begin
Inc(TimesFailed);
if TimesFailed >= 3 then
begin
//KillChicken; // commented out as i dont have these functions.
//AntiBan;
TimesFailed := 0;
end;
end;
if TimeFromMark(T) > 30000 then
begin
Logout;
TerminateScript;
end;
end;
end;
end;
end;

begin
SetupSRL;
SMART_ClearCanvas();
Repeat
SMART_ClearCanvas();
until(Not(FindRaw) or InvFull);
end.

it should run fine, just go into a crowded world at the chickens, and read my comments whilst running, try to understand how everything is working, you could even edit into your code, the debugging isnt actually nessesary.. ill post a clean version underneath.


Function FindRaw : Boolean;
var
I, T, TimesFailed : integer;
RawTPA : TPointArray;
Raw2DTPA : T2DPointArray;
TB : TBox;
begin
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.20, 0.44);
FindColorsTolerance(RawTPA, 9213099, MSX1, MSY1, MSX2, MSY2, 19);
SetColorToleranceSpeed(1);
SetToleranceSpeed2Modifiers(0.02, 0.02);
SplitTPAExWrap(RawTPA, 10, 10, Raw2DTPA);
SetLength(RawTPA, 0);
for I := 0 to High(Raw2DTPA) do
begin
TB := GetTPABounds(Raw2DTPA[I]);
if ((iAbs(TB.X1 - TB.X2) > 8) and (iAbs(TB.Y1 - TB.Y2) > 8) and
(iAbs(TB.X1 - TB.X2) < 15) and (iAbs(TB.Y1 - TB.Y2) < 15))
then
CombineTPAWrap(RawTPA, [MiddleTPA(Raw2DTPA[I])], RawTPA);
end;
SortTPAFrom(RawTPA, Point(MSCx, MSCy));
MarkTime(T);
for i := 0 to High(RawTPA) do
begin
MMouse(RawTPA[I].x, RawTPA[I].y, 2, 2);
if waituptext('aw ch', 100) and RBoolEx(2) then
begin
ClickMouse2(mouse_Left);
Result := WaitNotMoving(True);
Break;
end else
begin
if waituptext('ake', 500) then
begin
ClickMouse2(Mouse_Right);
if WaitOption('hicken', 600) then
begin
WaitNotMoving(true);
Result := True;
Break;
end;
end else
begin
if TimeFromMark(T) > 3000 then
begin
Inc(TimesFailed);
if TimesFailed >= 3 then
begin
KillChicken;
AntiBan;
TimesFailed := 0;
end;
end;
if TimeFromMark(T) > 30000 then
begin
Logout;
TerminateScript;
end;
end;
end;
end;
end;


Thanks for this help, I will take a look at after I get off work! Just sending this to let you know I didn't just forget about it!

EDIT: This is rather incredible, splitting the TPAs makes such a huge difference in speed, thankyou so much for showing me this.