Custom Death

From The DarkMod Wiki
Revision as of 09:41, 8 March 2009 by Greebo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

It's possible to override the default "Mission failed" event from happening when the player dies. To execute a custom script as soon as the player health reaches 0 or negative values, follow these steps:

  1. Set the custom_death_delay spawnarg on the map's worldspawn to a positive value. This value defines the amount of time in seconds which has to pass before the script will be launched.
  2. Add a .script file to your map (if you haven't already), like this: custom_death.script
  3. Define the custom_death(entity playerEnt) script function (in the global namespace), this is the function which will be called after the bespoken delay.
  4. Add your custom code to let the player respawn or do other things.

Example Script

There is one example map available (named test/custom_death.map) with the corresponding script file. The contents are like this:

void custom_death(entity playerEnt)
{
   sys.println("Died, restarting.");

   // Teleport the player back to the starting point
   playerEnt.setOrigin( $info_player_start_1.getOrigin() );

   // Restore the health
   playerEnt.setHealth( playerEnt.getIntKey("health") );
}

The above script basically teleports the player back to a certain starting point and restores the health to the initial value. That's all folks.

See also