SRL Archive - Help and Support

Setting a point of origin


Runaway

2011-12-30 20:36:57

Hey all,

I've been trying to come up with a way to stay within a certain distance of an area and returning to a certain spot on the MM if the player strays too far away.

So far I've got this:


program Pathfinder;

{$i SRL\SRL.scar}

var
MoveX, MoveY: array of integer;
TotalMoves, DistMoved: integer;

procedure ResetPath;
begin
if not LoggedIn then Exit;
TotalMoves := 0
SetArrayLength(MoveX, 1);
SetArrayLength(MoveY, 1);
MoveX[0] := 0
MoveY[0] := 0
end;

procedure MeasureClickPath(x, y: integer);
begin
If not LoggedIn then Exit;
DistMoved := Abs(Sqr(((x-MMCX)*2)+((y-MMCY)*2)))
if (DistMoved > 5) then
begin
Inc(TotalMoves);
SetArrayLength(MoveX, (TotalMoves + 1));
SetArrayLength(MoveY, (TotalMoves + 1));
MoveX[TotalMoves] := (x - MMCX)
MoveY[TotalMoves] := (y - MMCY)
end;
end;

procedure MeasureFlagPath;
var
bx, by, MMFlag: integer;
begin
If not LoggedIn then Exit;
MMFlag := BitmapFromString(3, 3, 'meJzjZv/ExXDRTFQFSHIxbAUyOBmKgSQQAQBYRQWy');
if FindBitmapToleranceIn(MMFlag, bx, by, MMX1, MMY1, MMX2, MMY2, 1) then
begin
DistMoved := Abs(Sqr(((bx-MMCX)*2)+(((by-MMCY)*2)-6)))
if (DistMoved > 5) then
begin
Inc(TotalMoves);
SetArrayLength(MoveX, (TotalMoves + 1));
SetArrayLength(MoveY, (TotalMoves + 1));
MoveX[TotalMoves] := (bx - MMCX)
MoveY[TotalMoves] := ((by - MMCY) - 6)
end;
end;
FreeBitmap(MMFlag);
end;

procedure ReturnPath(amount: integer);
var
i: integer;
begin
if not LoggedIn then Exit;
for i := (High(Movement)) to (High(Movement) - amount) do
begin
MouseFlag((MoveX[i] * -1), (MoveY[i] * -1), 3, 3, 5);
wait(500+random(1000));
end;
end;

To return to the origin, the DistMoved vars would be added and if they exceed a certain limit the player would then execute ReturnPath back to the initial location.

I know it's very simple, just wondering if it's the only way to do such a thing. And/or if anyone has any improvements upon the mechanics of this, I'm running a blank on this!

E: Just in case there is any confusion, MeasurePath would be used right before clicking the MM and then stores the difference of the x and y where it clicked relative to the center of the MM. This way a player can be returned to their tile of origin after moving any sort of distance by simply re-tracing it's steps.

Dynamite

2011-12-30 20:42:22

Sorry didn't finish the thread, this is off the top of my head.
Begin
SortTPA(TPA);
for i := 0 to High(TPA) do
begin
if (i = > 20) then
WeAreTooFar
else Break;
end;
end;

I might be talking out my bum hole, it is too late.

E: Ok just read the thread, sorry, I guess the statement above is true XD

-Boom

Runaway

2011-12-30 20:47:40

From: Dynamite
Sorry didn't finish the thread, this is off the top of my head.
Begin
SortTPA(TPA);
for i := 0 to High(TPA) do
begin
if (i = > 20) then
WeAreTooFar
else Break;
end;
end;

I might be talking out my bum hole, it is too late.

-Boom


Not necessarily what I was looking for, but I should definitely be using TPA's to do this!

I appreciate the help nonetheless Dynamite :D