diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 73f6e93b3..e6a50c3ba 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -208,8 +208,26 @@ int ObjectRef::l_punch(lua_State *L) time_from_last_punch = lua_tonumber(L, 3); ToolCapabilities toolcap = read_tool_capabilities(L, 4); dir.normalize(); + + s16 src_original_hp = co->getHP(); + s16 dst_origin_hp = puncher->getHP(); + // Do it co->punch(dir, &toolcap, puncher, time_from_last_punch); + + // If the punched is a player, and its HP changed + if (src_original_hp != co->getHP() && + co->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(), + co->getHP() == 0); + } + + // If the puncher is a player, and its HP changed + if (dst_origin_hp != puncher->getHP() && + puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)puncher)->getPeerID(), + puncher->getHP() == 0); + } return 0; } @@ -243,6 +261,9 @@ int ObjectRef::l_set_hp(lua_State *L) <<" hp="<<hp<<std::endl;*/ // Do it co->setHP(hp); + if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(), co->getHP() == 0); + } // Return return 0; } |