Game Development Community

Modifying the racing intro

by Simon Kilroy · in Torque Game Engine · 04/02/2007 (6:02 am) · 19 replies

I have built a mission based around the starter.racing mission, and changed all the details I have needed to. The one thing I would liek to get rid of is the intro the mission (where the camera is in free-pan around the player, and there is a countdown). So all I want to be left with is just a normal start, with the player able to start moving right away. I went into game.cs and deleted the following:
---------------------------------------------------------------------------------

function countThree()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 3);
}

schedule(1000, 0, "countTwo");
}

function countTwo()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 2);
}

schedule(1000, 0, "countOne");
}

function countOne()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 1);
}

schedule(1000, 0, "startRace");
}

--------------------------------------------------------------------------------

But when I did this, now the mission starts, and I can just free-rotate around the player, but never get to the stage where I can actually move..

Does anyone know how I can just revert this to a normal mission start, eliminating the countdown and the camera rotate? Cheers.

#1
04/02/2007 (6:37 am)
Wherever 'countThree' was called or scheduled, calling 'startRace' should fix that.
#2
04/02/2007 (6:48 am)
I tried that, but I had the same problem as before. The mission loaded and I just had the free camera. The countdown never happened, but I never left the free camera mode and I couldnt move the player as a result (which normally would happen after the countdown finished. Heres the relevant part of my game.cs code

------------------------------------------------------------------------------------

function startGame()
{
if ($Game::Running) {
error("startGame: End the game first!");
return;
}

schedule($Game::WaitTime, 0, "countThree");
}

function countThree()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 3);
}

schedule(1000, 0, "countTwo");
}

function countTwo()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 2);
}

schedule(1000, 0, "countOne");
}

function countOne()
{
// Tell the client to count.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'SetCounter', 1);
}

schedule(1000, 0, "startRace");
}

function startRace()
{
// 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.lap = 0;
%cl.nextCheck = 1;
%cl.setControlObject(%cl.car);
%cl.camera.setFlyMode();
}

// Start the game timer
// if ($Game::Duration)
// $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
$Game::Running = true;

$Game::Running = true;
}

function endGame()
{
if (!$Game::Running) {
error("endGame: No game running!");
return;
}

// Stop any game timers
cancel($Game::Schedule);

// Inform the client the game is over
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameEnd');
}

// Delete all the temporary mission objects
resetMission();
$Game::Running = false;
}

function onGameDurationEnd()
{
// This "redirect" is here so that we can abort the game cycle if
// the $Game::Duration variable has been cleared, without having
// to have a function to cancel the schedule.
if ($Game::Duration && !isObject(EditorGui))
cycleGame();
}

-------------------------------------------------------------------------------

All further suggestions appreciated!
#3
04/02/2007 (7:46 am)
Maybe the pause at the top of game.cs ?

$GameWaitTime = 5000;

and the %cl.camera.setFlyMode();
#4
04/02/2007 (9:01 am)
Sorry, still no luck. The game still starts with the pan and the countdown...
#5
04/02/2007 (10:01 am)
Look at the function:

GameConnection::onClientEnterGame(%this)
{
...

// Orbit the camera around the car....
this.camera.... whatever
}

take that part out...


Also CreateCar is where the client is given control of the car after it is spawned.
#6
04/03/2007 (7:27 am)
Thanks for the suggestion mb. Unfortunately there is no part about a camera orbit in the GameConnection part or even in the complete game.cs.. I have searched the whole file and it isnt there, possibly I had already removed it. Anyway Im still getting the player locked in position until the stupid countdown finishes. Ive deleted the countdown GUI, so now when I start the camera goes into free rotate for the 5 seconds until the countdown would have finished, then the game starts. I would have thought it would be simple to get rid of this but I cant find it anywhere!!!
#7
04/03/2007 (7:36 am)
Sure you dont have $GameWaitTime = 5000; at the top of server/scripts/game.cs?
#8
04/03/2007 (7:56 am)
Sorry I should have got that first time, I mustve made a mistake. Yeah I took the GameWaitTime out, so now there is no more camera pan, but still the countdown effect.. The players position resets to the original position when the countdown hits zero. But its already an improvement, thanks, and sorry I didnt fix that gamewait thing earlier!
#9
04/03/2007 (8:06 am)
Np, glad to help.

