L4D2 EMS/Appendix: Game Events

From Valve Developer Community
Jump to: navigation, search

Left 4 Dead Game Events

Game Events are messages that get broadcast when specific events in the game occur. The messages can then be acted upon by game systems other than the one that caused the event.

Game Events are defined in plain text .res files in the /resource/ folder of your game.

General game events can be found in this file:

/resource/gameevents.res

The Left 4 Dead game events can be found in this file:

/resource/modevents.res

Creating functions that get called when Game Events occur

If you add a function to your script that is prefixed with OnGameEvent_ and appended with the event you want to react to it will get called when the game event occurs.

In this example, when a player leaves the starting area the game event player_left_start_area occurs, and this function would then be called:

function OnGameEvent_player_left_start_area( params )
{
     // ...
}

The params table passed to the function contain data specific to the game event. In the case of player_left_start_area the params table contains the userid of the player who left the start area.

This is the player_left_start_area event definition, taken from resource/modevents.res:

	"player_left_start_area"		// when a player leaves the player start area
	{
		"userid"	"short"		// person who left
	}

Printing game events to the console as they occur while playing the game

You can view game events as they occur in game by enabling game event printing to the console:

developer 1
display_game_events 1