SRL Archive - OSR Intermediate Scripting Tutorials

A Breakdown my PowerCutter


Torrent of Flame

2008-12-21 13:28:12

Hello, this is my first tutorial in a while, but I feel that seeing as I am an SRL Tutorial Writer I should show why I have this cup!

I am breaking down my powercutter, which is currently at version 0.45.

Beginnings and basics


Program AnyWherePowerCutter;
{.include SRL/SRL.scar}
{.include SRL/SRL/Skill/WoodCutting.scar}

As you know, the program is always there, you can leave it as 'New' but its always nice to give it a name, and we are including SRL.scar and WoodCutting.scar as this is an SRL function script, and also a WoodCutting Script.


procedure DeclarePlayers;
begin
HowManyPlayers := 1; //How many Players
NumberOfPlayers(HowManyPlayers);
CurrentPlayer :=0; //Starting Player

Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[0].Integers[0]:= 50; // Loads to Do.
Players[0].Strings[0] := 'willow'; // ALL lowercase; normal, oak, willow, maple or yew
Players[0].Strings[1] := 'false'; // Is your axe equipped?

{ Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := False;
Players[1].Integers[0]:= 10; //Loads to Do;
Players[1].Strings[0] := 'oak';
Players[1].Strings[1] := 'true';

{ Players[2].Name := '';
Players[2].Pass := '';
Players[2].Nick := '';
Players[2].Active := True;
Players[2].Integers[0]:= 10; //Loads to Do;
Players[2].Strings[0] := 'willow';
Players[2].Strings[1] := 'true';

Players[3].Name := '';
Players[3].Pass := '';
Players[3].Nick := '';
Players[3].Active := True;
Players[3].Integers[0]:= 10; //Loads to Do;
Players[3].Strings[0] := 'maple';
Players[3].Strings[1] := 'true';

Players[4].Name := '';
Players[4].Pass := '';
Players[4].Nick := '';
Players[4].Active := True;
Players[4].Integers[0]:= 10; //Loads to Do;
Players[4].Strings[0] := 'yew';
Players[4].Strings[1] := 'true'; }
end;

This is the declare players forms. The Integers[0], Strings[0] and Strings[1] will be explained later on in this tutorial.

var x, y, i, Dropped, BrokenAxe, Loads, LoadsCompleted, LoadsUntilSwitch: integer;

These are the variables I have used in my script, they will all be explained later on, aswell.


Cutting Procedure


procedure CutTree;   
var Failed: integer;
TreeColors: array [0..3] of integer;
begin
if (not LoggedIn) then Exit;
case lowercase(Players[CurrentPlayer].strings[0]) of

'normal': begin
TreeColors[0] := 332817;
TreeColors[1] := 3765091;
TreeColors[2] := 2179633;
TreeColors[3] := 3230282;
for i := 0 to 3 do
if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) then
begin
repeat
FindEnts(x, y, True);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;
Wait(200 + Random(200));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])
MMouse(x, y, 2, 2);
AntiBan;
FindRandoms;
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']);
while (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) do
repeat
MakeCompass('S');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;
end;

'oak': begin
TreeColors[0] := 2584416;
TreeColors[1] := 3305828;
TreeColors[2] := 4162678;
TreeColors[3] := 5544845;
for i := 0 to 3 do
if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak']) then
begin
repeat
FindEnts(x, y, True);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;
Wait(2000 + Random(400));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])
MMouse(x, y, 2, 2);
AntiBan;
FindRandoms;
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak']);
while(not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])) do
repeat
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Oak', 'Oa', 'ak']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;
end;

'willow': begin
TreeColors[0] := 2181686;
TreeColors[1] := 6193521;
TreeColors[2] := 3755332;
TreeColors[3] := 3234376;
for i := 0 to 3 do
if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow']) then
begin
repeat
FindEnts(x, y, True);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;
Wait(3000 + Random(400));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])
MMouse(x, y, 2, 2);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])
Wait(3000 + Random(400));
AntiBan;
FindRandoms;
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow']);
while (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])) do
repeat
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Willow', 'Will', 'illo', 'llow']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;
end;

'maple': begin
TreeColors[0] := 1319487;
TreeColors[1] := 725796;
TreeColors[2] := 2177124;
TreeColors[3] := 1385537;
for i := 0 to 3 do
if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple']) then
begin

repeat
FindEnts(x, y, True);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;
Wait(2000 + Random(400));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])
MMouse(x, y, 2, 2);
AntiBan;
FindRandoms;
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple']);
while (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])) do
repeat
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Maple', 'Map', 'apl', 'ple']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;
end;

