Skip to content

Commit 14ba94a

Browse files
committedApr 21, 2013
Fix hud_change stat argument retrieval
1 parent 03868ff commit 14ba94a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎src/scriptapi_object.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -788,15 +788,17 @@ int ObjectRef::l_hud_change(lua_State *L)
788788
if (player == NULL)
789789
return 0;
790790

791-
u32 id = -1;
792-
if (!lua_isnil(L, 2))
793-
id = lua_tonumber(L, 2);
794-
795-
HudElementStat stat = (HudElementStat)getenumfield(L, 3, "stat",
796-
es_HudElementStat, HUD_STAT_NUMBER);
797-
791+
u32 id = !lua_isnil(L, 2) ? lua_tonumber(L, 2) : -1;
798792
if (id >= player->hud.size())
799793
return 0;
794+
795+
HudElementStat stat = HUD_STAT_NUMBER;
796+
if (!lua_isnil(L, 3)) {
797+
int statint;
798+
std::string statstr = lua_tostring(L, 3);
799+
stat = string_to_enum(es_HudElementStat, statint, statstr) ?
800+
(HudElementStat)statint : HUD_STAT_NUMBER;
801+
}
800802

801803
void *value = NULL;
802804
HudElement *e = player->hud[id];
@@ -832,7 +834,7 @@ int ObjectRef::l_hud_change(lua_State *L)
832834
e->dir = lua_tonumber(L, 4);
833835
value = &e->dir;
834836
}
835-
837+
836838
get_server(L)->hudChange(player, id, stat, value);
837839

838840
lua_pushboolean(L, true);

0 commit comments

Comments
 (0)
Please sign in to comment.