nearest player
#4

pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <foreach>
#include <zcmd>

// MAIN:

main()
{
    print("Development Mode: closest_player_to_player.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// COMMANDS:

CMD:closestplayer(playerid, params[])
{
    GetClosestPlayerToPlayer(playerid);
    return 1;
}

// FUNCTIONS:

stock GetClosestPlayerToPlayer(playerid)
{
    new Float:x, Float:y, Float:z, closest_player = -1, Float:distance, Float:temp;
    GetPlayerPos(playerid, x, y, z);

    foreach(new i: Player)
    {
        if(i == playerid) continue;

        if(closest_player != -1)
        {
            temp = GetPlayerDistanceFromPoint(i, x, y, z);

            if(temp < distance)
            {
                closest_player = i;
                distance = temp;
            }
        }
        else
        {
            closest_player = i;
            distance = GetPlayerDistanceFromPoint(i, x, y, z);
        }
    }

    new string[144];
    if(closest_player == -1) strcat(string, "No players have been found.");
    else format(string, sizeof(string), "%s (%d) is the closest player to you (%0.2f meters).", PlayerName(closest_player), closest_player, distance);
    return SendClientMessage(playerid, -1, string);
}

stock PlayerName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
Reply


Messages In This Thread
nearest player - by suni - 19.06.2015, 23:43
Re: nearest player - by JaydenJason - 20.06.2015, 00:49
Re: nearest player - by suni - 20.06.2015, 02:11
Re: nearest player - by SickAttack - 20.06.2015, 02:32
Re: nearest player - by FarTooBaked - 20.06.2015, 06:34
Re: nearest player - by suni - 20.06.2015, 21:42
Re: nearest player - by Crayder - 21.06.2015, 03:50
Re: nearest player - by SickAttack - 21.06.2015, 04:43

Forum Jump:


Users browsing this thread: 3 Guest(s)