aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi_object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scriptapi_object.cpp')
-rw-r--r--src/scriptapi_object.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp
index 531bb7a58..9152c9eb3 100644
--- a/src/scriptapi_object.cpp
+++ b/src/scriptapi_object.cpp
@@ -749,7 +749,7 @@ int ObjectRef::l_hud_add(lua_State *L)
elem->text = getstringfield_default(L, 2, "text", "");
elem->number = getintfield_default(L, 2, "number", 0);
elem->item = getintfield_default(L, 2, "item", 0);
- elem->dir = getintfield_default(L, 2, "dir", 0);
+ elem->dir = getintfield_default(L, 2, "direction", 0);
u32 id = get_server(L)->hudAdd(player, elem);
if (id == (u32)-1) {
@@ -788,15 +788,17 @@ int ObjectRef::l_hud_change(lua_State *L)
if (player == NULL)
return 0;
- u32 id = -1;
- if (!lua_isnil(L, 2))
- id = lua_tonumber(L, 2);
-
- HudElementStat stat = (HudElementStat)getenumfield(L, 3, "stat",
- es_HudElementStat, HUD_STAT_NUMBER);
-
+ u32 id = !lua_isnil(L, 2) ? lua_tonumber(L, 2) : -1;
if (id >= player->hud.size())
return 0;
+
+ HudElementStat stat = HUD_STAT_NUMBER;
+ if (!lua_isnil(L, 3)) {
+ int statint;
+ std::string statstr = lua_tostring(L, 3);
+ stat = string_to_enum(es_HudElementStat, statint, statstr) ?
+ (HudElementStat)statint : HUD_STAT_NUMBER;
+ }
void *value = NULL;
HudElement *e = player->hud[id];
@@ -832,7 +834,7 @@ int ObjectRef::l_hud_change(lua_State *L)
e->dir = lua_tonumber(L, 4);
value = &e->dir;
}
-
+
get_server(L)->hudChange(player, id, stat, value);
lua_pushboolean(L, true);