GetClosestPlayer
#1

Can someone give me that function? i searched but no results
Reply
#2

here's mine
pawn Код:
stock GetClosestPlayer(playerid,Float:limit)
{
    new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2;
    GetPlayerPos(playerid,x1,y1,z1);
    new Float:Range = 999.9;
    new id = -1;
    foreach(Player,i)
    {
        if(playerid != i)
        {
            GetPlayerPos(i,x2,y2,z2);
            new Float:Dist = GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
            if(floatcmp(Range,Dist) == 1 && floatcmp(limit,Range) == 1)
            {
                Range = Dist;
                id = i;
            }
        }
    }
    return id;
}
Reply
#3

GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
?

post that too
Reply
#4

this is from someone else, I think lucirado or something like it.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
    return floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1,rx2),2)),floatsqroot(floatpower(floatsub(ry1,ry2),2))),floatsqroot(floatpower(floatsub(rz1,rz2),2)));
}
Reply
#5

I have a function that works like this:

pawn Код:
stock ProxDetectorS(Float:radi, playerid, targetid)  //[GameMode] The GodFather Function
{
    if(IsPlayerConnected(playerid)&&IsPlayerConnected(targetid))
    {
        new Float:posx, Float:posy, Float:posz;
        new Float:oldposx, Float:oldposy, Float:oldposz;
        new Float:tempposx, Float:tempposy, Float:tempposz;
        GetPlayerPos(playerid, oldposx, oldposy, oldposz);
        GetPlayerPos(targetid, posx, posy, posz);
        tempposx = (oldposx -posx);
        tempposy = (oldposy -posy);
        tempposz = (oldposz -posz);
        if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
        {
            return 1;
        }
    }
    return 0;
}
I hope that i have helped
Reply
#6

Quote:
Originally Posted by cessil
Посмотреть сообщение
this is from someone else, I think lucirado or something like it.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:rx1,Float:ry1,Float:rz1,Float:rx2,Float:ry2,Float:rz2)
{
    return floatadd(floatadd(floatsqroot(floatpower(floatsub(rx1,rx2),2)),floatsqroot(floatpower(floatsub(ry1,ry2),2))),floatsqroot(floatpower(floatsub(rz1,rz2),2)));
}
function with tag result used before definition, forcing reparse. at the stock Float:... line
Reply
#7

heres a better i think, shouldnt range be 99999 for the whole of san andreas?

pawn Код:
public GetClosestPlayer(p1)
{
    new Float:dis,Float:dis2,player;
    player = -1;
    dis = 99999.99;
    foreach(Player,x)
    {
        if(x != p1)
        {
            dis2 = GetDistanceBetweenPlayers(x,p1);
            if(dis2 < dis && dis2 != -1.00)
            {
                dis = dis2;
                player = x;
            }
        }
    }
    return player;
}

new closest = GetClosestPlayer(playerid);
        if(closest == -1 || GetDistanceBetweenPlayers(playerid,closest) > 7) return SendClientMessage(playerid,COLOR_RED,"There are no players closes enough");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)