aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_entity.cpp28
-rw-r--r--src/script/cpp_api/s_entity.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp
index 4c1e296d4..a97b0c12c 100644
--- a/src/script/cpp_api/s_entity.cpp
+++ b/src/script/cpp_api/s_entity.cpp
@@ -262,6 +262,34 @@ bool ScriptApiEntity::luaentity_Punch(u16 id,
return retval;
}
+bool ScriptApiEntity::luaentity_on_death(u16 id, ServerActiveObject *killer)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ int error_handler = PUSH_ERROR_HANDLER(L);
+
+ // Get core.luaentities[id]
+ luaentity_get(L, id);
+ int object = lua_gettop(L);
+ // State: object is at top of stack
+ // Get function
+ lua_getfield(L, -1, "on_death");
+ if (lua_isnil(L, -1)) {
+ lua_pop(L, 2); // Pop on_death and entity
+ return false;
+ }
+ luaL_checktype(L, -1, LUA_TFUNCTION);
+ lua_pushvalue(L, object); // self
+ objectrefGetOrCreate(L, killer); // killer reference
+
+ setOriginFromTable(object);
+ PCALL_RES(lua_pcall(L, 6, 1, error_handler));
+
+ bool retval = lua_toboolean(L, -1);
+ lua_pop(L, 2); // Pop object and error handler
+ return retval;
+}
+
// Calls entity:on_rightclick(ObjectRef clicker)
void ScriptApiEntity::luaentity_Rightclick(u16 id,
ServerActiveObject *clicker)
diff --git a/src/script/cpp_api/s_entity.h b/src/script/cpp_api/s_entity.h
index 4e2a056bb..07b06edff 100644
--- a/src/script/cpp_api/s_entity.h
+++ b/src/script/cpp_api/s_entity.h
@@ -41,6 +41,7 @@ public:
bool luaentity_Punch(u16 id,
ServerActiveObject *puncher, float time_from_last_punch,
const ToolCapabilities *toolcap, v3f dir, s16 damage);
+ bool luaentity_on_death(u16 id, ServerActiveObject *killer);
void luaentity_Rightclick(u16 id,
ServerActiveObject *clicker);
};