lfnetwork.com mark read register faq members calendar

Thread: Select Random Client
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 02-16-2009, 06: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,
Old 02-16-2009, 09:14 PM   #2
Tinny
 
Tinny's Avatar
 
Join Date: Apr 2002
Posts: 1,188
Hey Cohsty, I'd do it this way.

I'd create a list of clients that are pickable from and store them in an array such as:

int selectableClients[MAX_CLIENTS];

I'd go through the list of the entities from 0 to < MAX_CLIENTS and then check if they are:

ent && ent->client,

g_entities[i].client->pers.connected == CON_CONNECTED,

g_entities[i].client->sess.sessionTeam != TEAM_SPECTATOR,

(and if you don't want it to be a bot)
!(g_entities[i].r.svFlags & SVF_BOT)

What is intermission, is that the time between siege defense/attack mode, between maps, or between cutscenes?

Ok, then as I go through the g_entities list I select the ones that meet all the criteria above and select their client nums with g_entities[i]->client.ps.clientNum and store it in selectableClients all the while incrementing the numSelectableClients counter or something.

Then I'd use q_irand to select a number from 0 to numSelectableClients, and select the client that's stored in that slot. Something sort of like.

int chosen = q_irand(0, numSelectableClients);

gentity_t *chosenClient = &g_entities[selectableClients[chosen]];

I think that might be the optimal way of doing it, not sure though. As to your other question, I don't think replacements go on. A lot of server and client code stores relations code with the ent's num:

ent->grappleIndex = bob's client num;

Meaning that Bob put ent in one of those strangle hold melee anims that the Kyle boss does or you can do with g_debugmelee. If replacements took place, these sorts of stored values would become useless. Which brings up the question, what happens if there are 32 clients connected, and someone drops and another person takes their place? I think that's how it works but I'm not sure, I'm not sure how it gets rid of relations when a client does get replaced though. So I believe you can have client numbers that are non consecutive.


Redeemed!

An old school mod for jedi academy.
Tinny is offline   you may: quote & reply,
Old 02-16-2009, 11:12 PM   #3
Cohsty243
Rookie
 
Cohsty243's Avatar
 
Join Date: Apr 2007
Posts: 67
Okay, thanks, I will definitely try that out.
Cohsty243 is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > Select Random Client

Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:14 PM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.