Adding Autosaves

Autosaves, or checkpoints, are an easily overlooked aspect of Half-Life 2 mapping.  In this brief tutorial, I describe how to add them and how the different functions work.  It was inspired by a recent competition on RunThinkShootLive where a mapper forgot to add Autosaves.

1. Place a logic_autosave
The entity that does the autosaving is logic_autosave.  Place this somewhere in your map and give it a name, like “autosave.”  There is an alternate entity called trigger_autosave which will save whenever the player enters the trigger, but I find logic_autosave is a more efficient approach because you can reuse it over and over again, whereas trigger_autosave is limited to the size of the trigger.

2. Saving
When you want to save, you simply call the autosave entity with the input Save.  You can do this off a trigger, pressing a button, etc.  It’s generally a good idea to do this first and postpone all other events by at least 0.1 seconds.

3. Saving Dangerously
Instead of using Save, you can also use SaveDangerous.  The idea behind SaveDangerous is to prevent players from getting into situations where they save and immediately die afterward (creating a death loop on reload).  The way it works is that when you send SaveDangerous, you also send a number of seconds as a parameter.  If the player has a certain minimum health, the game will create a temporary autosave.  If the player is still above a minimum health after the number of seconds have passed, we’ll commit the autosave and replace the previous one.  Otherwise, we’ll dispose of the temporary autosave.

The thresholds for this are set on the logic_autosave itself:

  • Minimum Hit Points: If the player’s health is less than this, and you call SaveDangerous, the autosave won’t happen.
  • Minimum Hit Points to Commit: If the player’s health is greater than Minimum Hit Points, and they are still above this value after the timer has expired, we’ll confirm the autosave.

Testing your Autosaves
Testing is easy.  At any point in your level, you can open the console and use kill command to kill yourself.  If your autosaves work, you should restore at them.

When Should You Autosave?

Here are some suggestions for where you should trigger autosaves:

  • After the intro of the level, if there is one.
  • Entering a new area
  • Before a large battle.
  • After a large battle.
  • After completing a puzzle mechanic, like pressing a button.

A Few Caveats

  • Valve’s Steampipe update to the engine created a bug where if multiple saves are created back-to-back, the game will stutter and halt for potentially several seconds.  This can easily occur if the designer uses the logic_autosave and if the player does a manual quicksave.  For your part, make sure you never call the logic_autosave entity within seconds of the last call.
  • Music will not resume properly from a save unless you use soundscripts to specify the track you want to play.  It either won’t play at all, or it will restart from the beginning.  So, on the ambient_generic that plays music, make sure you aren’t specifying the MP3 file directly.  Use their soundscript names, like song13, instead.
  • For more information, consult the Valve Developer Community.