GetClosestPlayer (originally posted by cessil)
#1

Hello! I took this code from some post by cessil, somebody tell what's wrong in this code!
It takes all players around san andreas instead of taking the closest one.

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)));
}

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.0; //What is float suppose to mean? i change it to 5.0 and still doesn't work
    new id = -1;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && 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;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if ((newkeys & KEY_LOOK_BEHIND) && !(oldkeys & KEY_LOOK_BEHIND)) //if he press this key, it will take the closest wanted player but it takes all wanted players in the game o_O"
    {
        GetClosestPlayer(playerid,5.0); //The wanted player must be in range of 5.0 from the cop
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsCop[playerid] == true && IsWanted[i] == true)
            {
                //rest of code
            }
        }
    }
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)