AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Crashing the server (https://forums.alliedmods.net/showthread.php?t=163886)

Diegorkable 08-04-2011 14:50

Crashing the server
 
I have a plugin that does this code every round start, and its crashing the server, and i dont know why. Anyone know why?

PHP Code:

public round_start()
{
    new 
enough get_maxplayers()
    
    if (
enough <= 1)
    {
        
client_print_color(0RED"%s ^4Can ^3NOT ^4start, minimum to start: ^32 ^4Players."PREFIX)
        return 
PLUGIN_HANDLED
    
}
    
    else
    {
        
        new 
players[32], pnumtempid
      
        
get_players(playerspnum"ch"); 
        
        new 
playertot random(pnum)
        new 
nameofp[60]
        
        for (new 
ii<pnum i++)
        {
            
tempid players[i]
            
g_didType[tempid] = false
        
}
        
        while ((
cs_get_user_team(players[playertot]) != CS_TEAM_UNASSIGNED) && (cs_get_user_team(players[playertot]) != CS_TEAM_SPECTATOR))
        {
            
playertot random(pnum)
        }
        
        
cs_set_user_team(players[playertot], CS_TEAM_T)
        
get_user_name(players[playertot], nameofp59)
                
        
client_print_color(0RED"%s ^4The player ^3%s ^4was chosen to be the Terrorist."PREFIXnameofp)
    }
    
    return 
PLUGIN_HANDLED 


fysiks 08-04-2011 14:58

Re: Crashing the server
 
Check for an infinite loop. It's usually easy to tell if it's cause by an infinite loop if you have access to the server's console but it's also easy to test for it. Like I've said many times before, you need to learn to debug.

Hunter-Digital 08-04-2011 15:24

Re: Crashing the server
 
That while() loop will seriously fail if there are no players in any team... even if you add a limiter, it won't do you any good, a better method would be: http://forums.alliedmods.net/showthread.php?t=74666

Diegorkable 08-04-2011 18:22

Re: Crashing the server
 
Instead, I could just add that if get_maxplayers == 0 ill return plugin_handled, hunter-digital.

but anyways, i have the 'enough' variable that is responsible for it, doesnt it work?

Hunter-Digital 08-04-2011 19:06

Re: Crashing the server
 
That makes no sense... get_maxplayers() doesn't change and surely can't be 0.

And like I said, even if you limit the loops to, let's say, the total number of players, it can't guarantee you'll pick every player and you can miss out players... so listen and use the method from that thread to pick random players.


All times are GMT -4. The time now is 03:30.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.