2015-11-22 20:07:41 +00:00
|
|
|
ctf.register_on_init(function()
|
|
|
|
ctf._set("match", false)
|
|
|
|
ctf._set("match.destroy_team", false)
|
|
|
|
ctf._set("match.break_alliances", true)
|
2016-03-29 23:24:12 +00:00
|
|
|
ctf._set("match.teams", 2)
|
|
|
|
ctf._set("match.team.1", "red")
|
|
|
|
ctf._set("match.team.1.color", "red")
|
|
|
|
ctf._set("match.team.1.pos", "7,65,93")
|
|
|
|
ctf._set("match.team.2", "blue")
|
|
|
|
ctf._set("match.team.2.color", "blue")
|
|
|
|
ctf._set("match.team.2.pos", "-22,66,-78")
|
2015-11-22 20:07:41 +00:00
|
|
|
ctf._set("match.clear_inv", false)
|
|
|
|
end)
|
|
|
|
|
2015-11-28 00:56:10 +00:00
|
|
|
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
|
|
|
|
|
2015-11-29 00:05:37 +00:00
|
|
|
ctf_match.registered_on_winner = {}
|
|
|
|
function ctf_match.register_on_winner(func)
|
|
|
|
if ctf._mt_loaded then
|
|
|
|
error("You can't register callbacks at game time!")
|
|
|
|
end
|
|
|
|
table.insert(ctf_match.registered_on_winner, func)
|
|
|
|
end
|
|
|
|
|
2015-11-28 00:56:10 +00:00
|
|
|
|
2015-11-22 20:07:41 +00:00
|
|
|
-- Load next match. May be overrided
|
|
|
|
function ctf_match.next()
|
2015-11-28 00:56:10 +00:00
|
|
|
for i = 1, #ctf_match.registered_on_new_match do
|
|
|
|
ctf_match.registered_on_new_match[i]()
|
|
|
|
end
|
|
|
|
|
2015-11-22 20:07:41 +00:00
|
|
|
ctf.reset()
|
2017-12-23 16:33:05 +00:00
|
|
|
|
|
|
|
ctf_match.create_teams()
|
|
|
|
|
|
|
|
for i, player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
|
|
|
local team = ctf.autoalloc(name, alloc_mode)
|
|
|
|
|
|
|
|
if alloc_mode ~= 0 and team then
|
|
|
|
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
|
|
|
ctf.join(name, team)
|
|
|
|
end
|
|
|
|
|
|
|
|
ctf.move_to_spawn(name)
|
|
|
|
|
|
|
|
if ctf.setting("match.clear_inv") then
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
inv:set_list("main", {})
|
|
|
|
inv:set_list("craft", {})
|
|
|
|
give_initial_stuff(player)
|
|
|
|
end
|
|
|
|
|
|
|
|
player:set_hp(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.set_timeofday(0.4)
|
|
|
|
|
|
|
|
minetest.chat_send_all("Next round!")
|
|
|
|
if minetest.global_exists("chatplus") then
|
|
|
|
chatplus.log("Next round!")
|
|
|
|
end
|
2015-11-22 20:07:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Check for winner
|
2015-12-03 22:27:22 +00:00
|
|
|
local game_won = false
|
2015-11-22 20:07:41 +00:00
|
|
|
function ctf_match.check_for_winner()
|
|
|
|
local winner
|
|
|
|
for name, team in pairs(ctf.teams) do
|
|
|
|
if winner then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
winner = name
|
|
|
|
end
|
|
|
|
|
|
|
|
-- There is a winner!
|
2015-12-03 22:27:22 +00:00
|
|
|
if not game_won then
|
|
|
|
game_won = true
|
|
|
|
ctf.action("match", winner .. " won!")
|
|
|
|
minetest.chat_send_all("Team " .. winner .. " won!")
|
|
|
|
for i = 1, #ctf_match.registered_on_winner do
|
|
|
|
ctf_match.registered_on_winner[i](winner)
|
|
|
|
end
|
|
|
|
minetest.after(2, function()
|
|
|
|
game_won = false
|
|
|
|
if ctf.setting("match") then
|
|
|
|
ctf_match.next()
|
|
|
|
end
|
|
|
|
end)
|
2015-11-22 20:07:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-23 16:33:05 +00:00
|
|
|
-- This is overriden by ctf_map
|
2016-03-29 23:24:12 +00:00
|
|
|
function ctf_match.create_teams()
|
2017-12-23 16:33:05 +00:00
|
|
|
error("Error! Unimplemented")
|
2016-03-29 23:24:12 +00:00
|
|
|
end
|
|
|
|
|
2015-11-22 20:07:41 +00:00
|
|
|
ctf_flag.register_on_capture(function(attname, flag)
|
|
|
|
if not ctf.setting("match.destroy_team") then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local fl_team = ctf.team(flag.team)
|
|
|
|
if fl_team and #fl_team.flags == 0 then
|
|
|
|
ctf.action("match", flag.team .. " was defeated.")
|
|
|
|
ctf.remove_team(flag.team)
|
|
|
|
minetest.chat_send_all(flag.team .. " has been defeated!")
|
|
|
|
end
|
|
|
|
|
|
|
|
ctf_match.check_for_winner()
|
|
|
|
end)
|