PDA

View Full Version : PowerCutter Tutorial



mat_de_b
09-04-2007, 08:34 PM
Mats PowerCutter Tutorial


This is an SRL 4 and Scar Divi 3.11 Tutorial so make sure you have both of them before starting

1. First Things First

With the tinyiest bit of prior knowledge everyone should know


// "//" starts a comment and everything after that wont be compiled
program PowerCutter; // The program name... Can't contain spaces
{.include srl/srl.scar} // This line includes SRL (Very useful :D)
const // This declares a constanst value
TreeColor = 2706759; // This value can't change all script
var // This declares a changing value
x,y:integer; // These are number values that can change DidItWork:boolean; // This is a variable boolean of True or False
TheWord:string; // This is a string of letters that can change

procedure DoThatStuff; // This is your first procedure Anything inbetween
begin // the begin and end is part of this procedure
end; // and can be called by typing DoThatStuff;


begin // This begins the main loop
SetupSRL; // This is needed at the start of SRL scripts
DoThatStuff; // This calls the procedure DoThatStuff;
end. // This ends the mainloop and scipt


2. Our First Procedure

We are now going to write a procedure to Cut a tree.


procedure Cut;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Cutting Tree');
wait(1000+random(1000));
end;
end;

That probably looks confusing so ill go through it bit by bit

1. An if()then statement

Everything after the if and before the then should be put in brackets ( LIKE HERE ) this is what the if is testing after the if everything you want to be done if the if is true must be put inside a begin and end

Example:

if(TheWorldIsRound)then
begin
KeepSailing;
TellTheWorld;
end;


2. FindObj(XCoord,YCoord,UpText,Color,Tolerance)

This function is used to find an object on the main RS screen.

The XCoord and YCoord should be stored to variables (normally X and Y), this is the location of the object thats found

The UpText is the text that is found in the top left corner when one mouses over an object. This value is a string such as 'ree' of Tree (strings must be in quotation marks). As a convention the capital letter is left off so for Mine it would be 'ine'...

The Color is basically the color you want it to find on the screen, use the color picker on Scar to find it

The Tolerance this is how leanient scar is with finding the color, for a tree we need to keep it quite low as there are lots of colors about, so 15 is what we will use... The Tolerance Finder by Abyssal in SRL 4 is very useful for this.

3. Mouse or MMouse

The function Mouse is "Mouse(XCoord,YCoord,XRandom,YRandom,LeftClick)"
The function MMouse is "MMouse(XCoord,YCoord,XRandom,YRandom)"

Move mouse (MMouse) will move the mouse to the position stated by XCoord and YCoord, with a random of Xrandom and YRandom (Randoms are needed to decrease detectability).

Mouse will do the same as MMouse but will either left click (True) or right click (False) depending on what the LeftClick boolean is set to

Example: Mouse(100,100,10,10,True);

4. Writeln(String)

Writeln will print whatever you write as an output to debug box at the bottom of scar, because it is a string it must be in 'quotes'...

Example: Writeln('Hello there would how is ones day?');

5. Wait(WaitTime)

This function will wait for however long the WaitTime is set to in milliseconds. Randoms are used in waits to decrease detectability again, a random is written Random(Number) and will result with any number less that the Number you say.

Example: Wait(1000+random(1000)) This will wait a maximum of 1999 and a
minimum of 1000

3.Improving our procedure

That procedure we made was good, i mean it'll get he job done... but its not really what we are looking for. We are now going to employ some failsafes and a repeat to get a quicker and better procedure


procedure Cut;
var C:integer;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Walking to Tree');
Flag;
Writeln('Cutting Tree');
C := InvCount;
repeat
wait(100);
if not(LoggedIn)then
Exit;
until(InvCount > C);
Writeln('Tree Cut');
end;
end;;

Lets talk about the new stuff then

1. Flag

