SRL Archive - OSR Help

I need some help/direction for first script


coldblitz

2012-03-17 13:33:04

EDIT: I've already had a couple issues solved here but I keep progressing and I keep adding more features to my script. Inevitably that means more problems.

I.e Rather then post a new question I'm just going to retailer this one. The title still fits.

What I want the script to do is, first Chop Willows, then when the inventory is full, walk to destination and begin lighting the logs, when finished lighting the logs, return to chopping willows.

My current problem is that once it has chopped down the willows, inventory is full, it walks to destination, then it wants to chop more trees rather then start the procedure for lighting the logs.

I think the problem is in my mainloop.



program ChopNBurn;

{$i srl/srl.simba}
{$i sps/sps.simba}


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

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active:=True;
end;

procedure AntiBan;
begin
if(not(LoggedIn))then
Exit;
FindNormalRandoms;
case Random(1000) of
0:
begin
HoverSkill('Woodcutting', false);
wait(2000+Random(1000));
end;
1: PickUpMouse;
2:
begin
MakeCompass('N');
wait(100+random(133));
MakeCompass('S');
wait(50+random(133));
MakeCompass('NE');
FindNormalRandoms;
end;
1: RandomRClick;
2:
end;
end;

function WillowTrunk: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(1.12, 3.02);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 1449756, MSX1, MSY1, MSX2, MSY2, 1);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 1.02) and (X <= 1.23) and (Y >= 1.19) and (Y <= 1.43) and (Z >= 0.82) and (Z <= 1.04) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

Function Chopping: Boolean;
var
PBox: TBox;
begin
PBox := IntToBox(245, 130, 285, 195);
Result := (AveragePixelShift(PBox, 250, 500) > 750);
end;

procedure ChopTree;
var
x, y: integer;
begin
if (not Chopping) then
repeat
if FindObj(x, y, 'hop', WillowTrunk, 20) then
begin
Mouse(x, y, 0, 0, false);
ChooseOption('hop');
end;
repeat
wait(400+random(250));
AntiBan;
Until not IsUpText('illow') or (InvFull);
until(InvFull);
end;

procedure WalkToFirePit;
var
myPath:TPointArray;
begin
SetupSRL;
SPS_Setup(RUNESCAPE_SURFACE,['8_8','9_8','10_9','8_9','7_9','8_7','9_7','10_8']);
myPath := [Point(3488, 3470), Point(3499, 3470), Point(3508, 3470), Point(3517, 3470),
Point(3531, 3470), Point(3543, 3470), Point(3555, 3470), Point(3568, 3470),
Point(3579, 3470), Point(3591, 3470), Point(3597, 3470), Point(3605, 3470)];
SPS_WalkPath(myPath);
end;


procedure DropLogs;
var
x, y, LogDTM, I:Integer;
SlotBox:TBox;
LogPattern:TIntegerArray;

begin
LogDTM := DTMFromString('m1gAAAHic42JgYJjCwsDQBsT9QDwTiOcC8UIgngbEvVC5ZiBWZmRgkAFiSSAWBWJZRoiYNhDrQWklILYyFgKaykQEJg4wEokRAAB/sAfX');
LogPattern := [1,5,9,13,17,21,25,2,6,10,14,18,22,26,3,7,11,15,19,23,27,4,8,12,16,20,24,28];

for I := 0 to 27 do
begin
SlotBox := InvBox(LogPattern[I]);
if FindDTM(LogDTM, x, y, SlotBox. X1, SlotBox. Y1, SlotBox. X2, SlotBox. Y2) then
begin
MouseItem (LogPattern[I], mouse_Right);
wait(400+random(200));
ChooseOption ('Light');
wait (1500+random(500));
end;
end;
end;

begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
repeat
ChopTree;
if invfull then
begin
WalkToFirePit;
DropLogs;
end;
until (False);
end.

xtrapsp

2012-03-17 19:25:31

shouldn't it be until (True);?

Also in the drop procedure what isn't it doing? is it right clicking then not dropping? I need a bit more of a detailed explanation as to what it DOES and what you WANT ;)

x[Warrior]x3500

2012-03-17 19:29:43

From: xtrapsp
shouldn't it be until (True);?


repeat … until(false); is just a standard infinite loop.

maybe ur dtm isnt correct?

xtrapsp

2012-03-17 19:30:49

From: x[Warrior]x3500
repeat … until(false); is just a standard infinite loop.

maybe ur dtm isnt correct?


Sorry it's late ;) haha

read over the OP a few times.. I still don't understand the issue fully

procedure ChopTree;
var
x, y: integer;
begin
repeat
if FindObj(x, y, 'hop', WillowTrunk, 20) then
begin
Mouse(x, y, 0, 0, false);
ChooseOption('hop');
end;
repeat
wait(400+random(250));
AntiBan;
Until not IsUpText('illow');
if InvFull then // It does the function before but if the inventory is full here while chopping it then drops logs ;) having it in the main loop could act as a backup?
begin
DropLogs;
end;
end;

