kts.SetRespawnFunction – set a function to be called whenever a knight respawns
function respawn_func(player) -- do stuff... -- then either: return x, y, direction -- or: return "retry" -- or: return nil end
kts.SetRespawnFunction(respawn_func)
Sets a function to be called whenever a knight needs to respawn.
The respawn_func
will be called with one parameter which is the Player that needs to respawn. It should return one of the following three possibilities:
x
, y
and direction
: The knight will respawn at the given (x,y) position and facing in the given direction (the direction is a string "north", "south", "east" or "west"). "retry"
: The game will wait for a short time and then try the respawn again later. This is useful if the intended respawn position is temporarily blocked (e.g. by monsters or other knights). nil
(or no value returned): In this case the system falls back to the normal respawn logic, as determined by kts.SetRespawnType. No value is returned.
An error results if the passed parameter is neither a valid function nor nil
.
This can only be called during game setup – the respawn function cannot be changed mid-game.
If both SetRespawnType and SetRespawnFunction
are used, then the "respawn function" takes priority, and the "respawn type" is only used if the respawn function returned nil.
If the parameter passed to SetRespawnFunction
is nil
, then any existing respawn function is cleared.
The Knights Tutorial uses a custom respawn function in order to perform certain actions at respawn time (e.g. turning off the "Chamber of Bats" if it is active) and also to set up custom respawn points depending on the player's progress through the tutorial (i.e. if they die half way through, then they respawn near to where they died, not all the way back at the beginning). This can be seen in tutorial/init.lua (the respawn function itself is here).