Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

Looping through victims for zombie

$
0
0
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


Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>