SRL Archive - OSR Help

Script done. Does not work. Need Help Please


kevin33

2011-12-28 20:56:26

Okay so I finished my ChopNBurn script. It all compiles so I began to test. When I test the mouse hovers all over the screen. I figure the chopping aspect is in need of a lot of help. Any ideas? Colors are probably bad. Im not really sure how to get unique colors for trees.
I get this error when I start it:
Warning! You passed a wrong ys to a finder function: -5. That is below 0, thus out of bounds. Setting the value to 0 for now.
Warning! You passed a wrong xs to a finder function: -16. That is below 0, thus out of bounds. Setting the value to 0 for now.
Any suggestions or help to try and fix the script would be greatly appreciated.

program KevysChopNBurn;
{.include SRL/SRL/misc/SMART.scar}
{.include SRL/SRL.scar}
{.include SRL/SRL/skill/firemaking.scar}

//have hatchet equipped
//be near some trees you want to cut
//Maples I do not have the colours for
//Colors may be off, fix them as you need to, I will do my best to fix them also
//Tinderbox must be in toolbelt or 1st inventory slot
//Under testing report any bugs and I will attempt to fix them and not sure if all trees work
Const
TREE_TOL = 5;
TREE = 0;
OAK = 1;
WILLOW = 2;
MAPLE = 3;
YEW = 4;

type
treeType = record
colors : TIntegerArray;
names : TStringArray;
end;

var
a: Integer;

procedure declarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
With Players[0] do
begin
Name := ''; //username
Pass := ''; //password
Nick := ''; //3-4 letters from your username
Active := true;
Integers[1] := 2; //tree you wish to cut
Booleans[0] := True; // Tinderbox is in your toolbelt
BoxRewards := ['mote', 'ostume', 'XP', 'Gem', 'ithril', 'oal', 'une', 'oins'];
end;
end;

procedure StatsGuise(wat:String);
Begin
Status(wat);
Disguise(wat);
End;

procedure setupScript;
begin
ClearDebug;
SetupSRL;
SMART_Server := 4;
SMART_Signed := True;
SMART_Members := False;
declarePlayers;
while not(RSReady) do
Wait(1000);
end;

{procedure IdentifyTree; //just extra info just in case I make a pure firemaker
var
TreeDTM: Integer;
begin
if not LoggedIn then Exit;
if TreeDTM <= 0 then
case Players [CurrentPlayer].Integers[1] of
TREE:
TreeDTM := DTMFromString ('mlwAAAHicY2dgYOhiYWCYDMRtQFwHxM1A3A/EM4A4mZGBIQKIo4A4BYjzgTibESLubiYP1M0ExsUxRnA2BOMGjHgwFAAAwEQIWg==');
OAK:
TreeDTM := DTMFromString ('mlwAAAHicY2dgYOhmYWCYDMRtQFwLxC1A3A/EM4C4nZGBoQaI64C4GYgnA3E/EHcCcaa/HlA3Ew6MGzDiwVAAAPTwCJ8=');
Willow:
TreeDTM := DTMFromString ('mlwAAAHicY2dgYLjPwsDwHIhvAPFFIL4OxI+B+A0QJzEyMEQAcRQQJwNxPhBnQ9nGuvxA3Uw4MG7AiAdDAQCWsAl2');
Maple:
TreeDTM := DTMFromString ('mlwAAAHicY2dgYNjCwsCwF4jXAfFyIN4MxPuA+BAQJzMyMEQAcRQQJwFxLhBnAXEKELvrcwF1M+HAuAEjHgwFAAXtCGk=');
Yew:
TreeDTM := DTMFromString ('mlwAAAHicY2dgYOBiZWAQBGJmIP7NwsDABOWLAXEyIwNDBBBHAXEcEOcDcRYjRNxOlwOomwkHxg0Y8WAoAAAN1ASo');
end; //just showing I can use DTMs :)
end;}

procedure setupPlayer;
begin
if LobbyScreen then LeaveLobby;
if not(LoggedIn) then LoginPlayer;
SetAngle(True); //select true if you want camera angle to rise *best to leave lowered
MakeCompass('N');
Players[CurrentPlayer].Integers[1] := 0; //chopped
Players[CurrentPlayer].Integers[2] := 0; //burned
end;

