17.02.2013, 22:10
You are probably not counting it correctly.
Try with GetPlayerDistanceFromPoint();
pawn Код:
stock GetNearestDynObject(playerid)
{
new
Float: px, Float: py, Float: pz,
currentobject = -1,
Float:distance = -1
;
GetPlayerPos( playerid, px, py, pz );
for( new index = 0; index < CountDynamicObjects(); index++ )
{
if ( !IsValidDynamicObject( index ) ) continue;
new
Float:ox,
Float:oy,
Float:oz
;
GetDynamicObjectPos( index, ox, oy, oz );
new Float:odist = GetPlayerDistanceFromPoint(playerid, ox, oy, oz)
if ( currentobject == -1 )
{
currentobject = index;
distance = odist;
}
else if ( odist < distance )
{
currentobject = index;
distance = odist;
}
}
return currentobject;
}