shaunthasheep
09-02-2007, 01:11 PM
Making your first woodcutting script.
Requirements:
SCAR Divi 3.11.
SRL 4 BETA.
Some basic scar knowledge.
Some time.
Note: This is a very simple Woodcutting Script.
This tutorial should teach you how to:
Using SRL's Multi-player Efficiently
Basic SRL functions and Procedures
Possibly other stuff on the way.
Also note that mainloop refers to me as the begin end.
Ok, let's get started. Open up Scar. You should see this:
program New;
begin
end.
Let's start by including SRL:
program New;
{.include SRL/SRL.scar}
begin
end.
And since we are using SRL, we need to add SetupSRL;
program New;
{.include SRL/SRL.scar}
begin
SetupSRL;
end.
We will start by adding Multiplayer. In SRL 4, they have 2 new procedures that make setting up your players easier. Let's start by making our DeclarePlayers procedure.
We start with this.
procedure DeclarePlayers;
begin
end;
The 2 new functions are these:
SetupPlayers;
LoadPlayerArray;
SetupPlayers sets the array length of Players to 100.
LoadPlayerArray; automatically shortens it to the ones we are using once it is called.
so now it looks like this:
procedure DeclarePlayers;
begin
SetupPlayers;
LoadPlayerArray;
end;
With some existing knowledge of SRL's Multiplayer, we need to add this:
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
See a tutorial on how to setup your players for information on how to fill these in.
so now it looks like this:
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
LoadPlayerArray;
end;
If we wanted to add another player, we would do this:
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
If you got to this part, now you (hopefully) understand SRL's Multiplayer!
Once we combine are current script with our new DeclarePlayers procedure, are script now looks like this:
program New;
{.include SRL/SRL.scar}
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
end.
but now we have to add DeclarePlayers; after SetupSRL; or the procedure will be useless. Remember SCAR only runs whats in the mainloop. which is the last
begin
end.
Adding DeclarePlayers; we should have this:
program New;
{.include SRL/SRL.scar}
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
end.
Before we create and add our Chop procedure, I'm going to create part of the main loop. Let's start with a simple repeat until.
Right now are main loop is this:
begin
SetupSRL;
DeclarePlayers;
end.
First we want to log in are first player.
But since the way SRL works, the player has to be loggedin by the script, or antirandoms(if you decide to add any) won't work. So we will logout any loggedin user, then Login are player. This is what it looks like once we do that:
begin
SetupSRL;
DeclarePlayers;
if Loggedin then Logout;
LoginPlayer;
end.
Now we will start on the part of the main loop that will do all the work. We will do this with a simple repeat until.
begin
SetupSRL;
DeclarePlayers;
if Loggedin then Logout;
LoginPlayer;
repeat
until false
end.
until false will mean it will loop forever.
Our current script is this:
program New;
{.include SRL/SRL.scar}
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
until false
end.
We are going to add a LoadPerPlayer type switching. So we are going to add a new constant at the top of the script name "LoadsPerPlayer".
program New;
{.include SRL/SRL.scar}
const
LoadsPerPlayer = 10; //Amounts of loads per player before switching.
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
until false
end.
Time to finish part of the main loop. This is where i'm going to use the bolded word "mod".
Mod is a math term like divide, add, etc. What it does is returns the remainder of a division problem.
So "5 mod 3 = 2" 5 divided by 3 = 1 with a remainder of 2
So part of our mainloop is this:
repeat
until false
Im going to be adding some stuff as it goes, not much for explanation on some of this stuff.
repeat
ChopTree;
until false
I added ChopTree; We havn't created this procedure yet but we will soon!!
repeat
ChopTree;
if InvFull then
begin
end;
until false
Once the inventory is full in will do the stuff between begin end;
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
end;
until false
Will drop from inventory spot 2 to 28. Note there is a bit of a bug in this procedure in SRL 4 Beta. Won't drop the last row some times.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
end;
until false
Inc(Players[CurrentPlayer].Banked);
Lets break this down a bit.
Inc(); will increase a number by 1, so number + 1;
Players[CurrentPlayer].Banked: Will hold the amount of Drops this player has done. Will be used later in the loop.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
end;
end;
until false
Wtf is this?
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
Its ok to be a bit (lot) confused here. This is why i'll try to explain the best I can.
Remeber Players[CurrentPlayer].Banked holds the amount of drops the player does.
And LoadsPerPlayer is how many LoadsPerPlayer a player should do before switching.
Also remember what mod does.
The player can be in the loop more then 1 time. Thats why we don't do this:
if Players[CurrentPlayer].Banked = LoadsPerPlayer then
If the player is still in the loop, that means nothing bad has happened to it.
That means he can have over 100 drops. But if his drops is dividable by LoadsPerPlayer and no remainder is left over, that means he has done enough loads and is ready to switch, as in this:
Example:
LoadsPerPlayer = 2
and in certain times of the script
.Banked = 2 or 4 or 6 or 8
Any of those numbers above divided by LoadsPerPlayer will have no left over remainder. Get it? hmm probally not.. Anyways we're moving on.
We currently have this:
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
end;
end;
until false
We are going to make it switch players.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
until false
NextPlayer(True);
NextPlayer will switch to the next ACTIVE player. if you do NextPlayer(True) then the current player will be still be active and will switch. If you do NextPlayer(False) and the currentplayer will be active=false and won't be used in the script again, and it will still switch to the next active player. What if there is no more ActivePlayers? SRL will catch that and will make it so the script won't go on any further.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
if not Loggedin then NextPlayer(False);
until false
if not Loggedin then NextPlayer(False);
if we are not logged in, then something bad has happened in the script,
and so we set it so the current player won't be used anymore and it will switch the the next active player.
That should be it for the main loop. Hopefully i didn't forget anything.
Now are script looks like this:
program New;
{.include SRL/SRL.scar}
const
LoadsPerPlayer = 10; //Amounts of loads per player before switching.
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
if not Loggedin then NextPlayer(False);
until false
end.
Time to make our ChopTree procedure, keeping in mind if we log out when something wrong happens, are mainloop will take care of it.
We will start as we did with our DeclarePlayers procedure:
procedure ChopTree;
begin
end;
For safety, i will add this
procedure ChopTree;
begin
if not Loggedin then Exit;
end;
this will Exit the procedure if we're not logged in.
We are going to add a repeat until false. Keeping in mind, if we use the Break; command, we can exit the repeat until false, and with Exit we can get out of the procedure.
procedure ChopTree;
begin
if not Loggedin then Exit;
repeat
until false
end;
Add a constant at the top of your script named "Treecolor" for this next part. (Add it under LoadsPerPlayer)
procedure ChopTree;
var
x, y : integer;
begin
if not Loggedin then Exit;
repeat
until false
end;
procedure ChopTree;
var
x, y : integer;
begin
if not Loggedin then Exit;
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
Ok, i added alot of stuff here.
First, im going to explain the MarkTime and TimefromMark.
MarkTime will set the current time to the var you enter, we entered MyMark.
So MyMark is holding the current time.
TimeFromMark will get the time that has passed since MyMark
(2 * 60 * 1000) equals 2 minutes in milliseconds.
so If 2 minutes goes by and we havn't chopped a tree, we logout, then exit the procedure.
Time to explain the FindObj
FindObj is a procedure in SRL
function FindObj(var cx, cy: Integer; Text: String; color, tolerance: Integer): Boolean;
where cx and cy will return the position of the object if it is found.
Text is the text that is in the corner of RS when you move your mouse over something. We are using 'hop' for Chop as in Chop Tree
color is the TreeColor. We are using the constant we added, the user must fill this in.
Tolerance is a number that tells the script to look for colors this close to our color we put in. Higher the tolerance, more colors it will look for, 0 means it will search for that color only. See another tutorial on tolerance if there is one, or the Scar Manual.
So if the tree is found, it will return the coordinates in X, Y.
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
We right click the coordinates of the object with 0 randomness.
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
if ChooseOption('hop') then
begin
end;
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
if it finds and successfully clicks the Chop in the right click menu, then do whats in the begin end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
if ChooseOption('hop') then
begin
//increase 1 to the total tree chop - if we had one
Exit; //We clicked chop, now we can exit this procedure.
end;
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
Since we clicked chop, we can exit the procedure.
After adding a waiting while chopping the tree,
Are script now looks like this:
program New;
{.include SRL/SRL.scar}
const
LoadsPerPlayer = 10; //Amounts of loads per player before switching.
TreeColor = 0; //Fill in the treecolor here.
WaitPerTree = 5000; //the time to wait while we are chopping the tree in Miliseconds.
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
if ChooseOption('hop') then
begin
//increase 1 to the total tree chop - if we had one
Wait(WaitPerTree);
Exit; //We clicked chop, now we can exit this procedure.
end;
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
if not Loggedin then NextPlayer(False);
until false
end.
Congratulations! You have made your first simple Woodcutter!
Now you can add Anti-Randoms and Other features to make it better :eek:
Hope you liked it, post feedbacks/suggestions/etc... :)
Requirements:
SCAR Divi 3.11.
SRL 4 BETA.
Some basic scar knowledge.
Some time.
Note: This is a very simple Woodcutting Script.
This tutorial should teach you how to:
Using SRL's Multi-player Efficiently
Basic SRL functions and Procedures
Possibly other stuff on the way.
Also note that mainloop refers to me as the begin end.
Ok, let's get started. Open up Scar. You should see this:
program New;
begin
end.
Let's start by including SRL:
program New;
{.include SRL/SRL.scar}
begin
end.
And since we are using SRL, we need to add SetupSRL;
program New;
{.include SRL/SRL.scar}
begin
SetupSRL;
end.
We will start by adding Multiplayer. In SRL 4, they have 2 new procedures that make setting up your players easier. Let's start by making our DeclarePlayers procedure.
We start with this.
procedure DeclarePlayers;
begin
end;
The 2 new functions are these:
SetupPlayers;
LoadPlayerArray;
SetupPlayers sets the array length of Players to 100.
LoadPlayerArray; automatically shortens it to the ones we are using once it is called.
so now it looks like this:
procedure DeclarePlayers;
begin
SetupPlayers;
LoadPlayerArray;
end;
With some existing knowledge of SRL's Multiplayer, we need to add this:
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
See a tutorial on how to setup your players for information on how to fill these in.
so now it looks like this:
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
LoadPlayerArray;
end;
If we wanted to add another player, we would do this:
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
If you got to this part, now you (hopefully) understand SRL's Multiplayer!
Once we combine are current script with our new DeclarePlayers procedure, are script now looks like this:
program New;
{.include SRL/SRL.scar}
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
end.
but now we have to add DeclarePlayers; after SetupSRL; or the procedure will be useless. Remember SCAR only runs whats in the mainloop. which is the last
begin
end.
Adding DeclarePlayers; we should have this:
program New;
{.include SRL/SRL.scar}
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
end.
Before we create and add our Chop procedure, I'm going to create part of the main loop. Let's start with a simple repeat until.
Right now are main loop is this:
begin
SetupSRL;
DeclarePlayers;
end.
First we want to log in are first player.
But since the way SRL works, the player has to be loggedin by the script, or antirandoms(if you decide to add any) won't work. So we will logout any loggedin user, then Login are player. This is what it looks like once we do that:
begin
SetupSRL;
DeclarePlayers;
if Loggedin then Logout;
LoginPlayer;
end.
Now we will start on the part of the main loop that will do all the work. We will do this with a simple repeat until.
begin
SetupSRL;
DeclarePlayers;
if Loggedin then Logout;
LoginPlayer;
repeat
until false
end.
until false will mean it will loop forever.
Our current script is this:
program New;
{.include SRL/SRL.scar}
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
until false
end.
We are going to add a LoadPerPlayer type switching. So we are going to add a new constant at the top of the script name "LoadsPerPlayer".
program New;
{.include SRL/SRL.scar}
const
LoadsPerPlayer = 10; //Amounts of loads per player before switching.
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
until false
end.
Time to finish part of the main loop. This is where i'm going to use the bolded word "mod".
Mod is a math term like divide, add, etc. What it does is returns the remainder of a division problem.
So "5 mod 3 = 2" 5 divided by 3 = 1 with a remainder of 2
So part of our mainloop is this:
repeat
until false
Im going to be adding some stuff as it goes, not much for explanation on some of this stuff.
repeat
ChopTree;
until false
I added ChopTree; We havn't created this procedure yet but we will soon!!
repeat
ChopTree;
if InvFull then
begin
end;
until false
Once the inventory is full in will do the stuff between begin end;
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
end;
until false
Will drop from inventory spot 2 to 28. Note there is a bit of a bug in this procedure in SRL 4 Beta. Won't drop the last row some times.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
end;
until false
Inc(Players[CurrentPlayer].Banked);
Lets break this down a bit.
Inc(); will increase a number by 1, so number + 1;
Players[CurrentPlayer].Banked: Will hold the amount of Drops this player has done. Will be used later in the loop.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
end;
end;
until false
Wtf is this?
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
Its ok to be a bit (lot) confused here. This is why i'll try to explain the best I can.
Remeber Players[CurrentPlayer].Banked holds the amount of drops the player does.
And LoadsPerPlayer is how many LoadsPerPlayer a player should do before switching.
Also remember what mod does.
The player can be in the loop more then 1 time. Thats why we don't do this:
if Players[CurrentPlayer].Banked = LoadsPerPlayer then
If the player is still in the loop, that means nothing bad has happened to it.
That means he can have over 100 drops. But if his drops is dividable by LoadsPerPlayer and no remainder is left over, that means he has done enough loads and is ready to switch, as in this:
Example:
LoadsPerPlayer = 2
and in certain times of the script
.Banked = 2 or 4 or 6 or 8
Any of those numbers above divided by LoadsPerPlayer will have no left over remainder. Get it? hmm probally not.. Anyways we're moving on.
We currently have this:
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
end;
end;
until false
We are going to make it switch players.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
until false
NextPlayer(True);
NextPlayer will switch to the next ACTIVE player. if you do NextPlayer(True) then the current player will be still be active and will switch. If you do NextPlayer(False) and the currentplayer will be active=false and won't be used in the script again, and it will still switch to the next active player. What if there is no more ActivePlayers? SRL will catch that and will make it so the script won't go on any further.
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
if not Loggedin then NextPlayer(False);
until false
if not Loggedin then NextPlayer(False);
if we are not logged in, then something bad has happened in the script,
and so we set it so the current player won't be used anymore and it will switch the the next active player.
That should be it for the main loop. Hopefully i didn't forget anything.
Now are script looks like this:
program New;
{.include SRL/SRL.scar}
const
LoadsPerPlayer = 10; //Amounts of loads per player before switching.
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
if not Loggedin then NextPlayer(False);
until false
end.
Time to make our ChopTree procedure, keeping in mind if we log out when something wrong happens, are mainloop will take care of it.
We will start as we did with our DeclarePlayers procedure:
procedure ChopTree;
begin
end;
For safety, i will add this
procedure ChopTree;
begin
if not Loggedin then Exit;
end;
this will Exit the procedure if we're not logged in.
We are going to add a repeat until false. Keeping in mind, if we use the Break; command, we can exit the repeat until false, and with Exit we can get out of the procedure.
procedure ChopTree;
begin
if not Loggedin then Exit;
repeat
until false
end;
Add a constant at the top of your script named "Treecolor" for this next part. (Add it under LoadsPerPlayer)
procedure ChopTree;
var
x, y : integer;
begin
if not Loggedin then Exit;
repeat
until false
end;
procedure ChopTree;
var
x, y : integer;
begin
if not Loggedin then Exit;
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
end;
until false
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
Ok, i added alot of stuff here.
First, im going to explain the MarkTime and TimefromMark.
MarkTime will set the current time to the var you enter, we entered MyMark.
So MyMark is holding the current time.
TimeFromMark will get the time that has passed since MyMark
(2 * 60 * 1000) equals 2 minutes in milliseconds.
so If 2 minutes goes by and we havn't chopped a tree, we logout, then exit the procedure.
Time to explain the FindObj
FindObj is a procedure in SRL
function FindObj(var cx, cy: Integer; Text: String; color, tolerance: Integer): Boolean;
where cx and cy will return the position of the object if it is found.
Text is the text that is in the corner of RS when you move your mouse over something. We are using 'hop' for Chop as in Chop Tree
color is the TreeColor. We are using the constant we added, the user must fill this in.
Tolerance is a number that tells the script to look for colors this close to our color we put in. Higher the tolerance, more colors it will look for, 0 means it will search for that color only. See another tutorial on tolerance if there is one, or the Scar Manual.
So if the tree is found, it will return the coordinates in X, Y.
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
We right click the coordinates of the object with 0 randomness.
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
if ChooseOption('hop') then
begin
end;
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
if it finds and successfully clicks the Chop in the right click menu, then do whats in the begin end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
if ChooseOption('hop') then
begin
//increase 1 to the total tree chop - if we had one
Exit; //We clicked chop, now we can exit this procedure.
end;
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
Since we clicked chop, we can exit the procedure.
After adding a waiting while chopping the tree,
Are script now looks like this:
program New;
{.include SRL/SRL.scar}
const
LoadsPerPlayer = 10; //Amounts of loads per player before switching.
TreeColor = 0; //Fill in the treecolor here.
WaitPerTree = 5000; //the time to wait while we are chopping the tree in Miliseconds.
procedure DeclarePlayers;
begin
SetupPlayers;
Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
Players[1].Name := '';
Players[1].Pass := '';
Players[1].Nick := '';
Players[1].Active := True;
LoadPlayerArray;
end;
procedure ChopTree;
var
x, y, MyMark : integer;
begin
if not Loggedin then Exit;
MarkTime(MyMark);
repeat
if FindObj(x, y, 'hop', TreeColor, 30) then
begin
Mouse(x, y, 0, 0, False);
if ChooseOption('hop') then
begin
//increase 1 to the total tree chop - if we had one
Wait(WaitPerTree);
Exit; //We clicked chop, now we can exit this procedure.
end;
end;
if TimeFromMark(MyMark) > (2 * 60 * 100) then
begin
Logout;
Exit;
end;
until false
end;
begin
SetupSRL;
DeclarePlayers;
if LoggedIn then Logout;
LoginPlayer;
repeat
ChopTree;
if InvFull then
begin
DropToPosition(2, 28);
Inc(Players[CurrentPlayer].Banked);
if Players[CurrentPlayer].Banked mod LoadsPerPlayer = 0 then
begin
NextPlayer(True);
end;
end;
if not Loggedin then NextPlayer(False);
until false
end.
Congratulations! You have made your first simple Woodcutter!
Now you can add Anti-Randoms and Other features to make it better :eek:
Hope you liked it, post feedbacks/suggestions/etc... :)