nearest Player
#1

how to make for example i made rob command

how for example if player did /rob without id it robs the nearest player


just give me the code of nearest player

i have rob command but id must be written

tell me how to make get nearest player if no id written

and if there is no near player it will say no near players\ /rob [id]

the range of point must be 8 (distance)
Reply
#2

pawn Код:
#define GetDistanceBetweenCoords(%1,%2,%3,%4,%5,%6) floatsqroot((%4 - %1)*(%4 - %1) + (%5 - %2)*(%5 - %2) + (%6 - %3)*(%6 - %3))

stock GetPlayerClosestPlayer(playerid,bool:NPC = true)
{
    new pid = INVALID_PLAYER_ID,
        Float:distance = 8.0,
        Float:tmp[7];
    GetPlayerPos(playerid,tmp[0],tmp[1],tmp[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        if(!IsPlayerConnected(i)) continue;
        if(NPC == false) if(IsPlayerNPC(i)) continue;
        GetPlayerPos(i,tmp[3],tmp[4],tmp[5]);
        tmp[6] = GetDistanceBetweenCoords(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
        if(distance < tmp[6]) continue;
        distance = tmp[6];
        pid = i;
    }
    return pid;
}

// Usage: GetPlayerClosestPlayer( playerid );
Reply
#3

command(rob, playerid, params[])
{
new ID;
return 1;
}
ok i gave u new ID
now for example do it for me in that code the nearest player
Reply
#4

Not finished, you should make it. I'll just give you some tips for the beginning.
pawn Код:
#define GetDistanceBetweenCoords(%1,%2,%3,%4,%5,%6) floatsqroot((%4 - %1)*(%4 - %1) + (%5 - %2)*(%5 - %2) + (%6 - %3)*(%6 - %3))

command(rob, playerid, params[])
{
    new
        ID
    ;
    if( !sscanf( params, "r", ID ) )
    {
        // Rob the ID
    }
    else GetPlayerClosestPlayer( playerid );
    return 1;
}

stock GetPlayerClosestPlayer(playerid,bool:NPC = true)
{
    new pid = INVALID_PLAYER_ID,
        Float:distance = 8.0,
        Float:tmp[7];
    GetPlayerPos(playerid,tmp[0],tmp[1],tmp[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        if(!IsPlayerConnected(i)) continue;
        if(NPC == false) if(IsPlayerNPC(i)) continue;
        GetPlayerPos(i,tmp[3],tmp[4],tmp[5]);
        tmp[6] = GetDistanceBetweenCoords(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
        if(distance < tmp[6]) continue;
        distance = tmp[6];
        pid = i;
    }
    return pid;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)