View Single Post
Old 02-16-2009, 07:35 PM   #1
Cohsty243
Rookie
 
Cohsty243's Avatar
 
Join Date: Apr 2007
Posts: 67
Question Select Random Client

I am trying to select a random client or rather a random client number, Like so:
Code:
//Choose a random client and set his values
	int randNum;
	do {
			randNum = Q_irand ( 0, level.maxclients );
	} while ( !level.clients[randNum] )
However I don't know if this works or if its efficient. What I am trying to do is make Q_irand return a random client number that is 0 through the highest client number which i believe is level.maxclients, but I am unsure.

I am also unsure whether or not this is including connected, intermission, or playing clients. I think it is all of the above. I could probably do a check with sessions right?

I added the condition (!level.clients[randNum]) because I wanted to make sure that a client actually existed at the number. not sure if that method is correct though.

I have another question too..
Okay say there are 3 clients. client[0], client[1], and client[2].
If client[1] disconnects, will the clientnumber of client[2] decrease to client[1]?
Or, if client[1] disconnects and a new client connects, does he replace client[1]'s slot?

I think what I am basically trying to ask is that, will there ever be times when the client numbers are NOT consecutive? like 1,4,5,6,7?
Cohsty243 is offline   you may: quote & reply,