That's funny, I'm working on a script to do exactly the same thing!
I see two potential problems. First, I wouldn't put a new inside a for loop. It's more efficient to create it once, and reuse it in the for loop. This may be the source of your crashing.
Second, this code is wrong:
PHP Code:
get_players(PlayerList, PlayerCount, "c");
for (new i=0; i<PlayerCount; i++)
It should be:
PHP Code:
for (new i = 1; i < 33; i++)
because cs_get_user_team() takes a parameter of 1 to 32, NOT 0 to 31 (player ID 0 is reserved for specifying all users) AND the player list is not always contiguous (there may be empty slots in the player array). You may also need to check every ID with is_user_connected(i) before you call cs_get_user_team() or that call may fail.