Move flag.lua to ctf_flag/
parent
81e4a2dc24
commit
821edc9637
|
@ -72,16 +72,16 @@ function ctf.area.nearest_flag(pos)
|
|||
return nil
|
||||
end
|
||||
|
||||
local nodes = minetest.env:find_nodes_in_area(
|
||||
local nodes = minetest.find_nodes_in_area(
|
||||
{
|
||||
x = pos.x - ctf.setting("flag_protect_distance"),
|
||||
y = pos.y - ctf.setting("flag_protect_distance"),
|
||||
z = pos.z - ctf.setting("flag_protect_distance")
|
||||
x = pos.x - ctf.setting("flag.protect_distance"),
|
||||
y = pos.y - ctf.setting("flag.protect_distance"),
|
||||
z = pos.z - ctf.setting("flag.protect_distance")
|
||||
},
|
||||
{
|
||||
x = pos.x + ctf.setting("flag_protect_distance"),
|
||||
y = pos.y + ctf.setting("flag_protect_distance"),
|
||||
z = pos.z + ctf.setting("flag_protect_distance")
|
||||
x = pos.x + ctf.setting("flag.protect_distance"),
|
||||
y = pos.y + ctf.setting("flag.protect_distance"),
|
||||
z = pos.z + ctf.setting("flag.protect_distance")
|
||||
},
|
||||
{"group:is_flag"}
|
||||
)
|
||||
|
@ -108,43 +108,44 @@ end
|
|||
function ctf.area.get_area(pos)
|
||||
local closest = ctf.area.nearest_flag(pos)
|
||||
if not closest then
|
||||
return false
|
||||
return nil
|
||||
end
|
||||
local flag = ctf.area.get_flag(closest)
|
||||
|
||||
if flag then
|
||||
return flag.team
|
||||
end
|
||||
return false
|
||||
return nil
|
||||
end
|
||||
|
||||
-- updates the spawn position for a team
|
||||
function ctf.area.get_spawn(team)
|
||||
ctf.area.asset_flags(team)
|
||||
|
||||
if team and ctf.teams and ctf.team(team) then
|
||||
if ctf.team(team).spawn and minetest.env:get_node(ctf.team(team).spawn).name == "ctf:flag" then
|
||||
local flag = ctf.area.get_flag(ctf.team(team).spawn)
|
||||
if not ctf.team(team) then
|
||||
return nil
|
||||
end
|
||||
|
||||
if not flag then
|
||||
return false
|
||||
end
|
||||
if ctf.team(team).spawn and minetest.env:get_node(ctf.team(team).spawn).name == "ctf:flag" then
|
||||
local flag = ctf.area.get_flag(ctf.team(team).spawn)
|
||||
|
||||
local _team = flag.team
|
||||
|
||||
-- Check to see if spawn is already defined
|
||||
if team == _team then
|
||||
return true
|
||||
end
|
||||
if not flag then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Get new spawn
|
||||
if #ctf.team(team).flags > 0 then
|
||||
ctf.team(team).spawn = ctf.team(team).flags[1]
|
||||
return true
|
||||
local _team = flag.team
|
||||
|
||||
-- Check to see if spawn is already defined
|
||||
if team == _team then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
return false
|
||||
|
||||
-- Get new spawn
|
||||
if #ctf.team(team).flags > 0 then
|
||||
ctf.team(team).spawn = ctf.team(team).flags[1]
|
||||
return ctf.team(team).spawn
|
||||
end
|
||||
end
|
||||
|
||||
function ctf.area.asset_flags(team)
|
||||
|
@ -164,3 +165,16 @@ function ctf.area.asset_flags(team)
|
|||
end
|
||||
end]]--
|
||||
end
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
if player and ctf.player(player:get_player_name()) then
|
||||
local team = ctf.player(player:get_player_name()).team
|
||||
if ctf.team(team) then
|
||||
local spawn = ctf.area.get_spawn(team)
|
||||
player:moveto(spawn, false)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end)
|
||||
|
|
|
@ -11,6 +11,10 @@ ctf.registered_on_init = {}
|
|||
function ctf.register_on_init(func)
|
||||
table.insert(ctf.registered_on_init, func)
|
||||
end
|
||||
ctf.registered_on_new_team = {}
|
||||
function ctf.register_on_new_team(func)
|
||||
table.insert(ctf.registered_on_new_team, func)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -49,28 +53,14 @@ function ctf.init()
|
|||
|
||||
-- See minetest.conf.example in the root of this subgame
|
||||
|
||||
-- Settings: Feature enabling
|
||||
ctf.log("init", "Creating Default Settings")
|
||||
|
||||
-- Settings: Flags and Territory
|
||||
ctf._set("node_ownership", true)
|
||||
ctf._set("multiple_flags", true)
|
||||
ctf._set("flag_capture_take", false)
|
||||
ctf._set("flag_names", true)
|
||||
|
||||
-- Settings: User Interface
|
||||
ctf._set("hud", true)
|
||||
|
||||
-- Settings: Teams
|
||||
ctf._set("diplomacy", true)
|
||||
ctf._set("players_can_change_team", true)
|
||||
ctf._set("allocate_mode", 0)
|
||||
ctf._set("maximum_in_team", -1)
|
||||
ctf._set("default_diplo_state", "war")
|
||||
|
||||
-- Settings: Misc
|
||||
ctf._set("flag_protect_distance", 25)
|
||||
ctf._set("team_gui_initial", "news")
|
||||
ctf._set("node_ownership", true)
|
||||
ctf._set("hud", true)
|
||||
|
||||
for i = 1, #ctf.registered_on_init do
|
||||
ctf.registered_on_init[i]()
|
||||
|
@ -172,13 +162,16 @@ function ctf.team(name) -- get or add a team
|
|||
|
||||
ctf.log("team", "Defining team "..name.name)
|
||||
|
||||
ctf.teams[name.name]={
|
||||
ctf.teams[name.name] = {
|
||||
data = name,
|
||||
spawn=nil,
|
||||
players={},
|
||||
flags = {}
|
||||
spawn = nil,
|
||||
players = {}
|
||||
}
|
||||
|
||||
for i = 1, #ctf.registered_on_new_team do
|
||||
ctf.registered_on_new_team[i](ctf.teams[name.name])
|
||||
end
|
||||
|
||||
ctf.save()
|
||||
|
||||
return ctf.teams[name.name]
|
||||
|
|
|
@ -125,61 +125,6 @@ ctf.gui.register_tab("news", "News", function(name, team)
|
|||
result)
|
||||
end)
|
||||
|
||||
-- Team interface
|
||||
ctf.gui.register_tab("flags", "Flags", function(name, team)
|
||||
local result = ""
|
||||
local t = ctf.team(team)
|
||||
|
||||
if not t then
|
||||
return
|
||||
end
|
||||
|
||||
local x = 1
|
||||
local y = 2
|
||||
result = result .. "label[1,1;Click a flag button to go there]"
|
||||
|
||||
if ctf.setting("gui.team.teleport_to_spawn") and minetest.get_setting("static_spawnpoint") then
|
||||
local x,y,z = string.match(minetest.get_setting("static_spawnpoint"), "(%d+),(%d+),(%d+)")
|
||||
|
||||
result = result ..
|
||||
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
||||
..f.x.."_"..f.y.."_"..f.z..";"
|
||||
|
||||
result = result .. "Spawn]"
|
||||
x = x + 2
|
||||
end
|
||||
|
||||
for i=1, #t.flags do
|
||||
local f = t.flags[i]
|
||||
|
||||
if x > 8 then
|
||||
x = 1
|
||||
y = y + 1
|
||||
end
|
||||
|
||||
if y > 6 then
|
||||
break
|
||||
end
|
||||
|
||||
result = result ..
|
||||
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
||||
..f.x.."_"..f.y.."_"..f.z..";"
|
||||
|
||||
if f.name then
|
||||
result = result .. f.name .. "]"
|
||||
else
|
||||
result = result .. "("..f.x..","..f.y..","..f.z..")]"
|
||||
end
|
||||
|
||||
x = x + 2
|
||||
end
|
||||
|
||||
minetest.show_formspec(name, "ctf:flags",
|
||||
"size[10,7]"..
|
||||
ctf.gui.get_tabs(name,team)..
|
||||
result)
|
||||
end)
|
||||
|
||||
-- Team interface
|
||||
ctf.gui.register_tab("diplo", "Diplomacy", function(name, team)
|
||||
local result = ""
|
||||
|
@ -267,7 +212,6 @@ local function formspec_is_ctf_tab(fsname)
|
|||
return true
|
||||
end
|
||||
end
|
||||
print(fsname .. " is not a ctf_tab")
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -291,7 +235,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
||||
ctf.team(ctf.players[name].team).log = {}
|
||||
ctf.save()
|
||||
ctf.gui.team_board(name, ctf.players[name].team)
|
||||
ctf.gui.show(name, "news")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
@ -299,10 +243,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
-- Settings page
|
||||
if fields.save and formname=="ctf:settings" then
|
||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
||||
ctf.gui.team_settings(name, ctf.players[name].team)
|
||||
ctf.gui.show(name, "settings")
|
||||
end
|
||||
if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then
|
||||
if minetest.registered_items["ctf:flag_top_"..fields.color] then
|
||||
if minetest.registered_items["ctf_flag:flag_top_"..fields.color] then
|
||||
ctf.team(ctf.players[name].team).data.color = fields.color
|
||||
ctf.save()
|
||||
else
|
||||
|
@ -329,7 +273,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
|
||||
table.remove(ctf.team(ctf.player(name).team).log,id)
|
||||
ctf.save()
|
||||
ctf.gui.team_board(name,ctf.player(name).team)
|
||||
ctf.gui.show(name, "news")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -337,27 +281,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- Todo: fix security issue here
|
||||
local name = player:get_player_name()
|
||||
if formname=="ctf:flags" then
|
||||
for key, field in pairs(fields) do
|
||||
local x,y,z = string.match(key, "goto_(%d+)_(%d+)_(%d+)")
|
||||
if x and y and x then
|
||||
player:setpos({x=x, y=y, z=z})
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
if formname=="ctf:diplo" then
|
||||
for key, field in pairs(fields) do
|
||||
local newteam = string.match(key, "team_(.+)")
|
||||
if newteam then
|
||||
ctf.gui.team_dip(name,newteam)
|
||||
ctf.gui.show(name, "diplo")
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -375,7 +305,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
end
|
||||
|
||||
ctf.gui.team_dip(name,team)
|
||||
ctf.gui.show(name, "diplo")
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -389,7 +319,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
ctf.post(newteam,{msg=team.." has declared war on you"})
|
||||
end
|
||||
|
||||
ctf.gui.team_dip(name,team)
|
||||
ctf.gui.show(name, "diplo")
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -401,7 +331,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
ctf.post(newteam,{type="request",msg="alliance",team=team,mode="diplo"})
|
||||
end
|
||||
|
||||
ctf.gui.team_dip(name,team)
|
||||
ctf.gui.show(name, "diplo")
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -413,123 +343,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
ctf.diplo.cancel_requests(team,newteam)
|
||||
end
|
||||
|
||||
ctf.gui.team_dip(name,team)
|
||||
ctf.gui.show(name, "diplo")
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Flag interface
|
||||
function ctf.gui.flag_board(name,pos)
|
||||
ctf.log("gui", name .. " views team_board")
|
||||
local flag = ctf.area.get_flag(pos)
|
||||
if not flag then
|
||||
return
|
||||
end
|
||||
|
||||
local team = flag.team
|
||||
if not team then
|
||||
return
|
||||
end
|
||||
|
||||
if ctf.can_mod(name,team) == false then
|
||||
if ctf.player(name) and ctf.player(name).team and ctf.player(name).team == team then
|
||||
ctf.gui.team_board(name,team)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local flag_name = flag.name
|
||||
|
||||
if not ctf.setting("flag_names") then
|
||||
flag.name = nil
|
||||
return
|
||||
end
|
||||
|
||||
if not ctf.setting("gui") then
|
||||
return
|
||||
end
|
||||
|
||||
if not flag_name then
|
||||
flag_name = ""
|
||||
end
|
||||
|
||||
if not ctf.gui.flag_data then
|
||||
ctf.gui.flag_data = {}
|
||||
end
|
||||
|
||||
ctf.gui.flag_data[name] = {pos=pos}
|
||||
|
||||
minetest.show_formspec(name, "ctf:flag_board",
|
||||
"size[6,3]"..
|
||||
"field[1,1;4,1;flag_name;Flag Name;"..flag_name.."]"..
|
||||
"button_exit[1,2;2,1;save;Save]"..
|
||||
"button_exit[3,2;2,1;delete;Delete]"
|
||||
)
|
||||
end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if not formname=="ctf:flag_board" then
|
||||
return false
|
||||
end
|
||||
|
||||
if fields.save and fields.flag_name then
|
||||
local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos)
|
||||
if not flag then
|
||||
return false
|
||||
end
|
||||
|
||||
local team = flag.team
|
||||
if not team then
|
||||
return false
|
||||
end
|
||||
|
||||
if ctf.can_mod(name,team) == false then
|
||||
return false
|
||||
end
|
||||
|
||||
local flag_name = flag.name
|
||||
if not flag_name then
|
||||
flag_name = ""
|
||||
end
|
||||
|
||||
flag.name = fields.flag_name
|
||||
|
||||
local msg = flag_name.." was renamed to "..fields.flag_name
|
||||
|
||||
if flag_name=="" then
|
||||
msg = "A flag was named "..fields.flag_name.." at ("..ctf.gui.flag_data[name].pos.x..","..ctf.gui.flag_data[name].pos.z..")"
|
||||
end
|
||||
|
||||
ctf.post(team,{msg=msg,icon="flag_info"})
|
||||
|
||||
return true
|
||||
elseif fields.delete then
|
||||
local pos = ctf.gui.flag_data[name].pos
|
||||
|
||||
local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos)
|
||||
|
||||
if not flag then
|
||||
return
|
||||
end
|
||||
|
||||
local team = flag.team
|
||||
if not team then
|
||||
return
|
||||
end
|
||||
|
||||
if ctf.can_mod(name,team) == false then
|
||||
return false
|
||||
end
|
||||
|
||||
ctf.area.delete_flag(team,pos)
|
||||
|
||||
minetest.env:set_node(pos,{name="air"})
|
||||
pos.y=pos.y+1
|
||||
minetest.env:set_node(pos,{name="air"})
|
||||
|
||||
return true
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -25,7 +25,6 @@ minetest.register_privilege("ctf_admin", {
|
|||
dofile(minetest.get_modpath("ctf").."/core.lua")
|
||||
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
||||
dofile(minetest.get_modpath("ctf").."/area.lua")
|
||||
dofile(minetest.get_modpath("ctf").."/flag.lua")
|
||||
dofile(minetest.get_modpath("ctf").."/gui.lua")
|
||||
dofile(minetest.get_modpath("ctf").."/hud.lua")
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ctf
|
|
@ -1,8 +1,8 @@
|
|||
ctf.flag_func = {
|
||||
ctf_flag = {
|
||||
on_punch_top = function(pos, node, puncher)
|
||||
pos.y=pos.y-1
|
||||
|
||||
ctf.flag_func.on_punch(pos,node,puncher)
|
||||
ctf_flag.on_punch(pos, node, puncher)
|
||||
end,
|
||||
on_rightclick_top = function(pos, node, clicker)
|
||||
pos.y=pos.y-1
|
||||
|
@ -13,12 +13,12 @@ ctf.flag_func = {
|
|||
end
|
||||
|
||||
if flag.claimed then
|
||||
if ctf.setting("flag_capture_take") then
|
||||
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
||||
minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team)
|
||||
if ctf.setting("flag.capture_take") then
|
||||
minetest.chat_send_player(player, "This flag has been taken by ".. flag.claimed.player)
|
||||
minetest.chat_send_player(player, "who is a member of team ".. flag.claimed.team)
|
||||
return
|
||||
else
|
||||
minetest.chat_send_player(player,"Oops! This flag should not be captured. Reverting.")
|
||||
minetest.chat_send_player(player, "Oops! This flag should not be captured. Reverting.")
|
||||
flag.claimed = nil
|
||||
end
|
||||
end
|
||||
|
@ -32,12 +32,12 @@ ctf.flag_func = {
|
|||
end
|
||||
|
||||
if flag.claimed then
|
||||
if ctf.setting("flag_capture_take") then
|
||||
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
||||
minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team)
|
||||
if ctf.setting("flag.capture_take") then
|
||||
minetest.chat_send_player(player, "This flag has been taken by "..flag.claimed.player)
|
||||
minetest.chat_send_player(player, "who is a member of team "..flag.claimed.team)
|
||||
return
|
||||
else
|
||||
minetest.chat_send_player(player,"Oops! This flag should not be captured. Reverting.")
|
||||
minetest.chat_send_player(player, "Oops! This flag should not be captured. Reverting...")
|
||||
flag.claimed = nil
|
||||
end
|
||||
end
|
||||
|
@ -55,12 +55,12 @@ ctf.flag_func = {
|
|||
end
|
||||
|
||||
if flag.claimed then
|
||||
if ctf.setting("flag_capture_take") then
|
||||
minetest.chat_send_player(player,"This flag has been taken by "..flag.claimed.player)
|
||||
minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team)
|
||||
if ctf.setting("flag.capture_take") then
|
||||
minetest.chat_send_player(player, "This flag has been taken by "..flag.claimed.player)
|
||||
minetest.chat_send_player(player, "who is a member of team "..flag.claimed.team)
|
||||
return
|
||||
else
|
||||
minetest.chat_send_player(player,"Oops! This flag should not be captured. Reverting.")
|
||||
minetest.chat_send_player(player, "Oops! This flag should not be captured. Reverting.")
|
||||
flag.claimed = nil
|
||||
end
|
||||
end
|
||||
|
@ -79,12 +79,12 @@ ctf.flag_func = {
|
|||
end
|
||||
|
||||
if diplo ~= "war" then
|
||||
minetest.chat_send_player(player,"You are at peace with this team!")
|
||||
minetest.chat_send_player(player, "You are at peace with this team!")
|
||||
return
|
||||
end
|
||||
|
||||
local flag_name = flag.name
|
||||
if ctf.setting("flag_capture_take") then
|
||||
if ctf.setting("flag.capture_take") then
|
||||
if flag_name and flag_name~="" then
|
||||
minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..ctf.player(player).team..")")
|
||||
ctf.post(team,{msg=flag_name.." has been taken by "..ctf.player(player).team,icon="flag_red"})
|
||||
|
@ -110,7 +110,7 @@ ctf.flag_func = {
|
|||
ctf.post(ctf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"})
|
||||
end
|
||||
ctf.team(team).spawn = nil
|
||||
if ctf.setting("multiple_flags") == true then
|
||||
if ctf.setting("flag.allow_multiple") == true then
|
||||
ctf.area.delete_flag(team,pos)
|
||||
ctf.area.add_flag(ctf.player(player).team,pos)
|
||||
else
|
||||
|
@ -121,8 +121,8 @@ ctf.flag_func = {
|
|||
ctf.save()
|
||||
else
|
||||
-- Clicking on their team's flag
|
||||
if ctf.setting("flag_capture_take") then
|
||||
ctf.flag_func._flagret(player)
|
||||
if ctf.setting("flag.capture_take") then
|
||||
ctf_flag._flagret(player)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@ -147,7 +147,7 @@ ctf.flag_func = {
|
|||
end
|
||||
fteam.spawn = nil
|
||||
local fpos = {x=ctf.claimed[i].x,y=ctf.claimed[i].y,z=ctf.claimed[i].z}
|
||||
if ctf.setting("multiple_flags") == true then
|
||||
if ctf.setting("flag.allow_multiple") == true then
|
||||
ctf.area.delete_flag(fteam.data.name,fpos)
|
||||
ctf.area.add_flag(ctf.claimed[i].claimed.team,fpos)
|
||||
else
|
||||
|
@ -180,8 +180,8 @@ ctf.flag_func = {
|
|||
-- add flag
|
||||
ctf.area.add_flag(team,pos)
|
||||
|
||||
if ctf.teams[team].spawn and minetest.env:get_node(ctf.teams[team].spawn).name == "ctf:flag" then
|
||||
if not ctf.setting("multiple_flags") then
|
||||
if ctf.teams[team].spawn and minetest.env:get_node(ctf.teams[team].spawn).name == "ctf_flag:flag" then
|
||||
if not ctf.setting("flag.allow_multiple") then
|
||||
-- send message
|
||||
minetest.chat_send_all(team.."'s flag has been moved")
|
||||
minetest.env:set_node(ctf.team(team).spawn,{name="air"})
|
||||
|
@ -209,7 +209,7 @@ ctf.flag_func = {
|
|||
ctf.save()
|
||||
end
|
||||
|
||||
minetest.env:set_node(pos2,{name="ctf:flag_top_"..ctf.team(team).data.color})
|
||||
minetest.env:set_node(pos2,{name="ctf_flag:flag_top_"..ctf.team(team).data.color})
|
||||
|
||||
local meta2 = minetest.env:get_meta(pos2)
|
||||
|
||||
|
@ -220,146 +220,3 @@ ctf.flag_func = {
|
|||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- The flag
|
||||
minetest.register_node("ctf:flag",{
|
||||
description = "Flag",
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
tiles = {
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0.250000,-0.500000,0.000000,0.312500,0.500000,0.062500}
|
||||
}
|
||||
},
|
||||
groups = {immortal=1,is_flag=1,flag_bottom=1},
|
||||
on_punch = ctf.flag_func.on_punch,
|
||||
on_rightclick = ctf.flag_func.on_rightclick,
|
||||
on_construct = ctf.flag_func.on_construct,
|
||||
after_place_node = ctf.flag_func.after_place_node
|
||||
})
|
||||
ctf.flag_colors = {
|
||||
red = "0xFF0000",
|
||||
green = "0x00FF00",
|
||||
blue = "0x0000FF"
|
||||
}
|
||||
|
||||
for color, _ in pairs(ctf.flag_colors) do
|
||||
minetest.register_node("ctf:flag_top_"..color,{
|
||||
description = "You are not meant to have this! - flag top",
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
tiles = {
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"flag_"..color.."2.png",
|
||||
"flag_"..color..".png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0.250000,-0.500000,0.000000,0.312500,0.500000,0.062500},
|
||||
{-0.5,0,0.000000,0.250000,0.500000,0.062500}
|
||||
}
|
||||
},
|
||||
groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1},
|
||||
on_punch = ctf.flag_func.on_punch_top,
|
||||
on_rightclick = ctf.flag_func.on_rightclick_top
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_node("ctf:flag_captured_top",{
|
||||
description = "You are not meant to have this! - flag captured",
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
tiles = {
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0.250000,-0.500000,0.000000,0.312500,0.500000,0.062500}
|
||||
}
|
||||
},
|
||||
groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1},
|
||||
on_punch = ctf.flag_func.on_punch_top,
|
||||
on_rightclick = ctf.flag_func.on_rightclick_top
|
||||
})
|
||||
|
||||
-- On respawn
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
if player and ctf.player(player:get_player_name()) then
|
||||
local team = ctf.player(player:get_player_name()).team
|
||||
if team and ctf.team(team) and ctf.area.get_spawn(team)==true then
|
||||
player:moveto(ctf.team(team).spawn, false)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end)
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:flag_bottom"},
|
||||
inteval = 5,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
local top = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local flagmeta = minetest.env:get_meta(pos)
|
||||
|
||||
if not flagmeta then
|
||||
return
|
||||
end
|
||||
|
||||
local flag_team_data = ctf.area.get_flag(pos)
|
||||
if not flag_team_data or not ctf.team(flag_team_data.team)then
|
||||
ctf.log("flag", "Flag does not exist! Deleting nodes. "..dump(pos))
|
||||
minetest.env:set_node(pos,{name="air"})
|
||||
minetest.env:set_node(top,{name="air"})
|
||||
return
|
||||
end
|
||||
local topmeta = minetest.env:get_meta(top)
|
||||
local flag_name = flag_team_data.name
|
||||
if flag_name and flag_name ~= "" then
|
||||
flagmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
|
||||
else
|
||||
flagmeta:set_string("infotext", flag_team_data.team.."'s flag")
|
||||
end
|
||||
|
||||
if not ctf.team(flag_team_data.team).data.color then
|
||||
ctf.team(flag_team_data.team).data.color = "red"
|
||||
ctf.save()
|
||||
end
|
||||
|
||||
if flag_team_data.claimed then
|
||||
minetest.env:set_node(top,{name="ctf:flag_captured_top"})
|
||||
else
|
||||
minetest.env:set_node(top,{name="ctf:flag_top_"..ctf.team(flag_team_data.team).data.color})
|
||||
end
|
||||
|
||||
topmeta = minetest.env:get_meta(top)
|
||||
if flag_name and flag_name ~= "" then
|
||||
topmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
|
||||
else
|
||||
topmeta:set_string("infotext", flag_team_data.team.."'s flag")
|
||||
end
|
||||
end
|
||||
})
|
|
@ -0,0 +1,182 @@
|
|||
-- Team interface
|
||||
ctf.gui.register_tab("flags", "Flags", function(name, team)
|
||||
local result = ""
|
||||
local t = ctf.team(team)
|
||||
|
||||
if not t then
|
||||
return
|
||||
end
|
||||
|
||||
local x = 1
|
||||
local y = 2
|
||||
result = result .. "label[1,1;Click a flag button to go there]"
|
||||
|
||||
if ctf.setting("gui.team.teleport_to_spawn") and minetest.get_setting("static_spawnpoint") then
|
||||
local x,y,z = string.match(minetest.get_setting("static_spawnpoint"), "(%d+),(%d+),(%d+)")
|
||||
|
||||
result = result ..
|
||||
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
||||
..f.x.."_"..f.y.."_"..f.z..";"
|
||||
|
||||
result = result .. "Spawn]"
|
||||
x = x + 2
|
||||
end
|
||||
|
||||
for i=1, #t.flags do
|
||||
local f = t.flags[i]
|
||||
|
||||
if x > 8 then
|
||||
x = 1
|
||||
y = y + 1
|
||||
end
|
||||
|
||||
if y > 6 then
|
||||
break
|
||||
end
|
||||
|
||||
result = result ..
|
||||
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
||||
..f.x.."_"..f.y.."_"..f.z..";"
|
||||
|
||||
if f.name then
|
||||
result = result .. f.name .. "]"
|
||||
else
|
||||
result = result .. "("..f.x..","..f.y..","..f.z..")]"
|
||||
end
|
||||
|
||||
x = x + 2
|
||||
end
|
||||
|
||||
minetest.show_formspec(name, "ctf:flags",
|
||||
"size[10,7]"..
|
||||
ctf.gui.get_tabs(name,team)..
|
||||
result)
|
||||
end)
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- Todo: fix security issue here
|
||||
local name = player:get_player_name()
|
||||
if formname=="ctf:flags" then
|
||||
for key, field in pairs(fields) do
|
||||
local x,y,z = string.match(key, "goto_(%d+)_(%d+)_(%d+)")
|
||||
if x and y and x then
|
||||
player:setpos({x=x, y=y, z=z})
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Flag interface
|
||||
function ctf.gui.flag_board(name,pos)
|
||||
ctf.log("gui", name .. " views flag board")
|
||||
local flag = ctf.area.get_flag(pos)
|
||||
if not flag then
|
||||
return
|
||||
end
|
||||
|
||||
local team = flag.team
|
||||
if not team then
|
||||
return
|
||||
end
|
||||
|
||||
if ctf.can_mod(name,team) == false then
|
||||
if ctf.player(name) and ctf.player(name).team and ctf.player(name).team == team then
|
||||
ctf.gui.show(name, "news")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local flag_name = flag.name
|
||||
|
||||
if not ctf.setting("flag.names") then
|
||||
flag.name = nil
|
||||
return
|
||||
end
|
||||
|
||||
if not ctf.setting("gui") then
|
||||
return
|
||||
end
|
||||
|
||||
if not flag_name then
|
||||
flag_name = ""
|
||||
end
|
||||
|
||||
if not ctf.gui.flag_data then
|
||||
ctf.gui.flag_data = {}
|
||||
end
|
||||
|
||||
ctf.gui.flag_data[name] = {pos=pos}
|
||||
|
||||
minetest.show_formspec(name, "ctf:flag_board",
|
||||
"size[6,3]"..
|
||||
"field[1,1;4,1;flag_name;Flag Name;"..flag_name.."]"..
|
||||
"button_exit[1,2;2,1;save;Save]"..
|
||||
"button_exit[3,2;2,1;delete;Delete]"
|
||||
)
|
||||
end
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if not formname=="ctf:flag_board" then
|
||||
return false
|
||||
end
|
||||
|
||||
if fields.save and fields.flag_name then
|
||||
local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos)
|
||||
if not flag then
|
||||
return false
|
||||
end
|
||||
|
||||
local team = flag.team
|
||||
if not team then
|
||||
return false
|
||||
end
|
||||
|
||||
if ctf.can_mod(name,team) == false then
|
||||
return false
|
||||
end
|
||||
|
||||
local flag_name = flag.name
|
||||
if not flag_name then
|
||||
flag_name = ""
|
||||
end
|
||||
|
||||
flag.name = fields.flag_name
|
||||
|
||||
local msg = flag_name.." was renamed to "..fields.flag_name
|
||||
|
||||
if flag_name=="" then
|
||||
msg = "A flag was named "..fields.flag_name.." at ("..ctf.gui.flag_data[name].pos.x..","..ctf.gui.flag_data[name].pos.z..")"
|
||||
end
|
||||
|
||||
ctf.post(team,{msg=msg,icon="flag_info"})
|
||||
|
||||
return true
|
||||
elseif fields.delete then
|
||||
local pos = ctf.gui.flag_data[name].pos
|
||||
|
||||
local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos)
|
||||
|
||||
if not flag then
|
||||
return
|
||||
end
|
||||
|
||||
local team = flag.team
|
||||
if not team then
|
||||
return
|
||||
end
|
||||
|
||||
if ctf.can_mod(name,team) == false then
|
||||
return false
|
||||
end
|
||||
|
||||
ctf.area.delete_flag(team,pos)
|
||||
|
||||
minetest.env:set_node(pos,{name="air"})
|
||||
pos.y=pos.y+1
|
||||
minetest.env:set_node(pos,{name="air"})
|
||||
|
||||
return true
|
||||
end
|
||||
end)
|
|
@ -0,0 +1,144 @@
|
|||
-- Initialise
|
||||
function init()
|
||||
ctf._set("flag.allow_multiple", true)
|
||||
ctf._set("flag.capture_take", false)
|
||||
ctf._set("flag.names", true)
|
||||
ctf._set("flag.protect_distance", 25)
|
||||
end
|
||||
init()
|
||||
ctf.register_on_new_team(function(team)
|
||||
team.flags = {}
|
||||
end)
|
||||
ctf_flag = {}
|
||||
dofile(minetest.get_modpath("ctf_flag") .. "/gui.lua")
|
||||
dofile(minetest.get_modpath("ctf_flag") .. "/flag_func.lua")
|
||||
|
||||
-- The flag
|
||||
minetest.register_node("ctf_flag:flag", {
|
||||
description = "Flag",
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
tiles = {
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0.250000,-0.500000,0.000000,0.312500,0.500000,0.062500}
|
||||
}
|
||||
},
|
||||
groups = {immortal=1,is_flag=1,flag_bottom=1},
|
||||
on_punch = ctf_flag.on_punch,
|
||||
on_rightclick = ctf_flag.on_rightclick,
|
||||
on_construct = ctf_flag.on_construct,
|
||||
after_place_node = ctf_flag.after_place_node
|
||||
})
|
||||
ctf.flag_colors = {
|
||||
red = "0xFF0000",
|
||||
green = "0x00FF00",
|
||||
blue = "0x0000FF"
|
||||
}
|
||||
|
||||
for color, _ in pairs(ctf.flag_colors) do
|
||||
minetest.register_node("ctf_flag:flag_top_"..color,{
|
||||
description = "You are not meant to have this! - flag top",
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
tiles = {
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"flag_"..color.."2.png",
|
||||
"flag_"..color..".png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0.250000,-0.500000,0.000000,0.312500,0.500000,0.062500},
|
||||
{-0.5,0,0.000000,0.250000,0.500000,0.062500}
|
||||
}
|
||||
},
|
||||
groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1},
|
||||
on_punch = ctf_flag.on_punch_top,
|
||||
on_rightclick = ctf_flag.on_rightclick_top
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_node("ctf_flag:flag_captured_top",{
|
||||
description = "You are not meant to have this! - flag captured",
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
tiles = {
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0.250000,-0.500000,0.000000,0.312500,0.500000,0.062500}
|
||||
}
|
||||
},
|
||||
groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1},
|
||||
on_punch = ctf_flag.on_punch_top,
|
||||
on_rightclick = ctf_flag.on_rightclick_top
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:flag_bottom"},
|
||||
inteval = 5,
|
||||
chance = 1,
|
||||
action = function(pos)
|
||||
local top = {x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local flagmeta = minetest.env:get_meta(pos)
|
||||
|
||||
if not flagmeta then
|
||||
return
|
||||
end
|
||||
|
||||
local flag_team_data = ctf.area.get_flag(pos)
|
||||
if not flag_team_data or not ctf.team(flag_team_data.team)then
|
||||
ctf.log("flag", "Flag does not exist! Deleting nodes. "..dump(pos))
|
||||
minetest.env:set_node(pos,{name="air"})
|
||||
minetest.env:set_node(top,{name="air"})
|
||||
return
|
||||
end
|
||||
local topmeta = minetest.env:get_meta(top)
|
||||
local flag_name = flag_team_data.name
|
||||
if flag_name and flag_name ~= "" then
|
||||
flagmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
|
||||
else
|
||||
flagmeta:set_string("infotext", flag_team_data.team.."'s flag")
|
||||
end
|
||||
|
||||
if not ctf.team(flag_team_data.team).data.color then
|
||||
ctf.team(flag_team_data.team).data.color = "red"
|
||||
ctf.save()
|
||||
end
|
||||
|
||||
if flag_team_data.claimed then
|
||||
minetest.env:set_node(top,{name="ctf_flag:flag_captured_top"})
|
||||
else
|
||||
minetest.env:set_node(top,{name="ctf_flag:flag_top_"..ctf.team(flag_team_data.team).data.color})
|
||||
end
|
||||
|
||||
topmeta = minetest.env:get_meta(top)
|
||||
if flag_name and flag_name ~= "" then
|
||||
topmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
|
||||
else
|
||||
topmeta:set_string("infotext", flag_team_data.team.."'s flag")
|
||||
end
|
||||
end
|
||||
})
|
Loading…
Reference in New Issue