PDA

View Full Version : Creating Your First Auto Miner!



Devoker
06-18-2009, 02:00 PM
Welcome to my Tutorial Thread!
I hope that you find my tutorial on SCAR Scripts to help you a lot.
I will break down sections of a mining script in my tutorial.
Remember, this is for intermediate scripters, not beginners.
Do not read any further if you are not ready to be reading a lot of information.

Program PowerMiner;
{.include SRL/SRL.Scar}

First of all, you must state the program title. You do this by putting, 'Program <ScriptNameHere>;'. Make sure there is a space after Program and there is no spaces in the title. Then make sure you put the semi-colon at the end.

Second, in every SRL Script you must add the include of SRL. This is so that the functions and procedures that you use in SRL scripts are implemented into your script except from a different file.

Var
X, Y, I, M : Integer;
RockColor : Array [0..2] Of Integer;

Now for stating the Variables. You should always state ALL the variables in the beginning of the script. Some people put certain variables in certain procedures must this way is more organized.

The X and the Y are represented as certain points on the screen in this script. The I represents the Array Number of a rock color that will be used later on tin the script and the M is the amount of rocks that were mined in the script. All of these variables can be changed in your script but for now, keep them the same as you learn.

RockColor, with the Array [0..2] of Integer states that the Variable, 'RockColor', is an Array meaning it is more than one Variable, and it is three variables because it is variable RockColor[0], RockColor[1], and RockColor[2]. The '..' means through so it's like 0 through 2.

Const //Valid Options
RockType = ''; //Copper, Tin, Iron, Coal
WieldAxe = ''; //True, False
RocksToMine = 0; //Integer

You can never forget the Constants. These are the strings and stuff that people fill out to make the script run. For instance, the Rock Type would be either Copper, Tin, Iron, ore Coal. I like to write the options that you can choose to make it easier for the reader.

Procedure DeclareColors;
Begin
End;

Procedure AntiBan;
Begin
End;

Procedure MineRock;
Begin
End;

Procedure DropRock;
Begin
End;

Procedure ProgressReport;
Begin
End;

Procedure MainLoop;
Begin
End;

After stating the title or your script and the variables and constants, you must start adding procedures to your script. I suggest that you name all the procedures before actually adding stuff into your procedure. This is so that you have an idea of your script and it will be more organized and easier to make.

Procedure DeclareColors;
Begin
Case RockType Of
'Copper' : Begin
RockColor[0] := 4813728
RockColor[1] := 4351888
RockColor[2] := 4154250
End;
'Tin' : Begin
RockColor[0] := 9539996
RockColor[1] := 9737632
RockColor[2] := 9342617
End;
'Iron' : Begin
RockColor[0] := 2964578
RockColor[1] := 2371919
RockColor[2] := 2832991
End;
'Coal' : Begin
RockColor[0] := 2241331
RockColor[1] := 2834239
RockColor[2] := 2636603
End;
End;
End;

We will start with the first procedure, which is declaring your colors. This is sometimes bitmaps or maybe dtms but in this script, we will use colors.

First of all, you must always put Begin in the beginning of the script. 'Case RockType Of' is saying that if the constanant is a certain thing, it will start a certain thing. In this case, if the RockType is a certain type, it will state the colors of the RockType.

RockColors and the number in parameters after is just saying that RockColors is more than one color. It is multiple colors and this will be used later on in the script.

Procedure AntiBan;
Var
RCompass : TStringArray;
Begin
LampSkill := 'Mining';
FindNormalRandoms;
RCompass := ['E', 'S', 'W'];
MakeCompass(RCompass);
Wait(2500 + Random(1000));
MakeCompass('N');
Case Random(25) Of
0: BoredHuman;
1: RandomMovement;
2: PickUpMouse;
3: HoverSkill('Mining', False);
4: MMouse(Random(X), Random(Y), 0, 0);
5: TypeSend('Mining Levels?');
End;
End;

