summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-03-02 17:31:31 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2015-03-03 16:06:04 +0100
commit64ff966bae99813229dff6629fd9131a91ba7484 (patch)
treead63765181af40910873520fc45cfe56a1380779 /src/script
parent056e8f7839d72dfc2e8aa0a68c5d19d7cc30a282 (diff)
downloadminetest-64ff966bae99813229dff6629fd9131a91ba7484.tar.gz
minetest-64ff966bae99813229dff6629fd9131a91ba7484.tar.bz2
minetest-64ff966bae99813229dff6629fd9131a91ba7484.zip
Send Player HP when setHP (or a setHP caller) is called instead of looping and testing the state change.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_object.cpp21
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;
}