This article relates to the game "Portal 2". Click here for more information.

Level Transition (Portal 2): Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(16 intermediate revisions by 8 users not shown)
Line 1: Line 1:
'''PAGE STILL UNDER CONSTRUCTION, DO NOT TAKE THIS INFORMATION AS 100% TRUE AS MESSING WITH THE FILES MENTIONED IS DANGEROUS TO THE FUNCTIONALITY OF YOUR GAME'''
{{languageBar|Level Transition (Portal 2)|title=Level Transition (''Portal 2'')}}
{{p2 topicon}}
=Coop=
Here is a way to make a sequence of test chambers for coop.
==Create Your Map==
First, [[Creating a Portal 2 Coop Map|create your coop map]]. Add another {{ent|func_instance}}, setting its VMF file to <code>instances/coop/coop_lighting_ents.vmf</code>. (All we're using is the {{ent|point_servercommand}} inside.)
==Modified Endlevel==
The end-of-map logic lives within the <code>instances/coop/coop_endlevel_room.vmf</code> instance. Load this map within Hammer and '''save a copy of it'''—e.g., <code>my_coop_endlevel_room.vmf</code>. 


To make a level transition, you must first create an elevator for both an entrance and exit to all the levels that you want to connect. Then go into "C:\Program Files\Steam\steamapps\common\portal 2\portal2\scripts\vscripts\transitions" for 32 bit and C:\Program Files(x86)\Steam\steamapps\common\portal 2\portal2\scripts\vscripts\transitions" for 64 bit. There are two files named "sp_transition_list.nut" and "sp_elevator_motifs.nut". Open each in Notepad. Please read the instructions carefully as messing with these files is dangerous and can cause problems with your game.
In a little room in this map you'll find a {{ent|logic_script}} named <code>transition_script</code>. (You can use the Find Entities command to select it.) You'll see that its Entity Scripts property is set to <code>debug_scripts/mp_coop_transition_list.nut</code>.
 
'''Don't modify that file!''' It's part of ''Portal 2'', and you don't want to touch it. Instead, change the Entity Scripts property to point to a script of your own—e.g., <code>debug_scripts/my_mp_coop_transition_list.nut</code>. Then, save the map.
 
Go back to your coop level, select the <code>func_instance</code> containing the endlevel room, and edit its VMF file to point to your modified version.
==Modified Script==
Now go to <code>scripts/vscripts/debugscripts</code> in the ''Portal 2'' installation and create this script. (Again, don't touch the Valve script.) All you really need is something like this:  
 
<source lang="text">
// Map order
MapPlayOrder<- [
"mp_coop_easiest",
"mp_coop_easiest_two"
]
 
function TransitionFromMap()
{
local nextmap = -2
// Loop through maps
foreach( index, map in MapPlayOrder )
{
if( GetMapName() == MapPlayOrder[index] )
{
// This is the map we're on
nextmap = -1
}
else
{
if (nextmap == -1)
{
// This is the first map past that one
nextmap = index
}
}
}
printl( "nextmap = " + nextmap )
if (nextmap > 0)
{
// We found a map; go to it
EntFire( "@command", "command", "changelevel " + MapPlayOrder[nextmap], 1.0 )
}
else
{
// No map found; we're done
EntFire( "@command", "command", "disconnect", 2.0 )
}
}
</source>
 
The array at the top, MapPlayOrder, is your list of maps in order. (For those not familiar with Squirrel, note that each map is enclosed in quotes, and there must be a comma ''in between'' each map. That is, the last map doesn't get a comma after it. And don't lose that final bracket!)
 
To go to the lobby after your maps, add "<code>mp_coop_lobby_2</code>" as the last map in the list (MapPlayOrder).
==Testing==
Make the additional coop maps, using your modified endlevel room instead of the default one. Compile them all.
 
Now you can [[Testing Portal 2 Co-Op Maps Alone|test your maps]]. Just load the first map and play it. When you get to the end, ''Portal 2'' will switch to the next map. Once it gets to the end, it will simply exit to the main menu.
 
(This method could be extended to create a hub as in the game. Look at <code>mp_coop_transition_list.nut</code> for ideas.)
 
=Single-Player=
The single-player case is similar.
==Modifed Transition Manager==
In single-player, the end-of-level logic lives in the {{ent|func_instance|arrival_departure_transition_ents.vmf}} in the <code>maps/instances/transitions</code> folder. Load this map in Hammer and '''save it under another name''', such as <code>my_arrival_departure_transition_ents.vmf</code>.
 
Within this instance, the smallest room contains a {{ent|logic_script}} named @transition_Script. Its Script Entity property points to <code>transitions/sp_transition_list.nut</code>.
 
'''Don't modify that file'''. Instead, point the property to a copy of your own, e.g. <code>transitions/my_sp_transition_list.nut</code>. 
 
While you're here, you might optionally change the {{ent|game_text}} named <code>@end_of_playtest_text</code> to display a line of text after the last map. Just change the Message Text property.
 
Save your modified VMF file.
==Modified Script==
There's a lot going on inside this script, and undoubtedly a much simpler version would do for a simple series of testchambers; however, here's the minimum you must do.
 
Look for the list of maps and search for "<code>demo_paint</code>," the last map in the file. Add your maps after this. (Again, map names are in quotes, and there's a comma afterward ''except'' for the last map. And don't lose the final bracket.)


First, in "sp_transition_list.nut" there is a list of maps, press "Ctrl+F" and type in "demo" to get to the final maps on the list. The last map should be "demo_paint".
You must copy the format of the header and the levels below and paste it on a line beneath the "demo_paint" level.
The result should look like this:
The result should look like this:


// ---------------------------------------------------<br>
<source lang="text">
// Demo files<br>
// ---------------------------------------------------
// ---------------------------------------------------<br>
// Demo files
"demo_intro",<br>
// ---------------------------------------------------
"demo_underground",<br>
"demo_intro",
"demo_paint",<br>
"demo_underground",
<br>
"demo_paint",
// ---------------------------------------------------<br>
// Your title<br>
// ---------------------------------------------------<br>
"your_first_level",<br>
"your_second_level",<br>
]<br>
<br>
Place the levels you want to play in order from top to bottom(will be played first to last). As long as you list the level there and keep everything in the same format, and have the elevators in each level listed, you will transition to the next level. Note the bracket at the final line, this must be kept there, even missing this small detail will ruin your game.


SAVE THE FILE AND CLOSE.
// ---------------------------------------------------
// Your title
// ---------------------------------------------------
"your_first_level",
"your_second_level"
]
</source>