Flag is a function that will check for a Flag on the minimap and will keep waiting until it disappears (i.e you've stopped walking)

2. C:= InvCount;

InvCount is an SRL function that counts the amount of items in your inventory and returns the value, so here i am setting C to equal the amount of items in your inventory.

3. repeat...until()

This will repeat anything inside until the part in brackets is true

Example

C:= 0 This will keep adding 1 to C until it is equal to 5
repeat
C:= C+1;
until(C=5);

4. if not(LoggedIn)then Exit;

This is a very important statement! It says that if you are not logged in (negative if statement) It will exit the current procedure. This stops your script getting stuck in an endless loop.

5. until(InvCount > C);

This means that the wait will repeat until either you become logged out, or your inventory count increase (i.e you get a log).

4. Debug Lesson

Here are some quick lessons in debugging, here is our entire script so far but with a few simple errors in it

program PowerCutter;
{.include srl/srl.scar}
const
TreeColor = 2706759;



procedure Cut;
var C:integer;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Walking to Tree');
Flag;
Writeln('Cutting Tree');
C = InvCount;
repeat
wait(100);
if not(LoggedIn)then
Exit;
until(InvCount > C);
end;
end;


begin
SetupSRL;
Cut;
end.

If this is compiled in scar these errors would appear



Line 11: [Error] (12242:12): Unknown identifier 'x' in script
Line 12: [Error] (12243:14): Unknown identifier 'y' in script
Line 18: [Error] (12249:3): Assignment expected in script


1. Unknown Identifier

This means that a variable or constant has not been declared. It can be fixed by placing:

var
x,y:integer;

at the top of our script, declaring those two constants.

2. Assignment expected

This is here because a colon ( : )is missing from an equation

Example: C = C+5 must instead be C:= C+5

However this rule does not apply if the equation is in brackets

Example: Until(C = 5)

5. Our FIRST EVER DTM OMFG :D

A DTM is a set of colors relevant to each other... it sounds complicated but its not really. The First thing we do is open Scar, target the RS window and then go to Tools -> DTM Editor...

You will now see:
http://img521.imageshack.us/img521/8869/dtmwindowih2.png

Your first click should be in the middle of the log, and have a tolerance of 255, this means that it could be any color

http://img57.imageshack.us/img57/6269/dtmwindowclick1zd3.jpg

You then want to choose 5 or 6 Points that are black on the outside of the log, the color you are looking for is 65536 as this color never changes

http://img515.imageshack.us/img515/9864/dtmwindowclick2zp0.jpg

After this you want to go to File -> DTM to Text and then close the DTM Editor and copy what is in the debug box into your script so you get something like this



procedure Drop;
var Logs:integer;
begin
Logs := DTMFromString('78DA637462626078C28002AAE3AC18FE036 94' +
'620FE0F048C1E40353719D000231209A4AD806AEE1050630C 54F3' +
'9A809A004CF760A87101AA7947408D0D50CD47FC6A00AFAD0 E3F');

end;


Congratulations on your first DTM :eek:

6. Our 2nd Procedure[: Dropping/U]

SRL contains lots of dropping functions, for instance you could skip this chapter and just use DropAll; but as this is a tutorial and we are hear to learn i will teach...

Now that we've declared our DTM we now ahve to learn how to use it so

procedure Drop;
var Logs:integer;
begin
Logs := DTMFromString('78DA637462626078C28002AAE3AC18FE036 94' +
'620FE0F048C1E40353719D000231209A4AD806AEE1050630C 54F3' +
'9A809A004CF760A87101AA7947408D0D50CD47FC6A00AFAD0 E3F');

if(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2))then
begin
Mouse(x,y,5,5,False);
if(ClickOption('rop',2))then
begin
wait(1000+random(500));
Writeln('Dropped');
end else
begin
ArrangeInv;
end;
end else
begin
ArrangeInv;
end;
end;


1. FindDTM(DTMName,XVar,YVar,TopX,TopY,BottomX,Bottom Y)

DTMName is where we put the name of our DTM... Logs.

The XVar is were we want the XCoord to be stored to
The YVar is the same as XVar but the Y Coord

The TopX+Y are the Coords of the top corner of the search box
The BottomX+Y are the coords of the bottom corner of the search box

2. ClickOption(OptionText,Place)

The Option text is the text that appears after a right click without the capital i.e for Drop its 'rop'

The Place is either 1 For main screeen, 2 For inventory, 3 for chat screen

3. end else

end else, means that if the above statement was not true it will do the else statement

Example

if(EarthIsRound)then
begin
KeepSailing;
end else
begin
StopSailing;
end;

4.ArrangeInv