'yew': begin
TreeColors[0] := 3241318;
TreeColors[1] := 2119755;
TreeColors[2] := 2645844;
TreeColors[3] := 3240035;
for i := 0 to 3 do
if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew']) then
begin
repeat
FindEnts(x, y, True);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;
Wait(2000 + Random(400));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])
MMouse(x, y, 2, 2);
AntiBan;
FindRandoms;
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew']);
while (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])) do
repeat
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Yew', 'Ye', 'ew']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;
end;
end;
end;

Ok, so that might look scary, but lets break it down into its component parts.

procedure CutTree;   
var Failed: integer;
TreeColors: array [0..3] of integer;

So we have given a name to the procedure, and declared the variables.

array[0..3] of integer just means that there is an array, or collection, of 4 integers which are TreeColors.

begin
if (not LoggedIn) then Exit;

The procedure begins, hence begin. There is also a failsafe, so if you character is not logged in the script will end.

case lowercase(Players[CurrentPlayer].strings[0]) of

This means that if strings[0] of the current player, could be for example 0, 1, 2, ect., is a certain lowercase string, then the script will take different routes of action. I will only explain the part which is
'normal':
but the same applies to the other 4 cases.

'normal': begin                               
TreeColors[0] := 332817;
TreeColors[1] := 3765091;
TreeColors[2] := 2179633;
TreeColors[3] := 3230282;
for i := 0 to 3 do
if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) then
begin
repeat
FindEnts(x, y, True);
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;
Wait(200 + Random(200));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])
MMouse(x, y, 2, 2);
AntiBan;
FindRandoms;
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']);
while (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) do
repeat
MakeCompass('S');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;
end;

Now to break this down aswell..

'normal': begin                               
TreeColors[0] := 332817;
TreeColors[1] := 3765091;
TreeColors[2] := 2179633;
TreeColors[3] := 3230282;

The case, which is if Strings[0] := normal, begins, and defines the array of the 4 TreeColors we have, and defines them a number between 0 and 3.

for i := 0 to 3 do

This means that 'i' is equivalent to all 4 of the colours, which becomes more useful in the next part.

if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) then
begin

So we are finding an object in the main screen, and the mouse moves over and tries to find the 4 colours, defined by 'i', which is useful as it means that the script does not try to find one colour on its own, as this can lead to problems with the script scanning alot of the game screen. The '30' is the tolerance from the colour, so it can find any colour within a 30 colour difference range of the 4 colours, the 2 signifies , the 15 and 25 mean that the colours have to be found in a area that is 15px wide and 25px tall. The 10 tells us the minimum count of these colours, meaning that there has to be 10 of the colours counted in this box. Continuing on, the ['Tree', 'Tre', 'ree'] tells the script that if it finds that Uptext, the text in the Top Left hand corner or the game screen, then it should begin this process;

repeat
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])
Wait(100 + Random(300));
MMouse(x, y, 2, 2);
begin
Wait(100 + Random(200));
Wait(100 + Random(200));
case Random(2) of
0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;
1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;
end;

So it repeats this process, it looks for the TPA again, and waits 101-400 milliseconds before clicking it, then moves the mouse over it, and waits again. Then the script chooses one of the 2 things to do to chop it, to make the script seem less bot like, it can either;

                  0: begin
Mouse(x, y, 4, 4, False);
Wait(100 + Random(200));
ChooseOption('hop');
WriteLn('Chopping Tree');;
end;

Begin a process that moves over the tree, right clicks it and chooses the "Chop Tree" option, and writes Chopping Tree in the Debug box so that we know it is working, or;

                  1: begin
Mouse(x, y, 4, 4, True);
WriteLn('Chopping Tree');
end;

It just moves straight over the tree and left clicks it straight off, writing Chopping Tree in the debug box again to show it is working.

After this, the script then continues on to wait for the cutting for a little while;

Wait(200 + Random(200));
FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])
MMouse(x, y, 2, 2);
if not (LoggedIn) then
NextPlayer(False);
LoginPlayer;
end;
until Invfull or not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']);

So the script waits again, for between 201-400 milliseconds, and mouses over the tree again so it doesnt loose it. If the player is not logged in, then the script will log in the next player, and make the current player become inactive. The repeat we saw above will continue repeating until the inventory is full, or until the script cannot Find our tree we want to cut.

