27.09.2017, 15:47
Modified version of this: http://forum.sa-mp.com/showpost.php?...50&postcount=2
Edit: oh, you want random not closest, your attempt is good, will check in a sec
pawn Code:
new Float:x, Float:y, Float:z;
FCNPC_GetPosition(npcid, x, y, z);
new Float:minDist = 9999.9; // I guess you don't have FLOAT_INFINITY
new id = INVALID_PLAYER_ID;
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if(!IsPlayerNPC(playerid) && IsPlayerConnected(playerid) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT && GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid) == 0)
{
new Float:dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(dist < minDist && dist < GetVictimDetectRange[playerid])
{
minDist = dist;
id = playerid;
}
}
}
if (id != INVALID_PLAYER_ID) {
// Here's your closest player id, otherwise none found in range
}