How do I get pointers to all the players on a server?
by Josh Albrecht · in Torque Game Engine · 09/09/2001 (11:43 am) · 5 replies
How would I get a list of all the clients from the code? I need it to be able to check for collision against my hitboxes. I searched through the docs but I cant seem to find what I need. How would I get pointers to all the players?
#2
09/09/2001 (1:23 pm)
Dont want to. It is too inefficient that way. I just need pointers to the players. There MUST be an obvious way to do this.
#3
To do it from compiled code:
09/09/2001 (2:51 pm)
To do it from a script:%n = ClientGroup.getCount();
for( %i = 0; %i < %n; %i++ ) {
// First get the player
%client = ClientGroup.getObject( %i );
%player = %client.player;
// Check to see if the client is actually controling
// the player object, otherwise he may be a observer
if( %client.getControlObject() == %client.player ) {
// Ok you have a player, do your processing
}
}To do it from compiled code:
SimGroup *clG = Sim::getClientGroup();
for( SimGroup::iterator i = clG->begin(); i != clG->end(); i++ ) {
GameConnection *t = dynamic_cast<GameConnection *>( *i )
if( t ) {
Player *p = dynamic_cast<Player *>( t->getControlObject() );
if( p ) {
// Ok you've got your player
}
}
}
#4
09/09/2001 (6:20 pm)
Thank you very much. After posting my second comment I realized I could just look at the missionLoad code, and I was right. I found exactly what you said there in teh scripts. Thank you though!
#5
Vector- list; // should I use Item or ItemData?
// list get's sent into a function where we obtain all health's on a particular level.....for example.
char* groupName = "L1Health";
SimGroup* pMissionGroup = dynamic_cast(Sim::findObject(groupName));
// it does loop the appropriate number of times, so I know that it is finding the objects
for(SimGroup::iterator itr = pMissionGroup->begin(); itr != pMissionGroup->end(); itr++){
list->push_back(dynamic_cast- (*itr)); // what does dynamic_cast
- (*itr) do????????
}
Now, I don't know if this is the proper way to obtain a list of pointers to these Items that I need. I think it is but what I really need to know is the position of that object. How do I get that?
I tried doing a for loop on my list to access each object in the list but can't seem to get anything. I'm not a C++ guru by all means but have slowly been figuring things out. This I cannot.
Any help would be hugely appreciated.
Thx.
DALO
01/23/2008 (8:59 pm)
Thank you, I've been searching that for quite sometime. I do however have a question. Now that I have the players. How do I keep track of a list of items in a specific SimGroup, (for my AI). Here's what I have:Vector
// list get's sent into a function where we obtain all health's on a particular level.....for example.
char* groupName = "L1Health";
SimGroup* pMissionGroup = dynamic_cast
// it does loop the appropriate number of times, so I know that it is finding the objects
for(SimGroup::iterator itr = pMissionGroup->begin(); itr != pMissionGroup->end(); itr++){
list->push_back(dynamic_cast
}
Now, I don't know if this is the proper way to obtain a list of pointers to these Items that I need. I think it is but what I really need to know is the position of that object. How do I get that?
I tried doing a for loop on my list to access each object in the list but can't seem to get anything. I'm not a C++ guru by all means but have slowly been figuring things out. This I cannot.
Any help would be hugely appreciated.
Thx.
DALO
Torque 3D Owner Pat Wilson