Left 4 Dead 2/Scripting/Expanded Mutation System/Creating a Simple Mutation - GamePlay

From Valve Developer Community
Jump to navigation Jump to search

Modifying your Mutation: Removing Map Entities

While some mutations can work on any map, for more focused mutations we can make changes to a specific map to make it more suitable for the mutation you're building. Right now we're going to talk about a process called sanitizing maps. Sanitizing is when your Mutation removes specific entities from the map. Many times these are entities placed in the map by Valve when the game was made. They have a specific purpose for the 'regular' Left 4 Dead 2 game but may cause problems with your Mutation. So let's talk about how to get rid of 'em.

For C3M3_Shantytown one of the things that you notice right off is that the survivors keep mentioning having to open the gate to move on. This bit of speech is triggered by an info_remarkable entity that the Survivors use to locate things to talk about. Since we aren't in the campaign mode, let's remove these so that the Survivors don't talk about the gate when our Mutation is running in this map.

We start by creating a custom Squirrel script file for this map. The purpose of this new script file is very specific: It will contain script code that indicates how we want the Mutation to behave when this specific map is being played. We will put this file in the same folder as simple.nut, the main file for our Mutation. The naming convention for this file is:

 "<map name> + <mutation name> + ".nut". 

So for this example, the correct filename is c3m3_shantytown_simple.nut:

 <Your Steam Folder>\steamapps\common\Left4Dead2\Left4Dead2\scripts\vscripts\c3m3_shantytown_simple.nut


We will put a few things in this file. First is the SanitizeTable - a table we use to identify which entities we'd like to have removed from the map when this map is loaded by our Mutation.

///////////////////////////////////////////////////////////////////////////////
// 'Simple' Mutation
//
// For the Shantytown map 
///////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------
// The Map Specific Spawn, State, Options, and Sanitize data
//---------------------------------------------------------
SanitizeTable <-
[
	{ classname = "info_remarkable", input = "kill"}
]


The SanitizeTable, if you provide one, is automatically loaded and processed when your Mutation starts. In this case we chose to remove all entities with the classname "info_remarkable" by sending them a "kill" input. We can test this pretty simply by restarting the Mutation and walking over to the lever and seeing if the characters say anything along the way. With the info_remarkable entities removed, there should be no talking about opening the gate.


The next step in preparing this map to work well for our Mutation is to add some new entities so that we can affect the way the map is played.

Modifying your Mutation: Adding Entities - The Escape

While it is fun to exclaim "You win" in text, nothing says victory like a helicopter ride out. So let's have the rescue helicopter arrive after the Survivors have cleared our single wave of infected and won the round. The process of the helicopter flying in and picking up the Survivors is mostly handled automatically by the existing Left4Dead2 game code. All we need to do in our Mutation scripts is provide a little bit of information about where the helicopter should go and when it should show up.

To do that, we'll be working with the Rescue Helicopter entity. The Rescue Helicopter is an entity group that was created for the mutation titled Holdout. We're going to borrow it for our Simple game mode. You can view the .vmf source file for the rescue helicopter (rescue_helicopter.vmf) provided in the SDK if you'd like to load it up in hammer to see how it works but that's not necessary for the purposes of this tutorial.

First we need to specify where we want the helicopter to pick up the Survivors, using the same method we used to specify where the Survivors should spawn in our Mutation. You can go into the Authoring Tools again and place an "info_item_position" entity where you want the helicopter to stop and pick up the Survivors. This entity should be named "rescue_helicopter_spawn". The rescue chopper entity group contains the entire chopper path so the point we are placing is actually the place the chopper will stop to pick you up.

You can edit the c3m3_shantytown_entities_simple.txt file and add the "info_item_position" entity directly. For this example, I went with these settings:

"entity"
{
	"classname" "info_item_position"
	"targetname" "rescue_helicopter_spawn"
	"filename" "../../left4dead2_dlc3/maps/instance/entitygroups/rescue_helicopter.vmf"
	"origin" "2296.005127 -4576.153809 10"
	"angles" "0 260 0"
	"group" 0
	"rarity" 0
}

