SRL Archive - Reflection Development

[Suggestion] New WalkPath


Iamadam

2011-03-29 22:43:59

Heya.
So, I'm sick of our current, laggy walk path function, so I made my own.
{*******************************************************************************
function walkPathEx(path: TTileArray; acceptableDistance, clickRandomness, waitTime: Integer) : boolean;
By: Iamadam
Description: Walks a tile path with minimum lag.
Variables:
path : The path to walk (as an array of TTiles)
acceptableDistance : The minimum distance from the destination to return true
tileRandomness: The amount of randomness (in tiles) to add to minimap clicks
waitTime: the amount of time to wait after a click, before searching for the next tile.
*******************************************************************************}
function walkPathEx(path: TTileArray; acceptableDistance, tileRandomness, waitTime: Integer) : boolean;
var index, lastClick, lastClickTime: Integer;
clickPoint : TPoint;
clickTile : TTile;
begin
if(not loggedIn) then
begin
result:= false;
exit;
end;
lastClickTime := getSystemTime;
while (distanceFrom(path[high(path)]) > acceptableDistance) do
begin
for index := high(path) downto 0 do
begin
if(tileOnMM(path[index])) then
break;
end;
//click the point
if(lastClick <> index) then //make sure we havn't already clicked there...
begin
if((index = 0) and (not tileOnMM(path[0]))) then //none of the tiles are on the minimap, return false
begin
result := false;
exit;
end;

lastClick := index;
clickTile := randomizeTile(path[index], tileRandomness, tileRandomness);
while (not tileOnMM(clickTile)) do
clickTile := randomizeTile(path[index], tileRandomness, tileRandomness); //Make sure the random tile is on the mmap.
clickPoint := tileToMM(clickTile);
Mouse(clickPoint.x, clickPoint.y, 1, 1, true);
lastClickTime := GetSystemTime;
wait(waitTime + random(500) + random(random(500)));
end else
begin
if(GetSystemTime - lastClickTime > 1000 * 20) then //its been 20 seconds since the last click... walking has failed.
begin
writeln('Please check your path. The tile at index ' + toStr(index) + ' is too far from the next tile');
result := false;
exit;
end
else
wait(random(500) + random(random(500))); //so, we already clicked the best tile, now we wait a little bit.
end;
end;
if(not loggedIn) then
result := false
else
result := true;
end;

function walkPath(path: TTileArray) : boolean;
begin
result := walkPathEx(path, 5, 1, 1000);
end;

Comment, test, rant etc.
It should work much better, and use far less cpu.

**BANNED The Man

2011-03-30 02:37:46

Yes.

rogeruk

2011-03-30 04:47:36

Already been reported as a bug.

I've been using this with no problems

(Change Write to Writeln)
Credits: Floor66
http://villavu.com/forum/showpost.php?p=790633&postcount=20

function f_WalkPath(Path : TTileArray; Invert : Boolean): Boolean;
var
i, j, dest, currTile, m : Integer;
t : TTile;
p : TPoint;
moved, nextOnMM : Boolean;
begin
if (not LoggedIn) or R_FindRandoms then
Exit;
if Invert then
InvertPath(Path);
dest := High(Path);
Result := TileOnMS(Path[dest], 0);
if Result then
Exit;
for i := dest downto 0 do
begin
if TileOnMM(Path[i]) then
begin
currTile := i;
Break;
end else
currTile := -1;
Wait(10 + Random(50));
end;
if currTile = -1 then
begin
Write('None of the tiles in the path were found!');
Exit;
end;
for i := currTile to dest do
begin
moved := False;
Result := TileOnMS(Path[dest], 0);
if Result then
Break;
if not nextOnMM then
begin
for j := dest downto (currTile + 1) do
begin
if TileOnMM(Path[j]) then
begin
currTile := j;
Break;
end else
currTile := -1;
Wait(10 + Random(50));
end;
if currTile = -1 then
begin
Write('None of the tiles in the path were found!');
Exit;
end;
end;
t := RandomizeTile(Path[currTile], 1, 1);
p := TileToMM(t);
Mouse(p.x, p.y, 2, 2, True);
if not WaitToMove(500 + Random(500)) then
begin
MarkTime(m);
while TimeFromMark(m) <= 5000 do
begin
if WaitToMove(500 + Random(150)) then
begin
moved := True;
Break;
end;
Wait(10 + Random(50));
end;
if not moved then
Write('We didn''t move!');
end;
nextOnMM := False;
while (GetSpeed > 0) (not nextOnMM) and (not Result) do
begin
Result := TileOnMS(Path[dest], 0);
for j := dest downto (currTile + 1) do
begin
if TileOnMM(Path[j]) then
begin
currTile := j;
nextOnMM := True;
Break;
end;
Wait(10 + Random(50));
end;
Wait(10 + Random(50));
end;
end;
Result := TileOnMS(Path[dest], 0);
if not Result then
Result := WalkToTile(Path[dest], 1, 0);
end;

Iamadam

2011-03-30 06:46:19

I know it's been reported. Twice actually. And nothing changed. So I'm proposing we change it instead of just saying there's a problem :)
That's why I wrote one that is simple & elegant.
If yours works better lets use it. But lets try them both out.

Echo_

2011-03-30 19:25:10

I support this, the current walking method is sketchy.

mormonman

2011-03-30 19:28:28

Change it to TileRandomness and use RandomTile();
Then I'll test and commit.

Floor66

2011-03-31 01:10:44

e: removed.

Just added the Randomness var. at the top (I was already doing 1,1 randomness before). Used this in several scripts, the lag never came back.

mormonman

2011-03-31 01:27:01

Floor your's seems like it has some redundant code…I haven't looked at it too much tho.

Floor66

2011-03-31 01:51:41

Looks that way to me too but tbh I couldn't get around it. I can't look into atm, I'm busy with a huge film project for school.

Iamadam

2011-03-31 01:54:50

Have edited original post. Now uses tile randomness. Sorry if it doesn't compile, just directly edited the post.

Floor66

2011-03-31 01:59:24

The thing for me was that I added waits in all my loops, idk if that un-lagged it for you Iamadam?

Iamadam

2011-03-31 02:02:43

Didn't try adding waits, although that should fix the original.
I figured it'd be better to write it from scratch, since the current one is overcomplicated anyway. The one I posted doesn't need any more waits - it'll just run through the main loop once every ~1000ms.

Flight

2011-03-31 07:28:51

I had alot of trouble with your WalkPath function, Floor. In some cases it seemed to 'skip' over the last 2 tiles in my path array and return True anyways…

Dgby714

2011-03-31 08:18:34

Iamadam's Functions cleaned….

function WalkPathEx(Path: TTileArray; AcceptableDistance, TileRandomness, WaitTime: integer): boolean;
var
I, H, lClick, lClickTime: integer;
ClickPoint: TPoint;
ClickTile: TTile;
begin
Result := (not (LoggedIn));
if (Result) then
Exit;

H := High(Path);
lClickTime := GetSystemTime;
while (DistanceFrom(Path[H]) > AcceptableDistance) do
begin
for I := H downto 0 do
if (TileOnMM(Path[I])) then
Break;


if (not (I = lClick)) then
begin
if ((I = 0) and (not (TileOnMM(Path[0])))) then
begin
Result := False;
Exit;
end;

lClick := I;

ClickTile := RandomizeTile(Path[I], TileRandomness, TileRandomness);
while (not (TileOnMM(ClickTile))) do
ClickTile := RandomizeTile(Path[I], TileRandomness, TileRandomness);

ClickPoint := TileToMM(ClickTile);

Mouse(ClickPoint.x, ClickPoint.y, 1, 1, True);
lClickTime := GetSystemTime;
Wait(WaitTime + Random(1000));
end else
begin
if (GetSystemTime - lClickTime > 1000 * 20) then
begin
WriteLn('Please check your path. The tile at index ' + ToStr(I) + ' is too far from the next tile');
Result := False;
Exit;
end else
Wait(random(1000));
end;
end;

Result := (LoggedIn);
end;

function WalkPath(Path: TTileArray): boolean;
begin
Result := WalkPathEx(Path, 5, 1, 1000);
end;

Iamadam

2011-03-31 09:13:15

Leave it as index and lastClick (instead of i and lClick - they aren't very descriptive).
Also,
 wait(waitTime + random(500) + random(random(500)));
is not the same as
wait(waitTime + random(1000))

I random numbers to be non-linearly distributed - less detectable (not saying it is detected at the moment, but it could be).
Anyway.

Oh also:
  Result := (not (LoggedIn));
if (Result) then
Exit;
That will exit if not logged in, but return true.
What's wrong with:
if(not loggedIn) then
begin
result:= false;
exit;
end;
It takes an extra line, but its clean and easy to understand.
A few extra lines is worth it if the code looks cleaner =)

Floor66

2011-03-31 09:28:14

From: Flight
I had alot of trouble with your WalkPath function, Floor. In some cases it seemed to 'skip' over the last 2 tiles in my path array and return True anyways…


Maybe that's because it checks if the last tile in the path is on the MS. You can remove that easily though.

Flight

2011-03-31 21:57:54

Not even the last tile mate, it skipped the last two on both of my tile arrays. Regular WalkPath has no problem at all walking it, but it is, as mentioned already, "laggy".

Iamadam

2011-03-31 22:26:43

Does the one I posted work?

Flight

2011-03-31 22:35:07