Now for the Anti Ban procedure which should be used in every script to get people from getting their accounts banned.

First, you may have noticed that I have stated a new variable. Well someitmes you can state a variable to a procedure and I don't usually do this unless the variable is very specific to the procedure. In this case, the TStringArray is so that you can make a variable more than one thing again except this time it is picked as only one of the random things that it is.

Second, you must state the Lamp Skill which means if you get a present, what skill do you want it to use.

FindNormalRandoms is self explanatory and RCompass is stating the TStringArray Strings. It then waits for a bit so that it isn't going fast and it lessens the chance of you being a bot.

After that, it Randomly picks a number out of 25, and depending on what number it picks, it will do what it's suppose to do. For instance, if you randomly pick a number out of 25, and you get a 3, it will do 'HoverSkill' at since HoverSkill is number 3. Any number that is not put down means nothing will happen.

Procedure MineRock;
Begin
DeclareColors;
AntiBan;
For I := 0 To 2 Do
If FindObj(x, y, 'Mine', RockColor[I], 10) Then Begin
Mouse(x, y, 6, 6, False);
ChooseOption('Mine');
inc(M);
Wait(2500 + Random(2500));
End;
End;

Now we are at the main part of the script. The MineRock procedure is obviously the procedure that mines the rocks.

First of all, you need to Declare the colors and to do this, easily name the procedure that we made in the beginning, 'DeclareColors'. Then call forth the AntiBan procedure so you don't get banned.

After that, you need to make sure that all the colors are in the FindObj Function and to do this you need to make a 'For' function which makes a variable more than one number in an array. Then you state the arrays and then you use the FindObj Function and the Mouse Function to click on the rock.

After clicking on the rock you have to put inc(M) to increase the value of M by 1. The reason we are doing this is for the progress report in the end. M is going to be for the rocks the we Mined.

Procedure DropRock;
Begin
Case WieldAxe Of
'True' : Begin
For I := 1 To 28 Do
DropItem(I);
End;
'False' : Begin
For I := 4 To 28 Do
DropItem(I);
End;
End;
End;

Now for the DropRock procedure. This is pretty self explanatory and everything in this procedure is similar to the other parts of the script so you should be able to analyze this and figure out what it means.

Procedure ProgressReport;
Begin
WriteLn('|||||||||||||||||||||||||||||||||||');
WriteLn('|| Power Miner ||');
WriteLn('|||||||||||||||||||||||||||||||||||');
WriteLn('Time Running: ' + TimeRunning );
WriteLn('Rocks Mined: ' + IntToStr(M) );
WriteLn('|||||||||||||||||||||||||||||||||||');
WriteLn('|| Created By: Devoker ||');
WriteLn('|||||||||||||||||||||||||||||||||||');
End;

Here is an example of a progress report that I use. WriteLn is pretty much a beginner script skill so I'm not going to explain this either.

Procedure MainLoop;
Begin
Wait(1000 + Random(500));
SetAngle(True);
MakeCompass('N');
If InvFull Then Begin
DropRock;
End Else MineRock;
End;

Now here you should have a main loop so that the last commands look organized and clean. This just basically begins all the procedures and is self explanatory if you look at it.

Begin
SetupSRL;
ActivateClient;
Repeat
MainLoop;
Until IsFKeyDown(9) or (M >= RocksToMine);
ProgressReport;
End.

These are the last commands that I used and basically you need to SetupSRL all the time and Activate the client so that it goes to the Runescape screen.

Then you need to make the script repeat itself and then you need a way to stop it where it will still show the progress report and a way for it to stop when you have a certain amount of rocks to mine done.

Program PowerMiner;
{.include SRL/SRL.Scar}

Var
X, Y, I, M : Integer;
RockColor : Array [0..2] Of Integer;

Const //Valid Options
RockType = ''; //Copper, Tin, Iron, Coal
WieldAxe = ''; //True, False
RocksToMine = 0; //Integer

