Skip to content

Commit

Permalink
Check hp_max > 0 for entities (minetest#12667)
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu authored Aug 13, 2022
1 parent 3132efc commit 0e439b2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ void read_object_properties(lua_State *L, int index,
int hp_max = 0;
if (getintfield(L, -1, "hp_max", hp_max)) {
prop->hp_max = (u16)rangelim(hp_max, 0, U16_MAX);
// hp_max = 0 is sometimes used as a hack to keep players dead, only validate for entities
if (prop->hp_max == 0 && sao->getType() != ACTIVEOBJECT_TYPE_PLAYER)
throw LuaError("The hp_max property may not be 0 for entities!");

if (prop->hp_max < sao->getHP()) {
PlayerHPChangeReason reason(PlayerHPChangeReason::SET_HP_MAX);
Expand Down

0 comments on commit 0e439b2

Please sign in to comment.