17.02.2013, 21:52
hm.. despite 3 or 4 optimisations, i cannot see why this algorithm should fail.. are you sure the surrounding code is ok? ^^
brb, onto editing later, expect some faster script, which will not change behavior i guess...
edit:done:
...this wont fix the bug, but its a little faster - the reasons are obvious. hm... despits that, i cant help without seeing: more coooode :P
edit2: ok, i will inlcude that snippet into my actual project FS, lets see what happens. iam on it, hope youre online in .. 1 hour
brb
brb, onto editing later, expect some faster script, which will not change behavior i guess...
edit:done:
pawn Код:
stock GetNearestDynObject(playerid)
{
new
Float:px,
Float:py,
Float:pz,
currentobject = -1,
Float:distance = 10000.0,
Float:ox,
Float:oy,
Float:oz,
Float:odist;
GetPlayerPos( playerid, px, py, pz );
for( new index = 0; index < CountDynamicObjects(); index++ )
{
if ( !IsValidDynamicObject( index ) ) continue;
GetDynamicObjectPos( index, ox, oy, oz );
odist = floatsqroot(
floatpower( floatsub( ox, px ), 2.0 ) +
floatpower( floatsub( oy, py ), 2.0 ) +
floatpower( floatsub( oz, pz ), 2.0 )
);
if ( odist < distance )
{
currentobject = index;
distance = odist;
}
}
return currentobject;
}
edit2: ok, i will inlcude that snippet into my actual project FS, lets see what happens. iam on it, hope youre online in .. 1 hour
