aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-01-22 00:20:55 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-13 23:56:05 +0100
commit9978f5af828550d819890fed1fc56d65838a2c4c (patch)
tree34ba1ca2f7b2607fcd60166419a3ca9ab436e9bb /src/script/cpp_api
parentcb3a61f8db6b7020dd69f7786a1086f6fe014dfc (diff)
downloadminetest-9978f5af828550d819890fed1fc56d65838a2c4c.tar.gz
minetest-9978f5af828550d819890fed1fc56d65838a2c4c.tar.bz2
minetest-9978f5af828550d819890fed1fc56d65838a2c4c.zip
[CSM] Add on_death, on_hp_modification & oh_damage_taken callbacks (#5093)
* Add on_death callback * Add on_hp_modification & on_damage_taken callbacks * move preview code to preview.lua
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_client.cpp35
-rw-r--r--src/script/cpp_api/s_client.h4
2 files changed, 39 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
index 08af8ebdc..f0676f4c2 100644
--- a/src/script/cpp_api/s_client.cpp
+++ b/src/script/cpp_api/s_client.cpp
@@ -59,3 +59,38 @@ bool ScriptApiClient::on_receiving_message(const std::string &message)
bool ate = lua_toboolean(L, -1);
return ate;
}
+
+void ScriptApiClient::on_damage_taken(int32_t damage_amount)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_chat_messages
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_damage_taken");
+ // Call callbacks
+ lua_pushinteger(L, damage_amount);
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+}
+
+void ScriptApiClient::on_hp_modification(int32_t newhp)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get core.registered_on_chat_messages
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_hp_modification");
+ // Call callbacks
+ lua_pushinteger(L, newhp);
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+}
+
+void ScriptApiClient::on_death()
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get registered shutdown hooks
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_death");
+ // Call callbacks
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+}
diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h
index 08fdd8fc0..3155c7e67 100644
--- a/src/script/cpp_api/s_client.h
+++ b/src/script/cpp_api/s_client.h
@@ -32,5 +32,9 @@ public:
// Chat message handlers
bool on_sending_message(const std::string &message);
bool on_receiving_message(const std::string &message);
+
+ void on_damage_taken(int32_t damage_amount);
+ void on_hp_modification(int32_t newhp);
+ void on_death();
};
#endif