summaryrefslogtreecommitdiff
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.cpp132
1 files changed, 78 insertions, 54 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 3ac8eeefb..6d6614e7d 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -31,10 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "hud.h"
#include "scripting_game.h"
-#define GET_ENV_PTR ServerEnvironment* env = \
- dynamic_cast<ServerEnvironment*>(getEnv(L)); \
- if (env == NULL) return 0
-
struct EnumString es_HudElementType[] =
{
{HUD_ELEM_IMAGE, "image"},
@@ -132,7 +128,6 @@ int ObjectRef::gc_object(lua_State *L) {
// remove(self)
int ObjectRef::l_remove(lua_State *L)
{
- NO_MAP_LOCK_REQUIRED;
GET_ENV_PTR;
ObjectRef *ref = checkobject(L, 1);
@@ -409,6 +404,7 @@ int ObjectRef::l_get_armor_groups(lua_State *L)
// physics_override_gravity, sneak, sneak_glitch)
int ObjectRef::l_set_physics_override(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
PlayerSAO *co = (PlayerSAO *) getobject(ref);
if (co == NULL) return 0;
@@ -441,6 +437,7 @@ int ObjectRef::l_set_physics_override(lua_State *L)
// get_physics_override(self)
int ObjectRef::l_get_physics_override(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
PlayerSAO *co = (PlayerSAO *)getobject(ref);
if (co == NULL)
@@ -509,7 +506,7 @@ int ObjectRef::l_get_animation(lua_State *L)
// set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed)
int ObjectRef::l_set_local_animation(lua_State *L)
{
- //NO_MAP_LOCK_REQUIRED;
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -534,7 +531,7 @@ int ObjectRef::l_set_local_animation(lua_State *L)
// get_local_animation(self)
int ObjectRef::l_get_local_animation(lua_State *L)
{
- //NO_MAP_LOCK_REQUIRED
+ NO_MAP_LOCK_REQUIRED
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -555,7 +552,7 @@ int ObjectRef::l_get_local_animation(lua_State *L)
// set_eye_offset(self, v3f first pv, v3f third pv)
int ObjectRef::l_set_eye_offset(lua_State *L)
{
- //NO_MAP_LOCK_REQUIRED;
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -585,7 +582,7 @@ int ObjectRef::l_set_eye_offset(lua_State *L)
// get_eye_offset(self)
int ObjectRef::l_get_eye_offset(lua_State *L)
{
- //NO_MAP_LOCK_REQUIRED;
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -642,7 +639,6 @@ int ObjectRef::l_get_bone_position(lua_State *L)
// set_attach(self, parent, bone, position, rotation)
int ObjectRef::l_set_attach(lua_State *L)
{
- NO_MAP_LOCK_REQUIRED;
GET_ENV_PTR;
ObjectRef *ref = checkobject(L, 1);
@@ -681,7 +677,6 @@ int ObjectRef::l_set_attach(lua_State *L)
// get_attach(self)
int ObjectRef::l_get_attach(lua_State *L)
{
- NO_MAP_LOCK_REQUIRED;
GET_ENV_PTR;
ObjectRef *ref = checkobject(L, 1);
@@ -709,7 +704,6 @@ int ObjectRef::l_get_attach(lua_State *L)
// set_detach(self)
int ObjectRef::l_set_detach(lua_State *L)
{
- NO_MAP_LOCK_REQUIRED;
GET_ENV_PTR;
ObjectRef *ref = checkobject(L, 1);
@@ -773,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})
@@ -1137,6 +1184,7 @@ int ObjectRef::l_get_player_control_bits(lua_State *L)
// hud_add(self, form)
int ObjectRef::l_hud_add(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1187,7 +1235,7 @@ int ObjectRef::l_hud_add(lua_State *L)
}
u32 id = getServer(L)->hudAdd(player, elem);
- if (id == (u32)-1) {
+ if (id == U32_MAX) {
delete elem;
return 0;
}
@@ -1199,6 +1247,7 @@ int ObjectRef::l_hud_add(lua_State *L)
// hud_remove(self, id)
int ObjectRef::l_hud_remove(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1218,6 +1267,7 @@ int ObjectRef::l_hud_remove(lua_State *L)
// hud_change(self, id, stat, data)
int ObjectRef::l_hud_change(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1294,6 +1344,7 @@ int ObjectRef::l_hud_change(lua_State *L)
// hud_get(self, id)
int ObjectRef::l_hud_get(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1344,6 +1395,7 @@ int ObjectRef::l_hud_get(lua_State *L)
// hud_set_flags(self, flags)
int ObjectRef::l_hud_set_flags(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1369,6 +1421,7 @@ int ObjectRef::l_hud_set_flags(lua_State *L)
int ObjectRef::l_hud_get_flags(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1394,6 +1447,7 @@ int ObjectRef::l_hud_get_flags(lua_State *L)
// hud_set_hotbar_itemcount(self, hotbar_itemcount)
int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1411,6 +1465,7 @@ int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
// hud_get_hotbar_itemcount(self)
int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1425,6 +1480,7 @@ int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
// hud_set_hotbar_image(self, name)
int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1439,6 +1495,7 @@ int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
// hud_get_hotbar_image(self)
int ObjectRef::l_hud_get_hotbar_image(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1452,6 +1509,7 @@ int ObjectRef::l_hud_get_hotbar_image(lua_State *L)
// hud_set_hotbar_selected_image(self, name)
int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1466,6 +1524,7 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
// hud_get_hotbar_selected_image(self)
int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1479,6 +1538,7 @@ int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
// set_sky(self, bgcolor, type, list)
int ObjectRef::l_set_sky(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1517,6 +1577,7 @@ int ObjectRef::l_set_sky(lua_State *L)
// get_sky(self)
int ObjectRef::l_get_sky(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1544,6 +1605,7 @@ int ObjectRef::l_get_sky(lua_State *L)
// override_day_night_ratio(self, brightness=0...1)
int ObjectRef::l_override_day_night_ratio(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1566,6 +1628,7 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
// get_day_night_ratio(self)
int ObjectRef::l_get_day_night_ratio(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
Player *player = getplayer(ref);
if (player == NULL)
@@ -1583,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)
{
@@ -1709,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),
@@ -1758,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}
};