SRL Archive - News and General

My Woodcutting Script


Gooneroo

2011-12-10 04:06:30

Hey guys, some of you may know me from the IRC chat.

Anyway, I'm making this thread cause I'm having trouble adding support for other trees in my script. I have an idea, though.

Here's the script.

program Woodcutter;
{$i srl/srl/misc/Smart.scar}
{.include SRL/SRL.scar}
{.include SRL/SRL/Skill/WoodCutting.scar}

var x, y: integer;
Loads: Integer;
ChopTime: Integer;
TreesChopped: Integer;
Dropper: Integer;

Procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := ''; //RS Username
Players[0].Pass := ''; //RS Password
Players[0].Nick := ''; //4 letters of Username
Players[0].Active := True;
Players[0].Integers[0] := 30; //Number of loads you want to do
end;

//*************************************************\\
///////////////DON'T TOUCH BELOW HERE!\\\\\\\\\\\\\\\\
//***************************************************\\

procedure AntiRandoms;
begin
if not LoggedIn then Exit;
FindNormalRandoms; // find random events
end;

procedure AntiBan;
begin
case random(100) of //do a random number so it won't always perform the antiban
0: RandomRClick;
1: BoredHuman;
2: HoverSkill('Woodcutting', False);
end;
end;

Procedure CutWood;
begin
if not LoggedIn then
Exit;
MakeCompass('N');
repeat
if FindObjCustom(x, y, ['ree'], [3164510, 3690597, 4020077], 25) then
begin
Mouse(x,y,0,0,false);
Wait(40 + (random(20)));
ChooseOption('hop');
end;
until(InvFull)
end;

Procedure Report;
Begin
cleardebug;

Writeln(' Lets Cut Wood ')
Writeln(' Worked For ' + TimeRunning);
Writeln(' Chopped ' + IntToStr(TreesChopped));
Writeln(' Dropped(by loads) ' + IntToStr(Dropper));
Writeln(' By Gooner ');
End;



//////Thanks to DeSnob for this function\\\\\\

Function IsChopping: Boolean;
begin
if (PixelShift(PointToBox(Point(MSCX-10, MSCY-10), Point(MSCX+10, MSCY+10)), +
RandomRange(100, 200)) > 100) then
MarkTime(ChopTime);
Result := (TimeFromMark(ChopTime) < RandomRange(750, 1500));
end;

begin
if not (LoggedIn) then
Exit;
ActivateClient;
SetUpSRL;
DeclarePlayers;
Report;
LoginPlayer;
LevelUp;

while(Loads <= (Players[CurrentPlayer].Integers[0]))do
begin
repeat
CutWood;
while (IsChopping) do
Wait(500 + Random(100));

until InvFull;
DropAllExcept([1]);
Inc(Loads);
end;
end.

Now, that works nicely. All I want to do is add support for Oaks, Willows and Yews. I sort of have an idea on how to do this, but I'm not exactly sure. My guess would be to make a separate procedure for each tree type, then call some if - then statements, but I don't really know. Any help on adding these would be greatly appreciated.

Also, Coh3n, if you happen to see this, I read the tutorial you showed me and followed it correctly, but it just wouldn't compile, no matter what I did.

Also, feel free to post errors/suggestions. :)

Thanks!

Flight

2011-12-10 04:35:46

This part right here is where you're searching for your tree colors:

if FindObjCustom(x, y, ['ree'], [3164510, 3690597, 4020077], 25) then
For something extremely simple you could do something like this:

Const
TreeType := 'normal';

Procedure CutWood;
var
TreeColors: TIntegerArray;
begin
if not LoggedIn then
Exit;
MakeCompass('N');
case LowerCase(TreeType) of
'normal': TreeColors := [3164510, 3690597, 4020077];
'oak': TreeColors := [];
'willow': TreeColors := [];
'yew': TreeColors := [];
end;

repeat
if FindObjCustom(x, y, ['ree'], TreeColors, 25) then
begin
Mouse(x,y,0,0,false);
Wait(40 + (random(20)));
ChooseOption('hop');
end;
until(InvFull)
end;

Then where you see the 'oak' (ect) you can add your tree colors there.

Gooneroo

2011-12-10 04:51:11

Looks good, thanks. Wouldn't then the ['ree'] part need to be changed each time, as the UpText changes? Or does that not matter?

Also, where the constant is, that's where the User chooses the tree they want to use, correct?

