Where is a player added to the client group?
by Mike Stoddart · in Torque Game Engine · 06/27/2002 (8:17 am) · 14 replies
I'm trying to find out where the player is added to the clientGroup. I don't have Visual Studio installed (due to PC reinstallation), so I'm limited to searching the scripts for now.
The reason I ask is that I'm adding a non-playing bot (purely for testing), but it doesn't appear to be part of the clientGroup. So when I retrieve a list of clients in the game the bot is not one of them.
Thanks
The reason I ask is that I'm adding a non-playing bot (purely for testing), but it doesn't appear to be part of the clientGroup. So when I retrieve a list of clients in the game the bot is not one of them.
Thanks
#2
Thanks
06/27/2002 (10:28 am)
Hmmm I'm already doing all that, but no sign of the bot in the client group.Thanks
#3
06/27/2002 (10:34 am)
a bot (aiPlayer) has its own client. The aiplayer adds a whole client to the game rather than just a playermodel.
#4
06/27/2002 (10:46 am)
This is what I'm doing:function GameConnection::onBotConnect(%client, %name)
{
%client.guid = 0;
addToServerGuidList( %client.guid );
// Set admin status
%client.isAdmin = false;
%client.isSuperAdmin = false;
// Save client preferences on the connection object for later use.
%client.gender = "Male";
%client.armor = "Light";
%client.race = "Human";
%client.skin = addTaggedString( "base" );
%client.setPlayerName(%name);
%client.score = 0;
//
$instantGroup = ServerGroup;
$instantGroup = MissionCleanup;
echo("CADD: " @ %client @ " " @ %client.getAddress());
$Server::PlayerCount++;
}
function addBot(%teamId, %classId, %numBots)
{
for (%count=0; %count<%numBots; %count++)
{
%bot = new GameConnection();
%bot.name = "Bot" @ %player;
%bot.nameBase = "Bot" @ %player;
%bot.onBotConnect(%bot.nameBase);
// Join Team
if (%teamId == 1)
{
%bot.team = $Game::Team1;
%bot.classId = %classId;
// Increase the number of players on the given team
%bot.team.numPlayers++;
//%this.spawnPlayer();
%spawnPoint = pickSpawnPoint(%bot);
}
else if (%teamId == 2)
{
%bot.team = $Game::Team2;
%bot.classId = %classId;
// Increase the number of players on the given team
%bot.team.numPlayers++;
//%this.spawnPlayer();
%spawnPoint = pickSpawnPoint(%bot);
}
// Create Player
%player = new Player() {
dataBlock = $Game::playerClassDatablocks[%teamId, %classId];
client = %bot;
};
MissionCleanup.add(%player);
%bot.name = "Bot" @ %player;
%bot.nameBase = "Bot" @ %player;
%bot.score = 0;
%bot.isABot = true;
%player.name = "Bot" @ %player;
%player.nameBase = "Bot" @ %player;
%player.setPlayerTeamId(%teamId);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(60);
%player.setShapeName(%player.name);
MessageAll('AddPlayerToTeam', '\c2%2 joined %4',
%bot,
%bot.nameBase,
%bot.team,
%bot.team.description,
%bot.score,
$Game::playerClassNames[%bot.team.teamId, %bot.classId]);
}
echo("We now have " @ ClientGroup.getCount() @ " players");
}
#5
-----------------------------------------------
Anybody have an idea how to add AIPlayers to the ClientGroup to be added at startup along with player?
I can add them from bound keys now after player is in the game and have them spawning at their own botSpawnPoints but I want to have the capability to also have them spawn in automatically as well.
Trying to add them in GameConnection::onClientEnterGame as suggested above doesn't appear to work because the clients have already been informed of the gameStart in the startGame function[ (server/scripts/game.cs)
What I think needs to happen is AIPlayers need to be "registered" with the clientGroup somehow (via the startGame function?) and then go the process of being added (along with players) thru the onClientEnterGame. Does this sound reasonable--or am I off track?
---------------------------------------------------
I am trying something similar; calling a function to addAIPlayer(s) but I don't see how the ClientGroup is derived. OR, as Robert suggests above, its the createPlayer function adding to the ClientGroup?
In common/server/missionDown.cs I find:
GameConnection::onClientEnterGame(%this)
...
%this.spawnPlayer();
Which leads to:
GameConnection::spawnPlayer(%this)
...
%this.createPlayer(%spawnPoint);
So this leads me to believe that the client has to be "registered" prior to createPlayer.
06/27/2002 (11:20 pm)
Mike, I missed your thread and posted almost the same question in another thread---> So I'm moving my question here:-----------------------------------------------
Anybody have an idea how to add AIPlayers to the ClientGroup to be added at startup along with player?
I can add them from bound keys now after player is in the game and have them spawning at their own botSpawnPoints but I want to have the capability to also have them spawn in automatically as well.
Trying to add them in GameConnection::onClientEnterGame as suggested above doesn't appear to work because the clients have already been informed of the gameStart in the startGame function[ (server/scripts/game.cs)
What I think needs to happen is AIPlayers need to be "registered" with the clientGroup somehow (via the startGame function?) and then go the process of being added (along with players) thru the onClientEnterGame. Does this sound reasonable--or am I off track?
---------------------------------------------------
I am trying something similar; calling a function to addAIPlayer(s) but I don't see how the ClientGroup is derived. OR, as Robert suggests above, its the createPlayer function adding to the ClientGroup?
In common/server/missionDown.cs I find:
GameConnection::loadMission(%this)
...
if (%this.isAIControlled())
{
// Cut to the chase...
%this.onClientEnterGame();
}
else--I really don't understand what's happening here.GameConnection::onClientEnterGame(%this)
...
%this.spawnPlayer();
Which leads to:
GameConnection::spawnPlayer(%this)
...
%this.createPlayer(%spawnPoint);
So this leads me to believe that the client has to be "registered" prior to createPlayer.
#6
Might this be what you want? I'm not actually using aiConnection although I'm starting to think that I should.
06/28/2002 (7:12 am)
I just found this in aiConnection.cc:ConsoleFunction(aiConnect, S32 , 2, 20, "aiConnect(val 0...n);")
{
// Create the connection
AIConnection *aiConnection = new AIConnection();
aiConnection->registerObject();
// Add the connection to the client group
[b]SimGroup *g = Sim::getClientGroup();
g->addObject( aiConnection );[/b]
// Prep the arguments for the console exec...
// Make sure and leav args[1] empty.
const char* args[21];
args[0] = "onConnect";
for (S32 i = 1; i < argc; i++)
args[i + 1] = argv[i];
// Execute the connect console function, this is the same
// onConnect function invoked for normal client connections
Con::execute(aiConnection, argc + 1, args);
return aiConnection->getId();
}Might this be what you want? I'm not actually using aiConnection although I'm starting to think that I should.
#7
06/28/2002 (8:51 am)
AHA...so then it's a matter of getting the aiconnection registered somewhere within game.cs prior to createPlayer, right? And prior to the startGame function being called?
#8
It doesn't work 100%, as it only seems to end up with 2 clients in the ClientGroup. I'll keep working on it though.
06/28/2002 (8:59 am)
I just added the following into my script right at the end of my addBot function:ClientGroup.add(%bot);
It doesn't work 100%, as it only seems to end up with 2 clients in the ClientGroup. I'll keep working on it though.
#9
06/28/2002 (9:06 am)
Loop through all the clients and if they are AI controlled then call that function.
#10
06/28/2002 (9:09 am)
Yeah silly me, I had the ClientGroup.add() outside of the for loop. Duuuuuh!
#11
However, if I'm right, then checking the pre-registered clients doesn't add a new client to the list.
help, I'm confused (color me dense but trying :)
06/28/2002 (9:17 am)
Robert, could you explain a little more about what the clients are? I am under the impression that the client is basically a "reserved" connection; that is, there would be a unique client for a given object. Is this correct? If it's not correct, then I understand your comment about checking for aiControlled clients....However, if I'm right, then checking the pre-registered clients doesn't add a new client to the list.
help, I'm confused (color me dense but trying :)
#12
What you have to do to add, lets say, 5 AI players into the game is create a loop, such as:
You'll want to do this before you load the mission and before you send mission loading info to the normal clients.
06/28/2002 (10:11 am)
Quote:Robert, could you explain a little more about what the clients are? I am under the impression that the client is basically a "reserved" connection; that is, there would be a unique client for a given object. Is this correct? If it's not correct, then I understand your comment about checking for aiControlled clients....Yes, it is my understanding that clients are a "reserved" connection.
However, if I'm right, then checking the pre-registered clients doesn't add a new client to the list.
help, I'm confused (color me dense but trying :)
What you have to do to add, lets say, 5 AI players into the game is create a loop, such as:
...
%count = 5;
while(%count--)
{
aiConnect("bot" @ %count);
}You'll want to do this before you load the mission and before you send mission loading info to the normal clients.
#13
06/28/2002 (11:11 am)
Thanks Robert: and, should that be done prior to the following in game.cs (function startGame()):// Inform the client we're starting up
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameStart');
// Other client specific setup..
%cl.score = 0;
}I tried to add such a loop on the onMissionLoaded function right before the call to startGame():function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
// Nothing special for now, just start up the game play.
startGame();but that called the error check at the beginning of:function startGame()
{
if ($Game::Running) {
error("startGame: End the game first!");
return;
}
#14
You are going to want to add it before you send anything to the clients. So I would suggest adding it on server creation in the function createServer.
EDIT:
In server.cs
Thats how I would do it.
06/28/2002 (11:19 am)
I would add it way before that. You are going to want to add it before you send anything to the clients. So I would suggest adding it on server creation in the function createServer.
EDIT:
In server.cs
function createServer(%serverType, %mission)
{
// whole bunch of stuff here ...
// Load the mission
$ServerGroup = new SimGroup(ServerGroup);
// Add Bot Stuff here
// or call a function to do it or whatever...
%count = 5;
while(%count--)
{
aiConnect("bot" @ %count);
}
onServerCreated();
loadMission(%mission, true);
}Thats how I would do it.
Torque 3D Owner Robert Blanchet Jr.
function GameConnection::createPlayer(%this, %spawnPoint)
line #276 and down