Looping through victims for zombie
#1

Well, I've this function to get the player within the range of zombie. Today I was with my friend and all the zombies were after him and ignored me, so I thought that the loop is taking the player which comes in it on first that means if there are more than 1 player near the zombies, it won't get the other players. So I'm thinking something like to get the ids of the players near the zombies and return a random id from those player ids for the zombie. But I got no idea how would I make that.

PHP Code:
for(new playerid 0playerid MAX_PLAYERSplayerid++)
    {
        if(!
IsPlayerNPC(playerid) && IsPlayerConnected(playerid))
        {
            new 
Float:xFloat:yFloat:z;
            
FCNPC_GetPosition(npcidxyz);
            if(
IsPlayerInRangeOfPoint(playeridGetVictimDetectRange[playerid], xyz) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT && GetPlayerInterior(playerid) == && GetPlayerVirtualWorld(playerid) == 0)
            {
                return 
playerid;
            }
        }
    } 
EDIT: At the moment, I made this, if I look it at it, the code looks pretty bad and unoptimized, so I gotta find a better way, help me.
PHP Code:
new ids[MAX_PLAYERS],i=0;
    for(new 
playerid 0playerid MAX_PLAYERSplayerid++)
    {
        if(!
IsPlayerNPC(playerid) && IsPlayerConnected(playerid))
        {
            new 
Float:xFloat:yFloat:z;
            
FCNPC_GetPosition(npcidxyz);
            if(
IsPlayerInRangeOfPoint(playeridGetVictimDetectRange[playerid], xyz) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT && GetPlayerInterior(playerid) == && GetPlayerVirtualWorld(playerid) == 0)
            {
                
ids[i] = playerid;
                
i++;
            }
        }
    }
    if(
!= 0)
    {
        return 
ids[random(i)];
    }
    return 
INVALID_PLAYER_ID
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: 2 Guest(s)