function colorIsFound(colors : TIntegerArray) : Boolean;
var
TPA : TPointArray;
I : Integer;
begin
for I := 0 to High(Colors) do
begin
FindColors(TPA, colors[I], MIX1, MIY2, MIX2, MIY2);
if(Length(TPA) > 0)then
Break;
end;
Result := Length(TPA) > 0;
end;

procedure BurnOfChop;
var
x,y : Integer;
I : Integer;
invSlot1, logSlot : TPoint;
begin
case(Players[CurrentPlayer].Booleans[0])of
True:
begin
if(colorIsFound([4413283, 4479334]))then //colors may need changing and again no maple log you may fix that yourself.
// Set colors to match tree(s) you wish to cut. Colors can be found lines 255-259
begin
Mouse(x, y, 4, 4, False);
Wait(RandomRange(250, 750));
ChooseOption('raf');
Wait(RandomRange(1000, 2000));
end;
end;
False:
begin
if(colorIsFound([5790300, 5527128]))then
begin
invSlot1 := ItemCoords(1);
for I := 2 to 28 do
begin
logSlot := ItemCoords(I);
Mouse(invSlot1.X, invSlot1.Y, 4, 4, True);
Wait(RandomRange(250, 1000));
Mouse(logSlot.X, logSlot.Y, 4, 4, True);
Wait(RandomRange(750, 1250)); // Wait for the log to be ignited
end;
end;
end;
end;
end;

procedure ChoppingAntiban;
begin
Case Random(250) Of
0: Begin StatsGuise('Antiban') GameTab(tab_Stats) HoverSkill('Woodcutting', False) GameTab(28) End;
1: Begin StatsGuise('Antiban') SleepAndMoveMouse(7000 + Random(500)); End;
2: Begin StatsGuise('Antiban') GameTab(tab_Inv) ExamineInv; GameTab(28); End;
3: Begin StatsGuise('AntiBan') RandomAngle(1); End;
4: Begin StatsGuise('AntiBan') GameTab(Tab_Stats); Wait(3000 + Random(500)); GameTab(28); End;
5: Begin StatsGuise('AntiBan') GameTab(tab_Stats) HoverSkill('random', False); GameTab(28); End;
6: Begin StatsGuise('Antiban') GameTab(tab_Stats) HoverSkill('Firemaking', False); GameTab(28); End;
end;
end;

function TheUpTextAll(Text: TStringArray): Boolean;
var
TheText: string;
i, n: Integer;
begin
TheText := GetUpText;
n := High(Text);
Result := True
for i := 0 to n do
if (Pos(Text[i], TheText) <= 0) then //
begin
Result := False;
Exit;
end;
end;

function WaitUpTextAll(S: TStringArray; Time: Integer): Boolean;
var
T: Integer;
begin
Result := false;
T := GetSystemTime + Time;
while (GetSystemTime < T) do
begin
if (TheUpTextAll(S)) then
begin
Result := True;
Exit;
end;
Wait(30 + Random(10));
end;
end;

function FindObjExAltered(var cx, cy: Integer; Text: TStringArray; Color: TIntegerArray;
Tol, Step, xs, ys, xe, ye: Integer): Boolean;
var
ChoX, ChoY, a, b, c, i: Integer;
Start: Boolean;
begin
for b := 0 to (GetArrayLength(Color)-1) do
begin
if (FindColorSpiralTolerance(cx, cy, color[b], xs, ys, xe, ye, Tol)) then
begin
Start := True;
Break;
end;
end;
if (Start) then
begin
ChoX := Round((xs + xe) div 2);
ChoY := Round((ys + ye) div 2) - Step;
i := 1;
repeat
for c := 1 to i do
begin
case a of
0: begin
a := a + 1;
i := 0;
ChoY := ChoY + Step;
end;
1: ChoX := ChoX + Step;
2: ChoY := ChoY - Step;
3: ChoX := ChoX - Step;
4: ChoY := ChoY + Step;
end;
if (ChoX >= xs) and (ChoX <= xe) and (ChoY >= ys) and (ChoY <= ye) then
begin
try
for b := 0 to (GetArrayLength(Color)-1) do
begin
if (FindColorTolerance(cx, cy, Color[b], ChoX-(Step div 2), ChoY-(Step div 2), ChoX+(Step div 2), ChoY+(Step div 2), Tol)) then
begin
MMouse(cx, cy, 3, 3);
If (WaitUptextAll(Text, 300)) then
begin
GetMousePos(cx, cy);
Result := True;
Exit;
end;
end;
end;
except
end;
end;
end;
a := a + 1;
if a mod 5 = 0 then a := 1;
if (a = 1) or (a = 3) then i := i + 1;
until (Result) or ((ChoX > xe) and (ChoY > ye))
end;
end;

