summaryrefslogtreecommitdiffstats
path: root/example/scripts
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-28 23:37:23 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-02 18:12:20 +0100
commitba5b55f3eba0aa3898c5fe42de9838b22473c24a (patch)
tree465e70d3bc4671b75f1af763d866eafa459f5d6f /example/scripts
parent05bb880a3b0ebe401bac83b7a2400aa315161f9c (diff)
downloadmanaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.tar.gz
manaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.tar.xz
manaserv-ba5b55f3eba0aa3898c5fe42de9838b22473c24a.zip
Use callbacks for handling character death and respawn
Rather than relying on the availability of global functions with certain predefined names, the Lua script now calls API functions to set which function should be called on these global events. This mechanism should make it easier to avoid name collisions in the global namespace, which is important now that there is only a single script state. For these global events this was not likely to become a problem, but this solution can also be used for callbacks on specific item or monster types, or even allow setting callbacks on certain instances. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
Diffstat (limited to 'example/scripts')
-rw-r--r--example/scripts/global_events.lua17
1 files changed, 11 insertions, 6 deletions
diff --git a/example/scripts/global_events.lua b/example/scripts/global_events.lua
index fe4175b..c320d16 100644
--- a/example/scripts/global_events.lua
+++ b/example/scripts/global_events.lua
@@ -10,24 +10,29 @@
--]]
-
--- This function is called when the hit points of a character reach zero.
-function on_chr_death(ch)
+-- Register the callback that is called when the hit points of a character
+-- reach zero.
+mana.on_character_death(function(ch)
mana.being_say(ch, "Noooooo!!!")
-end
+end)
-- This function is called when the player clicks on the OK button after the
-- death message appeared. It should be used to implement the respawn
-- mechanic (for example: warp the character to the respawn location and
-- bring HP above zero in some way)
-function on_chr_death_accept(ch)
+mana.on_character_death_accept(function(ch)
-- restores to full hp
mana.being_heal(ch)
-- restores 1 hp (in case you want to be less nice)
-- mana.being_heal(ch, 1)
-- warp the character to the respawn location
mana.chr_warp(ch, 1, 815, 100)
-end
+end)
+
+
+--
+-- TODO: All of the below functions are not implemented yet!
+--
-- This function is called after chr_death_accept. The difference is that
-- it is called in the context of the map the character is spawned on after