27.09.2017, 15:59
Your code is good. All I would improve, would be getting the NPC/Zombie position once, not on every iteration.
Other problem you might run into is how often you run this, it might make the zombie twitch between each player
pawn Code:
new ids[MAX_PLAYERS], count = 0;
new Float:x, Float:y, Float:z;
FCNPC_GetPosition(npcid, x, y, z);
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if(!IsPlayerNPC(playerid) && IsPlayerConnected(playerid))
{
if(IsPlayerInRangeOfPoint(playerid, GetVictimDetectRange[playerid], x, y, z) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT && GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid) == 0)
{
ids[count] = playerid;
count++;
}
}
}
if(count != 0)
{
return ids[random(count)];
}
return INVALID_PLAYER_ID;