From 421ab9f6609ee168e9a402c08abe81eaed22b9e7 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Tue, 13 Apr 2021 08:42:17 +0200 Subject: [PATCH] Add timeout to static hudbars --- mods/HUD/mcl_bossbars/init.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_bossbars/init.lua b/mods/HUD/mcl_bossbars/init.lua index 8ed08a613f..f1d99e0139 100644 --- a/mods/HUD/mcl_bossbars/init.lua +++ b/mods/HUD/mcl_bossbars/init.lua @@ -39,7 +39,7 @@ local last_id = 0 function mcl_bossbars.add_bar(player, def, dynamic, priority) local name = player:get_player_name() local bars = mcl_bossbars.bars[name] - local bar = {text = def.text, priority = priority or 0} + local bar = {text = def.text, priority = priority or 0, timeout = def.timeout} bar.color, bar.image = get_color_info(def.color, def.percentage) if dynamic then for _, other in pairs(bars) do @@ -119,7 +119,7 @@ minetest.register_on_leaveplayer(function(player) mcl_bossbars.bars[name] = nil end) -minetest.register_globalstep(function() +minetest.register_globalstep(function(dtime) for _, player in pairs(minetest.get_connected_players()) do local name = player:get_player_name() local bars = mcl_bossbars.bars[name] @@ -134,7 +134,12 @@ minetest.register_globalstep(function() local hud = table.remove(huds, 1) if bar and bar.id then - table.insert(bars_new, bar) + if bar.timeout then + bar.timeout = bar.timeout - dtime + end + if not bar.timeout or bar.timeout > 0 then + table.insert(bars_new, bar) + end end if bar and not hud then