mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add option to give every object a nametag
or change the nametag text of players
This commit is contained in:
parent
19f73e4efc
commit
9eee3c3f46
9 changed files with 111 additions and 95 deletions
|
@ -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}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue