SA-MP Forums Archive
how to - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: how to (/showthread.php?tid=174421)



how to - iJumbo - 05.09.2010

how to calcolate the player distance from player? like a command /distance playerid and show how much meters the playerid is to you?


Re: how to - [XST]O_x - 05.09.2010

pawn Код:
forward GetDistanceBetweenPlayers(playerid,toplayerid);
public GetDistanceBetweenPlayers(playerid,toplayerid)
{
    new Float:x,Float:y,Float:z,Float:x2,Float:y2,Float:z2,Float:result;
    GetPlayerPos(playerid,x,y,z);
    GetPlayerPos(toplayerid,x2,y2,z2);
    distance = floatsqroot(floatpower(floatabs(floatsub(x2,x)),2) + floatpower(floatabs(floatsub(y2,y)),2) + floatpower(floatabs(floatsub(z2,z)),2));
    return floatround(distance);
}



Re: how to - Voldemort - 05.09.2010

pawn Код:
forward Float:GetDistanceBetweenPlayers(p1,p2);

public Float:GetDistanceBetweenPlayers(p1,p2)
{
    new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
    if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
    {
        return -1.00;
    }
    GetPlayerPos(p1,x1,y1,z1);
    GetPlayerPos(p2,x2,y2,z2);
    return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
also
pawn Код:
forward GetClosestPlayer(p1);

public GetClosestPlayer(p1)
{
    new x,Float:dis,Float:dis2,player;
    player = -1;
    dis = 5.0;
    for (x=0;x<MAX_PLAYERS;x++)
    {
        if(IsPlayerConnected(x))
        {
            if(x != p1)
            {
                dis2 = GetDistanceBetweenPlayers(x,p1);
                if(dis2 < dis && dis2 != -1.00) { dis = dis2; player = x; }
            }
        }
    }
    return player;
}



Re: how to - willsuckformoney - 05.09.2010

that should work btw Calculate


Re: how to - iJumbo - 07.09.2010

how to print the distance like in a string ? (%d)


Re: how to - Hiddos - 07.09.2010

Quote:
Originally Posted by gigi1223
Посмотреть сообщение
how to print the distance like in a string ? (%d)
The function itself returns a float value, so your best try is to insert "%f" into your code, along with the corresponding variable.