SRL Archive - Blogs and Writing

Starting to script - Development Diary


Syntax

2015-01-26 06:27:33

Hi guys, I have decided I wanted to learn how to script for Simba. I thought I'd make this thread to share my code on and get some advice and also have it here as a sort of "record" I guess so I can see the progress I have made.
I'm planning on making a new post everyday with progress or stuff I am doing, but I'll see how it goes.

-Syntax

Syntax

2015-01-26 08:00:06

Done quite a bit tonight and learnt a lot. Using The Mayors guide here: https://villavu.com/forum/showthread.php?t=109161
And a lot of searching through my old topics and on here solving bugs.
This is what I have came up with so far:
program ChopnFletch;
//{$DEFINE SMART} //Starts SMART client
{$i srl-6/srl.simba} //Includes SRL

procedure findTree;
var
x, y: integer; //Variables that findObject output
begin
mainScreen.setAngle(MS_ANGLE_LOW); //sets camera angle low
minimap.setAngle(MM_DIRECTION_SOUTH); //sets minimap to the south
repeat
if mainscreen.findObject(x, y, 1711645, 4, ['ree'], MOUSE_RIGHT) then //finds a normal tree
begin
writeln('Found a Normal tree'); //For debug, only runs if script finds a tree
chooseOption.select(['hop down']); //Chops tree
wait(randomrange(6000,7000)); //Waits for 6-7 seconds
end
until(not isLoggedIn() or tabBackpack.isFull())
end

//procedure fletchlogs; //Fletch into arrowshafts
//repeat
//begin
//if tabBackpack.isFull() then
//Find log in inventory from research using DTMs?
//Fletch log, navigate menu
//end
//until(no normal logs in inventory)


begin
clearDebug();
setupSRL();
findTree;
end.

Syntax

2015-01-27 06:42:52

Pretty happy with the progress the script has made today, it went from hovering over everything to finding trees a lot more quickly and accurately to the point you couldn't make it any better.
98% of the progress on the script was thanks to The Mayors tutorials.
Also thanks to Olly and ianhedoesit on IRC.

Still a lot more to do for the ChopnFletch script, chopping is working though as expected which feels great.
program ChopnFletch;
{$DEFINE SMART} //Starts SMART client
{$i srl-6/srl.simba} //Includes SRL

procedure prepareplayer;
begin
//Wait(randomrange(800,1800));
Writeln('Please Wait...Setting Player up');
if not isLoggedIn() then
exit;
exitTreasure;
mainScreen.setAngle(MS_ANGLE_LOW); //sets camera low
minimap.setAngle(MM_DIRECTION_SOUTH); //sets compass south
end;
procedure chopDownTree;
var
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
//if mainscreen.findObject(x, y, 1711645, 4, ['ree'], MOUSE_RIGHT) then //finds a normal tree

begin
prepareplayer;
FindColorsSpiralTolerance(x, y, TPA, 2640486, mainscreen.getBounds(), 4, colorSetting(2, 0.40, 0.25)); //Function to findcolors


if length(TPA) < 1 then
exit;
//maybe move to different area or rotate display instead of exit?
ATPA := TPA.toATPA(30, 30);
ATPA.sortFromMidPoint(mainscreen.playerPoint);
//smartImage.debugATPA(ATPA); not functional atm

for i := 0 to high(ATPA) do
begin
mouse(middleTPA(ATPA[i]), MOUSE_MOVE);
if isMouseOverText(['ree'], 500) then
begin
writeln('Found a Normal tree'); //For debug, only runs if script finds a tree
wait(randomrange(300,800));
fastClick(MOUSE_RIGHT);
chooseOption.select(['hop down']); //Chops tree
tabBackpack.waitForShift(5000)
end else
begin
writeln('No trees found, please adjust color' +
'or move to a section with trees');
exit;
end;
end;
end;
//create an additional failsafe?


//repeat
//begin
//writeln('Found a Normal tree'); //For debug, only runs if script finds a tree
// chooseOption.select(['hop down']); //Chops tree
//wait(randomrange(6000,7000)); //Waits for 6-7 seconds
//end
// until(not isLoggedIn() or tabBackpack.isFull())

//procedure fletchlogs; //Fletch into arrowshafts
//repeat
//begin
//if tabBackpack.isFull() then
//Find log in inventory from research using DTMs?
//Fletch log, navigate menu
//end
//until(no normal logs in inventory)


begin
clearDebug();
setupSRL();
repeat
chopDownTree;
until(not isLoggedIn() or tabBackpack.isFull())
end.

masterBB

2015-01-27 08:55:58

Some hints from personal experience:

Remove code you know you wont use again instead of commenting them out

Add "TODO:" in front of comments made to your future self for improvements.

When commenting out code for longer as one debug run use /* code */ instead of tons of //

Smidqe

2015-01-27 09:37:10