NOTE If you choose to enter this text manually, be sure you add it to your c3m3_shantytown_entities_simple.txt file rather than either of the .nut files we've been working with.

I chose the location of the helicopter by using the getpos command and then editing the text file directly, but you can position the Helicopter pick-up location wherever you think is the most interesting.

If you run your Mutation now, you will notice the Helicopter does not appear. This is because we haven't spawned it yet. We still need to tell the Mutation what entities to add to this map when our Mutation runs. This is done by adding the entity names to a table called MapSpawns in the c3m3_shantytown_simple.nut file. Much like the Sanitize Table, the MapSpawns table is automatically processed at map load and tells the game which entities we'd like to add (spawn) when this map is loading using our Mutation:

MapSpawns <-
[
	[ "RescueHelicopter"]
]	

This will cause the built-in Rescue Helicopter entity to spawn. The Helicopter spawns in a hidden state and waits quietly for us to call for it.


Let's save the map-specific file and go back to the simple.nut file and write the code to call the Helicopter.

Stage 3 used to be a simple STAGE_RESULTS stage, let's make some changes to it.

When the RescueHelicopter object is added to a map it will create a "Rescue Manager" variable that can be used to access the helicopter functions. It will create that variable at this location:

g_RoundState.g_RescueManager

The function that we want to call to summon the rescue helicopter is called:

ForceSummonRescueChopper()

So to force the rescue helicopter to spawn we would make this function call:

g_RoundState.g_RescueManager.ForceSummonRescueChopper()

NOTE: Your vscripts folder contains the rescue_helicopter.nut file that creates the Rescue Manager and associated rescue helicopter functions.

Lets modify the Stage 3 case to call that function if there is a "g_RescueManager" variable in your mode. If the variable does not exist we'll just do what we used to do - set the stage to STAGE_RESULTS.

case 3:
	SessionOptions.ScriptedStageType = STAGE_ESCAPE
	if( "g_RescueManager" in g_RoundState )
		g_RoundState.g_RescueManager.ForceSummonRescueChopper()
	else // I guess they didn't include a chopper - set STAGE_RESULTS
		SessionOptions.ScriptedStageType = STAGE_RESULTS
	break

NOTE: STAGE_RESULTS and STAGE_ESCAPE are built-in features of the Left4Dead2 Mutation system and you can read more about them in the StageType Appendix.

Now when you finish the round, you will need to make your way to the escape chopper. Give it a try. If you placed the chopper yourself, you might want to play with the orientation or location. If you notice in our example, the angle is 0 260 0 - that was changed to have the rescue ladder face the survivor's path.

Modifying your Mutation: Blocking In Players

Right now players have one way they can cheese this map - They can run to the Saferoom. It is a long run, but doable. We don't want the Mutation to end in the Saferoom because then it's just a race to the Saferoom; We want players to have to fight their way out to the chopper, so let's stop them from making the run.

We need to go back into the Authoring Tools to do this. Load the map by choosing Tools->Entity Placement Mode and then open c3m3_shantytown_entities_simple.txt

Create a new template as shown - make sure to check Face Player as it will make layout much easier and start laying them down across a section of the map between where you placed the Helicopter and Saferoom.

Shantytown barrier.jpg


Once you are done there, we need to spawn them. To do that let's go back into c3m3_shantytown_simple.txt and edit the MapSpawns table to read:

  MapSpawns <-
 [
  	[ "RescueHelicopter"],
	[ "WrongwayBarrier"]
 ]	

How did we know to call it WrongwayBarrier? If we open up the nut file we pointed to - scripts\vscripts\entitygroups\wrongway_barrier_group.nut we will see at the bottom. WrongwayBarrier is one of the Entity Groups that are provided by the Mutation system for you to use- like the Rescue Helicopter we used earlier.

RegisterEntityGroup( "WrongwayBarrier", WrongwayBarrier )

So now you have your first Mutation! You can keep playing around here but if you want to learn how you can add your own entities to the world - let's say a couple of shotguns at the start if you remove all the other weapons - check out the GnomeHunter tutorial to see how you can add almost any item or model into the world and use them for your own Mutation.