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

Checking Ranges and respawning.

$
0
0
PHP Code:

timer ZombieRespawnTimer[5000]()
{
    new 
bool:true_foundidFloat:x,Float:y,Float:zcount_zombiesNPCSS[MAX_PLAYERS];
    
count_zombies=0;
     
    for(new 
i=0i<MAX_PLAYERSi++)
    {
        
GetPlayerPos(i,x,y,z);
        for(new 
k=0k<MAX_PLAYERSk++)
        {
            if(
IsPlayerNPC(k))
            {
                if(
IsPlayerInRangeOfPoint(k50xyz))
                {
                    
true_found=true;
                    
id k;
                }

            }    
        }
        if(
true_found)
        {
            
count_zombies++;
            
NPCSS[count_zombies] = id;
        }
        
    }
    if(
count_zombies 20)
    {
        
printf("Found %d more zombies in a area, respawning...",count_zombies-20);
        for(new 
i=0i<count_zombies-20i++)
        {
            
FCNPC_Respawn(NPCSS[i]);
        }
    }


Basically this is the (unoptimized and badly made as i am still testing) code i am using to check with a 5 seconds timer whether there are 20+ npc's in a range, if yes count them and respawn the count-20 npc's.

I am using double loop as i want to check through every npc, and loop to all other npc's, but the problem is the server kinda hangs when the timer gets called and i also know the reason... I was here to ask if someone has a better idea?

Viewing all articles
Browse latest Browse all 18226

Trending Articles



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