function setTreeType(which : Integer) : treeType;
var
tt : treeType;
begin
case(which)of
0: tt.colors := [4413283, 4479334]; //Trees
1: tt.colors := [3691619, 3757414]; //Oaks
2: tt.colors := [3556934, 3425092]; //Willows
3: tt.colors := []; //Maples don't currently have colors for
4: tt.colors := [4608859, 4740445]; //Yews
end;
tt.names := ['ree', 'ak', 'illow', 'aple', 'ew'];
Result := tt;
end;

procedure chop;
var
oldInv, originalInv: Integer;
x, y: Integer;
treeInfo : treeType;
TreeCounter: Integer;
begin
treeInfo := setTreeType(Players[CurrentPlayer].Integers[1]);
repeat
BurnOfChop;
if not(LoggedIn) then exit;
WriteLn('chopped ' + IntToStr(Players[CurrentPlayer].Integers[1]) + ' Logged In: ' + BoolToStr(LoggedIn));
OriginalInv := InvCount;
if FindObjExAltered(x, y, ['hop down', treeInfo.names[Players[CurrentPlayer].Integers[1]]], treeInfo.colors, TREE_TOL, 50, MSX1, MSY1, MSX2, MSY2) then
begin
Mouse(x, y, 0, 0, True);
repeat
oldInv:=InvCount;
ChoppingAntiban;
if not(LoggedIn) then exit;
until((oldInv <= InvCount) or (InvFull)) or (TimeFromMark(TreeCounter) > 7000);
wait(1000 + Random(2000));
end;
Players[CurrentPlayer].Integers[1] := Players[CurrentPlayer].Integers[1] + InvCount - OriginalInv; //number chopped
until(not(LoggedIn) or InvFull);
end;

begin
SetupSRL;
setupScript;
While not(AllPlayersInactive) do
begin
if random(5)=1 then ChangeWorld(RandomWorld(False, False));
setupPlayer;
a := GetSystemTime + 3000000 + random(600000);
repeat
chop;
BurnOfChop;
until((not(LoggedIn)) or (a > GetSystemTime));
RandomNextPlayer(LoggedIn);
Logout;
end;
FreeSRL;
end.

Flight

2011-12-28 20:59:11

What parts of the trees are you getting colors for?

Here, try my own personal normal tree-finder:

Function FindTree(Var X,Y: Integer): Boolean;
var
B: TBox;
TPA: TPointArray;
Hmod,Smod: Extended;
L,i,Tol,CTS,Col: Integer;
ATPA: T2DPointArray;
begin
Result := False;

While IsMoving_F do
Wait(1);

ReturnValues([3229015, 3427165, 3690596, 3822440], Hmod, Smod, Col, Tol);
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hmod, SMod);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Col, MSX1, MSY1, MSX2, MSY2, Tol);
ColorToleranceSpeed(CTS);
if (Length(TPA) < 1) then
Exit;
ATPA := TPAToATPAEx(TPA, 40, 40);
SortATPAFrom(ATPA, Point(MSCX,MSCY));
L := High(ATPA);
SetArrayLength(ATPA, L+1);
for i := 0 to L do
begin
if (GetArrayLength(ATPA[i]) > 5) then
begin
B := GetTPABounds(ATPA[i]);

MiddleTPAEx(ATPA[i], X, Y);
MMouse(X, Y, 15, 15);
if WaitUpTextMulti(['hop d', 'down'], 555) then
begin
Result := True;
GetMousePos(X, Y);
Exit;
end else
Result := False;

end;
end;

end;

You'll also need this: (Compliments of PoW)

Procedure ReturnValues(colors: TIntegerArray; var HueMods, SatMods: Extended; var color, Tolerance: Integer);
Var
h, s, t: Extended;
I,II : integer;
HSLColor : Array[1..3] of Extended;
HSL : Array[0..1] of Array[1..3] of Extended;
begin;
For I:= 1 to 3 do
begin;
HSL[0][i] := 255;
end;

For I:= 0 to High(Colors) do
begin;
ColortoHSL(Colors[i],HSLColor[1],HSLColor[2],HSLColor[3]);
For II:= 1 to 3 do
begin;
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
end;
end;

