Game Development Community

Racing.Starter dedicated server

by James W. · in Torque Game Engine · 11/25/2007 (11:47 am) · 2 replies

My current code
function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
   commandToClient(%this, 'SetMaxLaps', $Game::Laps);
   
   // Create a new camera object.
   %this.camera = new Camera() {
      dataBlock = Observer;
   };
   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);

   // Client controls the camera by default.
      %this.setControlObject(%this.camera);

// if(!$Game::Running)      //---Commented out, Client on connection to dedicated server 
                            // or hosted multiplayer
                            // if server is running it spawns a camera only and not a 
                            // car for player
                            
// {
   // Create a car object.
      %this.spawnCar();
   
     // %this.setControlObject(%this.car);  //--Temp hack to force control of the car,
                                          // upon spawn has imeditate control of car
                                          // does not wait for timer or start of race
                                          // in dedicated mode or hosted or single.
      // Orbit the camera around the car                                    
      %this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
// }
}

My problem is that when you are connecting to a dedicated server or a hosted multiplayer and the game is already running, it will only spawn a camera and not a player. ( I think, I fixed this)

What I am trying to figure now is how that is if 0 players on connection spawn the car and resart the game so that the countdown timer will work and if there is more than 2 players let the camera spawn and wait until race is over.

I was taking 1 step at a time by trying to figure out away to restart the game first, it would cycle over and over, I callled cycleGame(), but I couldn't figure out how to get it to break the cycle. (Earlier try's)

I hope I am thinking right on how this works.
Thanks in advanced

#1
11/25/2007 (12:07 pm)
I took the starter.fps game and modded it into a racing game. Then it works perfectly out of the box. You can do a dif on the files to figure out what the differences are.
#2
11/25/2007 (12:36 pm)
Thanks Mike,

I see the differnce. Maybe I can call a function to start the game when 2 more players enter the game. I'll give it a try and see what happens. I'll start porting it over.