Add ctf_flash
This commit is contained in:
parent
6bfcae834b
commit
d58e173cb1
@ -194,6 +194,7 @@ minetest.after(10, ctf.check_save)
|
|||||||
function ctf.save()
|
function ctf.save()
|
||||||
ctf.log("io", "Saving CTF state...")
|
ctf.log("io", "Saving CTF state...")
|
||||||
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
|
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
|
||||||
|
ctf.needs_save = false
|
||||||
if file then
|
if file then
|
||||||
local out = {
|
local out = {
|
||||||
teams = ctf.teams,
|
teams = ctf.teams,
|
||||||
|
@ -4,18 +4,6 @@ ctf.register_on_init(function()
|
|||||||
ctf._set("endgame.reset_on_winner", true)
|
ctf._set("endgame.reset_on_winner", true)
|
||||||
end)
|
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)
|
ctf_flag.register_on_capture(function(attname, flag)
|
||||||
if not ctf.setting("endgame.destroy_team") then
|
if not ctf.setting("endgame.destroy_team") then
|
||||||
return
|
return
|
||||||
@ -50,52 +38,3 @@ ctf_flag.register_on_capture(function(attname, flag)
|
|||||||
end)
|
end)
|
||||||
end
|
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)
|
|
||||||
|
@ -70,24 +70,6 @@ local function do_capture(attname, flag, returned)
|
|||||||
ctf.needs_save = true
|
ctf.needs_save = true
|
||||||
end
|
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)
|
local function player_drop_flag(player)
|
||||||
return ctf_flag.player_drop_flag(player:get_player_name())
|
return ctf_flag.player_drop_flag(player:get_player_name())
|
||||||
end
|
end
|
||||||
|
@ -83,6 +83,28 @@ function ctf_flag.collect_claimed()
|
|||||||
end
|
end
|
||||||
ctf_flag.collect_claimed()
|
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
|
-- add a flag to a team
|
||||||
function ctf_flag.add(team, pos)
|
function ctf_flag.add(team, pos)
|
||||||
if not team or team == "" then
|
if not team or team == "" then
|
||||||
|
2
mods/capturetheflag/ctf_flash/depends.txt
Normal file
2
mods/capturetheflag/ctf_flash/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ctf
|
||||||
|
ctf_flag
|
65
mods/capturetheflag/ctf_flash/init.lua
Normal file
65
mods/capturetheflag/ctf_flash/init.lua
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user