SRL Archive - General S.M.A.R.T.

TileWalking.


Wizzup?

2007-12-24 13:46:49

Hey, we need tile walking for SMART.
I made this, quickly.

It walks from edgeville to the zamorak mage (can be done on f2p and p2p, on f2p the zammy mage just isn't there. :p )

Is there a way to make the walking more accurate with rotation?
It works, but it isn't 100% acc.
Can you make a more accurate one, Ben?

Here's the code:


program New;

{.include smart.scar}
{.include srl/srl.scar}

{const
MMX1 = 570;
MMY1 = 5;
MMX2 = 715;
MMY2 = 160;
MMCX = 643;
MMCY = 84; }

Function AtTile(Tile: TPoint; Dist: Integer): Boolean;

Var
P: TPoint;
Begin
GetMyPos(P.X, P.Y);
Result := Distance(P.X, P.Y, Tile.X, Tile.Y) <= Dist;
writeln('Current Tile: (' + inttostr(p.x) + ' ,'+inttostr(p.y) + ')');
End;

Function WalkTile(Tile: TPoint; Disttol, Randomness: Integer): Boolean;

Var
wTile, P: TPoint;
d, degs: extended;
dist, t: integer;

Begin
Result := False;
Randomize(Tile.X, Randomness);
Randomize(Tile.Y, Randomness);

GetMyPos(P.X, P.Y);
Degs := rs_GetCompassAngleDegrees;
writeln('Compass angle: ' + floattostr(Degs));
D := Degrees(ArcTan2(p.y - tile.y, p.x-tile.x)) - 90;
d := d - degs;
writeln('Point angle' + floattostr(d));
writeln('CompassPoint angle: ' + floattostr(d - degs));
dist := Distance(MMCX, MMCY, p.x-tile.x + mmcx, p.y-tile.y + mmcy) * 4;
wTile.X := Round(MMCX + dist * Sin(D * pi / 180));
wTile.Y := Round(MMCY + dist * Cos(D * pi / 180));

If Not rs_OnMiniMap(wTile.X, wTile.Y) Then
Begin
WriteLn('Not in minimap');
WriteLn('('+inttostr(wtile.x)+','+inttostr(wtile.y)+')');
Exit;
End;
Result := True;
If AtTile(Tile, DistTol) Then
Begin
WriteLn('Already at tile');
Exit;
End;
mouse(wtile.x, wtile.y, 0, 0, true);
t := getsystemtime;
While Not AtTile(Tile, DistTol) And ((getsystemtime - t) < 60000) Do
Begin
Wait(2000);
End;

result := (getsystemtime - t) < 60000;
End;

Procedure RecordPath;

Var
I, x, y: Integer;
Begin
Repeat
Wait(500);
If IsFKeyDown(11) Then
Begin
GetMyPos(x, y);
WriteLn('TPA['+IntToStr(I) + '].X := ' + IntToStr(x)+';');
WriteLn('TPA['+IntToStr(I) + '].Y := ' + IntToStr(y)+';');
I := I + 1;
End;
Until IsFKeyDown(8);
End;

{var
x, y: integer; }

Var
TPA: TPointArray;
p:tpoint;
i:integer;

begin
ClearDebug;
SmartSetup('ams5', false, false);
SetTargetDC(SmartGetDC);
setupsrl;
SetLength(TPA, 9);
{3049, 4832} // Middle mage
TPA[0] := Point(3087, 3496); // Oustside bank
TPA[1] := Point(3094, 3491);
TPA[2] := Point(3100, 3500);
TPA[3] := Point(3103, 3510);
TPA[4] := Point(3104, 3517); // In front of ditch
TPA[5] := Point(3110, 3525);
TPA[6] := Point(3110, 3536);
TPA[7] := Point(3107, 3544);
TPA[8] := Point(3106, 3555); // At mage
for i := 0 to high(tpa) do
begin
GetMyPos(P.X, P.Y);
writeln(inttostr(tpa[i].x) + ','+inttostr(tpa[i].y));
writeln('Walking tile number: ' + inttostr(i));
WalkTile(tpa[i], 3, 0);
wait(1000);
end;
end.

Markus

2007-12-24 13:52:16

Instead of rs_getcompassangle use rs_getminimapangle. Is a bit more accurate, or at least it was in KYAB.

Wizzup?

2007-12-24 13:56:29

From: Markus
Instead of rs_getcompassangle use rs_getminimapangle. Is a bit more accurate, or at least it was in KYAB.


I discovered I forgot to call SetTargetDC(SmartGetDC). Setting it helped a bit, as well. :)

LordGregGreg

2007-12-24 14:04:57

i will stab a rusty school table leg through the person who released smart2 or tile walking to rs members.

other than that, good job wizzy :D

Wizzup?

2007-12-24 14:06:50

From: LordGregGreg
i will stab a rusty school table leg through the person who released smart2 or tile walking to rs members.

other than that, good job wizzy :D


It is only for SSRL. :)

pwnaz0r

2007-12-24 14:10:34

From: Wizzup?
It is only for SSRL. :)


GOOD.

Smartzkid

2007-12-24 15:30:22

const
MinimapInt1 = 'rg.o'; //int
MinimapInt2 = 'vf.c'; //int
CompassAngle = MinimapInt1;
MapOffsetAngle = MinimapInt2;

//Benland100; Returns the current map angle in degrees
function GetMinimapAngleDeg: extended;
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) and $7FF;
result:= clientAngle * 180 / 1024;
end;

//Benland100; Returns the current map angle in radians
function GetMinimapAngleRad: extended;
var
clientAngle: integer;
begin
clientAngle:= (SmartGetFieldInt(0,CompassAngle) + SmartGetFieldInt(0,MapOffsetAngle)) mod 2048;
result:= clientAngle * Pi / 1024;
end;

Accurate to 0.0001% according to Ben.

Returns the actual map rotation, not compass.

EDIT: This should be helpful, too:

//Benland100; converts the tile position tileX,tileY to a minimap location
procedure TileToMinimap(tileX, tileY: integer; var screenX, screenY: integer);
var
angle: extended;
tempX, tempY: integer;
begin
angle:= getMinimapAngleRad;
GetMyPos(tempX, tempY);
tempX:= (tileX - tempX) * 4 - 2;
tempY:= (tileY - tempY) * 4 - 2;
screenX:= round(tempX*cos(angle) - tempY*sin(angle)) + 643;
screenY:= round(tempX*sin(angle) + tempY*cos(angle)) + 84;
end;

Wizzup?

2007-12-24 17:07:21

It gives me compiling errors, Smartzkid… :(

BenLand100

2007-12-24 20:39:43

From: Wizzup?
It gives me compiling errors, Smartzkid… :(

Get the new SMART that I posted ;)

Wizzup?

2007-12-25 04:57:42

From: BenLand100
Get the new SMART that I posted ;)


Thanks…. lol. :garfield:

EDIT: updated the code. way more accurate.