From aa13baa30a45b0f834c23bd5c0407895eb8ec0ee Mon Sep 17 00:00:00 2001 From: TeTpaAka Date: Sat, 30 May 2015 16:56:42 +0200 Subject: Add minetest.register_on_player_hpchange --- src/script/cpp_api/s_player.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/script/cpp_api/s_player.cpp') diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index 9b2c3753c..a499130c7 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -69,6 +69,25 @@ bool ScriptApiPlayer::on_punchplayer(ServerActiveObject *player, return lua_toboolean(L, -1); } +s16 ScriptApiPlayer::on_player_hpchange(ServerActiveObject *player, + s16 hp_change) +{ + SCRIPTAPI_PRECHECKHEADER + + // Get core.registered_on_player_hpchange + lua_getglobal(L, "core"); + lua_getfield(L, -1, "registered_on_player_hpchange"); + lua_remove(L, -2); + + objectrefGetOrCreate(L, player); + lua_pushnumber(L, hp_change); + if (lua_pcall(L, 2, 1, m_errorhandler)) + scriptError(); + hp_change = lua_tointeger(L, -1); + lua_pop(L, -1); + return hp_change; +} + bool ScriptApiPlayer::on_respawnplayer(ServerActiveObject *player) { SCRIPTAPI_PRECHECKHEADER -- cgit v1.2.3