The countdown should be easy to remove. Try changing function startGame() - change the schedule at the end of that function from "countThree" to "startRace". That should skip the countdown code all-together. It uses the $GameWaitTime so just make that $GameWaitTime = 0; and it should work, Im at work now so I cant test it myself.
#10
04/05/2007 (6:30 am)
Hate to be bringing all this back up again. Well even though I had half fixed the problem, inadvertently all environment elements disappeared from my game, meaning in the end I was forced to go back to a backup. So the racing intro is back, and I cant get it out of the game! Ive taken so much code out of game.cs but all to no avail. I dont think that the relevant code could be anywhere else.. Surely there must be a way to just eliminate the 5 seconds before the player controls the car. It should be obvious in the code, but I just cant find it! Here is my entire game.cs from the mission loaded function.

-----------------------------------------------------------------------------------

function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
// Nothing special for now, just start up the game play.
startGame();
}

function onMissionEnded()
{
// Called by endMission(), right before the mission is destroyed

// Normally the game should be ended first before the next
// mission is loaded, this is here in case loadMission has been
// called directly. The mission will be ended if the server
// is destroyed, so we only need to cleanup here.
cancel($Game::Schedule);
$Game::Running = false;
$Game::Cycling = false;
}


//-----------------------------------------------------------------------------

function startGame()
{
if ($Game::Running) {
error("startGame: End the game first!");
return;
}

// Inform the client we're starting up
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameStart');




}

function endGame()
{
if (!$Game::Running) {
error("endGame: No game running!");
return;
}

// Stop any game timers
cancel($Game::Schedule);

// Inform the client the game is over
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameEnd');
}

// Delete all the temporary mission objects
resetMission();
$Game::Running = false;
}

function onGameDurationEnd()
{
// This "redirect" is here so that we can abort the game cycle if
// the $Game::Duration variable has been cleared, without having
// to have a function to cancel the schedule.
if ($Game::Duration && !isObject(EditorGui))
cycleGame();
}


//-----------------------------------------------------------------------------

function cycleGame()
{
// This is setup as a schedule so that this function can be called
// directly from object callbacks. Object callbacks have to be
// carefull about invoking server functions that could cause
// their object to be deleted.
if (!$Game::Cycling) {
$Game::Cycling = true;
$Game::Schedule = schedule(0, 0, "onCycleExec");
}
}

function onCycleExec()
{
// End the current game and start another one, we'll pause for a little
// so the end game victory screen can be examined by the clients.
endGame();
$Game::Schedule = schedule($Game::EndGamePause * 0, 0, "onCyclePauseEnd");
}

function onCyclePauseEnd()
{
$Game::Cycling = false;

// Just cycle through the missions for now.
%search = $Server::MissionFileSpec;
for (%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search)) {
if (%file $= $Server::MissionFile) {
// Get the next one, back to the first if there
// is no next.
%file = findNextFile(%search);
if (%file $= "")
%file = findFirstFile(%search);
break;
}
}
loadMission(%file);
}


//-----------------------------------------------------------------------------
// GameConnection Methods
// These methods are extensions to the GameConnection class. Extending
// GameConnection make is easier to deal with some of this functionality,
// but these could also be implemented as stand-alone functions.
//-----------------------------------------------------------------------------

function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
commandToClient(%this, 'SetMaxLaps', $Game::Laps);
commandToClient(%this, 'CameraToThirdPerson');


ServerConnection.setFirstPerson(false);


// 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)
{
// Create a car object.
%this.spawnCar();

// Orbit the camera around the car
// %this.camera.setOrbitMode(%this.car, %this.car.getTransform(), // 0.5, 4.5, 4.5);


}

function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.car))
%this.car.delete();
}


//-----------------------------------------------------------------------------

function GameConnection::onLeaveMissionArea(%this)
{
// The control objects invoked this method when they
// move out of the mission area.
}

function GameConnection::onEnterMissionArea(%this)
{
// The control objects invoked this method when they
// move back into the mission area.
}

