aboutsummaryrefslogtreecommitdiff
path: root/src/script
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 /src/script
parente50aa4ed06f36c74a892ec68d576c52ba9dc0b2c (diff)
downloadminetest-aa13baa30a45b0f834c23bd5c0407895eb8ec0ee.tar.gz
minetest-aa13baa30a45b0f834c23bd5c0407895eb8ec0ee.tar.bz2
minetest-aa13baa30a45b0f834c23bd5c0407895eb8ec0ee.zip
Add minetest.register_on_player_hpchange
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_player.cpp19
-rw-r--r--src/script/cpp_api/s_player.h1
2 files changed, 20 insertions, 0 deletions
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
diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h
index 9c8d1d1ad..2e4dc2222 100644
--- a/src/script/cpp_api/s_player.h
+++ b/src/script/cpp_api/s_player.h
@@ -43,6 +43,7 @@ public:
bool on_punchplayer(ServerActiveObject *player,
ServerActiveObject *hitter, float time_from_last_punch,
const ToolCapabilities *toolcap, v3f dir, s16 damage);
+ s16 on_player_hpchange(ServerActiveObject *player, s16 hp_change);
void on_playerReceiveFields(ServerActiveObject *player,
const std::string &formname, const StringMap &fields);
};