summaryrefslogtreecommitdiff
path: root/src/scriptapi_object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scriptapi_object.cpp')
-rw-r--r--src/scriptapi_object.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp
index 6669ad871..e2eec5104 100644
--- a/src/scriptapi_object.cpp
+++ b/src/scriptapi_object.cpp
@@ -52,6 +52,15 @@ struct EnumString es_HudElementStat[] =
{0, NULL},
};
+struct EnumString es_HudBuiltinElement[] =
+{
+ {HUD_BUILTIN_HOTBAR, "hotbar"},
+ {HUD_BUILTIN_HEALTHBAR, "healthbar"},
+ {HUD_BUILTIN_CROSSHAIR, "crosshair"},
+ {HUD_BUILTIN_WIELDITEM, "wielditem"},
+ {0, NULL},
+};
+
/*
ObjectRef
@@ -902,6 +911,33 @@ int ObjectRef::l_hud_get(lua_State *L)
return 1;
}
+// hud_builtin_enable(self, id, flag)
+int ObjectRef::l_hud_builtin_enable(lua_State *L)
+{
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ if (player == NULL)
+ return 0;
+
+ HudBuiltinElement id;
+ int id_i;
+
+ std::string s(lua_tostring(L, 2));
+
+ // Return nil if component is not in enum
+ if (!string_to_enum(es_HudBuiltinElement, id_i, s))
+ return 0;
+
+ id = (HudBuiltinElement)id_i;
+
+ bool flag = (bool)lua_toboolean(L, 3);
+
+ bool ok = get_server(L)->hudBuiltinEnable(player, id, flag);
+
+ lua_pushboolean(L, (int)ok);
+ return 1;
+}
+
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{
@@ -1012,6 +1048,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, hud_remove),
luamethod(ObjectRef, hud_change),
luamethod(ObjectRef, hud_get),
+ luamethod(ObjectRef, hud_builtin_enable),
//luamethod(ObjectRef, hud_lock_next_bar),
//luamethod(ObjectRef, hud_unlock_bar),
{0,0}