Next, open "sp_elevator_motifs.nut". This is a smaller file, and the level list is much shorter. Scroll to the last line that reads "{ map = "sp_a4_jump_polarity", speed = 200 },". If you copy this format and paste your levels on each succeeding line, you can control the speed at which you enter the level.
The actual logic to change maps is in TransitionFromMap. To make ''Portal 2'' exit to the main menu after displaying the end text, look for these lines:


Result should look like this:<br><br><nowiki>       
<source lang="text">
{ map = "sp_a4_jump_polarity", speed = 200 },<br>
EntFire( "end_of_playtest_text", "display", 0 )
{ map = "my_first_level", speed = 300},<br>
EntFire( "@end_of_playtest_text", "display", 0 )
{ map = "Longelvity", speed = 300 },<br>
</source>
]<br>
Again, note the bracket at the end, this must be kept at the end of the entire list to maintain functionality. The order of the maps on this list must be the same as the maps on the first file you edited.


SAVE THE FILE AND CLOSE.
and add this line after them:
<source lang="text">
EntFire( "@command", "Command", "disconnect", 2.0 )
</source>


Congratulations, your maps now transition!
Save the file. (Again, you're saving your modified copy of this <code>.nut</code> file—don't overwrite the Valve file!)
==Compile and Test==
Make and compile the additional maps. You can now go back to your first map and run it from Hammer; ''Portal 2'' will load and put you into your first map. When you get to the end, it'll run the next map from the script and exit to the main menu when all are done.
[[Category:Portal 2 Tutorials]]

Latest revision as of 19:58, 21 December 2024

English (en)Deutsch (de)Polski (pl)Русский (ru)中文 (zh)Translate (Translate)

Coop

Here is a way to make a sequence of test chambers for coop.

Create Your Map

