A guy asked me for a code that chooses 2 random players and send them to TT/CT. I gave him 2 codes, though I wonder which is better.
PHP Code:
new plr1, plr2
start:
plr1 = random_num(1, g_maxplayers)
if(!is_user_connected(plr1)) goto start
cs_set_user_team(plr1, CS_TEAM_CT)
second:
plr2 = random_num(1, g_maxplayers)
if(plr2 == plr1 || !is_user_connected(plr2)) goto second
cs_set_user_team(plr2, CS_TEAM_TT)
PHP Code:
new random, random2
do { random = random_num(1, g_maxplayers) } while(!is_user_connected(random))
cs_set_user_team(random, CS_TEAM_CT)
do { random2 = random_num(1, g_maxplayers) } while(random == random2 || !is_user_connected(random2))
cs_set_user_team(random2, CS_TEAM_TT)
IMO, they are the same, I mean, doesn't do-while work in that way?
PD: Pasta code