Skip to content

Commit

Permalink
Preserve immortal group for players when damage is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Jan 31, 2021
1 parent fd1c1a7 commit a01a02f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion builtin/settingtypes.txt
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions doc/lua_api.txt
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions src/script/lua_api/l_object.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit a01a02f

Please sign in to comment.