L4D2 EMS/GnomeHunter tutorial 7

From Valve Developer Community

Jump to: navigation, search

Spawning Infected: Setting up a GetNextStage

If you remember from the Simple tutorial, a GetNextStage() function is called by the Director to figure out what to do next. So if we are going to start managing spawns, that is a good place to do it. So lets create a GetNextStage() function for Gnome Hunter:

We eventually might want to change behavior based on stages, too - so lets put a variable in the MutationState table in to track how many times GetNextStage() is called so that we can do things to make the gameplay 'advance' with the stage of the game.

CurrentStage = -1 // initialize to -1 since we'll increment it each time GetNextStage() is called and we want to start at 0

And then add your GetNextStage() function.

function GetNextStage()
{
     printl(" ** GetNextStage() called!  We are on wave: " + SessionState.CurrentStage )
}

Setting up Infected Stages

Each time GetNextStage() is called, we want to set some different SessionOptions. This way each stage of gameplay will behave differently from the others.

NOTE: In previous versions of Left4Dead2, DirectorOptions was the name of the table used to change director variables in VScript. Those variables are now part of the SessionOptions table, and this table is parsed by the Director.


Lets make the first stage type be "STAGE_SETUP" for ten seconds to give the Survivors a little head start:

  • SessionOptions.ScriptedStageType = STAGE_SETUP
  • SessionOptions.ScriptedStageValue = 10 // seconds to stay in this stage

After setup we'll set the stage type to "STAGE_PANIC" which will cause common infected to attack:

  • SessionOptions.ScriptedStageType = STAGE_PANIC
  • SessionOptions.ScriptedStageValue = 1

After killing all the infected in the panic wave we'll go into a delay stage for 10 seconds:

  • SessionOptions.ScriptedStageType = STAGE_DELAY
  • SessionOptions.ScriptedStageValue = 10 // delay for 10 seconds

After the delay if the gnome has not been stored in the locker we'll send in another panic wave.

If the gnome has been placed in the locker lets switch to "STAGE_RESULTS" and end the game:

  • SessionOptions.ScriptedStageType = STAGE_RESULTS

Here's one way to do it:

// stages
FIRST_STAGE	<- 0
SECOND_STAGE	<- 1
THIRD_STAGE	<- 2
FOURTH_STAGE	<- 3
 
function GetNextStage()
{
	printl(" ** GetNextStage() called!  We are on stage: " + SessionState.CurrentStage )
 
	// determine which stage we should be on
 
	if( SessionState.GnomeInLocker )
	{
		// Getting the gnome into the locker is the win condition
		SessionState.CurrentStage = FOURTH_STAGE
	}
	else
	{
		SessionState.CurrentStage++
	}
 
	switch ( SessionState.CurrentStage )
	{
		case FIRST_STAGE: // setup stage
			SessionOptions.ScriptedStageType = STAGE_SETUP
			SessionOptions.ScriptedStageValue = 10 // seconds to stay in this stage
			break
 
		case SECOND_STAGE: // common infected attack!
			SessionOptions.ScriptedStageType = STAGE_PANIC
			SessionOptions.ScriptedStageValue = 1
			break
 
		case THIRD_STAGE: // reset back to STAGE_SETUP if the gnome hasn't been put in the locker
			SessionOptions.ScriptedStageType = STAGE_DELAY
			SessionOptions.ScriptedStageValue = 10 // delay for 10 seconds
 
			SessionState.CurrentStage = FIRST_STAGE// reset our stage back to 0
			break
 
		case FOURTH_STAGE: // you win!  the game will restart after a few moments
			SessionOptions.ScriptedStageType = STAGE_RESULTS
			break
	}
}

Fire up Gnome Hunter and see if your waves are spawning correctly. You should get waves of infected punctuated with delays until you put the gnome into the locker. Once the Gnome is in the locker and all infected are dead the round will re-start from the beginning, with the Survivors starting in the Gazebo.


Next: Adding message tickers to our Mutation so we can display messages for the players on the game HUD.

NEXT -->

Personal tools
Namespaces
Variants
Actions