Runescapian321
2010-03-12 20:22:34
Hooks you need (Updated 3/15):
CharMotion = 'Ac';
MyPlayer = 'f.U';
BaseX = 'sc.h';
BaseY = 'pr.e';
CurrentX = 'r';
CurrentY = 'h';
FlagX = 'hh.v';
FlagY = 'eh.P'; (Updated this on 3/14/10){*******************************************************************************
procedure R_FFlagEx(Tile: TPoint; Dist: Integer);
By: Tad
Description: Waits until you are Dist tiles away from Tile. Use of this, if
possible, is recommended over R_FFlag because the GetFlag hooks return false
negatives every once in a while.
*******************************************************************************}
procedure R_FFlagEx(Tile: TPoint; Dist: Integer);
var
Mark: integer;
Temp: TPoint;
begin
if not(WaitToMove(1000)) then exit;
if(GetFlag(Temp)) then Tile := Temp;
Mark := GetSystemTime;
while((DistanceFrom(Tile) > Dist) and (GetSystemTime - Mark < 25000) and (CharacterMoving))do
wait(randomrange(200,700));
end;
{*******************************************************************************
function NextTileToWalk(Path: TPointArray; Max: Integer): TPoint;
By: Tad
Description: Gets a suitable tile to walk to next, starts searching from the end
of the path. If there is more than one 'suitable' tile, it will choose a random
one, prioritzing the further ones. Max is the Index of the Path which the
function will stop searching at (This way the function won't return a tile
behind you), set to 0 if you do not mind. Used in R_WalkPath.
*******************************************************************************}
function NextTileToWalk(Path: TPointArray; Max: Integer): TPoint;
var
I, FromIndex, ToIndex: Integer;
PossibleTiles: TPointArray;
FirstTile: TPoint;
begin
FirstTile := Point(0,0);
for I:=High(Path) downto Max do
begin
if TileOnMM(Path[I]) then
begin
FirstTile := Path[I];
FromIndex := I;
ToIndex := I;
break;
end else if(I = Max) then
begin
result := Point(0,0);
exit;
end;
end;
for I:=Max to FromIndex do
if(DistanceFrom(Path[i]) > 8)then
begin
ToIndex := I;
break;
end;
for I:=FromIndex downto ToIndex do
begin
if(RBool)then
begin
result := Path[I];
break;
end;
if(I = ToIndex)then
result := Path[RandomRange(ToIndex,FromIndex)];
end;
end;
{*******************************************************************************
function R_WalkPath(Path: TPointArray; Randomness: Integer): boolean;
By: Tad
Description: Walks a path of tiles.
Path: TPointArray of the tiles you wish to walk
Randomness: Goes +/- Randomness tiles when clicking on MM. Set to 0 for default
randomness (recommended)
*******************************************************************************}
function R_WalkPath(Path: TPointArray; Randomness: Integer): boolean;
var
i, Index: integer;
TileToWalk, TileInPath, FSPoint, PointNow, LastTile, CurTile: TPoint;
ChangeRand: boolean;
begin
result := DistanceFrom(Path[High(Path)]) < 10;
if result then exit;
TileToWalk := Point(0,0);
LastTile := Point(0,0);
Index := 0;
if(Randomness = 0)then
ChangeRand := true;
while(Index < GetArrayLength(Path))do
begin
if(ChangeRand)then
Randomness := random(4);
TileInPath := NextTileToWalk(Path, Index);
if(not(CharacterMoving) and not(TileOnMM(TileInPath))) then break;
TileToWalk := Point(TileInPath.x+RandomRange(-Randomness,Randomness),
TileInPath.y+RandomRange(-Randomness,Randomness));
if not(TileOnMM(TileToWalk))then Continue;
if not(WalkToTile(TileToWalk, 0, 100)) then Continue;
if not(WaitToMove(1000)) then Continue;
if GetFlag(CurTile) then
begin
if ((CurTile.x = LastTile.x) and (CurTile.y = LastTile.y)) then
Continue;
end else
if LastTile.x = -1 then
Continue;
GetFlag(LastTile);
R_FFlagEx(TileToWalk, RandomRange(5,15));
Index := TileToIndex(TileInPath, Path)+1;
end;
R_Flag;
result := DistanceFrom(Path[High(Path)]) < 10;
end;Any comments on the code? I've been testing it, seems to work well and it's very humanlike (in my opinion). It is best used when you have a huge path (i.e. a point every 1-2 tiles along the path). This way, the function randomly selects points at random distances away along the path; you're not going to be clicking around the same location every single time.
Would really appreciate some testers. To make your paths, you can use my extremely old, poorly coded, yet functional pathmaker (includes an option for continuously adding points as you walk, so to create the path all you'd have to do is set it up and walk your path). Here is the pathmaker:
program New;
{.include srl/srl/misc/smart.scar}
{.include srl/srl.scar}
{.include srl\srl/reflection/reflection.scar}
//F2 - Adds a Point onto the Path
var
CurPath, BackPath : Array[0..1000] of TPoint;
ObstPath : Array of Integer;
timemark : integer;
etype : boolean;
const
DoFastPath = true; //False will use the F2 commands. True will automatically create a point every 1000ms
//Press F5 to pause during FastPath
EraseDoubles = true; //Will erase all tiles that are identical and sequential
function NextEmptySpot(myArray : Array of TPoint) : integer;
var
i : integer;
begin
for i:=0 to GetArrayLength(myarray) -1 do
begin
if (myarray[i].x = -1) and (myarray[i].y = -1) then
begin
result := i;
exit;
end;
end;
end;
function NextEmptySpotInt(myArray : Array of Integer) : integer;
var
i : integer;
begin
for i:=0 to GetArrayLength(myarray) -1 do
begin
if (myarray[i] = -1) then
begin
result := i;
exit;
end;
end;
end;
procedure AddAnObs;
begin
ObstPath[NextEmptySpotInt(ObstPath)] := NextEmptySpot(CurPath) - 1;
wait(1000);
end;
procedure InitPaths;
var
i : integer;
begin
for i:=0 to 1000 do
begin
CurPath[i] := Point(-1,-1);
BackPath[i] := Point(-1,-1);
ObstPath[i] := -1;
end;
end;
procedure AddMyPos;
var
TempArray : Array of TPoint;
i : integer;
temp : TPoint;
begin
temp := GetMyPos;
if NextEmptySpot(CurPath) <> 0 then
if (EraseDoubles) and (temp.x = CurPath[NextEmptySpot(CurPath) - 1].x) and (temp.y = CurPath[NextEmptySpot(CurPath) - 1].y) then Exit;
CurPath[NextEmptySpot(CurPath)] := temp;
Alert('Point Added at ('+IntToStr(temp.x)+','+IntToStr(temp.y)+').');
end;
procedure MakeBackPath;
var
temp : TPoint;
i,j : integer;
begin
clearreport;
// addtoreport('makebackpath');
i := NextEmptySpot(CurPath) - 1;
j := 0;
//addtoreport('i = '+IntToStr(i));
repeat
// addtoreport('adding backpath');
BackPath[j] := CurPath[i];
inc(j);
i := i - 1;
until (i = -1);
{ addtoreport('about to add...');
addtoreport('next empty backpath: '+IntToStr(NextEmptySpot(BackPath)));
for i:=0 to NextEmptySpot(BackPath) -1 do
begin
addtoreport('next print');
addtoreport(IntToStr(BackPath[i].x)+','+IntToStr(BackPath[i].y));
end; }
end;
procedure AddToS(var thestring : String; addwhat : String);
var
temp : string;
begin
temp := thestring;
thestring := temp+addwhat;
end;
function RevertObst( ThePath : Array of Integer): Array of Integer;
var
i, tValue : integer;
begin
SetArrayLength(result, GetArrayLength(ThePath));
tValue := NextEmptySpot(CurPath);
for i:=0 to 1000 do
result[i] := -1;
i := 0;
while ThePath[i] <> -1 do
begin
result[i] := tValue - ThePath[i];
Inc(i);
end;
end;
procedure PrintOutStuff;
var
i : integer;
thelast: string;
temp : array of integer;
begin
ClearDebug;
thelast := ' Path := [';
for i := 0 to NextEmptySpot(CurPath) - 1 do
begin
if (i <> 0) and (i mod 5 = 0) then
begin
writeln(copy(thelast,1,Length(thelast)-1)+',');
thelast := ' ';
end;
if CurPath[i].x <> 0 then
begin
thelast := thelast + 'Point('+IntToStr(CurPath[i].x)+','+IntToStr(CurPath[i].y)+'),';
end;
end;
writeln(copy(thelast,1,Length(thelast)-1)+'];');
end;
begin
ClearDebug;
Smart_Server := 138;
Smart_Members := false;
Smart_Signed := true;
Smart_SuperDetail := false;
SetupSRL;
// SetupReflection;
SetLength(ObstPath, 1001);
InitPaths;
repeat
MarkTime(timemark);
repeat
wait(10);
if IsFKeyDown(5) then
begin
wait(500);
while not IsFKeyDown(5) do
begin
if IsFKeyDown(2) then
begin
R_Flag;
wait(1000);
AddMyPos;
end;
if IsFKeyDown(4) then
begin
R_Flag;
wait(1000);
AddanObs;
end;
end;
wait(500);
end;
if not DoFastPath then
Etype := IsFKeyDown(2) or IsFKeyDown(4)
else
Etype := TimeFromMark(timemark) > 1000;
until(Etype);
//ReWriteFile(ScriptPath + 'PathDump.text');
if not DoFastPath then
begin
if IsFKeyDown(2) then
begin
R_Flag;
wait(1000);
AddMyPos;
end;
end else
AddMyPos;
if IsFKeyDown(4) then
begin
R_Flag;
wait(1000);
AddanObs;
end;
MakeBackPath;
PrintOutStuff;
until(false);
end.And if you're lazy, here's a testing script template :p:
program New;
{.include srl/srl/misc/smart.scar}
{.include srl/srl.scar}
{.include srl\srl/reflection/reflection.scar}
const
DebugIt = true;
//Put in your path where marked in the main loop
procedure DeclarePlayers;
begin
HowManyPlayers:= 1; // How many players are there arrays for?
CurrentPlayer:= 0; // Which player should we start with?
NumberOfPlayers(HowManyPlayers); // Do Not Change.
Players[0].Name := ''; // Username.
Players[0].Pass := ''; // Password.
Players[0].Nick := ''; //2-4 letters of your Username (that are not capital letters or spaces).
Players[0].Pin := ''; // Bank Pin. If none, leave as '' (blank).
Players[0].Active := True;
end;
var
MyPath: TPointArray;
begin
Smart_Members := true;
Smart_Signed := true;
Smart_Server := 138;
Smart_SuperDetail := false;
SetupSRL;
DeclarePlayers;
if not LoggedIn then Loginplayer;
MyPath := []; //PATH HERE
repeat
R_WalkPath(MyPath,0);
R_WalkPath(reversepath(MyPath),0);
until(False);
end.