while (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) do
repeat
MakeCompass('S');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
Inc(Failed);
until FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) or (Failed = 5);
if (Failed = 5) then
begin
WriteLn('Tree Finding Failed :(');
ProgressReport;
NextPlayer(False);
LoginPlayer;
end;
end;

Whilst the script cannot find the tree, it will rotate the screen to N, E, S then W, looking for the tree. If it cannot find the tree at any of these compass points, it will Increase the failed times by 1, hence Inc(failed). This failsafe will continue to happen until the tree is found, or until the Failed total reaches 5. If the tree cannot be found after 5 rotations, then the script will write 'Tree Finding Failed :(' in the Debug box, print a progress report, then activate the next player, but deactivating the current player, then will log in this new player. The two ends signify the end of the (Failed=5) procedure, and the end of the found tree in the first place procedure.

This same explanation works for all of the other 4 case values. At the end, remember to end the case and to end the procedure.

Power Dropper


Powerdroppers can be as simple as;

procedure PowerDrop;
begin
for i := 2 to 28
begin
DropItem(i);
end;
end;

My powerdrop procedure, however, is a little more complex, as it works in two ways, so if you equip your axe it drops the inventory as a whole from 1 - 28, but if you do not equip your axe, it drops from 2 to 28.

procedure PowerDrop;
begin
case lowercase(Players[CurrentPlayer].Strings[1]) of

'true': begin
for i:= 1 to 28 do
begin
DropItem(i);
Inc(Dropped);
end;
end;

'false': begin
for i:= 2 to 28 do
begin
DropItem(i);
Inc(Dropped);
end;
end;
end;
end;
end;

Ok, so we state another case. If we look at declare players we can see again the .Strings[1]. If htis is set to true, then 'i' is the inventory spaces between 1 and 28, as the axe is equipped and so fills up the whole inventory with logs. But if set to false, then 'i' is from 2 to 28, as the axe is in the first inventory slot and you do not want your axe to be dropped. The Inc(Dropped) increases by whatever size the intentory is, so Dropped for false is 27, and dropped for true is 28


Progress Report


A script normally encorperates a progress report so the person who owns it can see how long their script can run for.