feel free to correct me if im wrong ;) it's midnight and I'm tired as hell :P

bolshak25

2012-03-17 20:51:43

program WillowChopShop;

{$i srl/srl.simba}

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

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active:=True;
end;

procedure AntiBan;
begin
if(not(LoggedIn))then
Exit;
FindNormalRandoms;
case Random(8) of
0:
begin
HoverSkill('Woodcutting', false);
wait(2000+Random(1000));
end;
1: PickUpMouse;
2:
begin
MakeCompass('N');
wait(100+random(133));
MakeCompass('S');
wait(50+random(133));
MakeCompass('N');
FindNormalRandoms;
end;
1: RandomRClick;
2:
end;
end;

function WillowTrunk: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(1.12, 3.02);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 1449756, MSX1, MSY1, MSX2, MSY2, 1);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 1.02) and (X <= 1.23) and (Y >= 1.19) and (Y <= 1.43) and (Z >= 0.82) and (Z <= 1.04) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

procedure ChopTree;
var
x, y: integer;
begin
repeat
if FindObj(x, y, 'hop', WillowTrunk, 20) then
begin
Mouse(x, y, 0, 0, false);
ChooseOption('hop');
end;
repeat
wait(400+random(250));
AntiBan;
Until not IsUpText('illow') or (InvFull);
until(InvFull);
end;



procedure DropLogs;
var
x, y, LogDTM, I:Integer;
SlotBox:TBox;
LogPattern:TIntegerArray;

begin
LogDTM := DTMFromString('mggAAAHicY2NgYHBjYmCwBmJzJgjbC4iDgPgpIwPDbSB+C8Q3gfgNED8CYgtDQaAuJiwYO2DEgSEAANXrB5E=');
LogPattern := [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28];

for I := 0 to 27 do
begin
SlotBox := InvBox(LogPattern[I]);
if FindDTM(LogDTM, x, y, SlotBox. X1, SlotBox. Y1, SlotBox. X2, SlotBox. Y2) then
begin
MouseItem (LogPattern[I], mouse_Right);
ChooseOption ('Dro');
end;
end;
end;


begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
repeat
ChopTree;
if InvFull then
DropLogs;
until (False);
end.

compiles for me.
you were missing an end in droplogs, and its no longer true/false for mouse procedures. i changed it to mouse_right because im assuming thats what you wanted. and more help you need?

Havent tested the script to see if it actually works, but i did get it to compile

xtrapsp

2012-03-17 20:52:37

From: bolshak25
program WillowChopShop;

{$i srl/srl.simba}

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

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active:=True;
end;

procedure AntiBan;
begin
if(not(LoggedIn))then
Exit;
FindNormalRandoms;
case Random(8) of
0:
begin
HoverSkill('Woodcutting', false);
wait(2000+Random(1000));
end;
1: PickUpMouse;
2:
begin
MakeCompass('N');
wait(100+random(133));
MakeCompass('S');
wait(50+random(133));
MakeCompass('N');
FindNormalRandoms;
end;
1: RandomRClick;
2:
end;
end;

function WillowTrunk: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(1.12, 3.02);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 1449756, MSX1, MSY1, MSX2, MSY2, 1);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 1.02) and (X <= 1.23) and (Y >= 1.19) and (Y <= 1.43) and (Z >= 0.82) and (Z <= 1.04) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

procedure ChopTree;
var
x, y: integer;
begin
repeat
if FindObj(x, y, 'hop', WillowTrunk, 20) then
begin
Mouse(x, y, 0, 0, false);
ChooseOption('hop');
end;
repeat
wait(400+random(250));
AntiBan;
Until not IsUpText('illow') or (InvFull);
until(InvFull);
end;



procedure DropLogs;
var
x, y, LogDTM, I:Integer;
SlotBox:TBox;
LogPattern:TIntegerArray;

begin
LogDTM := DTMFromString('mggAAAHicY2NgYHBjYmCwBmJzJgjbC4iDgPgpIwPDbSB+C8Q3gfgNED8CYgtDQaAuJiwYO2DEgSEAANXrB5E=');
LogPattern := [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28];

for I := 0 to 27 do
begin
SlotBox := InvBox(LogPattern[I]);
if FindDTM(LogDTM, x, y, SlotBox. X1, SlotBox. Y1, SlotBox. X2, SlotBox. Y2) then
begin
MouseItem (LogPattern[I], mouse_Right);
ChooseOption ('Dro');
end;
end;
end;


begin
SetUpSRL;
ActivateClient;
DeclarePlayers;
LoginPlayer;
repeat
ChopTree;
if InvFull then
DropLogs;
until (False);
end.