From: masterBB

When commenting out code for longer as one debug run use /* code */ instead of tons of //


This isn't C, so I think you mean (* code *) or { code }? ;)

Syntax

2015-01-29 04:30:31

From: masterBB
Some hints from personal experience:

Remove code you know you wont use again instead of commenting them out

Add "TODO:" in front of comments made to your future self for improvements.

When commenting out code for longer as one debug run use /* code */ instead of tons of //


Ah thanks masterBB those are some great points will definitely incorporate it now :)

The Mayor

2015-01-29 04:59:53

From: Syntax
Ah thanks masterBB those are some great points will definitely incorporate it now :)


If you know what good standards look like, you should run it through the parser (it will remove all comments though). You can enable formatter.sex via extensions.


Harrier

2015-01-29 06:03:28

From: The Mayor
If you know what good standards look like, you should run it through the parser (it will remove all comments though). You can enable formatter.sex via extensions.


https://github.com/JohnPeel/ScriptFormater
Quite sure this doesn't remove comments and gives you hints :)

Syntax

2015-01-29 08:50:10

From: Harrier
https://github.com/JohnPeel/ScriptFormater
Quite sure this doesn't remove comments and gives you hints :)


Looks great Harrier, thanks a lot!

From: The Mayor
If you know what good standards look like, you should run it through the parser (it will remove all comments though). You can enable formatter.sex via extensions.



Oh wow, this is definitely a good extension, I just used it on my script one section isn't formatted though because I just wrote it.
Thanks The Mayor :staycool:

——

