SRL Archive - Reflection Help

MSToTile?


Runescapian321

2009-07-11 17:43:57

Well there's a TileToMS, I was wondering if it's possible to have an MSToTile? Something like:

function MSToTile(x,y : integer) : TPoint;

Here's TileToMS:

function TileToMS(Tile:TPoint; height: integer): TPoint;

var
cx, cy, cz, dx, dy, dz, locX, locY, layer: Integer;
pitch, yaw, sinYaw, cosYaw, sinPitch, cosPitch, rotation: extended;

begin
locX:= Tile.x - SmartGetFieldInt(0, BaseX);
locY:= Tile.y - SmartGetFieldInt(0, BaseY);
if not (InRange(LocX, 0, 103) or InRange(LocY, 0, 103)) then
Exit;
layer:= SmartGetFieldInt(0,BaseLayer);
if (layer < 3) and ((2 and SmartGetFieldArray3DByte(0,GroundSettings,1,locX,locY)) = 2) then
Inc(layer);
cz:= SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX,locY+1) +
SmartGetFieldArray3DInt(0,GroundHeights,layer,locX+1,locY+1);
cx:= locX * 128 + 64 - SmartGetFieldInt(0,CamX);
cy:= locY * 128 + 64 - SmartGetFieldInt(0,CamY);
cz:= (cz / 4) - height - SmartGetFieldInt(0,CamZ);
pitch:= SmartGetFieldInt(0,CamPitch) * Pi / 1024;
yaw:= SmartGetFieldInt(0,CamYaw) * Pi / 1024;
sinYaw:= sin(yaw);
cosYaw:= cos(yaw);
sinPitch:= sin(pitch);
cosPitch:= cos(pitch);
rotation:= cosYaw*cy-sinYaw*cx;
dx:= Round(sinYaw*cy+cosYaw*cx);
dy:= Round(sinPitch*cz+cosPitch*rotation);
dz:= Round(cosPitch*cz-sinPitch*rotation);
try
Result.x:= (dx * 512) / dy + 256;
Result.y:= (dz * 512) / dy + 167;
except end;
end;

I'd do it myself, but I don't really understand all of the SmartGetFieldInt stuff :\ Could someone tell me if this is possible and/or point me in the right direction and/or make an MSToTile function? :)

Da 0wner

2009-07-11 17:47:48

Go on MSN.

Btw I'll try.

Naike

2009-07-11 17:49:02

It's possible, but why?

You already got the tile infront of you, no need to click MM to get there ^^

Runescapian321

2009-07-11 17:49:50

I'm finding something with color, then I want the tile of it for future use :)

Da 0wner

2009-07-11 18:05:49

Yeah, that math is too complicated :(.

Ben can do it :D.

The Little

2009-07-11 20:48:14

That was actually a function I was missing :D, not nearly pro enough to help on it though :(

marpis

2009-07-11 23:13:43

This is not very efficient nor accurate, but you'll get the idea:

function MStoTile(x, y: integer): TPoint;
var
MyPos, MSP: TPoint;
ax, xy: integer;
begin
result := Point(-1, -1);
MyPos := GetMyPos;
for ax := (MyPos.x - 25) to (MyPos.x + 25) do
for ay := (MyPos.y - 25) to (MyPos.y + 25) do
begin
MSP := TileToMS(Point(ax, ay), 1);
if Distance(x, y, MSP.x, MSP.y) < 100 then
begin
result := Point(ax, ay);
exit;
end;
end;
end;