L4D2 EMS/GnomeHunter tutorial 2

From Valve Developer Community
Jump to: navigation, search

What does Gnome Hunter do?

As always, you should have a basic idea of what you want your Mutation to do. In this case we've come up with that for you:

  • This Mutation is playable only in c5m2_park
  • The Survivors start in the Gazebo
  • A gnome figure spawns somewhere in the map
  • The Survivors can pick up, carry and drop the gnome
  • The goal is to transport the gnome and place it in a locker somewhere in the level
  • The HUD will display updating messages telling the Survivors how to play

With this plan in mind, we can start building!

Creating the Mutation's definition file

The first thing you want to do when creating a new Mutation is create a definition file for the Mutation in the steamapps\common\Left 4 Dead 2\left4dead2\modes\ folder. Your Mutation is called gnomehunter. This means you'll create a .txt file named ' gnomehunter.txt '.

If you don't know how to make a Mutation definition file check out Creating a Simple Mutation and look under the heading adding the Mutation Definition.

You can also check out the file example_gnomehunter.txt in the modes folder. This file already contains everything that we're going to put into our gnomehunter.txt, and can be used as an example.

The contents of gnomehunter.txt should read:

"gnomehunter"
{
	"base" 			"gnomehunter"
	"maxplayers" 		"4"
	"hasdifficulty" 	"1"
	"singlechapter"		"1"
		
	"DisplayTitle"		"Gnome Hunter"
	"Description"		"Capture The Gnome!"
	"Image"			"maps/any"
	"Author"		"Me!"
}


Save gnomehunter.txt and let's move on!

Creating your VScript file

Now your Mutation has a definition file - Next you need a matching VScript file to hold the VScript code you will be writing. Create a new file named gnomehunter.nut and place it in the left4dead2/scripts/vscripts folder.

Adding your startup function

The first thing to add to your script is the OnGameplayStart() function. This function will be called after your Mutation is launched and your VScript becomes active. It is the entry point for your VScript code.

The OnGameplayStart() function follows a strict (though straightforward!) naming convention:

function OnGameplayStart()
{
     // gameplay start code goes here!
}

This is called by name, so if you mistype it or mis-capitalize or whatever... no luck.

Lets do something in OnGameplayStart()!

OnGameplayStart() is a great place to put any sort of setup or "spawn objects" code, or anything else you need to do each time a round of gameplay starts in your Mutation. For Gnome Hunter, this is where you add your player teleport code so your players move out of their spawn area (typically a safe room) to the spots you designate.

Before we can use the teleport function we need destination entities to use as positional markers. Use the Entity Placement Tool to place four info_item_position entities in c5m2_park inside the white gazebo. We are going to use the location of each of these entities as a new spawn location for each Survivor.

If you're not familiar with how to place info_item_position entities with the Entity Placement Tool you can learn how with This Tutorial.

After creating your player spawn points in the placement tool, save your file in the maps folder (the same folder that the .BSP files are stored). The name of your entity txt file must follow this format:<map name> + _entities_ + <mutation's "mode name">.txt. So make sure to save your entity file name as c5m2_park_entities_gnomehunter.txt in the folder steamapps\common\Left 4 Dead 2\left4dead2\maps!

The entities file will be automatically loaded when you load the c5m2_park map with your Mutation. This is why the naming convention is so important- the name of the Mutation is used to associate it with other files such as this group of entities, which is specific to the map in which the Mutation is currently being played.

If you want to skip this step you can crib from the existing c5m2_park_entities_example_gnomehunter.txt file (note that this example file will contain these spawn points and all the other entities we'll be using throughout this tutorial).

Tip.pngTip:if you examine the entities text file you can see the data the placement tool exports - it is plain text. If you are very experienced working with Hammer and entities you can edit the text file directly and hand-create entity data. For example, if you wanted to make a new entity by hand you could create one by following the format of other entities in the file. A handy way to get entity coordinates is to walk to a position in game and then use the getpos_exact command to get x,y,z coordinates of your player position.

Now that you have your start positions you can add the player teleport function call to your OnGameplayStart() function. The function will return false if it fails to find entities with the name playerstart_* so you can print an error message if you like:

function OnGameplayStart()
{
     // Teleport players out of the start room to their start positions
	if (!TeleportPlayersToStartPoints( "playerstart_*" ) )
		printl(" ** TeleportPlayersToStartPoints: Spawn point count or player count incorrect! Verify that there are 4 of each.")
}
Tip.pngTip:If you're interested in a full explanation of what the TeleportPlayersToStartPoints() function does, click the Appendix: Functions heading on the sidebar of this page and look it up!

And that's it -- you're done! Save your VScript file and try it out! Load up Left4Dead2 and enter into the console: map c5m2_park gnomehunter. The gnomehunter which appears after the mapname is a modename, and instructs the game to start up in the Gnome Hunter Mutation. This will automatically handle the loading of the game script files and map entity files for the Mutation.

When the map finishes loading you and the other Survivors should be standing out in the gazebo where you placed your four info_item_position player start entities!

NOTE: If the Survivors don't start in the Gazebo then you most likely have a typo in your VScript file or the line shown above. Re-check your work against the tutorial and fix any errors until the Mutation starts up properly, with the Survivors in the Gazebo.


Next: Putting the gnome in Gnome Hunter.


NEXT -->