Closest one!
#2

Found this with a little search:

pawn Код:
forward GetClosestPlayerToPlayer(playerid);
public GetClosestPlayerToPlayer(playerid)
{
    new Float:dist = 1000.0;
    new targetid = INVALID_PLAYER_ID;
    new Float:x1,Float:y1,Float:z1;
    new Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(i == playerid) continue;
        GetPlayerPos(i,x2,y2,z2);
        tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
        if(tmpdis < dist)
        {
            dist = tmpdis;
            targetid = i;
        }
    }
    return targetid;
}
Hope it helps or set's you in the right direction.
Reply


Messages In This Thread
Closest one! - by GNGification - 21.03.2011, 15:36
Re: Closest one! - by Stigg - 21.03.2011, 15:39
Re: Closest one! - by GNGification - 21.03.2011, 15:41
Re: Closest one! - by Stigg - 21.03.2011, 15:42
Re: Closest one! - by Roomeo - 21.03.2011, 15:43
Re: Closest one! - by XFlawless - 21.03.2011, 15:48
Re: Closest one! - by Roomeo - 21.03.2011, 15:52
AW: Closest one! - by Pablo Borsellino - 21.03.2011, 15:55
Re: Closest one! - by Roomeo - 21.03.2011, 16:32
Re: Closest one! - by Stigg - 21.03.2011, 16:36

Forum Jump:


Users browsing this thread: 1 Guest(s)