newgame + endgame = match
This commit is contained in:
parent
68e7cd397f
commit
f961d96d68
21
ctf/core.lua
21
ctf/core.lua
@ -144,6 +144,9 @@ function ctf.init()
|
|||||||
ctf._set("maximum_in_team", -1)
|
ctf._set("maximum_in_team", -1)
|
||||||
ctf._set("default_diplo_state", "war")
|
ctf._set("default_diplo_state", "war")
|
||||||
ctf._set("hud", true)
|
ctf._set("hud", true)
|
||||||
|
ctf._set("remove_player_on_leave", false)
|
||||||
|
ctf._set("autoalloc_on_joinplayer", true)
|
||||||
|
|
||||||
|
|
||||||
for i = 1, #ctf.registered_on_init do
|
for i = 1, #ctf.registered_on_init do
|
||||||
ctf.registered_on_init[i]()
|
ctf.registered_on_init[i]()
|
||||||
@ -266,21 +269,3 @@ function ctf.save()
|
|||||||
ctf.error("io", "CTF file failed to save!")
|
ctf.error("io", "CTF file failed to save!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctf.get_territory_owner(pos)
|
|
||||||
local largest = nil
|
|
||||||
local largest_weight = 0
|
|
||||||
for i = 1, #ctf.registered_on_territory_query do
|
|
||||||
local team, weight = ctf.registered_on_territory_query[i](pos)
|
|
||||||
if team and weight then
|
|
||||||
if weight == -1 then
|
|
||||||
return team
|
|
||||||
end
|
|
||||||
if weight > largest_weight then
|
|
||||||
largest = team
|
|
||||||
largest_weight = weight
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return largest
|
|
||||||
end
|
|
||||||
|
@ -330,24 +330,6 @@ function ctf.autoalloc(name, alloc_mode)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_newplayer(function(player)
|
|
||||||
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
|
||||||
if alloc_mode == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local team = ctf.autoalloc(name, alloc_mode)
|
|
||||||
if team then
|
|
||||||
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
|
||||||
ctf.join(name, team)
|
|
||||||
|
|
||||||
local spawn = ctf.get_spawn(team)
|
|
||||||
if spawn then
|
|
||||||
player:moveto(spawn, false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- updates the spawn position for a team
|
-- updates the spawn position for a team
|
||||||
function ctf.get_spawn(team)
|
function ctf.get_spawn(team)
|
||||||
if ctf.team(team) and ctf.team(team).spawn then
|
if ctf.team(team) and ctf.team(team).spawn then
|
||||||
@ -375,3 +357,68 @@ minetest.register_on_respawnplayer(function(player)
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
function ctf.get_territory_owner(pos)
|
||||||
|
local largest = nil
|
||||||
|
local largest_weight = 0
|
||||||
|
for i = 1, #ctf.registered_on_territory_query do
|
||||||
|
local team, weight = ctf.registered_on_territory_query[i](pos)
|
||||||
|
if team and weight then
|
||||||
|
if weight == -1 then
|
||||||
|
return team
|
||||||
|
end
|
||||||
|
if weight > largest_weight then
|
||||||
|
largest = team
|
||||||
|
largest_weight = weight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return largest
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_newplayer(function(player)
|
||||||
|
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
||||||
|
if alloc_mode == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local team = ctf.autoalloc(name, alloc_mode)
|
||||||
|
if team then
|
||||||
|
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
||||||
|
ctf.join(name, team)
|
||||||
|
|
||||||
|
local spawn = ctf.get_spawn(team)
|
||||||
|
if spawn then
|
||||||
|
player:moveto(spawn, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
if not ctf.setting("autoalloc_on_joinplayer") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
||||||
|
if alloc_mode == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local team = ctf.autoalloc(name, alloc_mode)
|
||||||
|
if team then
|
||||||
|
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
||||||
|
ctf.join(name, team)
|
||||||
|
|
||||||
|
local spawn = ctf.get_spawn(team)
|
||||||
|
if spawn then
|
||||||
|
player:moveto(spawn, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
if ctf.setting("remove_player_on_leave") then
|
||||||
|
ctf.remove_player(player:get_player_name())
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
ctf.register_on_init(function()
|
|
||||||
ctf._set("endgame.destroy_team", false)
|
|
||||||
ctf._set("endgame.break_alliances", true)
|
|
||||||
ctf._set("endgame.reset_on_winner", false)
|
|
||||||
end)
|
|
||||||
|
|
||||||
ctf_flag.register_on_capture(function(attname, flag)
|
|
||||||
if not ctf.setting("endgame.destroy_team") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local fl_team = ctf.team(flag.team)
|
|
||||||
if fl_team and #fl_team.flags == 0 then
|
|
||||||
ctf.action("endgame", flag.team .. " was defeated.")
|
|
||||||
ctf.remove_team(flag.team)
|
|
||||||
minetest.chat_send_all(flag.team .. " has been defeated!")
|
|
||||||
end
|
|
||||||
|
|
||||||
if ctf.setting("endgame.reset_on_winner") then
|
|
||||||
local winner = nil
|
|
||||||
for name, team in pairs(ctf.teams) do
|
|
||||||
if winner then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
winner = name
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Only one team left!
|
|
||||||
ctf.action("endgame", winner .. " won!")
|
|
||||||
minetest.chat_send_all("Team " .. winner .. " won!")
|
|
||||||
minetest.chat_send_all("Resetting the map, this may take a few moments...")
|
|
||||||
minetest.after(0.5, function()
|
|
||||||
--minetest.delete_area(vector.new(-16*4, -16*4, -16*4), vector.new(16*4, 16*4, 16*4))
|
|
||||||
|
|
||||||
minetest.after(1, function()
|
|
||||||
ctf.reset()
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
@ -1,2 +0,0 @@
|
|||||||
ctf
|
|
||||||
ctf_flag
|
|
@ -1,11 +1,44 @@
|
|||||||
ctf.register_on_init(function()
|
ctf.register_on_init(function()
|
||||||
ctf.log("flash", "Initialising...")
|
ctf._set("endgame.destroy_team", false)
|
||||||
ctf._set("remove_player_on_leave", true)
|
ctf._set("endgame.break_alliances", true)
|
||||||
ctf._set("new_game.teams", "")
|
ctf._set("endgame.reset_on_winner", false)
|
||||||
ctf._set("new_game.clear_inv", false)
|
ctf._set("newgame.teams", "")
|
||||||
-- ^ name, color, x, y, z; name, color, x, y, z
|
ctf._set("newgame.clear_inv", false)
|
||||||
-- ^ eg: red, red, 15, 7, 39; blue, blue, -9, 9, -43
|
end)
|
||||||
|
|
||||||
|
ctf_flag.register_on_capture(function(attname, flag)
|
||||||
|
if not ctf.setting("endgame.destroy_team") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local fl_team = ctf.team(flag.team)
|
||||||
|
if fl_team and #fl_team.flags == 0 then
|
||||||
|
ctf.action("endgame", flag.team .. " was defeated.")
|
||||||
|
ctf.remove_team(flag.team)
|
||||||
|
minetest.chat_send_all(flag.team .. " has been defeated!")
|
||||||
|
end
|
||||||
|
|
||||||
|
if ctf.setting("endgame.reset_on_winner") then
|
||||||
|
local winner = nil
|
||||||
|
for name, team in pairs(ctf.teams) do
|
||||||
|
if winner then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
winner = name
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Only one team left!
|
||||||
|
ctf.action("endgame", winner .. " won!")
|
||||||
|
minetest.chat_send_all("Team " .. winner .. " won!")
|
||||||
|
minetest.chat_send_all("Resetting the map, this may take a few moments...")
|
||||||
|
minetest.after(0.5, function()
|
||||||
|
--minetest.delete_area(vector.new(-16*4, -16*4, -16*4), vector.new(16*4, 16*4, 16*4))
|
||||||
|
|
||||||
|
minetest.after(1, function()
|
||||||
|
ctf.reset()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function safe_place(pos, node)
|
local function safe_place(pos, node)
|
||||||
@ -25,36 +58,8 @@ for i, flag in pairs(claimed) do
|
|||||||
flag.claimed = nil
|
flag.claimed = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
ctf.register_on_newgame(function()
|
||||||
if ctf.team(ctf.player(player:get_player_name()).team) then
|
local teams = ctf.setting("newgame.teams")
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
|
||||||
if alloc_mode == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local team = ctf.autoalloc(name, alloc_mode)
|
|
||||||
if team then
|
|
||||||
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
|
||||||
ctf.join(name, team)
|
|
||||||
|
|
||||||
local spawn = ctf.get_spawn(team)
|
|
||||||
if spawn then
|
|
||||||
player:moveto(spawn, false)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
if ctf.setting("remove_player_on_leave") then
|
|
||||||
ctf.remove_player(player:get_player_name())
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
ctf.register_on_new_game(function()
|
|
||||||
local teams = ctf.setting("new_game.teams")
|
|
||||||
if teams:trim() == "" then
|
if teams:trim() == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -113,7 +118,7 @@ ctf.register_on_new_game(function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctf.setting("new_game.clear_inv") then
|
if ctf.setting("newgame.clear_inv") then
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
inv:set_list("main", {})
|
inv:set_list("main", {})
|
||||||
inv:set_list("craft", {})
|
inv:set_list("craft", {})
|
Loading…
x
Reference in New Issue
Block a user