Add countdown on HUD for prematch build time

This commit is contained in:
rubenwardy 2015-11-28 01:10:02 +00:00
parent 9bbdc41967
commit b4df909ac6
3 changed files with 28 additions and 2 deletions

View file

@ -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()

View file

@ -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)

View file

@ -1,3 +1,4 @@
ctf
ctf_flag
vote
hudkit