From b4df909ac68dd81c33b12cc0bdd132e7cc168fe3 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 28 Nov 2015 01:10:02 +0000 Subject: [PATCH] Add countdown on HUD for prematch build time --- mods/ctf_barrier/init.lua | 2 -- mods/ctf_match/buildtime.lua | 27 +++++++++++++++++++++++++++ mods/ctf_match/depends.txt | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/mods/ctf_barrier/init.lua b/mods/ctf_barrier/init.lua index a15359c..4132f88 100644 --- a/mods/ctf_barrier/init.lua +++ b/mods/ctf_barrier/init.lua @@ -170,8 +170,6 @@ ctf_match.register_on_build_time_end(function() end end - print(n .. " invalid nodes out of " .. t .. " (" .. (t-n) .. " valid)") - vm:set_data(data) vm:write_to_map(data) vm:update_map() diff --git a/mods/ctf_match/buildtime.lua b/mods/ctf_match/buildtime.lua index c9bdb28..59d0fb9 100644 --- a/mods/ctf_match/buildtime.lua +++ b/mods/ctf_match/buildtime.lua @@ -33,6 +33,7 @@ ctf.register_on_new_game(function() end end) +local last = 0 minetest.register_globalstep(function(delta) if ctf_match.build_timer > 0 then ctf_match.build_timer = ctf_match.build_timer - delta @@ -41,6 +42,13 @@ minetest.register_globalstep(function(delta) ctf_match.registered_on_build_time_end[i]() end end + local rbt = math.floor(ctf_match.build_timer) + if last ~= rbt then + local text = math.floor(ctf_match.build_timer) .. "s until match begins!" + for _, player in pairs(minetest.get_connected_players()) do + ctf.hud:change(player, "ctf_match:countdown", "text", text) + end + end end end) @@ -53,4 +61,23 @@ end) ctf_match.register_on_build_time_end(function() minetest.chat_send_all("Build time over! Attack and defend!") minetest.setting_set("enable_pvp", "true") + for _, player in pairs(minetest.get_connected_players()) do + ctf.hud:remove(player, "ctf_match:countdown") + end +end) + +ctf.hud.register_part(function(player, name, tplayer) + if ctf_match.build_timer <= 0 then + ctf.hud:remove(player, "ctf_match:countdown") + elseif not ctf.hud:exists(player, "ctf_match:countdown") then + ctf.hud:add(player, "ctf_match:countdown", { + hud_elem_type = "text", + position = {x = 0.5, y = 0.5}, + scale = {x = 0, y = 70}, + text = math.floor(ctf_match.build_timer) .. "s until match begins!", + number = 0xFFFFFF, + offset = {x = -20, y = 20}, + alignment = {x = 0.2, y = 0} + }) + end end) diff --git a/mods/ctf_match/depends.txt b/mods/ctf_match/depends.txt index 0620afe..7430160 100644 --- a/mods/ctf_match/depends.txt +++ b/mods/ctf_match/depends.txt @@ -1,3 +1,4 @@ ctf ctf_flag vote +hudkit