Skip to content

Commit a01a02f

Browse files
committed
Preserve immortal group for players when damage is disabled
1 parent fd1c1a7 commit a01a02f

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

builtin/settingtypes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ default_stack_max (Default stack size) int 99
10851085
# Enable players getting damage and dying.
10861086
enable_damage (Damage) bool false
10871087

1088-
# Enable creative mode for new created maps.
1088+
# Enable creative mode for all players
10891089
creative_mode (Creative) bool false
10901090

10911091
# A chosen map seed for a new map, leave empty for random.

doc/lua_api.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,9 @@ to games.
17451745
### `ObjectRef` groups
17461746

17471747
* `immortal`: Skips all damage and breath handling for an object. This group
1748-
will also hide the integrated HUD status bars for players, and is
1749-
automatically set to all players when damage is disabled on the server.
1748+
will also hide the integrated HUD status bars for players. It is
1749+
automatically set to all players when damage is disabled on the server and
1750+
cannot be reset (subject to change).
17501751
* `punch_operable`: For entities; disables the regular damage mechanism for
17511752
players punching it by hand or a non-tool item, so that it can do something
17521753
else than take damage.

src/script/lua_api/l_object.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ int ObjectRef::l_set_armor_groups(lua_State *L)
355355
ItemGroupList groups;
356356

357357
read_groups(L, 2, groups);
358+
if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
359+
if (!g_settings->getBool("enable_damage") && !itemgroup_get(groups, "immortal")) {
360+
warningstream << "Mod tried to enable damage for a player, but it's "
361+
"disabled globally. Ignoring." << std::endl;
362+
infostream << script_get_backtrace(L) << std::endl;
363+
groups["immortal"] = 1;
364+
}
365+
}
366+
358367
sao->setArmorGroups(groups);
359368
return 0;
360369
}

src/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao, const PlayerHPChangeReason
13491349
return;
13501350

13511351
session_t peer_id = playersao->getPeerID();
1352-
bool is_alive = playersao->getHP() > 0;
1352+
bool is_alive = !playersao->isDead();
13531353

13541354
if (is_alive)
13551355
SendPlayerHP(peer_id);

0 commit comments

Comments
 (0)