H := (HSL[1][1] - HSL[0][1]);
S := (HSL[1][2] - HSL[0][2]);
T := (HSL[1][3] - HSL[0][3]);

try
HueMods := (H/T);
SatMods := (S/T);
Tolerance := Round(t);
except
HueMods := 0;
SatMods := 0;
Tolerance := Round(0.0);
end;

Color := HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2);
end;

kevin33

2011-12-28 21:01:24

I was using the trunks. Very unreliable.
I need colors for logs also for the burning part but I have yet to do so.
Where would I implement the two things you posted above?
What is the second part on Return values even for? (sorry I have never seen anything like it before)

Flight

2011-12-28 21:09:34

ReturnValues you don't really need to worry about how it works right now. All you need to for it is to plug an integer array (your colors) into it and it'll spit back out the CTS 2 modifiers, the best color to search for, and the appropriate tolerance. You can see how I used it in the 'FindTree' function.

Go ahead and alteast give it a try, tell me how it works for you.

kevin33

2011-12-28 21:25:00

Would I put in all the colours for all the trees or just like 1 type?
Should I implement the find tree or just the return values? I added the find tree also but I got error Unknown identifier 'IsMoving_F' at line 273. FAIL

NickMystre

2011-12-28 21:27:09

From: Flight
ReturnValues you don't really need to worry about how it works right now. …


Seeing this in the above ReturnValues procedure has reminded me of a question I've been meaning to ask.

In passing parameters to procedures, when do you use Var and when is it not necessary ?

Flight

2011-12-28 21:36:00

Those 'Vars' are what is returned back to you through the function. So that first parameter (colors) is all you need to input yourself, the rest will be given back to you, this is the purpose of the function.

@Kevin:
Use the colors from one type of tree, preferably similar colors. If you look in the 'FindTree' function I provided I already have some colors from the tree trunk. You can see they're relatively similar in color; this is for a reason.

NickMystre

2011-12-28 21:41:39

From: Flight
Those 'Vars' are what is returned back to you through the function. So that first parameter (colors) is all you need to input yourself, the rest will be given back to you, this is the purpose of the function.


OK, so if you are only returning a single value, then you use a FUNCTION. If you need multiple values returned, then you use a PROCEDURE with Var's. Yes ?

EDIT: @Flight - Appreciate it. TY! Another piece of the puzzle falls into place.

kevin33

2011-12-28 21:56:11

K Flight…
I used your find tree example just to test but when I compile I get an error:
I got error Unknown identifier 'IsMoving_F' at line 273. COMPILING FAIL
How do I identify it?

Btw how did you get your tree colors to put into the return values?

Flight

2011-12-28 22:01:19

From: NickMystre
OK, so if you are only returning a single value, then you use a FUNCTION. If you need multiple values returned, then you use a PROCEDURE with Var's. Yes ?


You're catching on quick, Nick. :thumbsup:

From: kevin33
K Flight…
I used your find tree example just to test but when I compile I get an error:
I got error Unknown identifier 'IsMoving_F' at line 273. COMPILING FAIL
How do I identify it?

Btw how did you get your tree colors to put into the return values?


Kevin, change "IsMoving_F" to "IsMoving".

Kyle Undefined

2011-12-28 22:06:04

Where are my credits? I basically rewrote the entire script for you.

kevin33

2011-12-28 22:09:14

From: Kyle Undefined
Where are my credits? I basically rewrote the entire script for you.


Kyle it isnt released yet. You will get all the credit you deserve when I release it when its working. I still need to make changes to get it to actually function.

Flight I replaced it and now I get another error of the same kind except for Return values as an unknown identifier.

Coh3n

2011-12-31 04:09:49

Where did you get that object finding function? It looks a little "odd" to me. You should read some tutorials on TPAs and CTS2 (you can probably learn some from Flight's example). That will really help improve your object finding. Trees are difficult, too. I suggest calling SetAngle(false); so the trunks are more visible, and rotating the camera (MakeCompass(235)) if necessary.

You also don't need to use a case for a boolean, an if statement is more efficient and looks nicer in my opinion. You're headed in the right direction. Once you get the chopping working properly, you can start adding more features like hatchet detection, progress reports, maybe even a player form. :)

Keep it up!

kevin33

2011-12-31 04:30:51

