summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-01-30 12:41:27 +0100
committersfan5 <sfan5@live.de>2021-01-31 20:38:12 +0100
commita01a02f7a1ec915c207632085cd5f24eab28da17 (patch)
treefd4eb76bf161237cf59e389821a6865ec0c74ef0
parentfd1c1a755eaa2251c99680df3c72ca8886ca0a4e (diff)
downloadminetest-a01a02f7a1ec915c207632085cd5f24eab28da17.tar.gz
minetest-a01a02f7a1ec915c207632085cd5f24eab28da17.tar.bz2
minetest-a01a02f7a1ec915c207632085cd5f24eab28da17.zip
Preserve immortal group for players when damage is disabled
-rw-r--r--builtin/settingtypes.txt2
-rw-r--r--doc/lua_api.txt5
-rw-r--r--src/script/lua_api/l_object.cpp9
-rw-r--r--src/server.cpp2
4 files changed, 14 insertions, 4 deletions
diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt
index 21118134e..8b6227b37 100644
--- a/builtin/settingtypes.txt
+++ b/builtin/settingtypes.txt
@@ -1085,7 +1085,7 @@ default_stack_max (Default stack size) int 99
# Enable players getting damage and dying.
enable_damage (Damage) bool false
-# Enable creative mode for new created maps.
+# Enable creative mode for all players
creative_mode (Creative) bool false
# A chosen map seed for a new map, leave empty for random.
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index df9e3f8b0..18499e15a 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -1745,8 +1745,9 @@ to games.
### `ObjectRef` groups
* `immortal`: Skips all damage and breath handling for an object. This group
- will also hide the integrated HUD status bars for players, and is
- automatically set to all players when damage is disabled on the server.
+ will also hide the integrated HUD status bars for players. It is
+ automatically set to all players when damage is disabled on the server and
+ cannot be reset (subject to change).
* `punch_operable`: For entities; disables the regular damage mechanism for
players punching it by hand or a non-tool item, so that it can do something
else than take damage.
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index ba201a9d3..07aa3f7c9 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -355,6 +355,15 @@ int ObjectRef::l_set_armor_groups(lua_State *L)
ItemGroupList groups;
read_groups(L, 2, groups);
+ if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ if (!g_settings->getBool("enable_damage") && !itemgroup_get(groups, "immortal")) {
+ warningstream << "Mod tried to enable damage for a player, but it's "
+ "disabled globally. Ignoring." << std::endl;
+ infostream << script_get_backtrace(L) << std::endl;
+ groups["immortal"] = 1;
+ }
+ }
+
sao->setArmorGroups(groups);
return 0;
}
diff --git a/src/server.cpp b/src/server.cpp
index 76a817701..8a86dbd82 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1349,7 +1349,7 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao, const PlayerHPChangeReason
return;
session_t peer_id = playersao->getPeerID();
- bool is_alive = playersao->getHP() > 0;
+ bool is_alive = !playersao->isDead();
if (is_alive)
SendPlayerHP(peer_id);