2020-09-03 18:48:33 +00:00
|
|
|
ctf_match.registered_on_skip_map = {}
|
|
|
|
function ctf_match.register_on_skip_map(func)
|
2015-11-29 00:05:37 +00:00
|
|
|
if ctf._mt_loaded then
|
|
|
|
error("You can't register callbacks at game time!")
|
|
|
|
end
|
2020-09-03 18:48:33 +00:00
|
|
|
table.insert(ctf_match.registered_on_skip_map, func)
|
2015-11-29 00:05:37 +00:00
|
|
|
end
|
|
|
|
|
2021-03-24 14:34:02 +00:00
|
|
|
function skip()
|
|
|
|
for i = 1, #ctf_match.registered_on_skip_map do
|
|
|
|
ctf_match.registered_on_skip_map[i]()
|
|
|
|
end
|
|
|
|
ctf_match.next()
|
|
|
|
end
|
|
|
|
|
|
|
|
local can_vote_skip = false
|
|
|
|
local voted_skip = false
|
|
|
|
local flags_hold = 0
|
2020-09-03 18:48:33 +00:00
|
|
|
function ctf_match.vote_next(name)
|
|
|
|
local tcolor = ctf_colors.get_color(ctf.player(name)).css or "#FFFFFFFF"
|
|
|
|
minetest.chat_send_all(minetest.colorize("#FFAA11", "Vote started by ") ..
|
|
|
|
minetest.colorize(tcolor, name))
|
2016-04-04 21:26:47 +00:00
|
|
|
|
2016-01-02 16:10:52 +00:00
|
|
|
return vote.new_vote(name, {
|
2015-12-01 18:18:29 +00:00
|
|
|
description = "Skip to next match",
|
|
|
|
help = "/yes, /no or /abstain",
|
|
|
|
duration = 60,
|
2019-11-13 08:51:01 +00:00
|
|
|
perc_needed = 0.6,
|
2015-12-01 18:18:29 +00:00
|
|
|
unanimous = 5,
|
|
|
|
|
|
|
|
on_result = function(self, result, results)
|
|
|
|
if result == "yes" then
|
|
|
|
minetest.chat_send_all("Vote to skip match passed, " ..
|
|
|
|
#results.yes .. " to " .. #results.no)
|
2021-03-24 14:34:02 +00:00
|
|
|
|
|
|
|
can_vote_skip = false
|
|
|
|
voted_skip = true
|
|
|
|
if flags_hold <= 0 then
|
|
|
|
skip()
|
2015-12-01 18:18:29 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
minetest.chat_send_all("Vote to skip match failed, " ..
|
|
|
|
#results.no .. " to " .. #results.yes)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2018-04-06 13:04:56 +00:00
|
|
|
on_vote = function(self, voter, value)
|
|
|
|
minetest.chat_send_all(voter .. " voted " .. value .. " to '" ..
|
2015-12-01 18:18:29 +00:00
|
|
|
self.description .. "'")
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2018-08-20 10:23:42 +00:00
|
|
|
ctf_match.register_on_new_match(vote.clear_vote)
|
|
|
|
|
2015-12-01 18:18:29 +00:00
|
|
|
minetest.register_chatcommand("vote", {
|
2015-07-17 17:10:17 +00:00
|
|
|
privs = {
|
2016-04-06 15:07:04 +00:00
|
|
|
interact = true,
|
|
|
|
vote_starter = true
|
2015-07-17 17:10:17 +00:00
|
|
|
},
|
2015-12-01 18:18:29 +00:00
|
|
|
func = ctf_match.vote_next
|
|
|
|
})
|
2015-07-17 17:10:17 +00:00
|
|
|
|
2020-09-03 18:48:33 +00:00
|
|
|
-- Automatically start a skip vote after 90m, and subsequent votes every 15m
|
|
|
|
|
|
|
|
local matchskip_time
|
|
|
|
local matchskip_timer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2021-03-24 14:34:02 +00:00
|
|
|
if not can_vote_skip then return end
|
2020-09-03 18:48:33 +00:00
|
|
|
|
|
|
|
matchskip_timer = matchskip_timer + dtime
|
|
|
|
|
|
|
|
if matchskip_timer > matchskip_time then
|
|
|
|
matchskip_timer = 0
|
|
|
|
|
|
|
|
-- Start vote and decrease time until next vote skip
|
|
|
|
ctf_match.vote_next("[CTF automatic skip-vote]"..matchskip_time)
|
2020-09-03 18:51:25 +00:00
|
|
|
matchskip_time = tonumber(minetest.settings:get("ctf_match.auto_skip_interval")) or 15 * 60
|
2015-07-17 17:10:17 +00:00
|
|
|
end
|
2015-12-01 18:18:29 +00:00
|
|
|
end)
|
2020-09-03 18:48:33 +00:00
|
|
|
|
2021-03-24 14:34:02 +00:00
|
|
|
ctf.register_on_new_game(function()
|
|
|
|
can_vote_skip = false
|
|
|
|
voted_skip = false
|
|
|
|
flags_hold = 0
|
|
|
|
end)
|
|
|
|
ctf_flag.register_on_pick_up(function()
|
|
|
|
flags_hold = flags_hold + 1
|
|
|
|
end)
|
2020-09-03 18:48:33 +00:00
|
|
|
ctf_flag.register_on_drop(function()
|
2021-03-24 14:34:02 +00:00
|
|
|
flags_hold = flags_hold - 1
|
|
|
|
if voted_skip and flags_hold <= 0 then
|
|
|
|
minetest.after(5, function()
|
|
|
|
skip()
|
|
|
|
end)
|
|
|
|
end
|
2020-09-03 18:48:33 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
ctf_match.register_on_build_time_end(function()
|
2021-03-24 14:34:02 +00:00
|
|
|
can_vote_skip = true
|
2020-09-03 18:48:33 +00:00
|
|
|
matchskip_timer = 0
|
2020-09-03 18:51:25 +00:00
|
|
|
-- Set to initial vote time
|
2021-02-09 17:42:23 +00:00
|
|
|
matchskip_time = tonumber(minetest.settings:get("ctf_match.auto_skip_delay")) or 50 * 60
|
2020-09-03 18:48:33 +00:00
|
|
|
end)
|