diff --git a/mods/capturetheflag/ctf/core.lua b/mods/capturetheflag/ctf/core.lua index 7ab1824..f5eb0b7 100644 --- a/mods/capturetheflag/ctf/core.lua +++ b/mods/capturetheflag/ctf/core.lua @@ -194,6 +194,7 @@ minetest.after(10, ctf.check_save) function ctf.save() ctf.log("io", "Saving CTF state...") local file = io.open(minetest.get_worldpath().."/ctf.txt", "w") + ctf.needs_save = false if file then local out = { teams = ctf.teams, diff --git a/mods/capturetheflag/ctf_endgame/init.lua b/mods/capturetheflag/ctf_endgame/init.lua index 532ace7..7180178 100644 --- a/mods/capturetheflag/ctf_endgame/init.lua +++ b/mods/capturetheflag/ctf_endgame/init.lua @@ -4,18 +4,6 @@ ctf.register_on_init(function() ctf._set("endgame.reset_on_winner", true) end) -local function safe_place(pos, node) - ctf.log("endgame", "attempting to place...") - minetest.get_voxel_manip(pos, { x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}) - minetest.set_node(pos, node) - if minetest.get_node(pos).name ~= node.name then - ctf.error("endgame", "failed to place node, retrying...") - minetest.after(0.5, function() - safe_place(pos, node) - end) - end -end - ctf_flag.register_on_capture(function(attname, flag) if not ctf.setting("endgame.destroy_team") then return @@ -50,52 +38,3 @@ ctf_flag.register_on_capture(function(attname, flag) end) end end) - -ctf.register_on_new_game(function() - ctf.log("endgame", "Setting up new game!") - - ctf.team({name="red", color="red", add_team=true}) - ctf.team({name="blue", color="blue", add_team=true}) - - local fred = {x=15, y=7, z=39, team="red"} - local fblue = {x=-9, y=9, z=-43, team="blue"} - ctf_flag.add("red", fred) - ctf_flag.add("blue", fblue) - - minetest.after(0, function() - safe_place(fred, {name="ctf_flag:flag"}) - safe_place(fblue, {name="ctf_flag:flag"}) - end) - - for i, player in pairs(minetest.get_connected_players()) do - local name = player:get_player_name() - local inv = player:get_inventory() - inv:set_list("main", {}) - inv:set_list("craft", {}) - - local alloc_mode = tonumber(ctf.setting("allocate_mode")) - if alloc_mode == 0 then - return - end - local team = ctf.autoalloc(name, alloc_mode) - if team then - ctf.log("autoalloc", name .. " was allocated to " .. team) - ctf.join(name, team) - end - - team = ctf.player(name).team - if ctf.team(team) then - local spawn = ctf.get_spawn(team) - if spawn then - player:moveto(spawn, false) - end - end - - minetest.log("action", "Giving initial stuff to player "..player:get_player_name()) - player:get_inventory():add_item('main', 'default:pick_steel') - player:get_inventory():add_item('main', 'default:sword_steel') - player:get_inventory():add_item('main', 'default:cobble 99') - end - minetest.log("endgame", "reset done") - minetest.chat_send_all("Next round!") -end) diff --git a/mods/capturetheflag/ctf_flag/flag_func.lua b/mods/capturetheflag/ctf_flag/flag_func.lua index 7e34518..44c4cb3 100644 --- a/mods/capturetheflag/ctf_flag/flag_func.lua +++ b/mods/capturetheflag/ctf_flag/flag_func.lua @@ -70,24 +70,6 @@ local function do_capture(attname, flag, returned) ctf.needs_save = true end -function ctf_flag.player_drop_flag(name) - for i = 1, #ctf_flag.claimed do - local flag = ctf_flag.claimed[i] - if flag.claimed.player == name then - flag.claimed = nil - ctf_flag.collect_claimed() - - local flag_name = "" - if flag.name then - flag_name = flag.name .. " " - end - flag_name = flag.team .. "'s " .. flag_name .. "flag" - - minetest.chat_send_all(flag_name.." has returned.") - - end - end -end local function player_drop_flag(player) return ctf_flag.player_drop_flag(player:get_player_name()) end diff --git a/mods/capturetheflag/ctf_flag/init.lua b/mods/capturetheflag/ctf_flag/init.lua index b194c36..1380516 100644 --- a/mods/capturetheflag/ctf_flag/init.lua +++ b/mods/capturetheflag/ctf_flag/init.lua @@ -83,6 +83,28 @@ function ctf_flag.collect_claimed() end ctf_flag.collect_claimed() +function ctf_flag.player_drop_flag(name) + if not name then + return + end + for i = 1, #ctf_flag.claimed do + local flag = ctf_flag.claimed[i] + if flag.claimed.player == name then + flag.claimed = nil + ctf_flag.collect_claimed() + + local flag_name = "" + if flag.name then + flag_name = flag.name .. " " + end + flag_name = flag.team .. "'s " .. flag_name .. "flag" + + ctf.action("flag", name .. " dropped " .. flag_name) + minetest.chat_send_all(flag_name.." has returned.") + end + end +end + -- add a flag to a team function ctf_flag.add(team, pos) if not team or team == "" then diff --git a/mods/capturetheflag/ctf_flash/depends.txt b/mods/capturetheflag/ctf_flash/depends.txt new file mode 100644 index 0000000..d8c974d --- /dev/null +++ b/mods/capturetheflag/ctf_flash/depends.txt @@ -0,0 +1,2 @@ +ctf +ctf_flag diff --git a/mods/capturetheflag/ctf_flash/init.lua b/mods/capturetheflag/ctf_flash/init.lua new file mode 100644 index 0000000..4a52032 --- /dev/null +++ b/mods/capturetheflag/ctf_flash/init.lua @@ -0,0 +1,65 @@ +local function safe_place(pos, node) + ctf.log("flash", "attempting to place...") + minetest.get_voxel_manip(pos, { x = pos.x + 1, y = pos.y + 1, z = pos.z + 1}) + minetest.set_node(pos, node) + if minetest.get_node(pos).name ~= node.name then + ctf.error("flash", "failed to place node, retrying...") + minetest.after(0.5, function() + safe_place(pos, node) + end) + end +end + +ctf_flag.collect_claimed() +for i, flag in pairs(ctf_flag.claimed) do + flag.claimed = nil +end +ctf_flag.collect_claimed() + +ctf.register_on_new_game(function() + ctf.log("flash", "Setting up new game!") + + ctf.team({name="red", color="red", add_team=true}) + ctf.team({name="blue", color="blue", add_team=true}) + + local fred = {x=15, y=7, z=39, team="red"} + local fblue = {x=-9, y=9, z=-43, team="blue"} + ctf_flag.add("red", fred) + ctf_flag.add("blue", fblue) + + minetest.after(0, function() + safe_place(fred, {name="ctf_flag:flag"}) + safe_place(fblue, {name="ctf_flag:flag"}) + end) + + for i, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local inv = player:get_inventory() + inv:set_list("main", {}) + inv:set_list("craft", {}) + + local alloc_mode = tonumber(ctf.setting("allocate_mode")) + if alloc_mode == 0 then + return + end + local team = ctf.autoalloc(name, alloc_mode) + if team then + ctf.log("autoalloc", name .. " was allocated to " .. team) + ctf.join(name, team) + end + + team = ctf.player(name).team + if ctf.team(team) then + local spawn = ctf.get_spawn(team) + if spawn then + player:moveto(spawn, false) + end + end + + minetest.log("action", "Giving initial stuff to player "..player:get_player_name()) + player:get_inventory():add_item('main', 'default:pick_steel') + player:get_inventory():add_item('main', 'default:sword_steel') + player:get_inventory():add_item('main', 'default:cobble 99') + end + minetest.chat_send_all("Next round!") +end)