//-----------------------------------------------------------------------------

function GameConnection::spawnCar(%this)
{
// Combination create player and drop him somewhere
%spawnPoint = pickSpawnPoint();
%this.createCar(%spawnPoint);
}

//-----------------------------------------------------------------------------

function GameConnection::createCar(%this, %spawnPoint)
{
if (%this.car > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}

// Create the player object
%car = new FlyingVehicle() {
dataBlock = Drone;
client = %this;
};

}


//-----------------------------------------------------------------------------
// Support functions
//-----------------------------------------------------------------------------

function pickSpawnPoint()
{
%groupName = "MissionGroup/PlayerDropPoints";
%group = nameToID(%groupName);

if (%group != -1) {
%count = %group.getCount();
if (%count != 0) {
%index = getRandom(%count-1);
%spawn = %group.getObject(%index);
return %spawn.getTransform();
}
else
error("No spawn points found in " @ %groupName);
}
else
error("Missing spawn points group " @ %groupName);

// Could be no spawn points, in which case we'll stick the
// player at the center of the world.
return "0 0 300 1 0 0 0";
}
-----------------------------------------------------------------------------------

If youre still with this, thanks for persevering with me!
#11
04/05/2007 (6:37 am)
Simon, I don't think anyone mentioned this but be aware that you should manually delete the .dso files in your script directories when you are having troubles like this. It often is the cause of a lot of confusion when you are trying different things but the symptom persists. I use a batch file that is linked at the top of my Start menu so I can poke at it before starting the engine. Have something in it like this, where %Torque% is your TGE path:

del /s %Torque%\*.dso

Of course this probably isn't the current issue but worth mentioning.

-tim
#12
04/05/2007 (6:45 am)
Tim, I deleted my .dso file but now the mission wont load anymore, it just freezes on "loading objects".. does this mean Ive deleted too much?
#13
04/05/2007 (7:14 am)
I hate to say it but you might want to just start fresh with a copy of starter.racing. Probably easier to start over than to find what you have deleted.

Also instead of deleting the code, put comments around them so if you have problems you can just take the comments out and its back to the way it was. I'm sure you know how to do this but I'll explain it anyways:


/*
function GameConnection::aFunction(%this)
{
// code...
}
*/
#14
04/05/2007 (7:16 am)
Torque Script doesn't support bulk commenting, you'll have to do each line individually:
// function GameConnection::aFunction(%this)
// {
// code...
// }
#15
04/05/2007 (7:33 am)
If startup freezes on loading after deleting the dso files, then some .cs files are missing from your build that were originally there. Take a look at your console output while loading to see what's going on. Getting a good handle on the loading process will avoid problems in the future too. You can include -console in you command line string so that that a dos box pops up everytime you start with all the details in it.

I sounds more and more like your loading sequence isn't loading the changes you think you are making.
#16
04/05/2007 (7:34 am)
Skipping the countdown is really easy, just call stargame immediately instead of the countdown.
you probably will want to comment out this:
if(!$Game::Running)
{
}
if you leave that in, a player that connects after the race has started won't get a car assigned (so just free camera mode I think)
I'm not sure though, its been 3 years since I played with the racing demo. But really, there isn't much code in there...
#17
04/05/2007 (10:34 am)
@Simon

Here's what I changed to make the game start with the player in the car and barely any start time.

function startGame()
{
   if ($Game::Running) {
      error("startGame: End the game first!");
      return;
   }

    schedule($Game::WaitTime, 0, "startRace");
}

function startRace()
{
   // 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.lap = 0;
      %cl.nextCheck = 1;
      %cl.setControlObject(%cl.car);
      //%cl.camera.setFlyMode();
   }

   // Start the game timer
//   if ($Game::Duration)
//      $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" );
   $Game::Running = true;
   
   $Game::Running = true;
}

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)
	{
		// Create a car object.
		%this.spawnCar();

         // Orbit the camera around the car
		//%this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
	}
}

That should work for what I think you want...
#18
04/11/2007 (4:05 am)
Just got round to trying this now. Works a charm! thanks mb
#19
04/11/2007 (7:06 am)
Np, Glad to hear it :)