SRL Archive - News and General

HowTo: Walking with Reflection


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:
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)

JuKKa

2008-07-18 05:01:00

nice job, i use my own "webwalk" function, has never failed :)

BobboHobbo

2008-07-18 05:14:41

Ooo nice! Ill test this out looks nice.

TheGuyWhoGotOn

2008-07-18 12:28:42

I had a LongWalk procedure however I can't get on KYAB right now…So this is really in SRL? I wish I had any idea how to create a program like SMART.

I also had something similar to your load path but it was easier to use I believe…

Scaper

2008-07-18 12:46:25

wow v niceill have to try that :D

TheGuyWhoGotOn

2008-07-18 13:08:16

Hmm: Line 13: [Error] (15590:1): Unknown identifier 'GetMyPos' in script

Am I using an outdated version of SMART? I have SRL Rev 20…

Also where can I read all the new reflection stuff that has been built in?

P1nky

2008-07-18 13:19:23

oh neat :) everything is going icefire's way and wizzup? thanks for telling us more.

Harry

2008-07-18 13:34:25

I guess this is the Java revolution. :)

Should be easier to walk now I guess.

Wizzup?

2008-07-18 14:19:39

From: P1NKY
oh neat :) everything is going icefire's way and wizzup? thanks for telling us more.


"Icefire's solution"?

From: TheGuyWhoGotOn
Hmm: Line 13: [Error] (15590:1): Unknown identifier 'GetMyPos' in script

Am I using an outdated version of SMART? I have SRL Rev 20…

Also where can I read all the new reflection stuff that has been built in?


Heh. You need Reflection.scar, it will be in the next SRL.

Timer

2008-07-18 14:20:23

Hmm, i have functions for this too… I made my own custom some days ago..!

TheGuyWhoGotOn

2008-07-18 14:21:49

From: Timer
Hmm, i have functions for this too… I made my own custom some days ago..!


Where did you get the list of plugin abilities? Did you just open it up in Delphi or something? Or did I miss a post? Or am I just an idiot?

BTW thanks Wizzup?

Timer

2008-07-18 14:30:24

You missed somthing… Reflection.scar

http://widget.pastebin.com/

Negaal

2008-07-18 15:07:47

Why am I feeling that SRL is getting better and better and it's very far from dieing..

See, rs cheating should be dead..but SRL community is just getting their hands warm..

Complicated..

And the text Wizzup wrote, I didn't understood a single sentence from there..

Now I'm also convinced that Wizzup is going to work for google or goverment aswell..:eek: So does SB100 and BL100..

Wanted

2008-07-18 16:16:41

From: P1NKY
oh neat :) everything is going icefire's way


What?

I had nothing to do with this, yea…

Nice functions Wizzup?

NiCbaZ

2008-07-18 18:36:55

nice functions cannot get to compile tho evanw ith reflection.scar ahh well :) nice.

Cazax

2008-07-18 19:23:33

Nice, nice. This makes walking too much easier :) but the old method pwns all.

Wanted

2008-07-18 19:35:13

From: Cazax
Nice, nice. This makes walking too much easier :) but the old method pwns all.


Did you read about the fail safes on the other thread? :duh:

Waddo

2008-07-18 19:36:01

some one needs to teach me reflection

Wanted

2008-07-18 19:46:20

From: Waddo
some one needs to teach me reflection


…well there were reflection tutorials around in the KYAB section.

Maybe someone could return that section of the forum?

Claymore

2008-07-23 13:11:03

I still dont get it, where did you get the coordinates

Result := [Point(3105, 3251), Point(3097, 3249), Point(3092, 3244)];

How did you get thaT? Sorry I am new at this "Reflection" and i just got accepted here, and im begging to learn this thing. Thanks.

Method

2008-07-23 14:18:56

Those are tile coordinates, I believe. You can find them using the SMART Debugger that n3ss3s posted, specifically using the WritePos procedure.