Game Development Community

by Robot Marble · in Technical Issues · 03/17/2007 (5:43 am) · 12 replies

Hi, I'm a coder for a game and we are having some problems with checkpoints. We have this in game.cs:

function GameConnection::setCheckpoint(%this,%object)
{
   // Store the last checkpoint which will be used to restore
   // the player when he goes out of bounds.
   if (%object != %this.checkPoint.pad) {
      %this.checkPoint.delete();
      %this.checkPoint = new ScriptObject() {
         pad = %object;
         time = PlayGUI.elapsedTime;
         gemCount = %this.gemCount;
         penaltyTime = %this.penaltyTime;
         bonusTime = %this.bonusTime;
         powerUp = %this.player.getPowerUp();
      };

      messageClient(%this, 'MsgCheckPoint', "\c0Check Point " @ %object.number @ " reached!");
   }
}

function GameConnection::getCheckpointPos(%this,%num)
{
   // Return the point a little above the object's center
   if (!isObject(%this.checkPoint.pad))
      return "0 0 300 1 0 0 0";
   return vectorAdd(%this.checkPoint.pad.getTransform(),"0 0 3") SPC
                    getWords(%this.checkPoint.pad.getTransform(), 3);
}


And We Know We Need a code for our triggers.cs and we think we might need one for commands.cs. I really need help with this can someone either help me or direct me to a resource?

#1
03/17/2007 (6:19 am)
Can you describe what your actual problem is? I find it hard to see the problem :-)
#2
03/18/2007 (4:48 am)
The Problem is my employer wants a checkpoint, he found this in our game.cs, and I have no idea how to make a trigger out of it. Just tell me how to make a checkpoint and I will be very grateful. I don't care if you need to redo this game.cs code or rewrite the game I could get fired.
#3
03/18/2007 (7:18 am)
checkpoint.cs init in server/scripts/game.cs

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
// Copyright (C) KenFinney, 3dgap1, Get the book from amazon.com or GarageGames.com
//-----------------------------------------------------------------------------

datablock TriggerData(CheckPointTrigger)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 100;
};

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

function CheckPointTrigger::onEnterTrigger(%this,%trigger,%obj)
{
	Parent::onEnterTrigger(%this,%trigger,%obj);

	if(%obj.client.nextCheck == %trigger.checkpoint)
	{
		if(%trigger.isLast)
		{
			// Player has completed a lap.
			%obj.client.lap++;

			if(%obj.client.lap >= $Game::Laps)
			{
				// Increase his score by 1.
				%obj.client.incScore(1);
            	// End the game
             	cycleGame();			
			}
			else {
				%obj.client.nextCheck = 0;  //changed from 1 to test and it works
				commandToClient(%obj.client, 'IncreaseLapCounter');
			}
		}
		else {
			// Continue to the next one.
			%obj.client.nextCheck++;
		}
	}
	else
		centerPrint(%obj.client, "Wrong Checkpoint!", 1, 1);
}

Once it's inited in game.cs, you should find it in the mission editor. Hope it helps.
#4
03/18/2007 (9:02 am)
Thanks Mike, I will test it now.
#5
03/18/2007 (9:07 am)
Unfortunatlly It Didn't work. I inited it, but I don't think the funtions in your code are the same as ours. For example our game does not have laps and is not a racing game.

I am also afraid that it might mess up our multiplayer as some other triggers have in the past, but this can be fixed later.

Does anyone know how to make one that works with our funtions which are above in the script?
#6
03/18/2007 (10:12 am)
Remove the lap stuff and replace it with your functions. This was written by Ken Finney (3d game programming all in one) and works great multiplayer. What I didn't include was the playGui code for the lap counter. (figured you had that already)
#7
03/19/2007 (12:44 pm)
I'm bad with tiggers and I don't know how to get it to work for multiple functions. I also don't have stuff in my commands.cs to work with the funtions. Can one of you help?
#8
03/20/2007 (5:54 pm)
In "client/ui/playGui.gui"
Add this to the end of the file, just before the closing "}"

new GuiTextCtrl(LapCounter) {
      profile = "GuiBigTextProfile";
      horizSizing = "left";
      vertSizing = "bottom";
      position = "450 5";
      extent = "170 39";
      minExtent = "8 2";
      visible = "1";
      text = "Laps: 0";
      maxLength = "255";
   };
   new GuiBitmapCtrl(counter) {
      profile = "GuiDefaultProfile";
      horizSizing = "center";
      vertSizing = "center";
      position = "130 110";
      extent = "380 260";
      minExtent = "8 2";
      visible = "0";
      bitmap = "./hud/go.png";
      wrap = "0";
   };

That will give you the lap counter and the "wrong checkpoint" warning message if using the code I posted above.
How to modify it for the use you want, I don't know.
#9
04/06/2007 (5:28 am)
I am still having problems with this. Our game dosn't have obj.client.(something) as far as I can tell. Is there a different code that can be used?
#10
04/06/2007 (7:16 am)
In the code below: %obj is the object that entered the trigger.

onEnterTrigger(%this,%trigger,%obj)

So %obj.client is the client that entered the trigger in the code Mike posted.

edit:

in this code below %obj is the object that left the trigger (pretty simple stuff):

onLeaveTrigger(%this,%trigger,%obj)
{
}
#11
04/06/2007 (12:20 pm)
I am really confused on this. If I give someone the game.cs could they make one with the funtions? I'm lost of this code.
#12
04/06/2007 (3:05 pm)
I don't want to be rude, but....
Quote:
The Problem is my employer wants a checkpoint, he found this in our game.cs, and I have no idea how to make a trigger out of it. Just tell me how to make a checkpoint and I will be very grateful. I don't care if you need to redo this game.cs code or rewrite the game I could get fired.
So you get paid for doing this? Yet you want someone to do the job for you for free?
If you took on a programming job, and you can't program, then you should get fired.