aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp75
1 files changed, 52 insertions, 23 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index f52e4892e..8ae99b929 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;
}
@@ -399,7 +408,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 +472,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<v3f>(L, 2, v3f(0, 0, 0));
+ v3f offset_third = readParam<v3f>(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 +546,9 @@ int ObjectRef::l_set_bone_position(lua_State *L)
if (sao == nullptr)
return 0;
- std::string bone = readParam<std::string>(L, 2);
- v3f position = check_v3f(L, 3);
- v3f rotation = check_v3f(L, 4);
+ std::string bone = readParam<std::string>(L, 2, "");
+ v3f position = readParam<v3f>(L, 3, v3f(0, 0, 0));
+ v3f rotation = readParam<v3f>(L, 4, v3f(0, 0, 0));
sao->setBonePosition(bone, position, rotation);
return 0;
@@ -554,7 +563,7 @@ int ObjectRef::l_get_bone_position(lua_State *L)
if (sao == nullptr)
return 0;
- std::string bone = readParam<std::string>(L, 2);
+ std::string bone = readParam<std::string>(L, 2, "");
v3f position = v3f(0, 0, 0);
v3f rotation = v3f(0, 0, 0);
@@ -578,10 +587,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 +599,9 @@ int ObjectRef::l_set_attach(lua_State *L)
old_parent->removeAttachmentChild(sao->getId());
}
- bone = readParam<std::string>(L, 3, "");
- position = read_v3f(L, 4);
- rotation = read_v3f(L, 5);
+ bone = readParam<std::string>(L, 3, "");
+ position = readParam<v3f>(L, 4, v3f(0, 0, 0));
+ rotation = readParam<v3f>(L, 5, v3f(0, 0, 0));
force_visible = readParam<bool>(L, 6, false);
sao->setAttachment(parent->getId(), bone, position, rotation, force_visible);
@@ -609,10 +618,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);
@@ -728,6 +737,18 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L)
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "bgcolor");
+ if (!lua_isnil(L, -1)) {
+ if (lua_toboolean(L, -1)) {
+ video::SColor color;
+ if (read_color(L, -1, &color))
+ prop->nametag_bgcolor = color;
+ } else {
+ prop->nametag_bgcolor = nullopt;
+ }
+ }
+ lua_pop(L, 1);
+
std::string nametag = getstringfield_default(L, 2, "text", "");
prop->nametag = nametag;
@@ -749,13 +770,24 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L)
if (!prop)
return 0;
- video::SColor color = prop->nametag_color;
-
lua_newtable(L);
- push_ARGB8(L, color);
+
+ push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "color");
+
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "bgcolor");
+ }
+
lua_pushstring(L, prop->nametag.c_str());
lua_setfield(L, -2, "text");
+
+
+
return 1;
}
@@ -892,9 +924,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<float>(L, 2) * core::RADTODEG;
entitysao->setRotation(v3f(0, yaw, 0));
@@ -2199,7 +2228,7 @@ int ObjectRef::l_set_minimap_modes(lua_State *L)
luaL_checktype(L, 2, LUA_TTABLE);
std::vector<MinimapMode> modes;
- s16 selected_mode = luaL_checkint(L, 3);
+ s16 selected_mode = readParam<s16>(L, 3);
lua_pushnil(L);
while (lua_next(L, 2) != 0) {