Checking Ranges and respawning.
#1

PHP код:
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?
Reply
#2

Tried this and it exceeds heap size:
PHP код:
timer ZombieRespawnTimer[5000]()
{
    new 
Float:x,Float:y,Float:zcount_zombiesNPCSS[MAX_PLAYERS][MAX_PLAYERS], NPCSSID[MAX_PLAYERS][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))
                {
                    
NPCSS[i][k] ++;
                    
NPCSSID[i][k] = k;
                }
            }    
        }
    }
    for(new 
i=0i<MAX_PLAYERSi++)
    {
        for(new 
k=0k<MAX_PLAYERSk++)
        {
            if(
NPCSS[i][k] > 20)
            {
                
printf("Found %d more zombies in a area, respawning...",NPCSS[i][k]-20);
                
FCNPC_Respawn(NPCSSID[i][k]);
            }
        }
    }         

Reply
#3

One word (or 5?), AttachDynamicAreaToPlayer.

Edit: k isn't after i if you didn't know lol
Reply
#4

Agreed about Dynamic Areas.
Also I recommend to use foreach:
PHP код:
foreach (new FCNPC
Reply
#5

without timers/loops but for 300.0 range
PHP код:
new StreamedNPC[MAX_PLAYERS];
public 
OnPlayerStreamIn(playeridforplayerid){
    if(
IsPlayerNPC(playerid) && IsPlayerNPC(forplayerid)){ //npc for npc
        
StreamedNPC[forplayerid]++;
        if(
StreamedNPC[forplayerid] >= 20){ //reached max npc in 300.0 range
            
        
}
    }
    return 
1;
}
public 
OnPlayerStreamOut(playeridforplayerid){
    if(
IsPlayerNPC(playerid) && IsPlayerNPC(forplayerid)){ //npc for npc
        
StreamedNPC[forplayerid]--;
    }
    return 
1;

Reply
#6

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
without timers/loops but for 300.0 range
PHP код:
new StreamedNPC[MAX_PLAYERS];
public 
OnPlayerStreamIn(playeridforplayerid){
    if(
IsPlayerNPC(playerid) && IsPlayerNPC(forplayerid)){ //npc for npc
        
StreamedNPC[forplayerid]++;
        if(
StreamedNPC[forplayerid] >= 20){ //reached max npc in 300.0 range
            
        
}
    }
    return 
1;
}
public 
OnPlayerStreamOut(playeridforplayerid){
    if(
IsPlayerNPC(playerid) && IsPlayerNPC(forplayerid)){ //npc for npc
        
StreamedNPC[forplayerid]--;
    }
    return 
1;

He wants 50.0 radius!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)