]> git.lizzy.rs Git - minetest.git/commitdiff
Check hp_max > 0 for entities (#12667)
authorLars Müller <34514239+appgurueu@users.noreply.github.com>
Sat, 13 Aug 2022 14:35:41 +0000 (16:35 +0200)
committerGitHub <noreply@github.com>
Sat, 13 Aug 2022 14:35:41 +0000 (15:35 +0100)
src/script/common/c_content.cpp

index 1669800256360b743644a2fbedec83e7bac4b187..fafb2edc9e029e5e3d0c159455ae6dfa71212998 100644 (file)
@@ -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);