Thanks again :)

EDIT: Also, do I edit my current CutWood, or make a completely new one?

Tried doing it so I edit my current CutWood. When I do -


Const
TreeType := 'normal';

Doesn't compile.


Const
TreeType = 'normal';

That does. :)

RISK

2011-12-10 05:08:41

Yes, that is where the user of your script would input what tree they would like to be cut down.
The "['ree']" part is perfectly fine. It does not need to be changed.
Don't change the function in question completely, simply use Flight's suggestion. It's good for what you are attempting to do.

Gooneroo

2011-12-10 05:15:25

How is the ['ree'] part fine - isn't it UpText? When I tried to use it, it would right click on the oak, even though it would find it. It then found a normal tree, and clicked on that.

Also, do you know how to fix - Error: Exception: Access violation at line 86?

Line 86 is: result:= SmartGetColor(x, y);

Thanks for your help, appreciate it very much. It's my first script. ;)

RISK

2011-12-10 05:24:17

Ah, you are right. I'm sorry, I wasn't in the right mind set when I answered that concern. You should, if you can, change the uptext to match accordingly to the tree that you are attempting to cut. You can use capital letters such as "Oak" or "Tree".

I am unsure of what that error is. You could try posting in the help section though if you want. Or wait until someone replies to the question here.

Gooneroo

2011-12-10 05:29:58

Thanks RISK. :) No need to apologise, I'm just happy I figured out something on my own! ;)

Is it possible to make it so the uptext automatically changes to 'ak', 'illow' etc, so I don't have to ask the player to go down to line x and change it themselves? Hope you understand what I'm trying to say.

RISK

2011-12-10 05:37:07

Try this:
procedure Example;
var
treeCol : TIntegerArray; // Array for the tree's colors
treeTex : string; // String for the tree's uptext
begin
case Lowercase(TreeType) of
'normal' :
begin
treeCol := [00000, 11111, 22222];
treeTex := 'Tree';
end;
end;

if FindObjCustom(X, Y, [treeTex], treeCol, 15) then
begin
end;
end;

Gooneroo

2011-12-10 05:39:04

Where would I apply that? Is it separate to my CutWood Procedure? :)

RISK

2011-12-10 05:40:00

You would put it in to your wood cutting procedure.

Gooneroo

2011-12-10 05:46:27

procedure CutWood;
var
treeCol : TIntegerArray; // Array for the tree's colors
treeTex : string; // String for the tree's uptext
begin
case Lowercase(TreeType) of
'normal' :
begin
treeCol := [3164510, 3690597, 4020077];
treeTex := 'Tree';
end;
end;

if FindObjCustom(X, Y, [treeTex], treeCol, 15) then
begin
Mouse(x,y,0,0,false);
Wait(40 + (random(20)));
ChooseOption('hop');
end;
until(InvFull)
end;

Where have I gone wrong? I get an error - [Error] (67:3): Identifier expected at line 66
Compiling failed.

Line 66 is until(InvFull).

RISK

2011-12-10 05:48:14

You need a matching 'repeat' for that 'until' and you also need a begin end nest for the FindObj.

Gooneroo

2011-12-10 05:52:00

Fixed! Thanks :) Now I need to run it, but I can't in SMART cause of that Line 86 error, and every time I try to run it in a browser it takes control of my computer. :/

Instead of testing it, I'm going to ask this. Here's what I have: http://paste.villavu.com/show/JkTPfNu1W2czzwbRt42Y/

What needs to be done to finalise that?

Thanks again :)

RISK

2011-12-10 05:55:57

Try completely updating your stuff. I don't get that error.

Do you want to add my MSN for more direct help? [email]riskeditall@live.com[/email]

Gooneroo

2011-12-10 05:57:32

Will do man. Just need to install MSN, as I'm on a Virtual Machine and I haven't installed it. :)

Flight

2011-12-10 06:58:12

From: Gooneroo

Tried doing it so I edit my current CutWood. When I do -


Const
TreeType := 'normal';

Doesn't compile.


Const
TreeType = 'normal';

That does. :)


Yeah you'll have to forgive me, I just threw that together without compiling or anything. Anything defined as a constant only need a "=", static variables would be ":=" which is what I used on accident. You did good by catching my mistake, nice job Gooneroo. :)

Gooneroo

2011-12-10 07:32:08

Cool Flight, thanks! :)