As SRL is only in BETA form they got the inventory Coords wrong and it doesnt find the last 4 items in your inventory, so i put in ArrangeInv to rearrange your inventory so that they can be dropped.

[U]7. The MainLoop

Currently our mainloop will cut one then drop one and then end so we need to change this


begin
SetupSRL;
repeat
repeat
if not(LoggedIn)then
Exit;
Cut;
until(InvFull)
repeat
if not(LoggedIn)then
Exit;
Drop;
until(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2));
until(False)
end.

1. FAILSAFES

We have once again added a LoggedIn check, so that now if we log out the script wont keep trying ot work...

2. until(InvFull)

Makes this statement repeat until you have a full inventory

3. until no(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2));

This means that it will keep dropping until it can no longer find the log DTM

Congratulations You've made your first power cutter....
Though i wouldn't use iit because it has no antirandoms or PlayerArray... but with all this knowledge i think you could start your own script? Give it a goe

Markus
09-04-2007, 08:36 PM
Good for beginners :)

mastaraymond
09-04-2007, 08:57 PM
If you liked or didnt like it leave feedback and feel free to REP thanks

Mat_de_b Rep system doesn't work..

mat_de_b
09-04-2007, 09:35 PM
Ow well, they can still leave feedback

WT-Fakawi
09-04-2007, 09:52 PM
Good work.

ywev
09-04-2007, 09:54 PM
ohh pictures, it's like show and tell!! Good work though :)

Method
09-04-2007, 11:26 PM
Dropping using DTMs works fine for me without using ArrangeInv;, so I don't think that's needed. Otherwise, it's a good tutorial to help users get started. Good work. :)

Aser
09-26-2007, 11:53 PM
Great tutorial thanks alot !

to bad rep isn't working...

thechaosc
09-28-2007, 12:43 AM
worked like a charm. thanks!

drizzt
09-29-2007, 04:02 PM
it is a very nice tut, but i think adding a proggy would be nice for some newbs (not me of course, thats just crazy talk) need to know that

ShowerThoughts
09-29-2007, 04:04 PM
i love it!! nice work ;)

[S]paz
09-30-2007, 10:34 AM
nice thx since im tryin to learn :) il try to add anti randoms and anti ban and post the script .. :) thx man

li_HAM1
10-03-2007, 05:13 AM
very helpful to learn and folo your examples to learn how to do

s1thslay3r0
10-04-2007, 10:40 PM
very helpful for beginners

Zeta
10-05-2007, 05:22 PM
thanks man, i actually understand dtms now, even with those couple of lines i understand it more than those huge tuts, althought this tut should go in intermediate because it would be hard for a begginer to understand., anyway +rep helpd me alot

red1
10-07-2007, 08:54 PM
How bout for SCAR 3.12?

mat_de_b
10-08-2007, 06:51 PM
nothing in here has changed in Scar 3.12 i dont believe

mat_de_b
10-14-2007, 11:36 AM
There were intentional errors in it? did you read the whole tutorial?

Submersal
10-15-2007, 10:20 PM
Love it - using it now. =]

EDIT: Help needed.

Tells me that it expects an identifier in Line 17...

Line17--|var
Line18--|x,y:integer;

mat_de_b
10-16-2007, 06:46 PM
have you got program woodcutter; at the top?

slackjaw7
10-17-2007, 10:04 AM
When I use someone elses scripts it always comes with an error that I don't understand or don't know how to fix. This gave me a better idea on how to use scar and even more, I was Completely lost on DTM. Now i have alteast a basic understanding. Major kudos for joo. you were able to help me in breaking the stupidity barrier. :duh: :duh: :duh:
Thanks Gobs!!
:spot:
Slackjaw7

Edit: Now i'm really confused. I ran my powercutter on a noob cutter and it worked. I put it on another and it gives me an error: (6:5): unknown identifier 'FindObj' in script. Help me please. Maybe i messed something up.

mat_de_b
10-17-2007, 04:08 PM
you sure you included srl? or have it on that computer?

Eugeniu
10-18-2007, 01:09 PM
Very helpful tut ^_^. Thanks. But I would really love to see tutorials where it just pics a random released script and explains every single step :(

Tri
11-02-2007, 01:48 PM
Pretty good, I didn't even know scar had a DTM thing... Now I somewhat know how to use it

rs2 cheating roks!
01-21-2008, 10:07 PM
nicely done thxxx for all the help.:)

