Wizzup?
2008-07-18 04:30:06
Hey guys.
I have seen several test reflection scripts, and they all use *wrong* walking methods. I'll quickly post what I made quite some time ago. (Thanks to Yakman for the General idea.)
Ok, so I have seen walking that looks like this:
This does not contain any failsafes, and is generally bad practice.
What the best thing would be to:
1. Create a path of tiles. (TPointArray)
2. Load the path, and walk it using the follow algorithh, which I will first explain.
The algorithm is relative simple, I don't think it actually deserves the term 'algorithm', but we will leave that out of the picture for now.
So, you are walking your path… And when you click, RS Loads some new objects, and it doesn't catch your MouseClick. If you are unlucky, the tile you'd click after the tile you have just clicked, is not on your Minimap. With some extra failsafes you might be able to safely get your character 'back on the road', but it can be done with a more effective method.
So, how does it work?
You basically get the tile that is closest to your current position, +1. (The closest one is the one your are currently on.) You repeat this until you end up at the place where you want to be. (Path[Current + 1] = High(Path) + 1)
The code:
After reading this code, I will show you how to implement it.
My ToBank:
Loading a path.
I'll try to add some more procedures in the next SRL. (In a seperate file called Reflection.scar, in SRL/misc)
I have seen several test reflection scripts, and they all use *wrong* walking methods. I'll quickly post what I made quite some time ago. (Thanks to Yakman for the General idea.)
Ok, so I have seen walking that looks like this:
WalkTile(3233, 3542);
WalkTile(3423, 5353);
WalkTile(3253, 3635); //Numbers are random...
This does not contain any failsafes, and is generally bad practice.
What the best thing would be to:
1. Create a path of tiles. (TPointArray)
2. Load the path, and walk it using the follow algorithh, which I will first explain.
The algorithm is relative simple, I don't think it actually deserves the term 'algorithm', but we will leave that out of the picture for now.
So, you are walking your path… And when you click, RS Loads some new objects, and it doesn't catch your MouseClick. If you are unlucky, the tile you'd click after the tile you have just clicked, is not on your Minimap. With some extra failsafes you might be able to safely get your character 'back on the road', but it can be done with a more effective method.
So, how does it work?
You basically get the tile that is closest to your current position, +1. (The closest one is the one your are currently on.) You repeat this until you end up at the place where you want to be. (Path[Current + 1] = High(Path) + 1)
The code:
Function AtTile(Tile: TPoint; Dist: Integer): Boolean;
Var
P: TPoint;
Begin
GetMyPos(P.X, P.Y); // Position in tiles.
Result := Distance(P.X, P.Y, Tile.X, Tile.Y) <= Dist;
End;
Function WalkTile(Tile: TPoint; Randomness, FlagD: Integer): Boolean;
Var
wTile: TPoint;
t: Integer;
Begin
Tile.X := RandomRange(Tile.X-Randomness, Tile.X+Randomness); // Randomness in tiles (4px)
Tile.Y := RandomRange(Tile.Y-Randomness, Tile.Y+Randomness);
TileToMiniMap(Tile.X, Tile.Y, wTile.X, wTile.Y);
If Not rs_OnMiniMap(wTile.X, wTile.Y) Then // not on map? exit.
Begin
Result := False;
Exit;
End;
Result := True;
MFNF(wTile.x, wTile.y, -1, -1);
t := getsystemtime;
FFlag(FlagD);// FFlag is just fine for walking.
Result := (GetSystemTime - t) < 60000;
End;
Function ClosestTile(Path: TPointArray): Integer;
// Get the closest tile index.
Var
I: Integer;
p: TPoint;
Begin
GetMyPos(p.X, p.Y);
Result := 0;
For I := 0 To High(Path) Do
If Distance(p.x, p.y, Path[I].X, Path[I].Y) < Distance(p.x, p.y, Path[Result].X, Path[Result].Y) Then
Result := I;
End;
Function WalkNextStep(Path: TPointArray; Rand, FlagD: Integer): Boolean;
// The actual function you will use in walking.
Var
I: Integer;
Begin
Result := False;
I := ClosestTile(Path);
If I = High(Path) Then
Exit;
If Not LoggedIn Then
Exit;
Result := True;
WalkTile(Path[I + 1], Rand, FlagD);
FindNormalRandoms;
End;After reading this code, I will show you how to implement it.
Procedure ToBank;
var
Path: TPointArray;
t: LongInt;
Begin
Path := LoadPath('ToBank');
T := GetSystemTime;
While WalkNextStep(Path, 1, 20) Do
Begin
Wait(50);
If GetSystemTime - T > 180000 Then
Begin
LogOut;
Exit;
End;
End;
FTWait(5);
FFlag(0);
SetLength(Path, 0);
End;My ToBank:
Procedure ToBank;
var
Path: TPointArray;
t: LongInt;
Begin
Path := LoadPath('ToBank');
T := GetSystemTime;
While WalkNextStep(Path, 1, 20) Do // Randomness in tiles. Tile - 1 to Tile + 1, three possibilities.
//X and Y: 3x3 = 9 possible tiles. 20 Flag distance so we don't stop walking (Bot like!!)
Begin
Wait(50);
If GetSystemTime - T > 180000 Then
Begin
LogOut;
Exit;
End;
End;
FTWait(5);
FFlag(0);
SetLength(Path, 0);
End;Loading a path.
Function LoadPath(PathType: String): TPointArray;
Begin
Case PathType Of
'ToBank':
Result := [Point(3105, 3251), Point(3097, 3249), Point(3092, 3244)];
End;
End;I'll try to add some more procedures in the next SRL. (In a seperate file called Reflection.scar, in SRL/misc)