SRL Archive - Jr. Member General Help and Discussion

Problem with mining iteration


Kaladin

2014-01-30 03:09:24

Hi guys, long night so not really sure what is causing this, all I know is that its not looping through the TPA's at a decent speed/at all.
Its something to do with my TryMine I think, any help would be much appreciated.

Thanks


program ResourceMiner;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}
{$i sps/lib/sps-rs3.simba}

// SETUP //-----------------------------------------------------------------------------------\\
//--------------------------------------------------------------------------------------------\\
//--------------------------------------------------------------------------------------------\\

const
nick:= 'agoWin';
file:= 'default';

//--------------------------------------------------------------------------------------------\\
//--------------------------------------------------------------------------------------------\\
//--------------------------------------------------------------------------------------------\\
//--------------------------------------------------------------------------------------------\\
//--------------------------------------------------------------------------------------------\\


Var
ores, b: integer;
banking, flagHard: boolean;
bounds: Tbox;

procedure init;
begin
smartEnableDrawing := true;
setupSRL;
banking:= false;
Players.Setup([nick], file);
CurrentPlayer := 0;
ores:=0;
bounds.setBounds(0,0,305,275);
end;

Function Antiban: Boolean;
Var
I: Integer;
Begin
Writeln('performing antiban');
I := Random(600);
Case I Of
1: boredHuman(false);
2..7:
Begin
hoverSkill(Skill_Mining);
Wait(GaussRangeInt(1000,2000));
End;
8..50: mouseMovingObject;
51..100: SleepAndMoveMouse(1000);
101..400:
Begin
MouseOffClient(Random(4));
Wait(1000+Random(100));
End;
501..600: Wait(RandomRange(1000, 2000));
End;
End;

function findOre: boolean;

var
x, y, i, r: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if not isLoggedIn then
exit;
if tabBackpack.count < 28 then
begin
if banking = false then // color // tol //CTS, hue, sat from ACA
if findColorsSpiralTolerance(x, y, TPA, 9461341, bounds, 30, colorSetting(2, 0.02, 0.20)) then
if (Length(TPA) < 1) then // if no matching TPoints are found, exit
exit;
ATPA := TPA.toATPA(50, 100); // split our TPA into boxes of 30 x 30 pixels and put into an ATPA
ATPA.sortFromMidPoint(mainscreen.playerPoint); // sort the array from player, so closest TPA to player is first in array
for i := 0 to high(ATPA) do
begin // move move to each TPA one at a time, until we get a match
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['Min', 'ithr', 'ore'], 200) then
begin
r:= random(100);
GetMousePos(x, y);
Mouse(point(x, y).rand(1), MOUSE_LEFT, MOUSE_HUMAN);
wait(200 + random(300));
if tabBackpack.waitForShift(30000) then
begin
inc(ores);
writeln(ores);
end;
end;
end;
end;
end;


function findBank: boolean;
var
x, y, i: integer;
TPA: TPointArray;
TP: TPoint;
ATPA: T2DPointArray;
begin
if findColorsSpiralTolerance(x, y, TPA, 1911999, mainScreen.getBounds(), 10, colorSetting(2, 0.04, 1.68)) then
if (Length(TPA) < 1) then // if no matching TPoints are found, exit
exit;
ATPA := TPA.toATPA(50, 100); // split our TPA into boxes of 30 x 30 pixels and put into an ATPA
ATPA.sortFromMidPoint(mainscreen.playerPoint); // sort the array from player, so closest TPA to player is first in array
for i := 0 to high(ATPA) do
begin // move move to each TPA one at a time, until we get a match
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
GetMousePos(x, y);
if isMouseOverText(['Exit Mysterious door'], 200) then
begin
b := Random(1000);
x:= x+80;
y:= y+40;
mouse(x,y, MOUSE_MOVE);
wait(100 + random(400));
fastClick(MOUSE_LEFT);
wait(200 + random(600));
exit(true);
end;
end;
end;

function tryBank(): boolean;
begin
if findBank then
begin
banking:= true;
wait(500+random(700));
mouse(340+random(5), 305+random(5), MOUSE_MOVE);
fastClick(MOUSE_LEFT);
wait(500+random(700));
mouse(464, 64, MOUSE_LEFT, MOUSE_MOVE);
fastClick(MOUSE_LEFT);
wait(300+random(400));
banking:= false;
end else
banking:= false;
exit(false);
end;

