Difference between revisions of "L4D2 EMS/GnomeHunter tutorial 5"

From Valve Developer Community
Jump to: navigation, search
m (changed arrows in code to comments.)
m (Added categories to the page)
Line 97: Line 97:
[[L4D2_EMS/GnomeHunter_tutorial_6|'''NEXT''' -->]]
[[L4D2_EMS/GnomeHunter_tutorial_6|'''NEXT''' -->]]
[[Category:Left_4_Dead_2]][[Category:Scripting]][[Category: Tutorials]]

Latest revision as of 10:36, 16 June 2019

Creating the Gnome Dropoff Point

In this section we're going to create a locker object that we'll use to house the gnome.

We're going to follow a bunch of the same steps we used to create the gnome:

  • In Hammer, create a new vmf with a prop_dynamic entity that uses the model models/props_waterfront/footlocker01.mdl
  • Name this prop_dynamic entity 'the_locker'
  • Save the .vmf into the sdk_content\mapsrc\ folder. Name the .vmf file gnomehunter_locker.vmf
  • Press F9 and select and execute the configuration for export entity group
  • Verify that the file gnomehunter_locker_group.nut was created in the left4dead2\scripts\vscripts\entitygroups folder
  • Close Hammer

Go into the Entity Placement Tool and add an info_item_position named locker_spawn to your c5m2_park_entities_gnomehunter.txt file. Pick a location near the gnome spawn point so testing will be easier, but don't place it too close.

Locker spawn pos.jpg

The top of the stairs near the map start looks like a good spot for the locker. The coordinates under the crosshair are -4429 -2218 -252

Save your work. Time to spawn the locker! Add the locker entity group name to your ModeSpawns table in gnomehunter.nut. You can name it whatever you want but I suggest using the naming convention covered in the gnome spawn tutorial so you don't have to supply all of the entity group parameters.

     ["GnomehunterGnome", "gnome_spawn", "gnomehunter_gnome_group", SPAWN_FLAGS.SPAWN],
     ["GnomehunterLocker", "locker_spawn", "gnomehunter_locker_group", SPAWN_FLAGS.SPAWN], // <--

You can now launch your Mutation in the game and verify that your locker is appearing.

Locker spawn pos1.jpgHuh. That was easy.

NOTE: The locker used in this tutorial does not have a collision hull.

Adding a locker spawn callback function

Now lets add a callback function so we can catch the locker entity after it spawns in the world and do some things with it. Add code so that your OnEntityGroupRegistered() function looks like this:

function OnEntityGroupRegistered( name, group )
	printl(" ** Registering: " + name )
	if( name == "GnomehunterGnome" )
	        // This is the 'Gnome' entity group!
		group.GetEntityGroup().SpawnTables[ "the_gnome" ].PostPlaceCB <- GnomeSpawnCB
	else if( name == "GnomehunterLocker" )
                // This is the 'Locker' entity group!
		group.GetEntityGroup().SpawnTables[ "the_locker" ].PostPlaceCB <- LockerSpawnCB

and the callback function LockerSpawnCB():

function LockerSpawnCB( entity, rarity )
     // locker has spawned!

The goal of having the locker spawn callback is to get a handle to the actual locker entity - the entity that we named "the_locker". Once we have that entity handle we can use it later to do various things, like animate the locker or make distance checks between it and the gnome in order to know if the gnome is inside the locker.

Store the entity in the MutationState table. First you'll need to add a variable in the MutationState table, call this variable LockerEntity:

	StartActive = true
	CarryingGnome = false
        LockerEntity = null // <--

Then set it in the LockerSpawnCB() callback.

function LockerSpawnCB( entity, rarity )
	// locker has spawned
	SessionState.LockerEntity = entity

Now that we have a locker and a handle to it we can detect when the gnome gets close to it!

Next: Figuring out if the gnome is in the locker.

NEXT -->