compiles for me.
you were missing an end in droplogs, and its no longer true/false for mouse procedures. i changed it to mouse_right because im assuming thats what you wanted. and more help you need?

Havent tested the script to see if it actually works, but i did get it to compile



didn't realise it was the compiling that was the issue ;) Didn't try it :P

coldblitz

2012-03-17 21:01:58

From: bolshak25
compiles for me.
you were missing an end in droplogs, and its no longer true/false for mouse procedures. i changed it to mouse_right because im assuming thats what you wanted. and more help you need?

Havent tested the script to see if it actually works, but i did get it to compile


Would you believe I spent three hours trying to do the same thing over and over again while expecting a different result? Definition of insanity right there.

Only other thing I wouldn't mind knowing is how do I stop my script from trying to chop another tree, or even the same tree, while still chopping the current one?

+rep… if I can figure out how :p

From: xtrapsp
didn't realise it was the compiling that was the issue ;) Didn't try it :P


Ya, I guess that was kind of my fault. I should have mentioned it was a compiling issue.

bolshak25

2012-03-17 21:12:15

From: coldblitz

Only other thing I wouldn't mind knowing is how do I stop my script from trying to chop another tree, or even the same tree, while still chopping the current one?


http://villavu.com/forum/showthread.php?t=74090

Pixelshift should be what your looking for. i havent read up on how to use it, but its good for this kind of thing

coldblitz

2012-03-17 22:03:04

As it turns out all this script is good for is right clicking the trees, selecting chop, then repeating that process. Such a headache. Thanks for the help guys. Much obliged. Time to scrap it and start anew. I'll get one right eventually.

bolshak25

2012-03-17 22:30:50

try in the mainloop putting
if invfull then
drop
before
choptree
otherwise it would keep doing choptree forever

coldblitz

2012-03-18 18:48:48

From: bolshak25
try in the mainloop putting
if invfull then
drop
before
choptree
otherwise it would keep doing choptree forever


You saved my script from going straight into the garbage and also got me excited again for what I've achieved and what I aim to achieve. Thank you.

Mind you after I tried this it still didn't work but that was because my LogDTM needed to be reworked. I don't think I made enough points the first time.

I can hardly believe I've actually put together a working script. It's primitive, but it works. Also, I switched things up a little and rather then simply dropping the logs, I'm lighting them. Why not train two skills at once? That part is working. :f:

Two things left to do

1. Figure out pixelshift so my guy stops trying to chop the same tree over and over. So annoying and I'm sure that's something jagex will spot. [DONE]

2. Incorporate some walking into the script so it walks to a set destination and begins lighting the logs… I've herd this is tough to do but lucky for me I only need to walk one way. After that, lighting the logs can be done in one long line which will bring me right back to the base of a willow tree. :sasmokin:

bolshak25

2012-03-18 23:12:42

well change the mainloop to
repeat
chop;
if invfull then
begin
walk;
light;
end;
until … blah blah

that would keep chopping until the inv is full then it will do the other items because they are in the begin end. in yours it would light them even if inv wasnt full. i dont know anything with sps so im no help there

coldblitz

2012-03-19 11:56:24

From: bolshak25
well change the mainloop to
repeat
chop;
if invfull then
begin
walk;
light;
end;
until … blah blah

that would keep chopping until the inv is full then it will do the other items because they are in the begin end. in yours it would light them even if inv wasnt full. i dont know anything with sps so im no help there


I fixed the sps issue. It was simple once I noticed I was missing a single line

SetupSRL;

I tried your mainloop recommendation but it's not working for me. The individual procedures all work on there own, I know that, now it's simply a matter of putting them together in a way that works.

Chop willows > Walk > Light > repeat

bolshak25

2012-03-19 16:14:06

try putting a
writeln('walked now lighting');
right after the first begin in droplogs. thatsll tell us if it gets there

coldblitz

2012-03-19 17:33:08

From: bolshak25
try putting a
writeln('walked now lighting');
right after the first begin in droplogs. thatsll tell us if it gets there


It was a stupid problem. When I previously fixed the DTM I didn't save so when I reopened the script I couldn't for the life of me figure out why… fixed the DTM once again and made sure I saved it this time.

Mind you I have more problems… forever more.

1. I need to set my DropLog procedure so it only goes to light another log once it has -1 log in inventory (I don't know how to do that but if I search the forums long enough I sure I can find the proper code.

2. If I let the script run for any length of time it eventually goes to chop a tree that is not a willow. I'm again not entirely sure how to fix this but I'm sure with enough playing around I'll find a solution.

EDIT:

3. I also need to free the LogDTM.

bolshak25

2012-03-19 18:06:11

add some variables to the droplogs. integers.
wait(400+random(200));
ChooseOption ('Light');
m:=Invcount;
repeat
wait (1500+random(500));
until invcount<m

something similar to that.
put
Freedtm(LOGDTM);
before the last end; in droplogs