function tryMine(): boolean;
var
t := getSystemTime() + 60000; // maximum one minute (can change to whatever you want) used as a failsafe in case something goes wrong
begin
while ((not result) and (getSystemTime() < t)) do
findOre;
result := (tabBackpack.count() = 28);
wait(500+random(400));
end;


Procedure mainLoop;
begin
if not isLoggedIn then
exit;
if tabBackpack.count = 28 then
begin
if not banking then
minimap.tpaWalk(3161795, 30, point(minimap.x2, minimap.y1), 10);
tryBank;
end else
tryMine();
end;

begin
init;
players[currentPlayer].login();
wait(1000+random(3000));
minimap.setAngle(MM_DIRECTION_EAST);
mainScreen.setAngle(MS_ANGLE_HIGH);
repeat
mainLoop;
until b > 10000 ;
end.

Also could be due to my bounds being incorrect, I want it so that it only searches the mainscreen (No inv etc), when I tried with just mainscreen.getbounds it was finding ore when there was none (I guessed inventory) so if I'm being dumb about anything I do apologize.

EDIT: Okay I've tested various things and it must be my colors. Will try fix and report back.
EDIT2: Not colours :S Tried alot of different fixes and I can't come up with the answer, the log reads as follows;


-- TPlayer.login()
---- Already logged in
---- Logged in: agoWin
-- TPlayer.login(): True
---- TRSGameTab.__initTabs(): Setup gametab properties

Any ideas? ;/

EDIT3: … Combination of various fails on my part, when doing recolouring I clicked a black square and didn't realize, as well as some other things I think xD Ah well, thanks for everyone who tried to help, all nighters make my brain not work well but its hard to sleep when having this much fun xD :D

Spartan 117

2014-01-30 03:54:13

Well for one it's mainscreen.getbounds(); with parenthesis. Idk how much that affects things but it's always best to use correct syntax. And also if you have had simba open for a while and every time something breaks and dtms aren't freed you might get memory leaks. This slows down loops and scripts in general A LOT. try closing out of smart and simba and just reopening to fix the speed. Otherwise it's the script and I'm on my phone right now so I can't really get a good look

Kaladin

2014-01-30 04:12:40

Alright cheers mate :) I might not have done the ACA well enough I'm gonna try improving that and report back :D

sdf

2014-01-30 04:56:07

Change this line:

if isMouseOverText(['Mine Mithril ore rocks'], 200) then
to
if isMouseOverText(['Min', 'ithr', 'ore'], 200) then

and see how it goes.

Kaladin

2014-01-30 05:53:20

Thanks sdf, changed but no luck im afraid :(


Okay so its definitely not a problem with the color as I just tested it.
Any ideas guys? Must be eitjher the MainLoop or TryMine() :S

sdf

2014-01-30 06:57:41

Give this a go.


program ResourceMiner;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}
{$i sps/lib/sps-rs3.simba}

const
nick:= 'agoWin';
file:= 'default';

var
ores, b: integer;
banking, flagHard: boolean;
bounds: Tbox;

procedure init;
begin
smartEnableDrawing := true;
setupSRL;
banking:= false;
Players.Setup([nick], file);
CurrentPlayer := 0;
ores:=0;
//bounds.setBounds(0,0,305,275);
bounds := mainScreen.getBounds();
end;

function Antiban: Boolean;
var
I: Integer;
begin
Writeln('performing antiban');
I := Random(600);
case I of
1: boredHuman(false);
2..7:
begin
hoverSkill(Skill_Mining);
Wait(GaussRangeInt(1000, 2000));
end;
8..50: mouseMovingObject;
51..100: SleepAndMoveMouse(1000);
101..400:
begin
MouseOffClient(Random(4));
Wait(1000 + Random(100));
end;
501..600: Wait(RandomRange(1000, 2000));
end;
end;

function findOre: boolean;
var
x, y, i, r: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if not isLoggedIn then
exit;
writeln('ATTEMPTING TO FIND ORE');
if not tabBackpack.isFull then
begin
if banking = false then
if findColorsSpiralTolerance(x, y, TPA, 6901082, bounds, 15, colorSetting(2, 0.56, 0.60)) then
if (Length(TPA) < 1) then
exit;
ATPA := TPA.toATPA(50, 100);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
for i := 0 to high(ATPA) do
begin
mouseBox(ATPA[i].getBounds, mouse_move, mouse_human);
//mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['Min', 'ithr', 'ore'], 50) then
begin
writeln('Cycling');
r:= random(100);
//GetMousePos(x, y);
//Mouse(point(x, y).rand(1), MOUSE_LEFT, MOUSE_HUMAN);
fastClick(Mouse_left);
wait(200 + random(300));
if tabBackpack.waitForShift(30000) then
begin
inc(ores);
writeln(ores);
if r > 85 then
begin
antiban;
exit(true);
end else
exit(true);
end;
end;
end;
end
else
exit(false);
end;

