Get The Closest Dynamic Object?
#10

Quote:
Originally Posted by MyLife
View Post
Try this.
pawn Code:
stock GetClosestDynamicObject(playerid)
{
    new Float:px,Float:py,Float:pz,
    Float:ox,Float:oy,Float:oz,Float:dist,result = 12345;
    GetPlayerPos(playerid,px,py,pz);
    for(new o; o < CountDynamicObjects(); o++)
    {
        GetDynamicObjectPos(o,ox,oy,oz);
        dist = floatsqroot(floatpower(floatabs(floatsub(px,ox)),2)+floatpower(floatabs(floatsub(py,oy)),2)+floatpower(floatabs(floatsub(pz,oz)),2));
        if(dist < result)
        {
            result = dist;
            return o;
        }
    }
    return 1;
}
Untested.
Quote:
Originally Posted by Tommy_Mandaz
View Post
Is there a way to add the object id? So like GetClosestDynamicObject(playerid, objectid); or something? So that way I can find out which object is the closest.
-.-

pawn Code:
new objectid = GetClosestDynamicObject(playerid);
Reply


Messages In This Thread
Get The Closest Dynamic Object? - by Tommy_Mandaz - 21.06.2011, 18:12
Re: Get The Closest Dynamic Object? - by Sasino97 - 21.06.2011, 18:45
Re: Get The Closest Dynamic Object? - by Babul - 21.06.2011, 18:51
Re: Get The Closest Dynamic Object? - by Tommy_Mandaz - 21.06.2011, 19:30
Re: Get The Closest Dynamic Object? - by Tommy_Mandaz - 25.06.2011, 18:03
Re: Get The Closest Dynamic Object? - by Mauzen - 25.06.2011, 18:04
Re: Get The Closest Dynamic Object? - by Tommy_Mandaz - 25.06.2011, 18:09
Re: Get The Closest Dynamic Object? - by MyLife - 25.06.2011, 18:29
Re: Get The Closest Dynamic Object? - by Tommy_Mandaz - 25.06.2011, 18:32
Re: Get The Closest Dynamic Object? - by Sasino97 - 25.06.2011, 19:57

Forum Jump:


Users browsing this thread: 2 Guest(s)