Add prematch build time

This commit is contained in:
rubenwardy 2015-11-28 00:56:10 +00:00
parent fcd1f108e2
commit 9bbdc41967
9 changed files with 177 additions and 14 deletions

View file

@ -0,0 +1,56 @@
ctf.register_on_init(function()
ctf._set("match.build_time", 10)
end)
ctf_match.registered_on_build_time_start = {}
function ctf_match.register_on_build_time_start(func)
if ctf._mt_loaded then
error("You can't register callbacks at game time!")
end
table.insert(ctf_match.registered_on_build_time_start, func)
end
ctf_match.registered_on_build_time_end = {}
function ctf_match.register_on_build_time_end(func)
if ctf._mt_loaded then
error("You can't register callbacks at game time!")
end
table.insert(ctf_match.registered_on_build_time_end, func)
end
ctf_match.build_timer = 0
function ctf_match.is_in_build_time()
return ctf_match.build_timer > 0
end
ctf.register_on_new_game(function()
ctf_match.build_timer = ctf.setting("match.build_time")
if ctf_match.build_timer > 0 then
for i = 1, #ctf_match.registered_on_build_time_start do
ctf_match.registered_on_build_time_start[i]()
end
end
end)
minetest.register_globalstep(function(delta)
if ctf_match.build_timer > 0 then
ctf_match.build_timer = ctf_match.build_timer - delta
if ctf_match.build_timer <= 0 then
for i = 1, #ctf_match.registered_on_build_time_end do
ctf_match.registered_on_build_time_end[i]()
end
end
end
end)
ctf_match.register_on_build_time_start(function()
minetest.chat_send_all("Prepare your base! Match starts in " ..
ctf.setting("match.build_time") .. " seconds.")
minetest.setting_set("enable_pvp", "false")
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")
end)

View file

@ -6,6 +6,7 @@ for i, flag in pairs(claimed) do
end
dofile(minetest.get_modpath("ctf_match") .. "/matches.lua")
dofile(minetest.get_modpath("ctf_match") .. "/buildtime.lua")
dofile(minetest.get_modpath("ctf_match") .. "/reset.lua")
dofile(minetest.get_modpath("ctf_match") .. "/chat.lua")
dofile(minetest.get_modpath("ctf_match") .. "/vote.lua")

View file

@ -6,8 +6,21 @@ ctf.register_on_init(function()
ctf._set("match.clear_inv", false)
end)
ctf_match.registered_on_new_match = {}
function ctf_match.register_on_new_match(func)
if ctf._mt_loaded then
error("You can't register callbacks at game time!")
end
table.insert(ctf_match.registered_on_new_match, func)
end
-- Load next match. May be overrided
function ctf_match.next()
for i = 1, #ctf_match.registered_on_new_match do
ctf_match.registered_on_new_match[i]()
end
ctf.reset()
-- Note: ctf.reset calls register_on_new_game, below.
end