function findBank: boolean;
var
x, y, i: integer;
TPA: TPointArray;
TP: TPoint;
ATPA: T2DPointArray;
begin
if findColorsSpiralTolerance(x, y, TPA, 1911999, mainScreen.getBounds(), 10, colorSetting(2, 0.04, 1.68)) then
if (Length(TPA) < 1) then
exit;
ATPA := TPA.toATPA(50, 100);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
GetMousePos(x, y);
if isMouseOverText(['Exit','Myst', 'door'], 200) then
begin
b := Random(1000);
x := x + 80;
y := y + 40;
mouse(x, y, MOUSE_MOVE);
wait(100 + random(400));
fastClick(MOUSE_LEFT);
wait(200 + random(600));
exit(true);
end;
end;
end;

function tryBank(): boolean;
begin
if findBank then
begin
banking := true;
wait(500 + random(700));
mouse(340 + random(5), 305 + random(5), MOUSE_MOVE);
fastClick(MOUSE_LEFT);
wait(500 + random(700));
mouse(464, 64, MOUSE_LEFT, MOUSE_MOVE);
fastClick(MOUSE_LEFT);
wait(300 + random(400));
banking := false;
end
else
banking := false;
exit(false);
end;

function tryMine(): boolean;
var
t := getSystemTime () + 60000;
begin
writeln('ATTEMPTING TO MINE');
result := false;
while ((not result) and (getSystemTime() < t)) do
begin
//result := (tabBackpack.count() = 28);
result := tabBackpack.isFull;
findOre;
wait(500 + random(400));
end;
end;

procedure mainLoop;
begin
if not isLoggedIn then
exit;
writeln('Starting Mainloop');
//if tabBackpack.count = 28 then
if tabBackpack.isFull then
begin
if not banking then
minimap.tpaWalk(3161795, 30, point(minimap.x2, minimap.y1), 10);
tryBank;
end
else
tryMine();
end;

begin
init;
if not isLoggedIn then
begin
players[currentPlayer].login();
wait(1000+random(5000));
end else;
minimap.setAngle(MM_DIRECTION_EAST);
mainScreen.setAngle(MS_ANGLE_HIGH);
repeat
mainLoop;
until b > 10000 ;
end.

It cycles fine for me (assuming you were at mining guild). The only possible wait between cycles was waiting for the mouse over text to timeout (which you had set as 200). I only changed a few things, I won't bother fixing the other procedures. The only other thing I could recommend is to set a higher mouse speed using something like

function VaryMS(BaseSpeed, Vary: Integer): String;
begin
mouseSpeed := baseSpeed + random(Vary);
result := IntToStr(mouseSpeed);
end;

Otherwise I don't know what you deem as 'slow' when cycling your TPA's.

Kaladin

2014-01-30 08:14:34

From: sdf
Give this a go.


program ResourceMiner;
{$DEFINE SMART}
{$I SRL-6/SRL.Simba}
{$i sps/lib/sps-rs3.simba}

const
nick:= 'agoWin';
file:= 'default';

var
ores, b: integer;
banking, flagHard: boolean;
bounds: Tbox;

procedure init;
begin
smartEnableDrawing := true;
setupSRL;
banking:= false;
Players.Setup([nick], file);
CurrentPlayer := 0;
ores:=0;
//bounds.setBounds(0,0,305,275);
bounds := mainScreen.getBounds();
end;

function Antiban: Boolean;
var
I: Integer;
begin
Writeln('performing antiban');
I := Random(600);
case I of
1: boredHuman(false);
2..7:
begin
hoverSkill(Skill_Mining);
Wait(GaussRangeInt(1000, 2000));
end;
8..50: mouseMovingObject;
51..100: SleepAndMoveMouse(1000);
101..400:
begin
MouseOffClient(Random(4));
Wait(1000 + Random(100));
end;
501..600: Wait(RandomRange(1000, 2000));
end;
end;

