Raised This Month: $ Target: $400
 0% 

Crashing the server


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 08-04-2011 , 14:50   Crashing the server
Reply With Quote #1

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 
Diegorkable is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-04-2011 , 14:58   Re: Crashing the server
Reply With Quote #2

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.
__________________
fysiks is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-04-2011 , 15:24   Re: Crashing the server
Reply With Quote #3

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
__________________
Hunter-Digital is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 08-04-2011 , 18:22   Re: Crashing the server
Reply With Quote #4

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?

Last edited by Diegorkable; 08-04-2011 at 18:24.
Diegorkable is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-04-2011 , 19:06   Re: Crashing the server
Reply With Quote #5

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.
__________________
Hunter-Digital is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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