Game Development Community

Loading new level

by Nathan Kent · in Technical Issues · 10/06/2007 (7:05 am) · 17 replies

I've been trying to figure this out, but have had no luck. How would I get a new level to load if the player steps past a certain point (AKA trigger)? Like, you are on a ground level, and you step through the entrance to a giant spaceship, loading up the new level. Understand? I've been trying for a while, but I just don't know how do program that into a game. Also, I'd like to know if there is a way to transfer information between missions. Also, how do you get the current mission? I'd like to use that in deciding what mission to load next.

#1
10/06/2007 (8:59 am)
Just use a trigger.

its like a thing that when you hit it, i meen like when you walk into it, something happens throu scripting.

so you just make it like. when you step through the entrance you hit the trigger, and then you will be transportet to an other mission.

Rik Girbes
#2
10/06/2007 (11:37 am)
Well, yeah, I know that. But how do I use that to load a new level? What Code do I use to do it?
#4
10/06/2007 (12:28 pm)
Ok, thanks. Now how do I get the current mission?
#5
10/06/2007 (2:03 pm)
Make a file called exit.cs

function exit0::onEnter(%this,%obj)
{
  %this.getScenegraph().schedule(100,"loadLevel","project_1/data/levels/level_2.t2d");
}
exit0 is the trigger, and you can put your own directory in place of mine.

Now make a trigger and name it exit0. If you want to make an exit for each level, make another like:

function exit1::onEnter(%this,%obj)
{
  %this.getScenegraph().schedule(100,"loadLevel","project/data/levels/level_3.t2d");
}

Make sure you put it in the same file and to put your own directory in it. Ohh and another thing, this was only used in TGB not TGE so you may need to do a little work (Probally just change the file directory).
#6
10/06/2007 (2:20 pm)
Thanks! I think that will be all I need! Thanks all!
#7
10/06/2007 (3:13 pm)
Beware, if you use that code in a multiplayer environment, it drags everyone with you. :-D
It's lots of fun to play with tho, and works fine in a single player environment.
#8
10/07/2007 (4:25 am)
Ok, the game I'm working on is single player. But it would be fun to toy around with it, and make it so it works on multiplayer, maybe modifiying it so it sends the client to a different server, and each server has a different mission loaded.
#9
10/09/2007 (6:34 pm)
You would have it better if you just have one main server loading each level, then do that.
#10
10/10/2007 (11:03 am)
Well, if you're doing multiplayer, and just have the one main server, wouldn't that send everyone to the new level, not just the ones who are trying to get there?
#11
10/16/2007 (5:51 am)
How do you dynamically trigger to move from one persistent world to another (where hundreds are already playing?)
#12
10/16/2007 (8:05 am)
You would disconnect from one server and connect to another.
#13
10/21/2007 (3:15 pm)
Would you be able to transfer information?
#14
10/21/2007 (3:31 pm)
You would probably need to have different servers for each level then. And you could either save information to the client and check it when you init the character, or find a way to save it onto the servers.
#15
10/21/2007 (3:50 pm)
Set up the servers to share an SQL database (MySQL probably) and save the data
for the character there, then when the character jumps from one server to another
just load the data back in and go.
#16
10/22/2007 (6:58 am)
I didn't think about that... That would work... I'll have to try this sometime.


Anyways, I tried the code you gave me above, but I couldn't get it to load the mission. So I changed it to loadMission(). Now the game just exits out! Any suggestions?
#17
10/25/2007 (3:43 pm)
Ok, I've gotten it to load a new level, but what I want it to do is to make the charictar exactly the same as before. Right now, I've gotten it to give you a crossbow if you had one before, but it doesn't work quite right. Everytime you fire, it tells you
Quote:Remote Command Error - command must be a tag.
What's up with that? Here's the spawning code I have right now:
function GameConnection::createPlayer(%this, %spawnPoint)
{
   if (%this.player > 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
   %player = new Player() {
      dataBlock = PlayerBody;
      client = %this;
   };
   MissionCleanup.add(%player);

   // Player setup...
	if($Nateck_isNotFirstLevel) {
			echo("Setting player transform - $Nateck_transform:" SPC $Nateck_transform);
			%player.setTransform($Nateck_transform);
			if($Nateck_hasWeapon $= "1") {
				%weapon = new Item(newCrossbow) {
					datablock = "Crossbow";
				};
				echo("Mounting player weapon - %Weapon:" SPC %weapon);
				%player.pickup(%weapon);
				echo("Setting player weapon ammo Amount - $Nateck_Ammo:" SPC $Nateck_Ammo);
				%player.incInv("CrossbowAmmo", $Nateck_Ammo);
				%player.hasWeapon = "1";
			}
	}
	else {
   		%player.setTransform(%spawnPoint);
	}
   %player.setEnergyLevel(60);
   %player.setShapeName(%this.name);
   
   // Update the camera to start with the player
   %this.camera.setTransform(%player.getEyeTransform());

   // Give the client control of the player
   %this.player = %player;
   %this.setControlObject(%player);
}
Would it be better to just not delete the player, and move him around when the level loads? How would I do that? Because whenever I try to do it myself, the game gets done loading the objects, and then stops, and nothing happens!! How do I fix this?