function findOre: boolean;
var
x, y, i, r: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if not isLoggedIn then
exit;
writeln('ATTEMPTING TO FIND ORE');
if not tabBackpack.isFull then
begin
if banking = false then
if findColorsSpiralTolerance(x, y, TPA, 6901082, bounds, 15, colorSetting(2, 0.56, 0.60)) then
if (Length(TPA) < 1) then
exit;
ATPA := TPA.toATPA(50, 100);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
for i := 0 to high(ATPA) do
begin
mouseBox(ATPA[i].getBounds, mouse_move, mouse_human);
//mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['Min', 'ithr', 'ore'], 50) then
begin
writeln('Cycling');
r:= random(100);
//GetMousePos(x, y);
//Mouse(point(x, y).rand(1), MOUSE_LEFT, MOUSE_HUMAN);
fastClick(Mouse_left);
wait(200 + random(300));
if tabBackpack.waitForShift(30000) then
begin
inc(ores);
writeln(ores);
if r > 85 then
begin
antiban;
exit(true);
end else
exit(true);
end;
end;
end;
end
else
exit(false);
end;

function findBank: boolean;
var
x, y, i: integer;
TPA: TPointArray;
TP: TPoint;
ATPA: T2DPointArray;
begin
if findColorsSpiralTolerance(x, y, TPA, 1911999, mainScreen.getBounds(), 10, colorSetting(2, 0.04, 1.68)) then
if (Length(TPA) < 1) then
exit;
ATPA := TPA.toATPA(50, 100);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
GetMousePos(x, y);
if isMouseOverText(['Exit','Myst', 'door'], 200) then
begin
b := Random(1000);
x := x + 80;
y := y + 40;
mouse(x, y, MOUSE_MOVE);
wait(100 + random(400));
fastClick(MOUSE_LEFT);
wait(200 + random(600));
exit(true);
end;
end;
end;

function tryBank(): boolean;
begin
if findBank then
begin
banking := true;
wait(500 + random(700));
mouse(340 + random(5), 305 + random(5), MOUSE_MOVE);
fastClick(MOUSE_LEFT);
wait(500 + random(700));
mouse(464, 64, MOUSE_LEFT, MOUSE_MOVE);
fastClick(MOUSE_LEFT);
wait(300 + random(400));
banking := false;
end
else
banking := false;
exit(false);
end;

function tryMine(): boolean;
var
t := getSystemTime () + 60000;
begin
writeln('ATTEMPTING TO MINE');
result := false;
while ((not result) and (getSystemTime() < t)) do
begin
//result := (tabBackpack.count() = 28);
result := tabBackpack.isFull;
findOre;
wait(500 + random(400));
end;
end;

procedure mainLoop;
begin
if not isLoggedIn then
exit;
writeln('Starting Mainloop');
//if tabBackpack.count = 28 then
if tabBackpack.isFull then
begin
if not banking then
minimap.tpaWalk(3161795, 30, point(minimap.x2, minimap.y1), 10);
tryBank;
end
else
tryMine();
end;

begin
init;
if not isLoggedIn then
begin
players[currentPlayer].login();
wait(1000+random(5000));
end else;
minimap.setAngle(MM_DIRECTION_EAST);
mainScreen.setAngle(MS_ANGLE_HIGH);
repeat
mainLoop;
until b > 10000 ;
end.

It cycles fine for me (assuming you were at mining guild). The only possible wait between cycles was waiting for the mouse over text to timeout (which you had set as 200). I only changed a few things, I won't bother fixing the other procedures. The only other thing I could recommend is to set a higher mouse speed using something like

function VaryMS(BaseSpeed, Vary: Integer): String;
begin
mouseSpeed := baseSpeed + random(Vary);
result := IntToStr(mouseSpeed);
end;

Otherwise I don't know what you deem as 'slow' when cycling your TPA's.


Sorry I updated my OP to say that I found the issue, earlier when I posted it was literally finding one rock, mining it then sits doing nothing, thank you very much though :)

Sjoe

2014-01-30 09:59:26

From: Kaladin
Sorry I updated my OP to say that I found the issue, earlier when I posted it was literally finding one rock, mining it then sits doing nothing, thank you very much though :)


I would keep that timeout on 200 incase of lag or people with slower pc's.

King

2014-01-30 14:53:53

I'm glad you found the answer, something I would suggest is to out the end's in proper places as it is easier to read. You could also use a waitforshift to detect ore, that way there would be a timeout built into the function. Like set the wait for 10000 (10 seconds) and then try to determine why it has not mined it ect… May also be easier to use superusers surface include if it works with SRL-6.