aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorTeTpaAka <TeTpaAka@users.noreply.github.com>2015-05-30 16:56:42 +0200
committerest31 <MTest31@outlook.com>2015-06-13 19:40:31 +0200
commitaa13baa30a45b0f834c23bd5c0407895eb8ec0ee (patch)
tree23fc218db4ad9fe4cb44f83fbaf40ac181335c8d /builtin
parente50aa4ed06f36c74a892ec68d576c52ba9dc0b2c (diff)
downloadminetest-aa13baa30a45b0f834c23bd5c0407895eb8ec0ee.tar.gz
minetest-aa13baa30a45b0f834c23bd5c0407895eb8ec0ee.tar.bz2
minetest-aa13baa30a45b0f834c23bd5c0407895eb8ec0ee.zip
Add minetest.register_on_player_hpchange
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/register.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index e5ba88f7d..3a13abfb3 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -407,6 +407,34 @@ local function make_registration_wrap(reg_fn_name, clear_fn_name)
return list
end
+core.registered_on_player_hpchanges = { modifiers = { }, loggers = { } }
+function core.registered_on_player_hpchange(player, hp_change)
+ local last = false
+ for i = #core.registered_on_player_hpchanges.modifiers, 1, -1 do
+ local func = core.registered_on_player_hpchanges.modifiers[i]
+ hp_change, last = func(player, hp_change)
+ if type(hp_change) ~= "number" then
+ local debuginfo = debug.getinfo(func)
+ error("The register_on_hp_changes function has to return a number at " ..
+ debuginfo.short_src .. " line " .. debuginfo.linedefined)
+ end
+ if last then
+ break
+ end
+ end
+ for i, func in ipairs(core.registered_on_player_hpchanges.loggers) do
+ func(player, hp_change)
+ end
+ return hp_change
+end
+function core.register_on_player_hpchange(func, modifier)
+ if modifier then
+ table.insert(core.registered_on_player_hpchanges.modifiers, func)
+ else
+ table.insert(core.registered_on_player_hpchanges.loggers, func)
+ end
+end
+
core.registered_biomes = make_registration_wrap("register_biome", "clear_registered_biomes")
core.registered_ores = make_registration_wrap("register_ore", "clear_registered_ores")
core.registered_decorations = make_registration_wrap("register_decoration", "clear_registered_decorations")