Procedure DeclareColors;
Begin
Case RockType Of
'Copper' : Begin
RockColor[0] := 4813728
RockColor[1] := 4351888
RockColor[2] := 4154250
End;
'Tin' : Begin
RockColor[0] := 9539996
RockColor[1] := 9737632
RockColor[2] := 9342617
End;
'Iron' : Begin
RockColor[0] := 2964578
RockColor[1] := 2371919
RockColor[2] := 2832991
End;
'Coal' : Begin
RockColor[0] := 2241331
RockColor[1] := 2834239
RockColor[2] := 2636603
End;
End;
End;

Procedure AntiBan;
Var
RCompass : TStringArray;
Begin
LampSkill := 'Mining';
FindNormalRandoms;
RCompass := ['E', 'S', 'W'];
MakeCompass(RCompass);
Wait(2500 + Random(1000));
MakeCompass('N');
Case Random(25) Of
0: BoredHuman;
1: RandomMovement;
2: PickUpMouse;
3: HoverSkill('Mining', False);
4: MMouse(Random(X), Random(Y), 0, 0);
5: TypeSend('Mining Levels?');
End;
End;

Procedure MineRock;
Begin
DeclareColors;
AntiBan;
For I := 0 To 2 Do
If FindObj(x, y, 'Mine', RockColor[I], 10) Then Begin
Mouse(x, y, 6, 6, False);
ChooseOption('Mine');
inc(M);
Wait(2500 + Random(2500));
End;
End;

Procedure DropRock;
Begin
Case WieldAxe Of
'True' : Begin
For I := 1 To 28 Do
DropItem(I);
End;
'False' : Begin
For I := 4 To 28 Do
DropItem(I);
End;
End;
End;

Procedure ProgressReport;
Begin
WriteLn('|||||||||||||||||||||||||||||||||||');
WriteLn('|| Power Miner ||');
WriteLn('|||||||||||||||||||||||||||||||||||');
WriteLn('Time Running: ' + TimeRunning );
WriteLn('Rocks Mined: ' + IntToStr(M) );
WriteLn('|||||||||||||||||||||||||||||||||||');
WriteLn('|| Created By: Devoker ||');
WriteLn('|||||||||||||||||||||||||||||||||||');
End;

Procedure MainLoop;
Begin
Wait(1000 + Random(500));
SetAngle(True);
MakeCompass('N');
If InvFull Then Begin
DropRock;
End Else MineRock;
End;

Begin
SetupSRL;
ActivateClient;
Repeat
MainLoop;
Until IsFKeyDown(9) or (M >= RocksToMine);
ProgressReport;
End.

This is how the script should look like all put together. After you are done making this Auto Miner and it works, you should try remaking it except without looking at the tutorial. The more that you have in your head, the better because you can't always be getting script parts from other people.

------------

Thank you for reading my tutorial and if you have any questions, feel free to PM me.

Rich
06-21-2009, 04:27 PM
I personally believe this should be in Beginners. Also, what about DeclarePlayers and AntiRandoms? All scripts should have AntiRandom. Other than that, good tutorial.

Da 0wner
06-21-2009, 04:30 PM
No dude, all variables should be local whenever they can...

ShowerThoughts
06-21-2009, 05:42 PM
Good try, + point is that it's nice for they eye, my tutorials aren't :(.
But after all I think in declaring the rockcolors you're limiting yourself.

marpis
06-21-2009, 07:25 PM
I think there are enough of these "1st script" tuts.

global variables are bad
why 'true' and 'false' are strings and not booleans?
integer arrays can be set like RockColor := [12312, 321321, 345345]; which is alot shorter
your mainloop should look like this:

Procedure MainLoop;
Begin
Wait(1000 + Random(500));
SetAngle(True);
MakeCompass('N');
If InvFull Then
DropRock;
MineRock;
End;