From ea5d6312c1ab6ff3e859fcd7a429a384f0f0ff91 Mon Sep 17 00:00:00 2001 From: Zughy <63455151+Zughy@users.noreply.github.com> Date: Thu, 21 Jan 2021 17:37:38 +0000 Subject: ObjectRef: fix some v3f checks (#10602) --- src/script/lua_api/l_object.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/script/lua_api/l_object.cpp') diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index f52e4892e..ba201a9d3 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -399,7 +399,7 @@ int ObjectRef::l_get_animation(lua_State *L) if (sao == nullptr) return 0; - v2f frames = v2f(1,1); + v2f frames = v2f(1, 1); float frame_speed = 15; float frame_blend = 0; bool frame_loop = true; @@ -463,8 +463,8 @@ int ObjectRef::l_set_eye_offset(lua_State *L) if (player == nullptr) return 0; - v3f offset_first = read_v3f(L, 2); - v3f offset_third = read_v3f(L, 3); + v3f offset_first = readParam(L, 2, v3f(0, 0, 0)); + v3f offset_third = readParam(L, 3, v3f(0, 0, 0)); // Prevent abuse of offset values (keep player always visible) offset_third.X = rangelim(offset_third.X,-10,10); @@ -537,9 +537,9 @@ int ObjectRef::l_set_bone_position(lua_State *L) if (sao == nullptr) return 0; - std::string bone = readParam(L, 2); - v3f position = check_v3f(L, 3); - v3f rotation = check_v3f(L, 4); + std::string bone = readParam(L, 2, ""); + v3f position = readParam(L, 3, v3f(0, 0, 0)); + v3f rotation = readParam(L, 4, v3f(0, 0, 0)); sao->setBonePosition(bone, position, rotation); return 0; @@ -554,7 +554,7 @@ int ObjectRef::l_get_bone_position(lua_State *L) if (sao == nullptr) return 0; - std::string bone = readParam(L, 2); + std::string bone = readParam(L, 2, ""); v3f position = v3f(0, 0, 0); v3f rotation = v3f(0, 0, 0); @@ -578,10 +578,10 @@ int ObjectRef::l_set_attach(lua_State *L) if (sao == parent) throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed."); - int parent_id = 0; + int parent_id; std::string bone; - v3f position = v3f(0, 0, 0); - v3f rotation = v3f(0, 0, 0); + v3f position; + v3f rotation; bool force_visible; sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible); @@ -590,9 +590,9 @@ int ObjectRef::l_set_attach(lua_State *L) old_parent->removeAttachmentChild(sao->getId()); } - bone = readParam(L, 3, ""); - position = read_v3f(L, 4); - rotation = read_v3f(L, 5); + bone = readParam(L, 3, ""); + position = readParam(L, 4, v3f(0, 0, 0)); + rotation = readParam(L, 5, v3f(0, 0, 0)); force_visible = readParam(L, 6, false); sao->setAttachment(parent->getId(), bone, position, rotation, force_visible); @@ -609,10 +609,10 @@ int ObjectRef::l_get_attach(lua_State *L) if (sao == nullptr) return 0; - int parent_id = 0; + int parent_id; std::string bone; - v3f position = v3f(0, 0, 0); - v3f rotation = v3f(0, 0, 0); + v3f position; + v3f rotation; bool force_visible; sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible); @@ -892,9 +892,6 @@ int ObjectRef::l_set_yaw(lua_State *L) if (entitysao == nullptr) return 0; - if (isNaN(L, 2)) - throw LuaError("ObjectRef::set_yaw: NaN value is not allowed."); - float yaw = readParam(L, 2) * core::RADTODEG; entitysao->setRotation(v3f(0, yaw, 0)); @@ -2199,7 +2196,7 @@ int ObjectRef::l_set_minimap_modes(lua_State *L) luaL_checktype(L, 2, LUA_TTABLE); std::vector modes; - s16 selected_mode = luaL_checkint(L, 3); + s16 selected_mode = readParam(L, 3); lua_pushnil(L); while (lua_next(L, 2) != 0) { -- cgit v1.2.3 From a01a02f7a1ec915c207632085cd5f24eab28da17 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 30 Jan 2021 12:41:27 +0100 Subject: Preserve immortal group for players when damage is disabled --- builtin/settingtypes.txt | 2 +- doc/lua_api.txt | 5 +++-- src/script/lua_api/l_object.cpp | 9 +++++++++ src/server.cpp | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/script/lua_api/l_object.cpp') 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); -- cgit v1.2.3