From: Coh3n
Where did you get that object finding function? It looks a little "odd" to me. You should read some tutorials on TPAs and CTS2 (you can probably learn some from Flight's example). That will really help improve your object finding. Trees are difficult, too. I suggest calling SetAngle(false); so the trunks are more visible, and rotating the camera (MakeCompass(235)) if necessary.

You also don't need to use a case for a boolean, an if statement is more efficient and looks nicer in my opinion. You're headed in the right direction. Once you get the chopping working properly, you can start adding more features like hatchet detection, progress reports, maybe even a player form. :)

Keep it up!


Ok so where would I implement the compass thing (I already have angle thing I think near top of script). I put case in cuz the SRL mem thing said it is something they look for. IDK how I got object finding function. I was looking at other scripts for help and I just wrote it. Nothing more to it :p How can I make the chopping better like implement Flights idea for all trees (thats what I was gonna do :p). BTW the chop function I have, does that need to be changed at all or will it work as long as I make find trees better?Also Return values as an unknown identifier how do I fix this error so I can continue it? And yea I will add more as soon as I get the script to actually function how I intended it to!

Coh3n

2011-12-31 04:39:14

I'm not sure about the ReturnValues issue. For the compass, I would just call MakeCompass if the trees aren't found. Change the compass angle, and look for the trees again. You could also look into using Smart Colors (srl/srl/misc/smartcolors.scar) as an object finding tool. It's probably one of the easiest and most reliable object finding tools available to you.

kevin33

2011-12-31 04:45:14

From: Coh3n
I'm not sure about the ReturnValues issue. For the compass, I would just call MakeCompass if the trees aren't found. Change the compass angle, and look for the trees again. You could also look into using Smart Colors (srl/srl/misc/smartcolors.scar) as an object finding tool. It's probably one of the easiest and most reliable object finding tools available to you.


Should I stick with what I got cuz Im certain it works or switch to the smart colors? Seems like more work. I really just want to get this script working so I can add more things to it. Ill stay with what I got and switch if there is a problem I guess. I will continue with Flights idea also and post what happens when Im done. Still need help figuring out why Randomvalues comes back as an unknown identifier though. Anyone help please? Tomorrow I will add compass thing. I forgot about that. Itll help a lot when I finally get the color thing done to actually find then chop the tree. Hopefully the burning aspect will work. Havent made it that far in testing.

Coh3n

2011-12-31 04:47:01

Burning should be simple, you can now right click logs and choose "Light". For the unknown identifier, make sure ReturnValues is declared before the function you're calling it in (i.e. it is pasted above the object finding procedure).

kevin33

2011-12-31 04:49:38

From: Coh3n
Burning should be simple, you can now right click logs and choose "Light". For the unknown identifier, make sure ReturnValues is declared before the function you're calling it in (i.e. it is pasted above the object finding procedure).


Yea I know I think my burn function will work. Kyle fixed it so it would right click I think. Do i declare it in variables as like integer or something? it is not currently listed above so there lies the problem.

Claymore

2011-12-31 14:44:23

Just use ACAv3,

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

Set up to CTS 2, pick your colors, record Hue, Sat and Tol value. This is if you dont want to take a shot in the dark and pick colors and allow the procedure to do its work. Even tho you dont know how it works ;p I dont too honestly.

Home

2011-12-31 14:52:40

From: Kyle Undefined
Where are my credits? I basically rewrote the entire script for you.


Man.. Relax :P

You can have some credits from me :)

~Home

Coh3n

2011-12-31 16:27:30

From: kevin33
Yea I know I think my burn function will work. Kyle fixed it so it would right click I think. Do i declare it in variables as like integer or something? it is not currently listed above so there lies the problem.
You just have to make sure the function is above the one you're calling it in.

kevin33

2012-01-01 01:10:07

From: Claymore
Just use ACAv3,

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

Set up to CTS 2, pick your colors, record Hue, Sat and Tol value. This is if you dont want to take a shot in the dark and pick colors and allow the procedure to do its work. Even tho you dont know how it works ;p I dont too honestly.


From: Coh3n
You just have to make sure the function is above the one you're calling it in.


Yea i took a look at the link and I crapped myself crying. That is very complicated and I dont know where to start. Im gonna stick with what Im doing and hope it works.
How do I make sure it is a function above where Im using it? Like where else would I put it?

Coh3n

2012-01-01 16:08:44


// this has to be pasted before procedure two() so that I can call one() in two()
procedure one();
begin
end;

procedure two();
begin
one(); // you'll get unknown identifier if one() is pasted below two()
end;
This will give an unknown identifier:

procedure two();
begin
one();
end;

procedure one();
begin
end;