Here is what I have been up to today:
{{TODO: In chopDownTree function, move to different area or rotate the display
instead of exiting the script.
Perfect chopDownTree, seems to be an issue chopping more than one tree at
a time.
Clean up code.
Anti-ban.
Progress report.
Fix up fletching/chopping not working with seperate procedures

}
program ChopnFletch;
{$DEFINE SMART}
{$i srl-6/srl.simba}

procedure prepareplayer;
begin
ClearDebug;
Writeln('Please Wait...Setting Player up');
if not isLoggedIn() then
exit;
exitTreasure;
mainScreen.setAngle(MS_ANGLE_HIGH);
minimap.setAngle(MM_DIRECTION_NORTH);
end;


procedure chopDownTree;
var
x, y, i: integer;
TPA: TPointArray;
ATPA: T2DPointArray;
begin
if not tabBackpack.isfull then
begin
prepareplayer;
FindColorsSpiralTolerance(x, y, TPA, 2107688, mainscreen.getBounds(), 2, colorSetting(2, 1.69, 0.80));
fletchLogs;
if length(TPA) < 10 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(['ree'], 500) then
begin
writeln('Found a Normal tree');
wait(randomrange(300, 800));
fastClick(MOUSE_RIGHT);
chooseOption.select(['hop down']);
tabBackpack.waitForShift(7900);
end else
begin
writeln('No trees found, please adjust color' + ' ' + 'or move to a section with trees');
exit;
end;
end;
end else
writeln('Inventory full, fletching the logs');
fletchLogs;
end;

procedure findLog;
var
Log, l, o: Integer;
begin
Log := DTMFromString('mlwAAAHicY2dgYHjHzMDwEIj/MUPY74H4JxA/AuJ5jAwMK4F4KRBPA+JVQDwDiGcDcYKHNlA3ExAzQmlkjBsw4sFQAAClmgvt');
if findDTM(Log, l, o, tabBackpack.getBounds()) then
begin
mouse(l, o, 3, 3, MOUSE_MOVE);
fastClick(MOUSE_LEFT);
FreeDTM(Log);
end else
FreeDTM(Log);
exit;
end;

procedure fletchLogs;
begin
//if tabBackpack.isFull then
begin
findLog;
if toolScreen.isOpen(3000) then
toolScreen.select('Knife');
if productionScreen.isOpen(10000) then
else end
writeln('Inventory isnt full');
begin
productionScreen.selectBox(1);
productionScreen.clickStart();
if progressScreen.isOpen(10000) then
begin
repeat
wait(1000);
until(not progressScreen.isOpen());
end;
end;
end;

begin
clearDebug();
smartEnableDrawing := true;
setupSRL();
fletchLogs;
{repeat
chopDownTree;
until (not isLoggedIn() or tabBackpack.isFull())}
end.

Ran into a few bugs today, when writing the fletchLogs function I ran into an issue where I was dependent on the logs always being in whichever slot was hardcoded. Instead I decided to use DTMs which I remember reading about in The Mayors tutorial, so I went back to the tutorial and incorporated it into my script to find the logs.
This allows a log to be anywhere in the inventory and it will still find it/fletch it.

Fletching is working as expected, tying it together is going to be a bit harder though. I can't call fletchLogs from chopDownTree and the other way around pretty sure that's because of the order I have written the procedures, won't help changing it.

Thinking about placing fletching on top of chopDownTree, then inside chopDownTree running a check if the inventory is full, then if it is will find the log dtm, fletch the logs whilst waiting until there is no change in the inventory. Do another check if the inventory is full then start chopping.
Not sure if that is the most efficent way though.

3Garrett3

2015-01-29 10:52:50

From: Syntax
Fletching is working as expected, tying it together is going to be a bit harder though. I can't call fletchLogs from chopDownTree and the other way around pretty sure that's because of the order I have written the procedures, won't help changing it.

Thinking about placing fletching on top of chopDownTree, then inside chopDownTree running a check if the inventory is full, then if it is will find the log dtm, fletch the logs whilst waiting until there is no change in the inventory. Do another check if the inventory is full then start chopping.
Not sure if that is the most efficent way though.


I'm not sure I see your problem. Do you mean you want to be able to call chopping and fletching together? Your main loop could have something like this:


begin
repeat
repeat
chopDownTree();
until (not isLoggedIn() or tabBackpack.isFull())
fletchLogs();
until (not isLoggedIn())
end.

That would do what I think you're trying to describe. No reason for it to be inside your chopDownTree function though, you can just make functions for the key events (in your case chopping and fletching) and then make the logic happen in your main loop.

If you have any other trouble with the logic part of scripting, I suggest you write things down. I keep scrap paper around all the time and I've got about 10 sheets of paper with random writing for how I could make the logic work with my merchant script. It really helps me keep track of my thoughts and logically lay out Action 1 -> Action 2 -> Action 3 and whatever network comes from that.

E: If you want to look through my Edgeville chopper and fletcher, it might help you. It isn't complicated compared to Asha's or Cohen's scripts, so it might be easier to break down for you, especially since it does the same function that you're working through so it might be easier to follow the logic.

masterBB

2015-01-29 12:56:58

restructuring would be better. But a dirty and dangerous solution would be with forwards:

program new;

procedure b(); forward;

procedure a();
begin
writeln('a');
b();
end;

procedure b();
begin
writeln('b');
end;

begin
b();
a();
end.

Using forwards is perfectly fine. But if b cals a which calls b which calls a…. etc etc. That is bad.

Syntax

2015-02-03 06:31:51

From: 3Garrett3
I'm not sure I see your problem. Do you mean you want to be able to call chopping and fletching together? Your main loop could have something like this:


begin
repeat
repeat
chopDownTree();
until (not isLoggedIn() or tabBackpack.isFull())
fletchLogs();
until (not isLoggedIn())
end.

That would do what I think you're trying to describe. No reason for it to be inside your chopDownTree function though, you can just make functions for the key events (in your case chopping and fletching) and then make the logic happen in your main loop.

If you have any other trouble with the logic part of scripting, I suggest you write things down. I keep scrap paper around all the time and I've got about 10 sheets of paper with random writing for how I could make the logic work with my merchant script. It really helps me keep track of my thoughts and logically lay out Action 1 -> Action 2 -> Action 3 and whatever network comes from that.

E: If you want to look through my Edgeville chopper and fletcher, it might help you. It isn't complicated compared to Asha's or Cohen's scripts, so it might be easier to break down for you, especially since it does the same function that you're working through so it might be easier to follow the logic.


Ah putting it in the main loop, I didn't think of this.
Genius.

Syntax

2015-02-09 08:11:32

Haven't done any updates lately because I finished the script and is working great.
I want to move onto a more challenging project. What do you guys think?
I will release the script here once I am back on my main computer again.

Daniel

2015-02-09 08:16:00

From: Syntax
Haven't done any updates lately because I finished the script and is working great.
I want to move onto a more challenging project. What do you guys think?
I will release the script here once I am back on my main computer again.


Nice work! :)

cosmasjdz

2015-02-09 08:21:04

From: Syntax
Haven't done any updates lately because I finished the script and is working great.
I want to move onto a more challenging project. What do you guys think?
I will release the script here once I am back on my main computer again.


I wanted but had no time green drag bots pker bot :) That would be hilarious. And even better than botting green drags, considering you arent botting for charms+cash combination. Bots finding on screen could be done using minimap to mainscreen functions and filtering out background and dragons colors. Not toohard combat system would be needed either. Then again after pk just minimap to mainscreen and filter again background and drags to pick loot, rebank and repeat. basicly could use like 1item or so not to risk much.

That would be epic next generation head above other drags bots. Farming drag bots instead of drags :) Also wondering how fast would other developers update their bots to use glories for instant teleportation out, but hen you could add teleblocking support:D

You would get alot of experience using sps/tpa/dtm walking methods. Would use various tpa filtering methods. Would learn combat basics at scripting. Would learn and develop surviving/teleporting/running after getting atacked by legit pkers skills.

Other suggestions would be farming runs bot. Elder/crystal trees bot.