JPHamlett
2010-07-09 15:59:00
Can someone test this i cant get my reflection to work at all
Function getnearestobjectbyId(id, objType : integer): TRSObject;
var
cur, o : TRSObject;
Dist : extended;
x, y, basey, basex, distTmp : integer;
isobject : boolean;
begin
cur := NullObject;
dist := -1;
for x:= 0 to 104 do
begin
for y:= 0 to 104 do
begin
basex := SmartGetFieldInt(0, hook_static_BaseX);
basey := SmartGetFieldInt(0, hook_static_BaseY);
tile := point(x + basex, y + basey);
o := getObjectAt(tile, objType);
if (o <> NullObject) then
begin
isObject := false;
if (o.ID = id) then
isObject := true;
end;
if (isObject) then
begin
distTmp := Distance(getmypos.x, getmypos.y, o.Tile.x, o.tile.y);
if (cur = nullobject) then
begin
dist := distTmp;
cur := o;
end else
if (distTmp < dist) then
begin
cur := o;
dist := distTmp;
end;
end;
end;
end;
result := cur;
end;