View Full Version : Anyway to make this simpler?
Element17
06-07-2012, 03:50 AM
Procedure Patch1; //Walks from loadstone to farming patch in Cath.
Begin
If(RadialWalkTolerance(1660230,290,300,70,2,2,10)) Then
Begin
Writeln('Walking to patch 1 is fine');
FFlag(0);
If(RadialWalkTolerance(1396030,307,325,35,2,2,10)) Then
Begin
Writeln('Ready to plant at patch 1');
Exit;
End;
End;
End;
Procedure Patch2; //Walks from loadstone to farming patch Fally/Draynor
Begin
If(RadialWalkTolerance(2907482,266,251,72,2,2,10)) Then
Begin
Writeln('Walking to patch 2 is fine..');
FFlag(3);
If(RadialWalkTolerance(2909285,275,265,73,2,2,10)) Then
Begin
Writeln('Walking to patch 2 is still okay..');
FFlag(3);
If(RadialWalkTolerance(2188651,307,300,74,2,2,10)) Then
Begin
FFlag(3);
Writeln('Walking to patch 2 is still okay, almost there..');
While(IsMoving) Do
AntiBan;
If Not IsMoving Then
Begin
Writeln('Ready to plant at patch 2');
End;
End;
End;
End;
End;
I feel like there could be a easier way to do this, or at lest look cleaner.
Runaway
06-07-2012, 04:06 AM
Quick example using cases and for..to..do:
function WalkTo(Which: String): Boolean;
var
PathVars: array of TIntegerArray;
PathColor: TIntegerArray;
// Whatever else: TIntegerArray;
hPathColor, i: Integer;
begin
Result := False;
case Lowercase(Which) of
'patch1':
begin
SetLength(PathVars, 2);
PathColor := [1660230,1396030];
PathVars[0] := [290,300,70,2,2,10];
PathVars[1] := [307,325,35,2,2,10];
end;
// 'patch2':
end;
hPathColor := High(PathColor);
for i := 0 to hPathColor do
begin
if RadialWalkTolerance(PathColor[i],PathVars[i][0],PathVars[i][1],PathVars[i][2],PathVars[i][3],PathVars[i][4],PathVars[i][5]) then
begin
// Writeln('Walking to '+Which+': '+IntToStr(i+1)+' of '+IntToStr(hPathColor+1));
FFlag(0);
if (i = hPathColor) then
Result := True;
// ...
end;
// ...
end;
end;
Then you can call it like this:
if WalkTo('patch1') then
// Writeln('Walked to patch 1!');
Element17
06-07-2012, 11:41 AM
I get most of it, but do you mind explaining
if RadialWalkTolerance(PathColor[i],PathVars[i][0],PathVars[i][1],PathVars[i][2],PathVars[i][3],PathVars[i][4],PathVars[i][5]) then
begin
// Writeln('Walking to '+Which+': '+IntToStr(i+1)+' of '+IntToStr(hPathColor+1));
FFlag(0);
if (i = hPathColor) then
Result := True;
// ...
end;
// ...
end;
end;
Runaway
06-07-2012, 06:01 PM
Sure.
Since you use RadialWalkTolerance() the whole time but just change the variables, that's what I've done here. You set all of the variables in the case, and then use them all in order with this "generic" statement. If you're confused about the whole PathColor[i] and PathVars[i][0] thing, hopefully this will clear it up:
PathColor[0] := 1660230;
PathVars[0][0] := 290;
PathVars[0][1] := 300;
PathVars[0][2] := 70;
// etc.
So when i := 0 in the for..to..do loop, the PathColor and PathVars will be the parameters of the first RadialWalkTolerance() of 'patch1' that you called in the original script. Then when that search is complete (and FFlag(0) is done) it will move onto i := 1 and the next vars will be loaded into RadialWalkTolerance().
Hopefully I explained it well enough >.<
Element17
06-07-2012, 06:35 PM
Okay, I think I understand...so like this right?
Function WalkTo(Which: String): Boolean;
Var
PathVars: array of TIntegerArray;
PathColor: TIntegerArray;
hPathColor, i: Integer;
Begin
Result := False;
Case Lowercase(Which) Of
'patch1':
Begin
SetLength(PathVars, 2);
PathColor := [1660230,1396030];
PathVars[0] := [290,300,70,2,2,10];
PathVars[1] := [307,325,35,2,2,10];
End;
'patch2':
Begin
SetLength(PathVars, 3);
PathColor := [2907482,2909285,2188651];
PathVars[0] := [266,251,72,2,2,10];
PathVars[1] := [275,265,73,2,2,10];
PathVars[2] := [307,300,74,2,2,10];
End;
End;
hPathColor := High(PathColor);
for i := 0 to hPathColor do
Begin
if RadialWalkTolerance(PathColor[i],PathVars[i][0],PathVars[i][1],PathVars[i][2],PathVars[i][3],PathVars[i][4],PathVars[i][5]) then
Begin
Writeln('Walking to '+Which+': '+IntToStr(i+1)+' of '+IntToStr(hPathColor+1));
FFlag(0);
if (i = hPathColor) then
Result := True;
// ...
End;
// ...
End;
End;
Runaway
06-07-2012, 06:39 PM
Yup :)
Element17
06-07-2012, 08:41 PM
Thank you! : )
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.