Looping through victims for zombie
#2

Modified version of this: http://forum.sa-mp.com/showpost.php?...50&postcount=2

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
}
Edit: oh, you want random not closest, your attempt is good, will check in a sec
Reply


Messages In This Thread
Looping through victims for zombie - by StrikerZ - 27.09.2017, 15:36
Re: Looping through victims for zombie - by Misiur - 27.09.2017, 15:47
Re: Looping through victims for zombie - by StrikerZ - 27.09.2017, 15:51
Re: Looping through victims for zombie - by Misiur - 27.09.2017, 15:59
Re: Looping through victims for zombie - by StrikerZ - 27.09.2017, 16:03
Re: Looping through victims for zombie - by StrikerZ - 29.09.2017, 06:04
Re: Looping through victims for zombie - by Misiur - 29.09.2017, 06:21
Re: Looping through victims for zombie - by StrikerZ - 29.09.2017, 06:24
Re: Looping through victims for zombie - by Misiur - 29.09.2017, 06:26
Re: Looping through victims for zombie - by AbyssMorgan - 29.09.2017, 06:32

Forum Jump:


Users browsing this thread: 1 Guest(s)