SRL Archive - Reflection Development

Get nearest object by ID


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;

NCDS

2010-07-09 16:13:15

AFAIK, hooks are broken right now?

Whats with the mass indentations? :blink:

Magiic

2010-07-09 16:31:41

Yeah, I thought hooks were broken too. I get reflection to login, but hooks are outdated.

Narcle

2010-07-09 16:39:43

Most of the hooks are updated, I'm guessing some of the object hooks are still outdated. If someone wants to help get them please don't hesitate. I'll commit it if someone posts them in #613 dev thread. (I can't get/find them all)

MylesMadness

2010-07-09 16:42:31

Holy crap your slandereds are HORRIBLE
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;
Maybe having it easier to read will help you find the error?

3Garrett3

2010-07-09 16:50:07

From: Narcle
Most of the hooks are updated, I'm guessing some of the object hooks are still outdated. If someone wants to help get them please don't hesitate. I'll commit it if someone posts them in #613 dev thread. (I can't get/find them all)


Find the cohen who isn't cohen, and ask him :)

JPHamlett

2010-07-09 17:54:18

From: MylesMadness
Holy crap your slandereds are HORRIBLE
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;
Maybe having it easier to read will help you find the error?


Something in the copy paste messed it up it looks good in my simba but not in villavu for w/e reason

JPHamlett

2010-07-10 20:43:45

Srry for the double post but any feedback on the actual function would be great

lordsaturn

2010-07-10 22:34:58

GetObjectByIDEx is much quicker, because it uses an outward spiral search from your character's position.

Daniel

2010-07-11 08:59:43

From: MylesMadness
Holy crap your slandereds are HORRIBLE

It's entirely up to the individual programmer which coding standards he/she prefers…

Drakan

2010-07-13 09:49:33

[QUOTE=Dan's The Man;723255]It's entirely up to the individual programmer which coding standards he/she prefers…

You remind me of the school systems. "Must be politically correct!"