aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp13
-rw-r--r--src/script/lua_api/l_object.cpp96
2 files changed, 68 insertions, 41 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index fe429b5d4..4d277ec59 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -201,6 +201,14 @@ void read_object_properties(lua_State *L, int index,
}
lua_pop(L, 1);
getboolfield(L, -1, "backface_culling", prop->backface_culling);
+ getstringfield(L, -1, "nametag", prop->nametag);
+ lua_getfield(L, -1, "nametag_color");
+ if (!lua_isnil(L, -1)) {
+ video::SColor color = prop->nametag_color;
+ if (read_color(L, -1, &color))
+ prop->nametag_color = color;
+ }
+ lua_pop(L, 1);
}
/******************************************************************************/
@@ -261,6 +269,11 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_setfield(L, -2, "automatic_face_movement_dir");
lua_pushboolean(L, prop->backface_culling);
lua_setfield(L, -2, "backface_culling");
+ lua_pushlstring(L, prop->nametag.c_str(), prop->nametag.size());
+ lua_setfield(L, -2, "nametag");
+ lua_newtable(L);
+ push_ARGB8(L, prop->nametag_color);
+ lua_setfield(L, -2, "nametag_color");
}
/******************************************************************************/
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 52190d60e..6d6614e7d 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -767,6 +767,59 @@ int ObjectRef::l_is_player(lua_State *L)
return 1;
}
+// set_nametag_attributes(self, attributes)
+int ObjectRef::l_set_nametag_attributes(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ ServerActiveObject *co = getobject(ref);
+
+ if (co == NULL)
+ return 0;
+ ObjectProperties *prop = co->accessObjectProperties();
+ if (!prop)
+ return 0;
+
+ lua_getfield(L, 2, "color");
+ if (!lua_isnil(L, -1)) {
+ video::SColor color = prop->nametag_color;
+ read_color(L, -1, &color);
+ prop->nametag_color = color;
+ }
+ lua_pop(L, 1);
+
+ std::string nametag = getstringfield_default(L, 2, "text", "");
+ if (nametag != "")
+ prop->nametag = nametag;
+
+ co->notifyObjectPropertiesModified();
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+// get_nametag_attributes(self)
+int ObjectRef::l_get_nametag_attributes(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ ServerActiveObject *co = getobject(ref);
+
+ if (co == NULL)
+ return 0;
+ ObjectProperties *prop = co->accessObjectProperties();
+ if (!prop)
+ return 0;
+
+ video::SColor color = prop->nametag_color;
+
+ lua_newtable(L);
+ push_ARGB8(L, color);
+ lua_setfield(L, -2, "color");
+ lua_pushstring(L, prop->nametag.c_str());
+ lua_setfield(L, -2, "text");
+ return 1;
+}
+
/* LuaEntitySAO-only */
// setvelocity(self, {x=num, y=num, z=num})
@@ -1593,45 +1646,6 @@ int ObjectRef::l_get_day_night_ratio(lua_State *L)
return 1;
}
-// set_nametag_attributes(self, attributes)
-int ObjectRef::l_set_nametag_attributes(lua_State *L)
-{
- NO_MAP_LOCK_REQUIRED;
- ObjectRef *ref = checkobject(L, 1);
- PlayerSAO *playersao = getplayersao(ref);
- if (playersao == NULL)
- return 0;
-
- lua_getfield(L, 2, "color");
- if (!lua_isnil(L, -1)) {
- video::SColor color = playersao->getNametagColor();
- if (!read_color(L, -1, &color))
- return 0;
- playersao->setNametagColor(color);
- }
-
- lua_pushboolean(L, true);
- return 1;
-}
-
-// get_nametag_attributes(self)
-int ObjectRef::l_get_nametag_attributes(lua_State *L)
-{
- NO_MAP_LOCK_REQUIRED;
- ObjectRef *ref = checkobject(L, 1);
- PlayerSAO *playersao = getplayersao(ref);
- if (playersao == NULL)
- return 0;
-
- video::SColor color = playersao->getNametagColor();
-
- lua_newtable(L);
- push_ARGB8(L, color);
- lua_setfield(L, -2, "color");
-
- return 1;
-}
-
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{
@@ -1719,6 +1733,8 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, set_detach),
luamethod(ObjectRef, set_properties),
luamethod(ObjectRef, get_properties),
+ luamethod(ObjectRef, set_nametag_attributes),
+ luamethod(ObjectRef, get_nametag_attributes),
// LuaEntitySAO-only
luamethod(ObjectRef, setvelocity),
luamethod(ObjectRef, getvelocity),
@@ -1768,7 +1784,5 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, get_local_animation),
luamethod(ObjectRef, set_eye_offset),
luamethod(ObjectRef, get_eye_offset),
- luamethod(ObjectRef, set_nametag_attributes),
- luamethod(ObjectRef, get_nametag_attributes),
{0,0}
};