procedure ProgressReport;
begin
ClearDebug;
Writeln(',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,');
Writeln('/\ Time Running : ' + TimeRunning + ' /\');
Writeln('/\ Done '+ IntToStr(Loads) +' loads /\');
Writeln('/\ Dropped '+ IntToStr(Dropped) +' logs /\');
Writeln('`````````````````````````````````````````````````');

end;

This will write the time that the script has been running, the amount of logs that have been dropped, as we have defined above in the dropping procedure, and the Loads, which is described next in the Main Loop.

Main Looping


procedure DoOnce;
begin
ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
end;

This is basically the setup of the script, the Debug box is cleared, SRL is set up, the players are declared and then logged in.

procedure MainLoop;
begin
LoadsCompleted:= 0;
SetAngle(True);
Wait(1000);
SetRun(True);
repeat
[B] repeat
[U] LoadsUntilSwitch := Players[CurrentPlayer].integers[0];
CutTree;
if Invfull then
begin
PowerDrop;
Inc(Loads);
end;
Inc(LoadsCompleted);
ProgressReport;
until (LoadsCompleted = LoadsUntilSwitch) or (not LoggedIn)[/U]
if LoadsCompleted = LoadsUntilSwitch then
NextPlayer(True);
if (not LoggedIn) then
NextPlayer(False);
ProgressReport;
LoginPlayer;[/B]
until (AllPlayersInactive);
ProgressReport;
TerminateScript;
end;

So the main loop begins, and then sets LoadsCompleted, a variable integer from the start of the script, to 0, which helps us with the looping. It then sets angle to the highest point, waits a second, and sets run to true, so running is active to make you switch trees quicker. Then the script is told to repeat the part in bold, and then the parts underlined are repeated in this repetition before this. So the repeat in the repeat tells the script to run the cut tree procedure, and in the cut tree procedure it says carry on until the inventory is full, if the inventory is full, then the script runs the PowerDrop procedure, and increases the number of loads by 1. LoadsCompleted is also increased by one, to help with the looping. A progress report is then printed in the debug box. This underlined repeat will continue repeating until LoadsCompleted is equivalent to LoadsUntilSwitch. LoadsUntilSwitch is equivalent to .Integers[0] as defined in the setup players at the start. When LoadsCompleted is the same as LoadsUntilSwitch, a failsafe ensures that the script is still logged in, if not it switches players and sets the current to inactive, but if it is still logged in then it switches players and leaves the current player still active, so the loop will continue again and again, it then prints another Progress Report, then Logs in the new player. The bolded repeat will continue until all the players are inactive, for whatever reason. Then finally, a Progress Report is printed, and the script is terminated.


Finishing up, the MainLoop and DoOnce procedures have to be run themselves, so we create a final running.

begin
DoOnce;
MainLoop;
ProgressReport;
end.

So the script will begin, run the DoOnce procedure, and then loop the MainLoop until the players are inactive, then the progress report will be printed for a final time, then the script ends.






Thank you for reading through! I put alot of time into writing this tutorial and would appreciate any comments :)

~ ToF

jakeyboy29

2008-12-21 13:52:35

mint, will look over in detail in 20 mins.

Edit: i can see how this would be very usefull, rep++

Torrent of Flame

2008-12-21 16:07:52

Thanks (:

NiCbaZ

2008-12-21 17:42:12

Nice tut should fix up the standers a bit tho makes heaps easy to read, i think your biggest problem is

If then.

 
MakeCompass('S');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('N');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('E');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
MakeCompass('W');
Wait(100 + Random(300));
if (not FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree'])) then
Inc(Failed);

Ethan1221

2008-12-21 20:19:50

Where can i download this?

NCDS

2008-12-21 20:29:18

Wow, very nice. I actually picked up a couple things from this that will help in my thiever!
rep+
nice job!

Torrent of Flame

2008-12-22 04:29:23

Yeah NiCbaZ, I was never a fan of standards anyway. I used to have this .exe which fixed the standards for me, but when I System Restored I lost it, so I dont really get on with standards lol :p

Unreal

2008-12-22 04:52:39

hope to see it working =)

Torrent of Flame

2008-12-22 08:29:54

Hope to see what working?

@Ethan - Wtf? What you on about dude 0_o

designed by

2008-12-22 18:36:15

Thank you for this breakdown. The more and more I read breakdowns like this the more I start to understand scripting with SRL and start contributing with my own scripts. I seem to understand breakdowns more than anything so thanks.

DeSnob

2008-12-28 12:53:29

EDIT: Nevermind, found the problem

kingstun

2009-01-03 21:19:48

It will give you runtime errors because of this:

if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) then
FindObjTPa can only support 1 color.

IronGummy Bear

2009-01-03 22:36:42

Thanks, the breakdown helped alot, this was exactly wat I was looking for.

Torrent of Flame

2009-01-04 07:13:42

From: kingstun
It will give you runtime errors because of this:

if FindObjTPA(x, y, TreeColors[i], 30, 2, 15, 25, 10, ['Tree', 'Tre', 'ree']) then
FindObjTPa can only support 1 color.


No, FindObjTPA can find an array of integers, hence the TreeColors declared. is the variable of 0 to 3 of the tree colors, so the script searches for 4 colors.

kingstun

2009-01-04 10:44:17

Anyways Thanks ToF.
I made my power cutter using your idea of FindObjTPA.

Dropsy

2009-01-13 21:40:58

Thanks for the tut! It showed me quite a few things about powercutters =P

r3dr4g0n

2009-01-19 00:28:45

Thank you very much. I needed something like this.

TheSantaMan

2009-01-26 15:41:01

yeah plus the point of an array is to store multiple sets of data. :P

Smarter Child

2009-01-26 23:02:15

I like the way you write your tutorials. :p what about ent finding? (0-it's a big one-0)

bank

2009-01-29 07:26:51

that was great! took me a while to understand, haha, still learning. well done, nice set out, easy on the brain :)

Naum

2009-01-31 07:41:39

Very nice tutorial Rep++

Gearsnare

2009-03-02 16:26:18

You helped me create and understand my first script, thank you very much but I have one little error:
Line 25: [Error] (16709:1): Unknown identifier 'Player' in script C:\Documents and Settings\Administrator\My Documents\Runescape\PowerCutter.scar
How do I sort it out?

Thanks!

kingstun

2009-03-02 17:08:25

The procedure or variable "Player" is not declared.

Gearsnare

2009-03-02 17:15:27

Edit: Had errors due to typing errors.

Script runs great!
I'm so pleased that I've created a script which I actually understand, tyvm!

kooldude

2009-03-06 23:16:10

Heyyy! thanks for the scripting tut. :)
i havent been on srl in months, and im trying to start up again.
Your tut was the first one i read and i believe its truly written amazing
considering that it replenished some things i forgot.

-Kooldude
:sasmokin: