SRL Archive - Reflection Development

[Reflection] Walking.scar


Widget

2008-08-07 04:22:38

I've kept telling Wizzup and myself that I'd clean up all the useless/overly-specific functions in the reflection include, so now I'm finally doing it, but I'm at a loss for what people would actually use.

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines - Walking --||
//------------------------------------------------------------------//
// * Function DistanceFrom(TileX, TileY: Integer) : Integer; // * by Widget
// * Function ClickTile(TileX, TileY, Height : Integer; // * by ss23 and Widget
// Left : Boolean) : Boolean; // º
// * Function WalkToTile(TileX, TileY : Integer): Boolean; // * by ss23 and Widget
// * Function WalkToTileTol(TileX, TileY, Tol : Integer): Boolean; // * by ss23 and Widget and TheGuyWhoGotOn
// * Function AlmostThere: Boolean; // * by TheGuyWhoGotOn
// * function LongWalkEx(TileX, TileY, DisX, DisY, // * by TheGuyWhoGotOn
// * Tol : integer): boolean; // º
// * function LongWalk(TileX, TileY, Tol : integer): boolean; // * by TheGuyWhoGotOn
// * function PathWalk(Path : array of TPoint; Long : boolean; // * by TheGuyWhoGotOn
// * Tol : integer): Boolean; // º
// * Function GoToTile(XTile, YTile, FlagD: Integer): Boolean; // * by Timer
// * Function WalkPath(Path: TPointArray; StartTile, // * by Timer
// * FlagD: Integer): Boolean; // º
// * Function GetLowest(aVar: TIntegerArray): Integer; // * by Timer
// * Function GetHighest(aVar: TIntegerArray): Integer; // * by Timer
// * Function FindMeOnPath(Var aVar: Integer; Path: TPointArray; // * by Timer
// * LocateTo: Boolean): Boolean; // º
// * Function WalkThePath(Path: TPointArray): Boolean; // * by Timer
// * Function WalkToTileEx(TileX, TileY, XTRandom, YTRandom, // * by Nicbaz
// * FFlag : Integer): Boolean; // º
// * Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX, // * by MasterKill
// * TilePosY: Integer): TPointArray; // * º
// * Function BlindWalkToTile(TilePosX, TilePosY): Boolean; // * by MasterKill
// * Procedure R_Flag; // * by Timer
// * procedure R_FFlag(Distance: Integer); // * ZephyrsFury

//------------------------------------------------------------------//

function GetFlag(var x, y: Integer): boolean; forward;

{*******************************************************************************
Function DistanceFrom(TileX, TileY: Integer) : Integer;
By: Widget
Description: Returns the distance between your player and the tile
*******************************************************************************}
Function DistanceFrom(TileX, TileY: Integer) : Integer;
Var
MyX,MyY : integer;
Begin
GetMyPos(MyX, MyY);
result := Distance(TileX, TileY, MyX, MyY);
end;

{*******************************************************************************
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
By: ss23 and Widget
Description: Clicks a tile. Height is the approximate heigh in pixels
Height doesnt matter if HighestAngle;
*******************************************************************************}
Function ClickTile(TileX, TileY, Height : Integer; Left : Boolean) : Boolean;
Var
x, y : Integer;
Begin
TileToMS(TileX, TileY, Height, x, y);
result := TileOnMs(x,y,height);
if not result then
Exit;
Mouse(x, y, 5, 5, False);
end;

{*******************************************************************************
procedure R_FFlag(Distance: Integer);
By: ZephyrsFury
Description: Similar to the original except it uses Reflection.
*******************************************************************************}
procedure R_FFlag(Dist: Integer);
var
Dx, Dy, Mx, My, Tx, Ty, m, d1, d2, w, h: Integer;
begin
while (GetFlag(Dx, Dy)) do
begin
GetMyPos(Mx, My);
w := (Dx - Mx) * 4;
h := (Dy - My) * 4;
d1 := Round(Sqrt(Sqr(w) + Sqr(h)));
if (d1 >= Dist) then
begin
Inc(m);
Wait(100);
if (Random(100) = 0) then IdleTime(500, 1000, 0.01);
if (m mod 100 = 0) then
if (d1 = d2) then
begin
if (FindColor(Tx, Ty, 255, MMX1, MMY1, MMX2, MMY2)) then
Mouse(Tx, Ty + 14, 0, 0, True)
else
Mouse(MMCX, MMCY, 0, 0, True);
end else d2 := d1;
end else Break;
end;
end;

{*******************************************************************************
Function - WalkToTile(TileX, TileY : Integer): Boolean;
By: ss23 and Widget
Description: Walks to the tile using minimap.
*******************************************************************************}
Function WalkToTile(TileX, TileY : Integer): Boolean;
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, 3, 3, True);
Result := True;
end;

{*******************************************************************************
Function - WalkToTileTol(TileX, TileY, Tol : Integer): Boolean;
By: ss23 and Widget and TheGuyWhoGotOn
Description: Walks to the tile using minimap and tolerance.
*******************************************************************************}
Function WalkToTileTol(TileX, TileY, Tol : Integer): Boolean;
Var
x, y : Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if not TileOnMM(TileX, TileY) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, Tol, Tol, True);
Result := True;
end;

{*******************************************************************************
Function - WalkToTileEx(TileX, TileY, XTRandom, YTRandom, FFlag : Integer): Boolean;
By: Nicbaz
Description: Walks to the tile using minimap and randomness + Flag
*******************************************************************************}
Function WalkToTileEx(TileX, TileY, XTRandom, YTRandom, FFlag : Integer): Boolean;
Var
x, y : Integer;
Begin
Walktotile(TileX+random(XTRandom),TileY+random(YTRandom));
R_FFlag(FFlag);
end;

{*******************************************************************************
Function - LongWalkEx(TileX, TileY, DisX, DisY, Tol : Integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks to a far tile using the minimap and tolerance.
DisX/DisY is how many tiles it will move at a time.
*******************************************************************************}
function LongWalkEx(TileX, TileY, DisX, DisY, Tol : integer): boolean;
var TX, TY, DX, DY : integer;
begin
repeat
GetMyPos(TX, TY);
if ((DX) > (TileX - DisX)) and ((DX) < (TileX + DisX)) then else
if TileX > TX then DX := TX + DisX
else DX := TX - DisX;
if ((DY) > (-TileY - DisY)) and ((DY) < (TileY + DisY)) then else
if TileY > TY then DY := TY + DisY
else DY := TY - DisY;
WalkToTileTol(DX, DY, Tol);
repeat
Wait(1000 + Random(500));
until (Flag) or (not(CharacterMoving));
until (TileOnMM(TileX, TileY)) or (not(TileOnMM(DX, DY)));
Result := WalkToTileTol(TileX, TileY, Tol);
end;

{*******************************************************************************
Function - LongWalk(TileX, TileY, Tol : Integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks to a far tile using the minimap and tolerance.
*******************************************************************************}
function LongWalk(TileX, TileY, Tol : integer): boolean;
begin
Result := LongWalkEx(TileX, TileY, 11, 11, Tol);
end;

{*******************************************************************************
Function - PathWalk(Path : array of TPoint; Long : boolean; Tol : integer): Boolean;
By: TheGuyWhoGotOn
Description: Walks a path for you with LongWalk options.
*******************************************************************************}
function PathWalk(Path : array of TPoint; Long : boolean; Tol : integer): Boolean;
var Count : integer;
begin
Count := 0;
repeat
if Long then Result := LongWalk(Path[Count].x, Path[Count].y, Tol)
else Result := WalkToTileTol(Path[Count].x, Path[Count].y, Tol);
repeat
Wait(1000 + Random(500));
until (Flag) or (not(CharacterMoving));
if not(Result) then
begin
WriteLn('Path walk failed');
Exit;
end;
Count := Count + 1;
until (not(Result)) or (Count = GetArrayLength(Path))
end;

{*******************************************************************************
Function GoToTile(XTile, YTile, FlagD: Integer): Boolean;
By: Timer
Description: If goes to the tile, results true, FFlags.
*******************************************************************************}
Function GoToTile(XTile, YTile, FlagD: Integer): Boolean;
Begin
Result := WalkToTile(XTile, YTile);
If (Not (Result)) Then
Exit;

FFlag(FlagD);
End;

{*******************************************************************************
Function WalkPath(Path: TPointArray; StartTile, FlagD: Integer): Boolean;
By: Timer
Description: Walks a path, if sucsess, results true.
*******************************************************************************}
Function WalkPath(Path: TPointArray; StartTile, FlagD: Integer): Boolean;

Var
H, I: Integer;

Begin
H := High(Path);

For I := StartTile To H Do
If (Not (GoToTile(Path[I].X, Path[I].Y, FlagD))) Then
Exit;

Result := True;
End;

{*******************************************************************************
Function GetLowest(aVar: TIntegerArray): Integer;
By: Timer
Description: Get the lowest integer.
*******************************************************************************}
Function GetLowest(aVar: TIntegerArray): Integer;

Var
H, I, T, Y: Integer;

Begin
H := High(aVar);

For I := 0 To H Do
If (aVar[I] > Y) Then
Begin
Y := aVar[I];
T := I;
End;

Result := T;
End;

{*******************************************************************************
Function GetHighest(aVar: TIntegerArray): Integer;
By: Timer
Description: Get the highest integer.
*******************************************************************************}
Function GetHighest(aVar: TIntegerArray): Integer;

Var
H, I, T, Y: Integer;

Begin
H := High(aVar);
For I := 0 To H Do
If (aVar[I] < Y) Then
Begin
Y := aVar[I];
T := I;
End;
Result := T;
End;

{*******************************************************************************
Function FindMeOnPath(Var aVar: Integer; Path: TPointArray; LocateTo: Boolean): Boolean;
By: Timer
Description: Finds your character on a specified path. Results True If Sucsess.
aVar is the tile.
*******************************************************************************}
Function FindMeOnPath(Var aVar: Integer; Path: TPointArray; LocateTo: Boolean): Boolean;

Var
I, H, X, Y: Integer;
D: TIntegerArray;

Begin
H := High(Path);
SetArrayLength(D, (H + 1));
GetMyPos(X, Y);
For I := 0 To H Do
D[I] := Distance(Path[I].X, Path[I].Y, X, Y);
H := GetLowest(D);
aVar := H;
If (LocateTo) Then
GoToTile(Path[H].X, Path[H].Y, 0);
Result := TileOnMM(Path[H].X, Path[H].Y);
End;

{*******************************************************************************
Function WalkThePath(Path: TPointArray): Boolean;
By: Timer
Description: Walks a path, start at beggining of the path..! :)
*******************************************************************************}
Function WalkThePath(Path: TPointArray): Boolean;

Var
I: Integer;

Begin
If (Not (WalkPath(Path, 0, 8))) Then
If (FindMeOnPath(I, Path, False)) Then
If (WalkPath(Path, I, 0)) Then
Result := True;
End;

{*******************************************************************************
Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX,
TilePosY: Integer): TPointArray;
By: MasterKill
Description: Makes a path from star till end poss.
*******************************************************************************}
Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX, TilePosY: Integer): TPointArray;
Var
I, XToWalk, YToWalk, RandX, RandY: Integer;
Begin
XToWalk := TilePosX - StartTilePosX;
YToWalk := TilePosY - StartTilePosY;
I := 0;
Repeat
RandX := Random(10);
RandY := Random(10);
If (XToWalk <> 0) Then
If (XToWalk > 0) Then
Begin
If (XToWalk > 65) Then
XToWalk := XToWalk - (55 + RandX)
Else
XToWalk := 0;
End Else
If (XToWalk > -65) Then
XToWalk := 0
Else
XToWalk := XToWalk + 55 + RandX;
If (YToWalk <> 0) Then
If (YToWalk > 0) Then
Begin
If (YToWalk > 65) Then
YToWalk := YToWalk - (55 + RandY)
Else
YToWalk := 0;
End Else
If (YToWalk < -65) Then
YToWalk := YToWalk + 55 + RandY
Else
YToWalk := 0;
SetArrayLength(Result, 1 + I);
Result[I] := IntToPoint(TilePosX - XToWalk, TilePosY - YToWalk);
If (XToWalk = 0) And (YToWalk = 0) Then Exit;
I := I + 1;
Until False
End;

{*******************************************************************************
Function BlindWalkToTile(TilePosX, TilePosY): Boolean;
By: MasterKill
Description: Makes a path from star till end poss.
*******************************************************************************}
Function BlindWalkToTile(TilePosX, TilePosY: Integer): Boolean;
Var
x, y: Integer;
WalkArray: TPointArray;
Begin
GetMyPos(X, Y);
WalkArray := GerneratePath(x, y, TilePosX, TilePosY);
Result := WalkThePath(WalkArray);
End;

{*******************************************************************************
Procedure R_Flag;
By: Timer
Description: Waits Till A COMPLETE Stop.
*******************************************************************************}
Procedure R_Flag;

Var
Ticker: Integer;

Begin
Ticker := (GetSystemTime + 30000);

While (CharacterMoving) Do
Begin
Wait(10 + Random(10));

If (GetSystemTime > Ticker) Then
Exit;
End;

Wait(500 + Random(50));
End;


So basically, I'm making a poll, pick the parts that you think should be in the include, and [please :)] post why you think they should be kept and maybe good uses for them, or suggest new things to add/rewrite.

Lee Lok Hin

2008-08-07 04:38:02

Little thing on IRC.


{*******************************************************************************
function ClosestTileinArray(Tiles:tPointarray):integer;
By: Lee Lok Hin and ZephyrsFury
Description: Results the closest tile to current position in Tiles
*******************************************************************************}
function ClosestTileinArray(Tiles:tPointarray):integer;
var
i,temp,last,tx,ty:integer;
begin
if not(LoggedIn) then exit;
GetMyPos(tx,ty);
Last:= 1 shl 20; //@Zeph
for i:=0 to High(tiles) do
begin
temp:=Distance(tx,ty,tiles[i].x,tiles[i].y);
if temp > last then continue;
last:= temp;
Result:=i;
end;
end;
{*******************************************************************************
function WalkToEndTile(PathTile:TPointarray;BacktoFront:boolean;FlagDist:integer):boolean;
By: Lee Lok Hin
Description: Walks the path Tiles. It will continue from any tile in the middle,
or will retry three times for every tile.
*******************************************************************************}
function WalkToEndTile(PathTile:TPointarray;BacktoFront:boolean;FlagDist:integer):boolean;
var
i,num,fails:integer;
Tiles:TPointArray;
begin
if not(LoggedIn) then exit;
Tiles:=PathTile;
if BackToFront then InvertTPA(tiles);
i:= ClosestTileinArray(Tiles);
num:=High(tiles);
//writeln('Closest Tile is '+inttostr(i));
if WalkToTile(Tiles[num].x,Tiles[num].y) then
begin
Result:=true;
Exit;
end;
if not(WalkToTile(Tiles[i].x,tiles[i].y)) then
begin
Result:=false;
exit;
end;
Flag;
repeat
fflag(2);
if InTileRange(tiles[i].x,tiles[i].y,10) then
i:=closesttileinarray(tiles) + 1
else
i:=closesttileinarray(tiles);
//Writeln('I is now '+inttostr(i));
if WalkToTiletol(tiles[num].x,tiles[num].y,5) then
begin
Result:=true;
r_flag;
AntiRandom;
exit;
end;
AntiRandom;
// writeln('Trying to walk to tile '+inttostr(tiles[i].x)+' '+inttostr(tiles[i].y));
if not(WalkToTile(tiles[i].x,tiles[i].y)) then
begin
if fails >= 3 then
begin
Result:=false;
Exit;
end else
fails:=fails+1;
end else
begin
fails:=0;
r_fflag(flagdist);
//writeln('Walked to '+inttostr(tiles[i].x)+' '+inttostr(tiles[i].y));
end;
until(false)
R_flag;
end;

Widget

2008-08-07 04:52:00

[banana](3:47:48 AM) Wizzup: don't poll
(3:47:56 AM) Wizzup: just use your own knowledge
(3:48:19 AM) Wizzup: : <
(3:48:20 AM) Widget^: we have like 5 different walktotiles
(3:48:32 AM) Wizzup: We DON'T NEED a walktotile
(3:48:39 AM) Zeph`: Widget^, get rid of it all except for one
(3:48:44 AM) Zeph`: and then you'll know what they use
(3:48:50 AM) Wizzup: Zeph` : none at al
(3:49:07 AM) Wizzup: Remove al
(3:49:08 AM) Wizzup: all[/banana]

I'm still for keeping one though =\

NiCbaZ

2008-08-07 04:52:47

Keep Timers Path Walks and 23ss one also keep this cause it used 23ss function :p
/ * Function WalkToTileEx(TileX, TileY, XTRandom, YTRandom, // * by Nicbaz
// * FFlag : Integer): Boolean; // º

n3ss3s

2008-08-07 12:14:25

My eyes! What were you thinking timer?



Function GetHighest(TIA: TIntegerArray): Integer;

Begin
BubbleSortB(TIA);
Result := TIA[0];
End;


Function GetLowest(TIA: TIntegerArray): Integer;

Begin
BubbleSort(TIA);
Result := TIA[0];
End;

Now go tell your mommy what you did :(


And btw, when Ben comes back I'll make a GeneratePath that generates a real walkable path from tiles that have been checked with an isWalkable(tx, ty: Integer): Boolean function, and can dodge a whole mountain unlike something based on pure minus plus math :(


End rant.


http://www.villavu.com/forum/showthread.php?t=32941?t=35679&highlight=walking

Amen.

Timer

2008-08-07 12:19:48

Masterkills path generation was my idea, he over wrote my functions, plus, they don't work *to my knowledge* he only divides the tiles, u need to multiply in some cases too…

n3ss3s

2008-08-07 12:29:54

This shit is getting out of hands, if he overwrote your functions why aren't they in his credits, and if they don't work why are they / non working versions still there?


You're the project manager…

MasterKill

2008-08-07 12:43:28

From: Timer
Masterkills path generation was my idea, he over wrote my functions, plus, they don't work *to my knowledge* he only divides the tiles, u need to multiply in some cases too…

From: n3ss3s
This shit is getting out of hands, if he overwrote your functions why aren't they in his credits, and if they don't work why are they / non working versions still there?


we allready discussed this. I had the same idee making that. And when I saw you allready made i thought: :( but then I saw "NOT WORKING YET" so I thought make one! :p you finaly agreed.

~

but I agree with wizzup, people should make there own walking stuffs. Remove them all eccept for Flag and FFlag

Timer

2008-08-07 12:48:15

How about…

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines - Walking --||
//------------------------------------------------------------------//
// * Function WalkToTile(TileX, TileY, Rx, Ry: Integer): Boolean; // * by ss23 and Widget and Timer
// * Function GetMyPosOnPath(Var aVar: Integer; Path: TPointArray):
// * Boolean; // * by Timer
// * procedure R_FFlag(Distance: Integer); // * by ZephyrsFury
// * Function PathWalk(Path: TPointArray): Boolean; // * by Timer and TheGuyWhoGotOn
//------------------------------------------------------------------//

function GetFlag(var x, y: Integer): boolean; forward;

{*******************************************************************************
Function WalkToTile(TileX, TileY: Integer): Boolean;
By: ss23 and Widget and Timer
Description: Walks to the tile using minimap.
*******************************************************************************}
Function WalkToTile(TileX, TileY, Rx, Ry: Integer): Boolean;
Var
x, y: Integer;
Begin
TileToMinimap(Tilex, Tiley, x, y);
if (not (TileOnMM(TileX, TileY))) then
begin
Writeln('Tile off minimap!');
Result := False;
Exit;
end;
Mouse(x, y, Rx, Rx, True);
Result := True;
end;

{*******************************************************************************
Function GetMyPosOnPath(Var aVar: Integer; Path: TPointArray): Boolean;
By: Timer
Description: Finds your character on a specified path. Results True If Sucsess.
aVar is the tile in array;
*******************************************************************************}
Function GetMyPosOnPath(Var aVar: Integer; Path: TPointArray): Boolean;

Var
aPath: TPointArray;
Px, Py, I: Integer;

Begin
GetMyPox(Px, Py);
aPath := Path;
SortTPAFrom(aPath, Px, Py);
If (Not (TileOnMM(aPath[0].X, aPath[0].Y))) Then
Exit;
For I := 0 To High(Path) Do
If (Path[I] = aPath[0]) Then
Begin
aVar := I;
Result := True;
Exit;
End;
End;

{*******************************************************************************
procedure R_FFlag(Distance: Integer);
By: ZephyrsFury
Description: Similar to the original except it uses Reflection.
*******************************************************************************}
procedure R_FFlag(Dist: Integer);
var
Dx, Dy, Mx, My, Tx, Ty, m, d1, d2, w, h: Integer;
begin
while (GetFlag(Dx, Dy)) do
begin
GetMyPos(Mx, My);
w := (Dx - Mx) * 4;
h := (Dy - My) * 4;
d1 := Round(Sqrt(Sqr(w) + Sqr(h)));
if (d1 >= Dist) then
begin
Inc(m);
Wait(100);
if (Random(100) = 0) then IdleTime(500, 1000, 0.01);
if (m mod 100 = 0) then
if (d1 = d2) then
begin
if (FindColor(Tx, Ty, 255, MMX1, MMY1, MMX2, MMY2)) then
Mouse(Tx, Ty + 14, 0, 0, True)
else
Mouse(MMCX, MMCY, 0, 0, True);
end else d2 := d1;
end else Break;
end;
end;

{*******************************************************************************
Function PathWalk(Path: TPointArray): Boolean;
By: Timer
Description: Walks The Path, If Lost, Finds Character, And Reverts To A
R_FFlag(0); Instead Of R_FFlag(8); - Randomizes Tiles.
*******************************************************************************}
Function PathWalk(Path: TPointArray): Boolean;

Var
I, I2: Integer;

Begin
For I := 0 To High(Path) Do
If (Not (WalkToTile(Path[I].X + (Random(3) - Random(3)), Path[I].Y + (Random(3) - Random(3)), 3, 3))) Then
Begin
Result := False;
Break;
End Else
Begin
R_FFlag(8);
FindNormalRandoms;
Result := True;
End;
If (Result) Then
Exit;
If (GetMyPosOnPath(I2, Path)) Then
Begin
For I := I2 To High(Path) Do
If (Not (WalkToTile(Path[I].X + (Random(3) - Random(3)), Path[I].Y + (Random(3) - Random(3)), 3, 3))) Then
Begin
Result := False;
Exit;
End Else
Begin
R_FFlag(0);
FindNormalRandoms;
Result := True;
End;
End;
End;

Not trying to be picky about what functions get in…

n3ss3s

2008-08-07 12:58:00

*Blood boils*

Could you use the r_FFlag in WalkTile too so it won't be just hanging in there?

Timer

2008-08-07 12:59:46

no… :p

Method

2008-08-07 13:11:39

I really only see the need for one tile walking function and one path walking function. R_FFlag I can understand, but I think the rest are unnecessary.

I don't really like any of the poll options for the path walking specifically, so I'm going to only vote for the WalkToTile function.

EvilChicken!

2008-08-07 14:07:49

I'm not sure if MasterKill's GeneratePath even works, it didn't for me at least.
If it works like the name suggests, it generates a path from A to B, then all his path generation procs should be fixed and kept.

So, the question is: Does BlindWalkToTile work, and if so - how?

Bobarkinator

2008-08-07 14:17:18

WalkToTile(TileX, TileY); and WalkToTileTol(TileX, TileY, Tol);

Or just WalkToTile(TileX, TileY, Tol);

Narcle

2008-08-07 14:17:32

We only need a WalkToTile(x, y, ranx, rany); imo, where ranx/rany is the mouse clicks random.

Path walker - possible if its the way n3s wants to do it where it can walk around a mountain by itself. Otherwise personally I would just make my own path walker depending on the script.

Current path walker - no

Edit:
Hell even using a TBox array for WalkToTile would be nice, so each walk to tile can have its separate randomness if you choose so.

To many possibilities, I think thats why Wizzup and the others don't want it in there.

MasterKill

2008-08-07 14:24:14

From: EvilChicken!
I'm not sure if MasterKill's GeneratePath even works, it didn't for me at least.
If it works like the name suggests, it generates a path from A to B, then all his path generation procs should be fixed and kept.

So, the question is: Does BlindWalkToTile work, and if so - how?


not yet, the tiles are to far of but it takes 20 seconds to fix that.

Shuttleu

2008-08-07 14:35:58

change my vote from
WalkToTile functions by ss23, LongWalk functions by TheGuyWhoGotOn, PathWalk function by TheGuyWhoGotOn
to
WalkToTile functions by ss23, Path-walking functions by Timer

~shut

Naike

2008-08-07 16:00:16

Keep WalkToTile.
Simple, and good name :)

Hobbit

2008-08-07 18:05:17

They all look good to me, I think people should be able to choose which they use in a script. But its upto you.

Maybe make XWalking.scar for the other ones that get taken out so people can still use if thats the one they preffer.

MylesMadness

2008-08-07 18:09:19

I say WalkToTile and WalkToTile only

Widget

2008-08-07 22:32:57

Current proposal:

//------------------------------------------------------------------\\
//-- Scar Non-Standard Resource Library --||
//-- » Reflection Routines - Walking --||
//------------------------------------------------------------------//
// * function WalkToTile(TileX, TileY : Integer): Boolean; // * by ss23 and Widget
// * function GetFlag(var x, y: Integer): boolean; // * by TheGuyWhoGotOn
// * procedure R_Flag; // * by Timer
// * procedure R_FFlag(Distance: Integer); // * ZephyrsFury
// * Function DistanceFrom(TileX, TileY: Integer) : Integer; // * by Widget
//------------------------------------------------------------------//


{*******************************************************************************
Function - WalkToTile(TileX, TileY, RandX, RandY : Integer): Boolean;
By: ss23 and Widget
Description: Walks to the tile using minimap.
*******************************************************************************}
Function WalkToTile(TileX, TileY, RandX, RandY : Integer): Boolean;
Var
x, y, tx, ty : Integer;
Begin
tx := TileX + Random(RandX + 1) - Random(RandX + 1);
ty := TileY + Random(RandY + 1) - Random(RandY + 1);
TileToMinimap(tx, ty, x, y);
if not TileOnMM(tx, ty) then
begin
Writeln('Tile off minimap');
Result := False;
Exit;
end;
Mouse(x, y, 3, 3, True);
Result := True;
end;

{*******************************************************************************
procedure - GetFlag(var x, y: Integer): boolean;
By: TheGuyWhoGotOn
Description: Gets your destination (Tiles)
*******************************************************************************}
function GetFlag(var x, y: Integer): boolean;
begin
x:= SmartGetFieldInt(0,BaseX) + SmartGetFieldInt(0,FlagX);
y:= SmartGetFieldInt(0,BaseY) + SmartGetFieldInt(0,FlagY);
Result := ((SmartGetFieldInt(0,FlagX) > 0) and (SmartGetFieldInt(0,FlagY) > 0));
end;

{*******************************************************************************
procedure R_FFlag(Distance: Integer);
By: ZephyrsFury
Description: Similar to the original except it uses Reflection.
*******************************************************************************}
procedure R_FFlag(Dist: Integer);
var
Dx, Dy, Mx, My, Tx, Ty, m, d1, d2, w, h: Integer;
begin
while (GetFlag(Dx, Dy)) do
begin
GetMyPos(Mx, My);
w := (Dx - Mx) * 4;
h := (Dy - My) * 4;
d1 := Round(Sqrt(Sqr(w) + Sqr(h)));
if (d1 >= Dist) then
begin
Inc(m);
Wait(100);
if (Random(100) = 0) then IdleTime(500, 1000, 0.01);
if (m mod 100 = 0) then
if (d1 = d2) then
begin
if (FindColor(Tx, Ty, 255, MMX1, MMY1, MMX2, MMY2)) then
Mouse(Tx, Ty + 14, 0, 0, True)
else
Mouse(MMCX, MMCY, 0, 0, True);
end else d2 := d1;
end else Break;
end;
end;

{*******************************************************************************
Procedure R_Flag;
By: Timer
Description: Waits Till A COMPLETE Stop. (Not dependant on Flag hooks)
*******************************************************************************}
Procedure R_Flag;
Var
Ticker: Integer;
Begin
Ticker := (GetSystemTime + 30000);
While (CharacterMoving) Do
Begin
Wait(10 + Random(10));
If (GetSystemTime > Ticker) Then
Exit;
End;
Wait(500 + Random(50));
End;

{*******************************************************************************
Function DistanceFrom(TileX, TileY: Integer) : Integer;
By: Widget
Description: Returns the distance between your player and the tile
*******************************************************************************}
Function DistanceFrom(TileX, TileY: Integer) : Integer;
Var
MyX, MyY : integer;
Begin
GetMyPos(MyX, MyY);
result := Distance(TileX, TileY, MyX, MyY);
end;

Other functions will be moved to Depricated.scar in case you want to copy/paste them into your script.

Method

2008-08-07 22:43:37

Looks good to me. Making our own path walking won't be hard.

Markus

2008-08-08 04:52:03

writeln('Tile off minimap'); -> srl_Warn('WalkToTile', 'Tile off minimap!', warn_Warning);

EvilChicken!

2008-08-08 08:39:52

Widget, I honestly think that MasterKill's path-generation and blindwalk functions could be really useful once fixed, since if generates a random path every time, and also simplifies a whole lot.

Could I have your thoughts about it, please?

Edit: Shut, three things:

- Not even an idiot would use it to walk around buildings, and that was not what it was created to do.
- It doesn't work, yet - MasterKill said fixing it would take 20 seconds. (Then do it! :p )
- Fix your signature. It is NOT meant to be that way, and it was for a specific reason that Wizzup? and the administrators decided to "crop" them. (Less traffic = lower cost)


Edit2: MK <3

Shuttleu

2008-08-08 08:48:17

it could be useful but it doesnt work i mean i made a path which took 15 steps
i put the begining tiles in and then the end tiles and it said that it could make it in three clicks
plus also how would it make its way around wals and houses etc.

so yeah if it is fixed then it could come useful but it is way off for now

~shut

MasterKill

2008-08-08 09:43:04

This should work, not tested though :o

Function WalkTileWalkPath(PathPoints: TPointArray): Boolean; // by MasterKill
Var
MK, x, y: Integer;
Begin
For MK := 0 To High(PathPoints) Do
Begin
If Not LoggedIn Then Exit;
If TileOnMM(PathPoints[MK].x, PathPoints[MK].y) Then
Begin
TileToMinimap(PathPoints[MK].x, PathPoints[MK].y, x, y);
Mouse(x, y, 0, 0, True);
Repeat
If Not LoggedIn Then Exit;
Case Random(2) Of
0: Wait(RandomRange(300, 600));
1: SleepAndMoveMouse(RandomRange(300, 600));
End;
If Not (MK = High(PathPoints)) Then
If TileOnMM(PathPoints[MK + 1].x, PathPoints[MK + 1].y) Then
Break;
AntiRandoms;
Until (Not CharacterMoving)
End Else
Begin
srl_Warn('Tile not found, walking phail', 'Tile not found, walking phail', warn_Warning);
LogOut;
Players[CurrentPlayer].Loc := 'walking phail'; // I'll make a failsave for this.
End;
End;
Result := True;
End;

{*******************************************************************************
Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX,
TilePosY: Integer): TPointArray;
By: MasterKill
Description: Makes a path from star till end poss.
*******************************************************************************}
Function GerneratePath(StartTilePosX, StartTilePosY, TilePosX, TilePosY: Integer): TPointArray;
Var
I, XToWalk, YToWalk, RandX, RandY: Integer;
Begin
XToWalk := TilePosX - StartTilePosX;
YToWalk := TilePosY - StartTilePosY;
I := 0;
Repeat
RandX := Random(5);
RandY := Random(5);
If (XToWalk <> 0) Then
If (XToWalk > 0) Then
Begin
If (XToWalk > 15) Then
XToWalk := XToWalk - (10 + RandX)
Else
XToWalk := 0;
End Else
If (XToWalk > -15) Then
XToWalk := 0
Else
XToWalk := XToWalk + 10 + RandX;
If (YToWalk <> 0) Then
If (YToWalk > 0) Then
Begin
If (YToWalk > 15) Then
YToWalk := YToWalk - (10 + RandY)
Else
YToWalk := 0;
End Else
If (YToWalk < -15) Then
YToWalk := YToWalk + 10 + RandY
Else
YToWalk := 0;
SetArrayLength(Result, 1 + I);
Result[I] := IntToPoint(TilePosX - XToWalk, TilePosY - YToWalk);
If (XToWalk = 0) And (YToWalk = 0) Then Exit;
I := I + 1;
Until False
End;

{*******************************************************************************
Function BlindWalkToTile(TilePosX, TilePosY): Boolean;
By: MasterKill
Description: Makes a path from star till end poss.
*******************************************************************************}
Function BlindWalkToTile(TilePosX, TilePosY: Integer): Boolean;
Var
x, y: Integer;
WalkArray: TPointArray;
Begin
GetMyPos(X, Y);
WalkArray := GerneratePath(x, y, TilePosX, TilePosY);
Result := WalkTileWalkPath(WalkArray);
End;