PHP Code:
for(new i=0; i<get_maxplayers(); i++) {
if(get_user_team(i) == 1 && get_user_team(i) == 2)
cs_set_user_team(i, CS_TEAM_CT)
g_Players++;
}
You shouldn't put i<get_maxplayers() as the condition; the function gets called for every loop. Instead you should store get_maxplayer() in a variable before and use that.
Also, it seems like you're checking if the user is on T and CT at the same time. I think this would be better:
PHP Code:
if(get_user_team(i) == 1)
Another problem... since you don't check to see if the player index is connected before doing g_Players++, your random number can have a player index that doesn't exist. If you have half your server full, roughly 50% of the time it won't work. You should do something like:
PHP Code:
new maxplayers = get_maxplayers()
for(new i=1; i<=maxplayers; i++) {
if(is_user_connected(i)
g_Players++
if(get_user_team(i) == 1)
cs_set_user_team(i, CS_TEAM_CT)
}
Notice it's starting at 1 because index 0 is the server.
[edit] Oh and you'll want to check i<=maxplayers, since if you have 32 slots, index 32 is a valid player index. Goes from 1 to maxplayers. Updated code to match.
Also I just realized the situation is somewhat more complicated, in that you could have empty spots in your player indexes. You'll have to create an array to store the valid player indexes connected to your server.
PHP Code:
new maxplayers = get_maxplayers()
new indexArray[32]
for(new i=1; i<=maxplayers; i++) {
if(is_user_connected(i)
{
indexArray[g_Players] = i
g_Players++
}
if(get_user_team(i) == 1)
cs_set_user_team(i, CS_TEAM_CT)
}
new g_ID = indexArray[random_num(0, g_Players - 1)]