I forget what it did wrong but so far none of them have worked for me. :/ If they work for everyone else then obviously it's a problem with my internet/computer. So I guess I'm just screwed either way. :(

Iamadam

2011-03-31 23:57:41

Hmm. I'm going to test mine again and see how it goes. Will edit this in a few mins..
Edit: It didn't compile, because I forgot to add a colon somewhere. /facepalm.
Give it a go now.


Here's a script to test it. Should walk to edgeville from lumbridge respawn point.
program new;
{$Define SMART}
{.include SRL\srl.scar}
{.include reflection\reflection.simba}

function walkPathEx(path: TTileArray; acceptableDistance, tileRandomness, waitTime: Integer) : boolean;
var index, lastClick, lastClickTime: Integer;
clickPoint : TPoint;
clickTile : TTile;
begin
if(not loggedIn) then
begin
result:= false;
exit;
end;
lastClickTime := getSystemTime;
while (distanceFrom(path[high(path)]) > acceptableDistance) do
begin
for index := high(path) downto 0 do
begin
if(tileOnMM(path[index])) then
break;
end;
//click the point
if(lastClick <> index) then //make sure we havn't already clicked there...
begin
if((index = 0) and (not tileOnMM(path[0]))) then //none of the tiles are on the minimap, return false
begin
result := false;
exit;
end;

lastClick := index;
clickTile := randomizeTile(path[index], tileRandomness, tileRandomness);
while (not tileOnMM(clickTile)) do
clickTile := randomizeTile(path[index], tileRandomness, tileRandomness); //Make sure the random tile is on the mmap.
clickPoint := tileToMM(clickTile);
Mouse(clickPoint.x, clickPoint.y, 1, 1, true);
lastClickTime := GetSystemTime;
wait(waitTime + random(500) + random(random(500)));
end else
begin
if(GetSystemTime - lastClickTime > 1000 * 20) then //its been 20 seconds since the last click... walking has failed.
begin
writeln('Please check your path. The tile at index ' + toStr(index) + ' is too far from the next tile');
result := false;
exit;
end
else
wait(random(500) + random(random(500))); //so, we already clicked the best tile, now we wait a little bit.
end;
end;
if(not loggedIn) then
result := false
else
result := true;
end;

function walkPath1(path: TTileArray) : boolean;
begin
result := walkPathEx(path, 5, 1, 1000);
end;

var ppath : TTileArray;
begin
Smart_Server := 1;
Smart_Signed := true;
Smart_Members := false;
setupSRL;
setupReflection;
ppath := [Tile(3222, 3218),
Tile(3229, 3219),
Tile(3234, 3221),
Tile(3231, 3229),
Tile(3226, 3234),
Tile(3222, 3239),
Tile(3220, 3246),
Tile(3218, 3253),
Tile(3217, 3260),
Tile(3216, 3269),
Tile(3213, 3277),
Tile(3206, 3279),
Tile(3199, 3279),
Tile(3191, 3284),
Tile(3190, 3292),
Tile(3186, 3301),
Tile(3181, 3309),
Tile(3172, 3314),
Tile(3162, 3313),
Tile(3152, 3314),
Tile(3150, 3321),
Tile(3150, 3330),
Tile(3147, 3336),
Tile(3146, 3344),
Tile(3144, 3351),
Tile(3140, 3358),
Tile(3137, 3365),
Tile(3135, 3373),
Tile(3132, 3378),
Tile(3125, 3384),
Tile(3116, 3387),
Tile(3109, 3393),
Tile(3105, 3400),
Tile(3103, 3409),
Tile(3101, 3417),
Tile(3099, 3425),
Tile(3099, 3434),
Tile(3096, 3442),
Tile(3092, 3451),
Tile(3089, 3457),
Tile(3084, 3463),
Tile(3077, 3465),
Tile(3075, 3473),
Tile(3075, 3480),
Tile(3074, 3487),
Tile(3074, 3495),
Tile(3078, 3502),
Tile(3083, 3499),
Tile(3089, 3492),
Tile(3093, 3492)];

if(walkPath1(ppath)) then
writeln('Walked!')
else
writeln('Failed...');
end.

Flight

2011-04-01 00:18:03

I'll be sure to test it later man, thanks. :) I wonder, though, if it has anything to do with the fact I'm using the Debug version of Simba which is over 9 times larger than the regular. Maybe because of this everything is much slower… I'll try a few test runs on my scripts and your new walking method using the regular Simba.exe and see if that makes a difference.

mormonman

2011-04-01 00:55:15

I actually want to implement walking in the same form as Nava and Zeph created. It takes less tiles and is more random.

Floor66

2011-04-04 11:37:35

How did they do it then?

Also, to anyone, don't use the one I made before. It's too slow when using huge paths (like a deathwalk). I'm re-doing it atm.

mormonman

2011-04-04 12:50:51

http://code.google.com/p/nzmm/source/browse/trunk/MM.simba

Bad Boy JH

2011-04-06 08:10:08

We could do this mathamatically, we know the size of the screen, we know the distance from tileA to tile B, we should be able to work out what number to put into R_FFlag() to wait the right time…

Sorry I'm not doing it, but I am focusing on uni, trying to learn 2 new languages is a challenge, (Java and C# for those interested).

Flight

2011-04-07 21:40:37

I've come up with an idea for a new walk system that excludes reflection, I'm going to be building it today, but if it works like I think it will then it'll be a new way to walk, extremely simple.

Iamadam

2011-04-08 23:25:09

Ok.
Do I need to do a pull request or what?

WalkPath is horrible.
It must be fixed.
It's been brought up A LOT.
Suggestions have been made and new code has been written by multiple people.

Yet… it still has not been fixed.

Why?

Yago

2011-04-08 23:28:37

Adam can you have an invert boolean like floor66 if yours is going to be implemented?

Flight

2011-04-08 23:36:37

If it's proven successful then, if I were you, I'd go ahead and push it as a request, have the Dev team test it out for a while, and decide if it should be implanted.

mormonman

2011-04-08 23:59:19

From: Iamadam
Ok.
Do I need to do a pull request or what?

WalkPath is horrible.
It must be fixed.
It's been brought up A LOT.
Suggestions have been made and new code has been written by multiple people.

Yet… it still has not been fixed.

Why?


Because I have a lack of time and other devs haven't worked on it.

Yago

2011-04-09 15:54:59

From: mormonman
Because I have a lack of time and other devs haven't worked on it.


Adam's is good though. No need to fix when there's a better one…

Edit: Is this ever going to be implemented?