Closest Dynamic Object
#4

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
Simplified version
pawn Код:
stock GetClosestDynamicObject(playerid)
{
    new px, py, pz, currentobject = -1, Float:distance = -1;
    GetPlayerPos( playerid, px, py, pz );
   
    for( new index = 0; index < CountDynamicObjects(); index++ )
    {
    if ( !IsValidDynamicObject( index ) )
        continue;

        Float:ox, Float:oy, Float:oz;
        GetDynamicObjectPos( index, ox, oy, oz );

        new Float:odist = floatsqroot(
            floatpower( floatabs( floatsub( ox, px ) ), 2.0 ) +
            floatpower( floatabs( floatsub( oy, py ) ), 2.0 ) +
            floatpower( floatabs( floatsub( oz, pz ) ), 2.0 )
        );

        if ( currentobject == -1 )
        {
            currentobject = index;
            distance = odist;
        } else if ( odist < distance )
        {
            currentobject = index;
            distance = odist;
        }
    }

    return currentobject;
}
Edit: It will return the closest object id.
Thanks, +repped.

GetPlayerPos(playerid, px, py, pz);
warning 213: tag mismatch
Reply


Messages In This Thread
Closest Dynamic Object - by Oh - 18.01.2012, 05:48
Re: Closest Dynamic Object - by T0pAz - 18.01.2012, 06:32
Re: Closest Dynamic Object - by T0pAz - 18.01.2012, 08:52
Re: Closest Dynamic Object - by Oh - 18.01.2012, 09:01
Re: Closest Dynamic Object - by PrawkC - 18.01.2012, 09:13
Re: Closest Dynamic Object - by T0pAz - 18.01.2012, 09:14
Re: Closest Dynamic Object - by Oh - 18.01.2012, 09:16
Re: Closest Dynamic Object - by T0pAz - 18.01.2012, 09:19
Re: Closest Dynamic Object - by Oh - 18.01.2012, 09:33

Forum Jump:


Users browsing this thread: 1 Guest(s)