First, create your coop map. Add another func_instance, setting its VMF file to instances/coop/coop_lighting_ents.vmf. (All we're using is the point_servercommand inside.)

Modified Endlevel

The end-of-map logic lives within the instances/coop/coop_endlevel_room.vmf instance. Load this map within Hammer and save a copy of it—e.g., my_coop_endlevel_room.vmf.

In a little room in this map you'll find a logic_script named transition_script. (You can use the Find Entities command to select it.) You'll see that its Entity Scripts property is set to debug_scripts/mp_coop_transition_list.nut.

Don't modify that file! It's part of Portal 2, and you don't want to touch it. Instead, change the Entity Scripts property to point to a script of your own—e.g., debug_scripts/my_mp_coop_transition_list.nut. Then, save the map.

Go back to your coop level, select the func_instance containing the endlevel room, and edit its VMF file to point to your modified version.

Modified Script

Now go to scripts/vscripts/debugscripts in the Portal 2 installation and create this script. (Again, don't touch the Valve script.) All you really need is something like this:

// Map order
MapPlayOrder<- [
"mp_coop_easiest",
"mp_coop_easiest_two"
]

function TransitionFromMap()
{	
	local nextmap = -2
	
	// Loop through maps
	foreach( index, map in MapPlayOrder )
	{
		if( GetMapName() == MapPlayOrder[index] )
		{
			// This is the map we're on
			nextmap = -1
		}
		else 
		{
			if (nextmap == -1)
			{
				// This is the first map past that one
				nextmap = index
			}
		}
	}
		
	printl( "nextmap = " + nextmap )
		
	if (nextmap > 0)
	{
		// We found a map; go to it
		EntFire( "@command", "command", "changelevel " + MapPlayOrder[nextmap], 1.0 )
	}
	else
	{
		// No map found; we're done
		EntFire( "@command", "command", "disconnect", 2.0 )
	}
}

The array at the top, MapPlayOrder, is your list of maps in order. (For those not familiar with Squirrel, note that each map is enclosed in quotes, and there must be a comma in between each map. That is, the last map doesn't get a comma after it. And don't lose that final bracket!)

To go to the lobby after your maps, add "mp_coop_lobby_2" as the last map in the list (MapPlayOrder).

Testing

Make the additional coop maps, using your modified endlevel room instead of the default one. Compile them all.

Now you can test your maps. Just load the first map and play it. When you get to the end, Portal 2 will switch to the next map. Once it gets to the end, it will simply exit to the main menu.

(This method could be extended to create a hub as in the game. Look at mp_coop_transition_list.nut for ideas.)

Single-Player

The single-player case is similar.

Modifed Transition Manager

In single-player, the end-of-level logic lives in the func_instance arrival_departure_transition_ents.vmf in the maps/instances/transitions folder. Load this map in Hammer and save it under another name, such as my_arrival_departure_transition_ents.vmf.

Within this instance, the smallest room contains a logic_script named @transition_Script. Its Script Entity property points to transitions/sp_transition_list.nut.

Don't modify that file. Instead, point the property to a copy of your own, e.g. transitions/my_sp_transition_list.nut.

While you're here, you might optionally change the game_text named @end_of_playtest_text to display a line of text after the last map. Just change the Message Text property.

Save your modified VMF file.

Modified Script

There's a lot going on inside this script, and undoubtedly a much simpler version would do for a simple series of testchambers; however, here's the minimum you must do.

Look for the list of maps and search for "demo_paint," the last map in the file. Add your maps after this. (Again, map names are in quotes, and there's a comma afterward except for the last map. And don't lose the final bracket.)

The result should look like this:

// ---------------------------------------------------
// 	Demo files
// ---------------------------------------------------
"demo_intro",
"demo_underground",
"demo_paint",

// ---------------------------------------------------
// 	Your title
// ---------------------------------------------------
"your_first_level",
"your_second_level"
]

The actual logic to change maps is in TransitionFromMap. To make Portal 2 exit to the main menu after displaying the end text, look for these lines:

		EntFire( "end_of_playtest_text", "display", 0 )
		EntFire( "@end_of_playtest_text", "display", 0 )

and add this line after them:

		EntFire( "@command", "Command", "disconnect", 2.0 )

Save the file. (Again, you're saving your modified copy of this .nut file—don't overwrite the Valve file!)

Compile and Test

Make and compile the additional maps. You can now go back to your first map and run it from Hammer; Portal 2 will load and put you into your first map. When you get to the end, it'll run the next map from the script and exit to the main menu when all are done.