diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 1a9202f57..6a0dbfbd5 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1611,22 +1611,32 @@ static int lib_hudenabled(lua_State *L) static int lib_hudsetvotebackground(lua_State *L) { + // Reset to default memset(VoteScreen.luaPrefix, 0, sizeof(VoteScreen.luaPrefix)); + VoteScreen.timePerAnimFrame = 2; - if (lua_isnoneornil(L, 1)) + if (!lua_isnoneornil(L, 1)) { - return 0; + const char *prefix = luaL_checkstring(L, 1); + + if (strlen(prefix) != 4) + { + return luaL_argerror(L, 1, "prefix should 4 characters wide"); + } + + strncpy(VoteScreen.luaPrefix, prefix, 4); + strupr(VoteScreen.luaPrefix); } - const char *prefix = luaL_checkstring(L, 1); - - if (strlen(prefix) != 4) + if (!lua_isnoneornil(L, 2)) { - return luaL_argerror(L, 1, "prefix should 4 characters wide"); - } + INT32 time_per_frame = luaL_checkinteger(L, 2); - strncpy(VoteScreen.luaPrefix, prefix, 4); - strupr(VoteScreen.luaPrefix); + if (time_per_frame <= 0) + return luaL_argerror(L, 2, "time per frame should be 1 or more"); + + VoteScreen.timePerAnimFrame = time_per_frame; + } return 0; } diff --git a/src/y_inter.c b/src/y_inter.c index f9acc45f1..32cffdac4 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1082,6 +1082,9 @@ static void Y_VoteScreenCheck(void) VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0; VoteScreen.currentAnimFrame = 0; + if (VoteScreen.timePerAnimFrame == 0) + VoteScreen.timePerAnimFrame = 2; + INT32 i = 1; // check for lua vote background replacements @@ -1173,7 +1176,7 @@ static void Y_DrawLuaVoteScreenPatch(boolean widePatch) Y_VoteBackgroundDrawer(votebg); - if (renderisnewtic && (votetic % 2 == 0) && !paused) + if (renderisnewtic && (votetic % VoteScreen.timePerAnimFrame == 0) && !paused) VoteScreen.currentAnimFrame = (nextframe > tempfoundAnimLuaVoteFrames) ? 0 : nextframe; } diff --git a/src/y_inter.h b/src/y_inter.h index e2ec9f2cb..88d610ac8 100644 --- a/src/y_inter.h +++ b/src/y_inter.h @@ -65,6 +65,7 @@ typedef struct char luaPrefix[5]; // prefix for lua votescreens INT32 currentAnimFrame; // current animated background frame + INT32 timePerAnimFrame; // time for 1 frame in ticks, 2 by default INT32 foundLuaVoteFrames; // normal lua patch frames INT32 foundLuaVoteWideFrames; // widescreen lua patch frames