From ba91624d8c354bac49c35a449029b6712022d0cb Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 30 Apr 2018 18:43:49 +0200 Subject: Allow damage for attached objects, add attach/detach callbacks (#6786) * Allow right-clicking on attached LuaEntities --- src/script/cpp_api/s_entity.cpp | 53 +++++++++++++++++++---------------------- src/script/cpp_api/s_entity.h | 9 +++++-- 2 files changed, 32 insertions(+), 30 deletions(-) (limited to 'src/script/cpp_api') diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp index df4b77936..88dbcc620 100644 --- a/src/script/cpp_api/s_entity.cpp +++ b/src/script/cpp_api/s_entity.cpp @@ -262,7 +262,9 @@ bool ScriptApiEntity::luaentity_Punch(u16 id, return retval; } -bool ScriptApiEntity::luaentity_on_death(u16 id, ServerActiveObject *killer) +// Calls entity[field](ObjectRef self, ObjectRef sao) +bool ScriptApiEntity::luaentity_run_simple_callback(u16 id, + ServerActiveObject *sao, const char *field) { SCRIPTAPI_PRECHECKHEADER @@ -273,14 +275,14 @@ bool ScriptApiEntity::luaentity_on_death(u16 id, ServerActiveObject *killer) int object = lua_gettop(L); // State: object is at top of stack // Get function - lua_getfield(L, -1, "on_death"); + lua_getfield(L, -1, field); if (lua_isnil(L, -1)) { - lua_pop(L, 2); // Pop on_death and entity + lua_pop(L, 2); // Pop callback field and entity return false; } luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushvalue(L, object); // self - objectrefGetOrCreate(L, killer); // killer reference + objectrefGetOrCreate(L, sao); // killer reference setOriginFromTable(object); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); @@ -290,33 +292,28 @@ bool ScriptApiEntity::luaentity_on_death(u16 id, ServerActiveObject *killer) return retval; } -// Calls entity:on_rightclick(ObjectRef clicker) -void ScriptApiEntity::luaentity_Rightclick(u16 id, - ServerActiveObject *clicker) +bool ScriptApiEntity::luaentity_on_death(u16 id, ServerActiveObject *killer) { - SCRIPTAPI_PRECHECKHEADER - - //infostream<<"scriptapi_luaentity_step: id="<