SRL Archive - RS3 Help

Need help with my first script


jamesayo

2015-04-07 23:51:14

Hi, I'm new to Simba and SRL in general. Following along with a few tutorials on how to make scripts, I attempted to make a yew cutting script. It home teles to Port Sarim, runs to the Remmy yews, and banks by hometeleing to Burthorpe and banking there.
It mostly works fine, except that it is very bad at click on the yew trees and i'm not sure how to keep it from clicking away while chopping without having to wait a long time before moving to the next tree when the current tree gets chopped down.
I'm looking for any suggestions!
Here's my script:
program yewCutter;

{$DEFINE SMART}
{$I SRL-6/SRL.simba}
{$I SPS/lib/SPS-RS3.Simba}

var
LoadsDone: integer;

procedure declarePlayers();
begin
setLength(players, 1);
with players[0] do
begin
loginName := '';
password := '';
isActive := true;
isMember := false;
end
currentPlayer := 0;
end;

procedure teleToPortSarim();
var
p: TPoint;

begin
if not isLoggedIn() then
exit;
repeat
lodestoneScreen.teleportTo(LOCATION_PORT_SARIM);
wait(randomRange(14500, 16000));
until (not isLoggedIn()) or minimap.findSymbol(p, MM_SYMBOL_SHOP_FISHING, minimap.getBounds());

end;

procedure runToTrees();
var
pathToTrees: TPointArray;
begin
if not isLoggedIn() then
exit;

pathToTrees := [Point(354, 183), Point(322, 175), Point(294, 158), Point(256, 154), Point(223, 153), Point(193, 145), Point(166, 144), Point(141, 130), Point(120, 116), Point(92, 110), Point(63, 109), Point(50, 114)]

if SPS.walkPath(pathToTrees) then
minimap.waitPlayerMoving()
else
writeLn('Failed to walk to the trees');
end;

procedure cutTrees();
var
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
cutTimer: TTimeMarker;

begin
if not isLoggedIn() then
exit;

cutTimer.start();

repeat

findColorsSpiralTolerance(x, y, TPA, 2574889, mainScreen.getBounds(), 6, colorSetting(2, 1.09, 1.05))

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

ATPA := TPA.toATPA(30, 30);
ATPA.filterBetween(0, 10);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
smartImage.debugATPA(ATPA);

for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['Yew', 'ew'], 500) then
begin
fastClick(MOUSE_LEFT);
smartImage.clear;
break;
end;
end;
tabBackpack.waitForShift(20000);

until tabBackpack.isFull() or (cutTimer.getTime() > 2700000);

end;

procedure teleToBurthorpe();
var
p: TPoint;
begin
if not isLoggedIn() then
exit;
repeat
lodestoneScreen.teleportTo(LOCATION_BURTHORPE);
wait(randomRange(14500, 16000));
until (not isLoggedIn()) or minimap.findSymbol(p, MM_SYMBOL_BANK, minimap.getBounds());

end;

procedure findBanker();
var
pathToBank: TPointArray;

begin
if not isLoggedIn() then
exit;
pathToBank := [Point(210, 168), Point(199, 178), Point(185, 191), Point(163, 200)]
if SPS.walkPath(pathToBank) then
minimap.waitPlayerMoving()
else
writeLn('Failed to walk to the bank');
end;

procedure depositYews();
var
bankTimer: TTimeMarker;

begin
if not isLoggedIN() then
exit;
if bankScreen.open(BANK_TABLE_BURTHORPE) then
repeat
if (tabBackPack.count > 0) then
begin
bankScreen.quickDeposit(QUICK_DEPOSIT_INVENTORY);
wait(randomRange(1000, 2000));
end;
until(tabBackPack.isEmpty()) or (not isLoggedIN()) or (bankTimer.getTime() > 10000);
inc(LoadsDone);
bankScreen.close();
end;

procedure progressReport();
var
logsCut, profit, profitPerHour, exp, expPerHour: integer;
begin
logsCut := LoadsDone * 28;
profit := (logsCut * 250);
profitPerHour := round((profit * 60) / (getTimeRunning() / 60000));
exp := logsCut * 175;
expPerHour := round((exp*60) / (getTimeRunning() / 60000));

writeLn('===============================');
writeLn('James Ayo''s Yew Power House Cutter');
writeLn('Time Run: ' + timeRunning);
writeLn('Logs Cut: ' + intToStr(logsCut));
writeLn('Loads Done: ' + intToStr(loadsDone));
writeLn('Profit Made: ' + intToStr(profit));
writeLn('Profit/hour: ' + intToStr(profitPerHour));
writeLn('Exp gained: ' + intToStr(exp));
writeLn('Exp/hr: ' + intToStr(expPerHour));
end;

// main loop
begin
clearDebug();
smartEnableDrawing := true;
setupSRL();
declarePlayers();

repeat
if not isLoggedIn() then
begin
players[currentPlayer].login();
minimap.setAngle(MM_DIRECTION_NORTH);
mainScreen.setAngle(MS_ANGLE_HIGH);
exitTreasure();
end;

if tabBackpack.isFull() then
begin
teleToBurthorpe();
findBanker();
depositYews();
end;

progressReport();

SPS.setup('RIMM_MAP', RUNESCAPE_OTHER);
teleToPortSarim();
runToTrees();
cutTrees();
SPS.setup('BURTH_MAP', RUNESCAPE_OTHER);
teleToBurthorpe();
findBanker();
depositYews();
until(false);
end.

Citrus

2015-04-08 02:21:52

You only need to setup SPS once, so I'd take it out of your loop.
Also, you can replace the "SPS" in SPS.setup with anything you want, as long as you declare it as a TSPSArea.

// main loop
begin
clearDebug();
smartEnableDrawing := true;
setupSRL();
declarePlayers();
RIMM.setup('RIMM_MAP', RUNESCAPE_OTHER); //I would put these here
BURTH.setup('BURTH_MAP', RUNESCAPE_OTHER); //and rename them
repeat
...
end.

As far as color detection goes, you probably just need to do some more color picking. Debug your TPA to make sure it is finding everything it should and/or not finding too much.
Also maybe check out cluster(). I pretty much never use use toATPA(), but it sometimes is the better choice.

Determining whether or not you're still chopping can be tricky, especially with something slow like yews. Pixel shift is unreliable because the trees can cover you up.
I used something like this in a woodcutting script once:

while isMouseOverText(['hop down']) do
begin
wait(randomRange(500, 1000);
if tabBackPack.isFull() then exit();
end;
The idea is that when the tree disappears, the mouse-over text will go away and you can start chopping the next tree. It's kinda bootleg but it worked for me.

yourule97

2015-04-08 11:00:09

Extending on evilcitrus' point, you can also just have one SPS map that contains two different locations by making one image file with two maps posted in it. This works because SPS detects colors on your minimap and compares to that which is posted in the image file and plots points based on the image size and your minimap. Just be sure to place some black space inbetween the two maps. I'll edit this post with an example once I find a suitable example.