From 64ff966bae99813229dff6629fd9131a91ba7484 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Mon, 2 Mar 2015 17:31:31 +0100 Subject: Send Player HP when setHP (or a setHP caller) is called instead of looping and testing the state change. --- src/script/lua_api/l_object.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/script/lua_api') 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="<setHP(hp); + if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(), co->getHP() == 0); + } // Return return 0; } -- cgit v1.2.3