Custom Death: Difference between revisions
From The DarkMod Wiki
Jump to navigationJump to search
No edit summary |
|||
Line 21: | Line 21: | ||
== See also == | == See also == | ||
* [[A Beginner's Guide to Scripting]] | * [[A Beginner's Guide to Scripting]] | ||
[[Category:Scripting]] | |||
[[Category:Editing]] |
Latest revision as of 09:41, 8 March 2009
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:
- 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.
- Add a .script file to your map (if you haven't already), like this: custom_death.script
- Define the custom_death(entity playerEnt) script function (in the global namespace), this is the function which will be called after the bespoken delay.
- 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.