mikevskater
01-22-2008, 02:26 AM
Wow, Thanks for this tut, it will really help me become better with power'ers
I found an error btw*

// "//" starts a comment and everything after that wont be compiled
program PowerCutter; // The program name... Can't contain spaces
{.include srl/srl.scar} // This line includes SRL (Very useful :D)
const // This declares a constanst value
TreeColor = 2706759; // This value can't change all script
var // This declares a changing value
x,y:integer; // These are number values that can change DidItWork:boolean; // This is a variable boolean of True or False
TheWord:string; // This is a string of letters that can change

procedure DoThatStuff; // This is your first procedure Anything inbetween
begin // the begin and end is part of this procedure
end; // and can be called by typing DoThatStuff;


begin // This begins the main loop
SetupSRL; // This is needed at the start of SRL scripts
DoThatStuff; // This calls the procedure DoThatStuff;
end. // This ends the mainloop and scipt


// "//" starts a comment and everything after that wont be compiled
program PowerCutter; // The program name... Can't contain spaces
{.include srl/srl.scar} // This line includes SRL (Very useful :D)
const // This declares a constanst value
TreeColor = 2706759; // This value can't change all script
var // This declares a changing value
x,y:integer; // These are number values that can change
DidItWork:boolean; // This is a variable boolean of True or False
TheWord:string; // This is a string of letters that can change

procedure DoThatStuff; // This is your first procedure Anything inbetween
begin // the begin and end is part of this procedure
end; // and can be called by typing DoThatStuff;


begin // This begins the main loop
SetupSRL; // This is needed at the start of SRL scripts
DoThatStuff; // This calls the procedure DoThatStuff;
end. // This ends the mainloop and scipt

DidItWork is on the same line as x,y...

MasterOfStuff
01-22-2008, 03:00 PM
Awesome, I've been planning on writing a powercutter script for my first script and this is extremely helpful.

bumbles
01-27-2008, 05:22 AM
Wow this created my first script and it helped
it took my scar know-how from 35% - 50%
Thanks a bunches

facebooknega
01-31-2008, 07:09 PM
Decent woodcutting tutorial, a little confusing the me but hey, im a beginner.

Overall im going to try and make one myself using this tutorial and other information I have gathered.

Da 0wner
02-07-2008, 12:08 AM
Thanks Matt! This helped me with DTMS. The one thing is that it dosent really work because some objects have the same shape =/. But still thanks a lot. It helped me with many things. +REP

Edit: W00t. I added 2 ur rep =]

eckypwns
02-07-2008, 03:37 AM
awesome tut for a beginner

essex_jay
02-07-2008, 12:52 PM
Great tut, pics are always good, Hopefuly using this i can get started in scripting. (not very good at this kind of thing)

Thanks

diemega
02-08-2008, 05:09 AM
awesome job..

V Macro V
06-12-2008, 03:11 AM
thx for the great script but i dont think that the give rep is working maybe it is i dunno =p

and can u show how it is supposed to look after u complete the compiling so it can work plz

thebob142
06-12-2008, 05:15 AM
thx for the great script but i dont think that the give rep is working maybe it is i dunno =p

and can u show how it is supposed to look after u complete the compiling so it can work plz

out of date dude

V Macro V
06-12-2008, 11:07 AM
out of date dude

oooo ok

s3bu
06-12-2008, 01:25 PM
Thanks! That helps me a Lot

s3bu
06-12-2008, 01:29 PM
Thanks! That helps me a Lot

Mr_Bum
10-11-2008, 10:37 AM
Line 42: [Error] (16150:4): Unknown identifier 'ClickOption' in script
I am using Scar DIVI 3.15b is there something to do the same thing inthis version of scar?

TheChineseMan
10-11-2008, 10:50 AM
no its not ur version its the tut its a really old tut so its outdated to fix that u put

chooseOption('Drop');

T0xicblood
11-26-2008, 07:30 PM
Hmm, maybe I should try some more easier scripting first.

m4r1us
11-26-2008, 07:34 PM
amazing. thanks for tutorial