Rename 'cf' table to 'ctf'

This commit is contained in:
rubenwardy 2014-12-27 16:43:41 +00:00
parent fdffb19c0d
commit 8fab1cb55a
9 changed files with 371 additions and 371 deletions

View File

@ -1,28 +1,28 @@
cf.area = {} ctf.area = {}
-- add a flag to a team -- add a flag to a team
function cf.area.add_flag(team,pos) function ctf.area.add_flag(team,pos)
if not team or team == "" then if not team or team == "" then
return return
end end
if not cf.team(team).flags then if not ctf.team(team).flags then
cf.team(team).flags = {} ctf.team(team).flags = {}
end end
pos.team = team pos.team = team
table.insert(cf.team(team).flags,pos) table.insert(ctf.team(team).flags,pos)
cf.save() ctf.save()
end end
-- get a flag from a team -- get a flag from a team
function cf.area.get_flag(pos) function ctf.area.get_flag(pos)
if not pos then if not pos then
return return
end end
local result = nil local result = nil
for _, team in pairs(cf.teams) do for _, team in pairs(ctf.teams) do
for i = 1, #team.flags do for i = 1, #team.flags do
if ( if (
team.flags[i].x == pos.x and team.flags[i].x == pos.x and
@ -48,36 +48,36 @@ function cf.area.get_flag(pos)
end end
-- delete a flag from a team -- delete a flag from a team
function cf.area.delete_flag(team,pos) function ctf.area.delete_flag(team,pos)
if not team or team == "" then if not team or team == "" then
return return
end end
print(dump(cf.team(team).flags)) print(dump(ctf.team(team).flags))
for i = 1, #cf.team(team).flags do for i = 1, #ctf.team(team).flags do
if ( if (
cf.team(team).flags[i].x == pos.x and ctf.team(team).flags[i].x == pos.x and
cf.team(team).flags[i].y == pos.y and ctf.team(team).flags[i].y == pos.y and
cf.team(team).flags[i].z == pos.z ctf.team(team).flags[i].z == pos.z
) then ) then
table.remove(cf.team(team).flags,i) table.remove(ctf.team(team).flags,i)
return return
end end
end end
end end
-- Gets the nearest flag in a 25 metre radius block -- Gets the nearest flag in a 25 metre radius block
function cf.area.nearest_flag(pos) function ctf.area.nearest_flag(pos)
if not pos then if not pos then
print ("No position provided to nearest_flag()") print ("No position provided to nearest_flag()")
return nil return nil
end end
print("cf.setting('flag_protect_distance') is "..dump(cf.setting("flag_protect_distance"))) print("ctf.setting('flag_protect_distance') is "..dump(ctf.setting("flag_protect_distance")))
local nodes = minetest.env:find_nodes_in_area( local nodes = minetest.env:find_nodes_in_area(
{x=pos.x-cf.setting("flag_protect_distance"),y=pos.y-cf.setting("flag_protect_distance"),z=pos.z-cf.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+cf.setting("flag_protect_distance"),y=pos.y+cf.setting("flag_protect_distance"),z=pos.z+cf.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"} {"group:is_flag"}
) )
@ -99,12 +99,12 @@ function cf.area.nearest_flag(pos)
end end
-- gets the name of the owner of that location -- gets the name of the owner of that location
function cf.area.get_area(pos) function ctf.area.get_area(pos)
local closest = cf.area.nearest_flag(pos) local closest = ctf.area.nearest_flag(pos)
if not closest then if not closest then
return false return false
end end
local flag = cf.area.get_flag(closest) local flag = ctf.area.get_flag(closest)
if flag then if flag then
return flag.team return flag.team
@ -113,12 +113,12 @@ function cf.area.get_area(pos)
end end
-- updates the spawn position for a team -- updates the spawn position for a team
function cf.area.get_spawn(team) function ctf.area.get_spawn(team)
cf.area.asset_flags(team) ctf.area.asset_flags(team)
if team and cf.teams and cf.team(team) then if team and ctf.teams and ctf.team(team) then
if cf.team(team).spawn and minetest.env:get_node(cf.team(team).spawn).name == "ctf:flag" then if ctf.team(team).spawn and minetest.env:get_node(ctf.team(team).spawn).name == "ctf:flag" then
local flag = cf.area.get_flag(cf.team(team).spawn) local flag = ctf.area.get_flag(ctf.team(team).spawn)
if not flag then if not flag then
return false return false
@ -133,22 +133,22 @@ function cf.area.get_spawn(team)
end end
-- Get new spawn -- Get new spawn
if #cf.team(team).flags > 0 then if #ctf.team(team).flags > 0 then
cf.team(team).spawn = cf.team(team).flags[1] ctf.team(team).spawn = ctf.team(team).flags[1]
return true return true
end end
end end
return false return false
end end
function cf.area.asset_flags(team) function ctf.area.asset_flags(team)
if not team or not cf.team(team) then if not team or not ctf.team(team) then
return false return false
end end
print("Checking the flags of "..team) print("Checking the flags of "..team)
local tmp = cf.team(team).flags local tmp = ctf.team(team).flags
for i=1,#tmp do for i=1,#tmp do
if tmp[i] and (not minetest.env:get_node(tmp[i]) or not minetest.env:get_node(tmp[i]).name == "ctf:flag") then if tmp[i] and (not minetest.env:get_node(tmp[i]) or not minetest.env:get_node(tmp[i]).name == "ctf:flag") then

View File

@ -22,12 +22,12 @@ minetest.register_chatcommand("team", {
if test then if test then
print("is a player request "..test) print("is a player request "..test)
if cf.player(test) then if ctf.player(test) then
if cf.player(test).team then if ctf.player(test).team then
if cf.player(test).auth then if ctf.player(test).auth then
minetest.chat_send_player(name,test.." is in team "..cf.player(test).team.." (team owner)",false) minetest.chat_send_player(name,test.." is in team "..ctf.player(test).team.." (team owner)",false)
else else
minetest.chat_send_player(name,test.." is in team "..cf.player(test).team,false) minetest.chat_send_player(name,test.." is in team "..ctf.player(test).team,false)
end end
else else
minetest.chat_send_player(name,test.." is not in a team",false) minetest.chat_send_player(name,test.." is not in a team",false)
@ -40,7 +40,7 @@ minetest.register_chatcommand("team", {
if privs and privs.team == true then if privs and privs.team == true then
if ( if (
string.match(create,"([%a%b_]-)") string.match(create,"([%a%b_]-)")
and cf.team({name=create,add_team=true}) and ctf.team({name=create,add_team=true})
and create ~= "" and create ~= ""
and create ~= nil and create ~= nil
) then ) then
@ -53,7 +53,7 @@ minetest.register_chatcommand("team", {
end end
elseif param == "all" then elseif param == "all" then
minetest.chat_send_player(name, "Teams:",false) minetest.chat_send_player(name, "Teams:",false)
for k,v in pairs(cf.teams) do for k,v in pairs(ctf.teams) do
if v and v.players then if v and v.players then
local numItems = 0 local numItems = 0
for k,v in pairs(v.players) do for k,v in pairs(v.players) do
@ -66,10 +66,10 @@ minetest.register_chatcommand("team", {
minetest.chat_send_player(name, ">> "..k.." ("..numItems2.." flags, "..numItems.." players)",false) minetest.chat_send_player(name, ">> "..k.." ("..numItems2.." flags, "..numItems.." players)",false)
end end
end end
elseif cf.team(param) then elseif ctf.team(param) then
minetest.chat_send_player(name,"Team "..param..":",false) minetest.chat_send_player(name,"Team "..param..":",false)
local count = 0 local count = 0
for _,value in pairs(cf.team(param).players) do for _,value in pairs(ctf.team(param).players) do
count = count + 1 count = count + 1
if value.aut == true then if value.aut == true then
minetest.chat_send_player(name,count..">> "..value.name.." (team owner)",false) minetest.chat_send_player(name,count..">> "..value.name.." (team owner)",false)
@ -81,13 +81,13 @@ minetest.register_chatcommand("team", {
minetest.chat_send_player(name,"joining '"..tplayer.."' to team '"..tteam.."'",false) minetest.chat_send_player(name,"joining '"..tplayer.."' to team '"..tteam.."'",false)
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.team == true then if privs and privs.team == true then
local player = cf.player(tplayer) local player = ctf.player(tplayer)
if not player then if not player then
player = {name=tplayer} player = {name=tplayer}
end end
if cf.add_user(tteam,tplayer) == true then if ctf.add_user(tteam,tplayer) == true then
minetest.chat_send_all(tplayer.." has joined team "..tteam) minetest.chat_send_all(tplayer.." has joined team "..tteam)
end end
else else
@ -101,22 +101,22 @@ minetest.register_chatcommand("team", {
team_console_help(name) team_console_help(name)
end end
if ( if (
cf and ctf and
cf.players and ctf.players and
cf.players[name] and ctf.players[name] and
cf.players[name].team and ctf.players[name].team and
cf.setting("gui") ctf.setting("gui")
) then ) then
if cf.setting("team_gui_initial") == "news" and cf.setting("news_gui") then if ctf.setting("team_gui_initial") == "news" and ctf.setting("news_gui") then
cf.gui.team_board(name,cf.players[name].team) ctf.gui.team_board(name,ctf.players[name].team)
elseif cf.setting("team_gui_initial") == "flags" and cf.setting("flag_teleport_gui") then elseif ctf.setting("team_gui_initial") == "flags" and ctf.setting("flag_teleport_gui") then
cf.gui.team_flags(name,cf.players[name].team) ctf.gui.team_flags(name,ctf.players[name].team)
elseif cf.setting("team_gui_initial") == "diplo" and cf.setting("diplomacy") then elseif ctf.setting("team_gui_initial") == "diplo" and ctf.setting("diplomacy") then
cf.gui.team_dip(name,cf.players[name].team) ctf.gui.team_dip(name,ctf.players[name].team)
elseif cf.setting("team_gui_initial") == "admin" then elseif ctf.setting("team_gui_initial") == "admin" then
cf.gui.team_settings(name,cf.players[name].team) ctf.gui.team_settings(name,ctf.players[name].team)
elseif cf.setting("news_gui") then elseif ctf.setting("news_gui") then
cf.gui.team_board(name,cf.players[name].team) ctf.gui.team_board(name,ctf.players[name].team)
end end
end end
end end
@ -127,7 +127,7 @@ minetest.register_chatcommand("join", {
params = "team name", params = "team name",
description = "Add to team", description = "Add to team",
func = function(name, param) func = function(name, param)
cf.join(name, param, false) ctf.join(name, param, false)
end, end,
}) })
minetest.register_chatcommand("list_teams", { minetest.register_chatcommand("list_teams", {
@ -136,7 +136,7 @@ minetest.register_chatcommand("list_teams", {
func = function(name, param) func = function(name, param)
minetest.chat_send_player(name, "This command will be made obsolete! Use '/team all' instead!",false) minetest.chat_send_player(name, "This command will be made obsolete! Use '/team all' instead!",false)
minetest.chat_send_player(name, "Teams:") minetest.chat_send_player(name, "Teams:")
for k,v in pairs(cf.teams) do for k,v in pairs(ctf.teams) do
if v and v.players then if v and v.players then
local numItems = 0 local numItems = 0
for k,v in pairs(v.players) do for k,v in pairs(v.players) do
@ -158,7 +158,7 @@ minetest.register_chatcommand("ateam", {
privs = {team=true}, privs = {team=true},
func = function(name, param) func = function(name, param)
minetest.chat_send_player(name, "This command will be made obsolete! Use '/team add name' instead!",false) minetest.chat_send_player(name, "This command will be made obsolete! Use '/team add name' instead!",false)
if string.match(param,"([%a%b_]-)") and cf.team({name=param,add_team=true}) and param ~= "" and param~= nil then if string.match(param,"([%a%b_]-)") and ctf.team({name=param,add_team=true}) and param ~= "" and param~= nil then
minetest.chat_send_player(name, "Added team "..param,false) minetest.chat_send_player(name, "Added team "..param,false)
else else
minetest.chat_send_player(name, "Error adding team "..param,false) minetest.chat_send_player(name, "Error adding team "..param,false)
@ -170,8 +170,8 @@ minetest.register_chatcommand("ctf", {
description = "Do admin cleaning stuff", description = "Do admin cleaning stuff",
privs = {team=true}, privs = {team=true},
func = function(name, param) func = function(name, param)
cf.clean_player_lists() ctf.clean_player_lists()
cf.collect_claimed() ctf.collect_claimed()
minetest.chat_send_player(name, "CTF cleaned!") minetest.chat_send_player(name, "CTF cleaned!")
end, end,
}) })
@ -180,8 +180,8 @@ minetest.register_chatcommand("reload_ctf", {
description = "reload the ctf main frame and get settings", description = "reload the ctf main frame and get settings",
privs = {team=true}, privs = {team=true},
func = function(name, param) func = function(name, param)
cf.save() ctf.save()
cf.init() ctf.init()
minetest.chat_send_player(name, "CTF core reloaded!") minetest.chat_send_player(name, "CTF core reloaded!")
end end
}) })
@ -191,15 +191,15 @@ minetest.register_chatcommand("team_owner", {
description = "Make player team owner", description = "Make player team owner",
privs = {team=true}, privs = {team=true},
func = function(name, param) func = function(name, param)
if cf and cf.players and cf.player(param) and cf.player(param).team and cf.team(cf.player(param).team) then if ctf and ctf.players and ctf.player(param) and ctf.player(param).team and ctf.team(ctf.player(param).team) then
if cf.player(param).auth == true then if ctf.player(param).auth == true then
cf.player(param).auth = false ctf.player(param).auth = false
minetest.chat_send_player(name, param.." was downgraded from team admin status",false) minetest.chat_send_player(name, param.." was downgraded from team admin status",false)
else else
cf.player(param).auth = true ctf.player(param).auth = true
minetest.chat_send_player(name, param.." was upgraded to an admin of "..cf.player(name).team,false) minetest.chat_send_player(name, param.." was upgraded to an admin of "..ctf.player(name).team,false)
end end
cf.save() ctf.save()
else else
minetest.chat_send_player(name, "Unable to do that :/ "..param.." does not exist, or is not part of a valid team.",false) minetest.chat_send_player(name, "Unable to do that :/ "..param.." does not exist, or is not part of a valid team.",false)
end end
@ -210,13 +210,13 @@ minetest.register_chatcommand("all", {
params = "msg", params = "msg",
description = "Send a message on the global channel", description = "Send a message on the global channel",
func = function(name, param) func = function(name, param)
if not cf.setting("global_channel") then if not ctf.setting("global_channel") then
minetest.chat_send_player(name,"The global channel is disabled",false) minetest.chat_send_player(name,"The global channel is disabled",false)
return return
end end
if cf.player(name) and cf.player(name).team then if ctf.player(name) and ctf.player(name).team then
minetest.chat_send_all(cf.player(name).team.." <"..name.."> "..param) minetest.chat_send_all(ctf.player(name).team.." <"..name.."> "..param)
else else
minetest.chat_send_all("GLOBAL <"..name.."> "..param) minetest.chat_send_all("GLOBAL <"..name.."> "..param)
end end
@ -229,16 +229,16 @@ minetest.register_chatcommand("post", {
description = "Post a message on your team's message board", description = "Post a message on your team's message board",
func = function(name, param) func = function(name, param)
if cf and cf.players and cf.players[name] and cf.players[name].team and cf.teams[cf.players[name].team] then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team and ctf.teams[ctf.players[name].team] then
if not cf.player(name).auth then if not ctf.player(name).auth then
minetest.chat_send_player(name, "You do not own that team") minetest.chat_send_player(name, "You do not own that team")
end end
if not cf.teams[cf.players[name].team].log then if not ctf.teams[ctf.players[name].team].log then
cf.teams[cf.players[name].team].log = {} ctf.teams[ctf.players[name].team].log = {}
end end
table.insert(cf.teams[cf.players[name].team].log,{msg=param}) table.insert(ctf.teams[ctf.players[name].team].log,{msg=param})
minetest.chat_send_player(name, "Posted: "..param) minetest.chat_send_player(name, "Posted: "..param)
else else
@ -250,15 +250,15 @@ minetest.register_chatcommand("post", {
-- Chat plus stuff -- Chat plus stuff
if chatplus then if chatplus then
chatplus.register_handler(function(from,to,msg) chatplus.register_handler(function(from,to,msg)
if not cf.setting("team_channel") then if not ctf.setting("team_channel") then
return nil return nil
end end
local fromp = cf.player(from) local fromp = ctf.player(from)
local top = cf.player(to) local top = ctf.player(to)
if not fromp then if not fromp then
if not cf.setting("global_channel") then if not ctf.setting("global_channel") then
minetest.chat_send_player(from,"You are not yet part of a team, so you have no mates to send to",false) minetest.chat_send_player(from,"You are not yet part of a team, so you have no mates to send to",false)
else else
minetest.chat_send_player(to,"GLOBAL <"..from.."> "..msg,false) minetest.chat_send_player(to,"GLOBAL <"..from.."> "..msg,false)

View File

@ -1,60 +1,60 @@
function cf.init() function ctf.init()
print("[CaptureTheFlag] Initialising...") print("[CaptureTheFlag] Initialising...")
-- Set up structures -- Set up structures
cf._defsettings = {} ctf._defsettings = {}
cf.teams = {} ctf.teams = {}
cf.players = {} ctf.players = {}
cf.claimed = {} ctf.claimed = {}
cf.diplo = {diplo = {}} ctf.diplo = {diplo = {}}
-- Settings: Feature enabling -- Settings: Feature enabling
cf._set("node_ownership",true) ctf._set("node_ownership",true)
cf._set("multiple_flags",true) ctf._set("multiple_flags",true)
cf._set("flag_capture_take",false) -- whether flags need to be taken to home flag when captured ctf._set("flag_capture_take",false) -- whether flags need to be taken to home flag when captured
cf._set("gui",true) -- whether GUIs are used ctf._set("gui",true) -- whether GUIs are used
cf._set("team_gui",true) -- GUI on /team is used ctf._set("team_gui",true) -- GUI on /team is used
cf._set("flag_teleport_gui",true) -- flag tab in /team ctf._set("flag_teleport_gui",true) -- flag tab in /team
cf._set("spawn_in_flag_teleport_gui",false) -- show spawn in the flag teleport team gui ctf._set("spawn_in_flag_teleport_gui",false) -- show spawn in the flag teleport team gui
cf._set("news_gui",true) -- news tab in /team ctf._set("news_gui",true) -- news tab in /team
cf._set("diplomacy",true) ctf._set("diplomacy",true)
cf._set("flag_names",true) -- can flags be named ctf._set("flag_names",true) -- can flags be named
cf._set("team_channel",true) -- do teams have their own chat channel ctf._set("team_channel",true) -- do teams have their own chat channel
cf._set("global_channel",true) -- Can players chat with other teams on /all. If team_channel is false, this does nothing. ctf._set("global_channel",true) -- Can players chat with other teams on /all. If team_channel is false, this does nothing.
cf._set("players_can_change_team",true) ctf._set("players_can_change_team",true)
-- Settings: Teams -- Settings: Teams
--cf._set("allocate_mode",0) -- (COMING SOON):how are players allocated to teams? --ctf._set("allocate_mode",0) -- (COMING SOON):how are players allocated to teams?
cf._set("default_diplo_state","war") -- what is the default diplomatic state? (war/peace/alliance) ctf._set("default_diplo_state","war") -- what is the default diplomatic state? (war/peace/alliance)
--cf._setb("delete_teams",false) -- (COMING SOON):should teams be deleted when they are defeated? --ctf._setb("delete_teams",false) -- (COMING SOON):should teams be deleted when they are defeated?
-- Settings: Misc -- Settings: Misc
--cf._set("on_game_end",0) -- (COMING SOON):what happens when the game ends? --ctf._set("on_game_end",0) -- (COMING SOON):what happens when the game ends?
cf._set("flag_protect_distance",25) -- how far do flags protect? ctf._set("flag_protect_distance",25) -- how far do flags protect?
cf._set("team_gui_initial","news") -- [news/flags/diplo/admin] - the starting tab ctf._set("team_gui_initial","news") -- [news/flags/diplo/admin] - the starting tab
local file = io.open(minetest.get_worldpath().."/ctf.txt", "r") local file = io.open(minetest.get_worldpath().."/ctf.txt", "r")
if file then if file then
local table = minetest.deserialize(file:read("*all")) local table = minetest.deserialize(file:read("*all"))
if type(table) == "table" then if type(table) == "table" then
cf.teams = table.teams ctf.teams = table.teams
cf.players = table.players ctf.players = table.players
cf.diplo.diplo = table.diplo ctf.diplo.diplo = table.diplo
return return
end end
end end
end end
-- Set settings -- Set settings
function cf._set(setting,default) function ctf._set(setting,default)
cf._defsettings[setting] = default ctf._defsettings[setting] = default
end end
function cf.setting(name) function ctf.setting(name)
if minetest.setting_get("ctf_"..name) then if minetest.setting_get("ctf_"..name) then
return minetest.setting_get("ctf_"..name) return minetest.setting_get("ctf_"..name)
elseif cf._defsettings[name] ~= nil then elseif ctf._defsettings[name] ~= nil then
return cf._defsettings[name] return ctf._defsettings[name]
else else
print("[CaptureTheFlag] Setting "..name.." not found!") print("[CaptureTheFlag] Setting "..name.." not found!")
return nil return nil
@ -62,67 +62,67 @@ function cf.setting(name)
end end
-- Save game -- Save game
function cf.save() function ctf.save()
print("[CaptureTheFlag] Saving data...") print("[CaptureTheFlag] Saving data...")
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w") local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
if file then if file then
file:write(minetest.serialize({ file:write(minetest.serialize({
teams = cf.teams, teams = ctf.teams,
players = cf.players, players = ctf.players,
diplo = cf.diplo.diplo diplo = ctf.diplo.diplo
})) }))
file:close() file:close()
end end
end end
-- Get or add a team -- Get or add a team
function cf.team(name) -- get or add a team function ctf.team(name) -- get or add a team
if type(name) == "table" then if type(name) == "table" then
if not name.add_team then if not name.add_team then
error("Invalid table given to cf.team") error("Invalid table given to ctf.team")
return return
end end
print("Defining team "..name.name) print("Defining team "..name.name)
cf.teams[name.name]={ ctf.teams[name.name]={
data = name, data = name,
spawn=nil, spawn=nil,
players={}, players={},
flags = {} flags = {}
} }
cf.save() ctf.save()
return cf.teams[name.name] return ctf.teams[name.name]
else else
return cf.teams[name] return ctf.teams[name]
end end
end end
-- get a player -- get a player
function cf.player(name) function ctf.player(name)
return cf.players[name] return ctf.players[name]
end end
-- Player joins team -- Player joins team
function cf.join(name, team, force) function ctf.join(name, team, force)
if not name or name == "" or not team or team == "" then if not name or name == "" or not team or team == "" then
return false return false
end end
local player = cf.player(name) local player = ctf.player(name)
if not player then if not player then
player = {name = name} player = {name = name}
end end
if not force and not cf.setting("players_can_change_team") and (not player.team or player.team == "") then if not force and not ctf.setting("players_can_change_team") and (not player.team or player.team == "") then
minetest.chat_send_player(name, "You are not allowed to switch teams, traitor!") minetest.chat_send_player(name, "You are not allowed to switch teams, traitor!")
return false return false
end end
if cf.add_user(team, player) == true then if ctf.add_user(team, player) == true then
minetest.chat_send_all(name.." has joined team "..team) minetest.chat_send_all(name.." has joined team "..team)
return true return true
end end
@ -130,19 +130,19 @@ function cf.join(name, team, force)
end end
-- Add a player to a team in data structures -- Add a player to a team in data structures
function cf.add_user(team, user) function ctf.add_user(team, user)
local _team = cf.team(team) local _team = ctf.team(team)
local _user = cf.player(user.name) local _user = ctf.player(user.name)
if _team and user and user.name then if _team and user and user.name then
if _user and _user.team and cf.team(_user.team) then if _user and _user.team and ctf.team(_user.team) then
cf.teams[_user.team].players[user.name] = nil ctf.teams[_user.team].players[user.name] = nil
end end
user.team = team user.team = team
user.auth = false user.auth = false
_team.players[user.name]=user _team.players[user.name]=user
cf.players[user.name] = user ctf.players[user.name] = user
cf.save() ctf.save()
return true return true
else else
@ -151,31 +151,31 @@ function cf.add_user(team, user)
end end
-- Cleans up the player lists -- Cleans up the player lists
function cf.clean_player_lists() function ctf.clean_player_lists()
for _, str in pairs(cf.players) do for _, str in pairs(ctf.players) do
if str and str.team and cf.teams[str.team] then if str and str.team and ctf.teams[str.team] then
print("Adding player "..str.name.." to team "..str.team) print("Adding player "..str.name.." to team "..str.team)
cf.teams[str.team].players[str.name] = str ctf.teams[str.team].players[str.name] = str
else else
print("Skipping player "..str.name) print("Skipping player "..str.name)
end end
end end
end end
-- Get info for cf.claimed -- Get info for ctf.claimed
function cf.collect_claimed() function ctf.collect_claimed()
cf.claimed = {} ctf.claimed = {}
for _, team in pairs(cf.teams) do for _, team in pairs(ctf.teams) do
for i = 1, #team.flags do for i = 1, #team.flags do
if team.flags[i].claimed then if team.flags[i].claimed then
table.insert(cf.claimed, team.flags[i]) table.insert(ctf.claimed, team.flags[i])
end end
end end
end end
end end
-- Sees if the player can change stuff in a team -- Sees if the player can change stuff in a team
function cf.can_mod(player,team) function ctf.can_mod(player,team)
local privs = minetest.get_player_privs(player) local privs = minetest.get_player_privs(player)
if privs then if privs then
@ -184,8 +184,8 @@ function cf.can_mod(player,team)
end end
end end
if player and cf.teams[team] and cf.teams[team].players and cf.teams[team].players[player] then if player and ctf.teams[team] and ctf.teams[team].players and ctf.teams[team].players[player] then
if cf.teams[team].players[player].auth == true then if ctf.teams[team].players[player].auth == true then
return true return true
end end
end end
@ -193,17 +193,17 @@ function cf.can_mod(player,team)
end end
-- post a message to a team board -- post a message to a team board
function cf.post(team,msg) function ctf.post(team,msg)
if not cf.team(team) then if not ctf.team(team) then
return false return false
end end
if not cf.team(team).log then if not ctf.team(team).log then
cf.team(team).log = {} ctf.team(team).log = {}
end end
table.insert(cf.team(team).log,1,msg) table.insert(ctf.team(team).log,1,msg)
cf.save() ctf.save()
return true return true
end end

View File

@ -1,27 +1,27 @@
-- diplo states: war, peace, alliance -- diplo states: war, peace, alliance
cf.diplo = {} ctf.diplo = {}
function cf.diplo.get(one,two) function ctf.diplo.get(one,two)
if not cf.diplo.diplo then if not ctf.diplo.diplo then
return cf.setting("default_diplo_state") return ctf.setting("default_diplo_state")
end end
for i=1,#cf.diplo.diplo do for i=1,#ctf.diplo.diplo do
local dip = cf.diplo.diplo[i] local dip = ctf.diplo.diplo[i]
if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then
return dip.state return dip.state
end end
end end
return cf.setting("default_diplo_state") return ctf.setting("default_diplo_state")
end end
function cf.diplo.set(one,two,state) function ctf.diplo.set(one,two,state)
if not cf.diplo.diplo then if not ctf.diplo.diplo then
cf.diplo.diplo = {} ctf.diplo.diplo = {}
else else
for i=1,#cf.diplo.diplo do for i=1,#ctf.diplo.diplo do
local dip = cf.diplo.diplo[i] local dip = ctf.diplo.diplo[i]
if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then
dip.state = state dip.state = state
return return
@ -29,12 +29,12 @@ function cf.diplo.set(one,two,state)
end end
end end
table.insert(cf.diplo.diplo,{one=one,two=two,state=state}) table.insert(ctf.diplo.diplo,{one=one,two=two,state=state})
return return
end end
function cf.diplo.check_requests(one,two) function ctf.diplo.check_requests(one,two)
local team = cf.team(two) local team = ctf.team(two)
if not team.log then if not team.log then
return nil return nil
@ -49,8 +49,8 @@ function cf.diplo.check_requests(one,two)
return nil return nil
end end
function cf.diplo.cancel_requests(one,two) function ctf.diplo.cancel_requests(one,two)
local team = cf.team(two) local team = ctf.team(two)
if not team.log then if not team.log then
return return

View File

@ -1,19 +1,19 @@
cf.flag_func = { ctf.flag_func = {
on_punch_top = function(pos, node, puncher) on_punch_top = function(pos, node, puncher)
pos.y=pos.y-1 pos.y=pos.y-1
cf.flag_func.on_punch(pos,node,puncher) ctf.flag_func.on_punch(pos,node,puncher)
end, end,
on_rightclick_top = function(pos, node, clicker) on_rightclick_top = function(pos, node, clicker)
pos.y=pos.y-1 pos.y=pos.y-1
local flag = cf.area.get_flag(pos) local flag = ctf.area.get_flag(pos)
if not flag then if not flag then
return return
end end
if flag.claimed then if flag.claimed then
if cf.setting("flag_capture_take") 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,"This flag has been taken by "..flag.claimed.player)
minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team) minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team)
return return
@ -23,16 +23,16 @@ cf.flag_func = {
end end
end end
cf.gui.flag_board(clicker:get_player_name(),pos) ctf.gui.flag_board(clicker:get_player_name(),pos)
end, end,
on_rightclick = function(pos, node, clicker) on_rightclick = function(pos, node, clicker)
local flag = cf.area.get_flag(pos) local flag = ctf.area.get_flag(pos)
if not flag then if not flag then
return return
end end
if flag.claimed then if flag.claimed then
if cf.setting("flag_capture_take") 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,"This flag has been taken by "..flag.claimed.player)
minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team) minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team)
return return
@ -41,7 +41,7 @@ cf.flag_func = {
flag.claimed = nil flag.claimed = nil
end end
end end
cf.gui.flag_board(clicker:get_player_name(),pos) ctf.gui.flag_board(clicker:get_player_name(),pos)
end, end,
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
local player = puncher:get_player_name() local player = puncher:get_player_name()
@ -49,13 +49,13 @@ cf.flag_func = {
return return
end end
local flag = cf.area.get_flag(pos) local flag = ctf.area.get_flag(pos)
if not flag then if not flag then
return return
end end
if flag.claimed then if flag.claimed then
if cf.setting("flag_capture_take") 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,"This flag has been taken by "..flag.claimed.player)
minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team) minetest.chat_send_player(player,"who is a member of team "..flag.claimed.team)
return return
@ -70,12 +70,12 @@ cf.flag_func = {
return return
end end
if cf.players and cf.team(team) and cf.player(player) and cf.player(player).team then if ctf.players and ctf.team(team) and ctf.player(player) and ctf.player(player).team then
if cf.player(player).team ~= team then if ctf.player(player).team ~= team then
local diplo = cf.diplo.get(team,cf.player(player).team) local diplo = ctf.diplo.get(team,ctf.player(player).team)
if not diplo then if not diplo then
diplo = cf.setting("default_diplo_state") diplo = ctf.setting("default_diplo_state")
end end
if diplo ~= "war" then if diplo ~= "war" then
@ -83,51 +83,51 @@ cf.flag_func = {
return return
end end
--cf.post(team,{msg=flag_name.." has been captured by "..cf.player(player).team,icon="flag_red"}) --ctf.post(team,{msg=flag_name.." has been captured by "..ctf.player(player).team,icon="flag_red"})
--cf.post(cf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"}) --ctf.post(ctf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"})
--cf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..cf.player(player).team,icon="flag_red"}) --ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..ctf.player(player).team,icon="flag_red"})
--cf.post(cf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) --ctf.post(ctf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"})
local flag_name = flag.name local flag_name = flag.name
if cf.setting("flag_capture_take") then if ctf.setting("flag_capture_take") then
if flag_name and flag_name~="" then if flag_name and flag_name~="" then
minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..cf.player(player).team..")") minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..ctf.player(player).team..")")
cf.post(team,{msg=flag_name.." has been taken by "..cf.player(player).team,icon="flag_red"}) ctf.post(team,{msg=flag_name.." has been taken by "..ctf.player(player).team,icon="flag_red"})
cf.post(cf.player(player).team,{msg=player.." snatched '"..flag_name.."' from "..team,icon="flag_green"}) ctf.post(ctf.player(player).team,{msg=player.." snatched '"..flag_name.."' from "..team,icon="flag_green"})
else else
minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has taken by "..player.." (team "..cf.player(player).team..")") minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has taken by "..player.." (team "..ctf.player(player).team..")")
cf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been taken by "..cf.player(player).team,icon="flag_red"}) ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been taken by "..ctf.player(player).team,icon="flag_red"})
cf.post(cf.player(player).team,{msg=player.." snatched flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) ctf.post(ctf.player(player).team,{msg=player.." snatched flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"})
end end
flag.claimed = { flag.claimed = {
team = cf.player(player).team, team = ctf.player(player).team,
player = player player = player
} }
table.insert(cf.claimed, flag) table.insert(ctf.claimed, flag)
else else
if flag_name and flag_name~="" then if flag_name and flag_name~="" then
minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..cf.player(player).team..")") minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..ctf.player(player).team..")")
cf.post(team,{msg=flag_name.." has been captured by "..cf.player(player).team,icon="flag_red"}) ctf.post(team,{msg=flag_name.." has been captured by "..ctf.player(player).team,icon="flag_red"})
cf.post(cf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"}) ctf.post(ctf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"})
else else
minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has been captured by "..player.." (team "..cf.player(player).team..")") minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has been captured by "..player.." (team "..ctf.player(player).team..")")
cf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..cf.player(player).team,icon="flag_red"}) ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..ctf.player(player).team,icon="flag_red"})
cf.post(cf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) ctf.post(ctf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"})
end end
cf.team(team).spawn = nil ctf.team(team).spawn = nil
if cf.setting("multiple_flags") == true then if ctf.setting("multiple_flags") == true then
cf.area.delete_flag(team,pos) ctf.area.delete_flag(team,pos)
cf.area.add_flag(cf.player(player).team,pos) ctf.area.add_flag(ctf.player(player).team,pos)
else else
minetest.env:set_node(pos,{name="air"}) minetest.env:set_node(pos,{name="air"})
cf.area.delete_flag(team,pos) ctf.area.delete_flag(team,pos)
end end
end end
cf.save() ctf.save()
else else
-- Clicking on their team's flag -- Clicking on their team's flag
if cf.setting("flag_capture_take") then if ctf.setting("flag_capture_take") then
cf.flag_func._flagret(player) ctf.flag_func._flagret(player)
end end
end end
else else
@ -136,30 +136,30 @@ cf.flag_func = {
end, end,
_flagret = function(player) _flagret = function(player)
minetest.chat_send_player(player,"Own flag") minetest.chat_send_player(player,"Own flag")
for i=1, #cf.claimed do for i=1, #ctf.claimed do
if cf.claimed[i].claimed.player == player then if ctf.claimed[i].claimed.player == player then
minetest.chat_send_player(player,"Returning flag") minetest.chat_send_player(player,"Returning flag")
local fteam = cf.team(cf.claimed[i].team) local fteam = ctf.team(ctf.claimed[i].team)
local flag_name = cf.claimed[i].name local flag_name = ctf.claimed[i].name
if flag_name and flag_name~="" then if flag_name and flag_name~="" then
minetest.chat_send_all(flag_name.." has been taken from "..fteam.data.name.." by "..cf.claimed[i].claimed.player.." (team "..cf.claimed[i].claimed.team..")") minetest.chat_send_all(flag_name.." has been taken from "..fteam.data.name.." by "..ctf.claimed[i].claimed.player.." (team "..ctf.claimed[i].claimed.team..")")
cf.post(fteam,{msg=flag_name.." has been captured by "..cf.claimed[i].claimed.team,icon="flag_red"}) ctf.post(fteam,{msg=flag_name.." has been captured by "..ctf.claimed[i].claimed.team,icon="flag_red"})
cf.post(cf.claimed[i].claimed.team,{msg=player.." captured '"..flag_name.."' from "..fteam.data.name,icon="flag_green"}) ctf.post(ctf.claimed[i].claimed.team,{msg=player.." captured '"..flag_name.."' from "..fteam.data.name,icon="flag_green"})
else else
minetest.chat_send_all(fteam.data.name.."'s flag at ("..cf.claimed[i].x..","..cf.claimed[i].z..") has been captured by "..player.." (team "..cf.claimed[i].claimed.team..")") minetest.chat_send_all(fteam.data.name.."'s flag at ("..ctf.claimed[i].x..","..ctf.claimed[i].z..") has been captured by "..player.." (team "..ctf.claimed[i].claimed.team..")")
cf.post(fteam.data.name,{msg="The flag at ("..cf.claimed[i].x..","..cf.claimed[i].z..") has been captured by "..cf.claimed[i].claimed.team,icon="flag_red"}) ctf.post(fteam.data.name,{msg="The flag at ("..ctf.claimed[i].x..","..ctf.claimed[i].z..") has been captured by "..ctf.claimed[i].claimed.team,icon="flag_red"})
cf.post(cf.claimed[i].claimed.team,{msg=player.." captured flag ("..cf.claimed[i].x..","..cf.claimed[i].z..") from "..fteam.data.name,icon="flag_green"}) ctf.post(ctf.claimed[i].claimed.team,{msg=player.." captured flag ("..ctf.claimed[i].x..","..ctf.claimed[i].z..") from "..fteam.data.name,icon="flag_green"})
end end
fteam.spawn = nil fteam.spawn = nil
local fpos = {x=cf.claimed[i].x,y=cf.claimed[i].y,z=cf.claimed[i].z} local fpos = {x=ctf.claimed[i].x,y=ctf.claimed[i].y,z=ctf.claimed[i].z}
if cf.setting("multiple_flags") == true then if ctf.setting("multiple_flags") == true then
cf.area.delete_flag(fteam.data.name,fpos) ctf.area.delete_flag(fteam.data.name,fpos)
cf.area.add_flag(cf.claimed[i].claimed.team,fpos) ctf.area.add_flag(ctf.claimed[i].claimed.team,fpos)
else else
minetest.env:set_node(fpos,{name="air"}) minetest.env:set_node(fpos,{name="air"})
cf.area.delete_flag(fteam.data.name,fpos) ctf.area.delete_flag(fteam.data.name,fpos)
end end
cf.collect_claimed() ctf.collect_claimed()
end end
end end
end, end,
@ -178,30 +178,30 @@ cf.flag_func = {
return return
end end
if cf.players and cf.players[placer:get_player_name()] and cf.players[placer:get_player_name()].team then if ctf.players and ctf.players[placer:get_player_name()] and ctf.players[placer:get_player_name()].team then
local team = cf.players[placer:get_player_name()].team local team = ctf.players[placer:get_player_name()].team
meta:set_string("infotext", team.."'s flag") meta:set_string("infotext", team.."'s flag")
-- add flag -- add flag
cf.area.add_flag(team,pos) ctf.area.add_flag(team,pos)
if cf.teams[team].spawn and minetest.env:get_node(cf.teams[team].spawn).name == "ctf:flag" then if ctf.teams[team].spawn and minetest.env:get_node(ctf.teams[team].spawn).name == "ctf:flag" then
if not cf.setting("multiple_flags") then if not ctf.setting("multiple_flags") then
-- send message -- send message
minetest.chat_send_all(team.."'s flag has been moved") minetest.chat_send_all(team.."'s flag has been moved")
minetest.env:set_node(cf.team(team).spawn,{name="air"}) minetest.env:set_node(ctf.team(team).spawn,{name="air"})
minetest.env:set_node({ minetest.env:set_node({
x=cf.team(team).spawn.x, x=ctf.team(team).spawn.x,
y=cf.team(team).spawn.y+1, y=ctf.team(team).spawn.y+1,
z=cf.team(team).spawn.z z=ctf.team(team).spawn.z
},{name="air"}) },{name="air"})
cf.team(team).spawn = pos ctf.team(team).spawn = pos
end end
else else
cf.area.get_spawn(team) ctf.area.get_spawn(team)
end end
cf.save() ctf.save()
local pos2 = { local pos2 = {
x=pos.x, x=pos.x,
@ -209,12 +209,12 @@ cf.flag_func = {
z=pos.z z=pos.z
} }
if not cf.team(team).data.color then if not ctf.team(team).data.color then
cf.team(team).data.color = "red" ctf.team(team).data.color = "red"
cf.save() ctf.save()
end end
minetest.env:set_node(pos2,{name="ctf:flag_top_"..cf.team(team).data.color}) minetest.env:set_node(pos2,{name="ctf:flag_top_"..ctf.team(team).data.color})
local meta2 = minetest.env:get_meta(pos2) local meta2 = minetest.env:get_meta(pos2)
@ -247,10 +247,10 @@ minetest.register_node("ctf:flag",{
} }
}, },
groups = {immortal=1,is_flag=1,flag_bottom=1}, groups = {immortal=1,is_flag=1,flag_bottom=1},
on_punch = cf.flag_func.on_punch, on_punch = ctf.flag_func.on_punch,
on_rightclick = cf.flag_func.on_rightclick, on_rightclick = ctf.flag_func.on_rightclick,
on_construct = cf.flag_func.on_construct, on_construct = ctf.flag_func.on_construct,
after_place_node = cf.flag_func.after_place_node after_place_node = ctf.flag_func.after_place_node
}) })
local colors = {"red","green","blue"} local colors = {"red","green","blue"}
@ -277,8 +277,8 @@ for i=1,#colors do
} }
}, },
groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1}, groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1},
on_punch = cf.flag_func.on_punch_top, on_punch = ctf.flag_func.on_punch_top,
on_rightclick = cf.flag_func.on_rightclick_top on_rightclick = ctf.flag_func.on_rightclick_top
}) })
end end
@ -302,17 +302,17 @@ minetest.register_node("ctf:flag_captured_top",{
} }
}, },
groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1}, groups = {immortal=1,is_flag=1,flag_top=1,not_in_creative_inventory=1},
on_punch = cf.flag_func.on_punch_top, on_punch = ctf.flag_func.on_punch_top,
on_rightclick = cf.flag_func.on_rightclick_top on_rightclick = ctf.flag_func.on_rightclick_top
}) })
-- On respawn -- On respawn
minetest.register_on_respawnplayer(function(player) minetest.register_on_respawnplayer(function(player)
if player and cf.player(player:get_player_name()) then if player and ctf.player(player:get_player_name()) then
local team = cf.player(player:get_player_name()).team local team = ctf.player(player:get_player_name()).team
if team and cf.team(team) and cf.area.get_spawn(team)==true then if team and ctf.team(team) and ctf.area.get_spawn(team)==true then
print("Player "..player:get_player_name().." moved to team spawn") print("Player "..player:get_player_name().." moved to team spawn")
player:moveto(cf.team(team).spawn, false) player:moveto(ctf.team(team).spawn, false)
return true return true
end end
end end
@ -332,8 +332,8 @@ minetest.register_abm({
return return
end end
local flag_team_data = cf.area.get_flag(pos) local flag_team_data = ctf.area.get_flag(pos)
if not flag_team_data or not cf.team(flag_team_data.team)then if not flag_team_data or not ctf.team(flag_team_data.team)then
print("Flag does not exist! "..dump(pos)) print("Flag does not exist! "..dump(pos))
minetest.env:set_node(pos,{name="air"}) minetest.env:set_node(pos,{name="air"})
minetest.env:set_node(top,{name="air"}) minetest.env:set_node(top,{name="air"})
@ -347,15 +347,15 @@ minetest.register_abm({
flagmeta:set_string("infotext", flag_team_data.team.."'s flag") flagmeta:set_string("infotext", flag_team_data.team.."'s flag")
end end
if not cf.team(flag_team_data.team).data.color then if not ctf.team(flag_team_data.team).data.color then
cf.team(flag_team_data.team).data.color = "red" ctf.team(flag_team_data.team).data.color = "red"
cf.save() ctf.save()
end end
if flag_team_data.claimed then if flag_team_data.claimed then
minetest.env:set_node(top,{name="ctf:flag_captured_top"}) minetest.env:set_node(top,{name="ctf:flag_captured_top"})
else else
minetest.env:set_node(top,{name="ctf:flag_top_"..cf.team(flag_team_data.team).data.color}) minetest.env:set_node(top,{name="ctf:flag_top_"..ctf.team(flag_team_data.team).data.color})
end end
topmeta = minetest.env:get_meta(top) topmeta = minetest.env:get_meta(top)

View File

@ -1,21 +1,21 @@
cf.gui = {} ctf.gui = {}
if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are enabled if ctf.setting("team_gui") and ctf.setting("gui") then -- check if team guis are enabled
-- Get tab buttons -- Get tab buttons
function cf.gui.tabs(name,team) function ctf.gui.tabs(name,team)
local result = "" local result = ""
local id = 1 local id = 1
local function addtab(name,text) local function addtab(name,text)
result = result .. "button["..(id*2-1)..",0;2,1;"..name..";"..text.."]" result = result .. "button["..(id*2-1)..",0;2,1;"..name..";"..text.."]"
id = id + 1 id = id + 1
end end
if cf.setting("news_gui") then if ctf.setting("news_gui") then
addtab("board","News") addtab("board","News")
end end
if cf.setting("flag_teleport_gui") then if ctf.setting("flag_teleport_gui") then
addtab("flags","Flags") addtab("flags","Flags")
end end
if cf.setting("diplomacy") then if ctf.setting("diplomacy") then
addtab("diplo","Diplomacy") addtab("diplo","Diplomacy")
end end
addtab("admin","Settings") addtab("admin","Settings")
@ -23,9 +23,9 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
end end
-- Team interface -- Team interface
function cf.gui.team_board(name,team) function ctf.gui.team_board(name,team)
local result = "" local result = ""
local data = cf.teams[team].log local data = ctf.teams[team].log
if not data then if not data then
data = {} data = {}
@ -35,7 +35,7 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
for i=1,#data do for i=1,#data do
if data[i].type == "request" then if data[i].type == "request" then
if cf.can_mod(name,team)==true then if ctf.can_mod(name,team)==true then
amount = amount + 2 amount = amount + 2
local height = (amount*0.5) + 0.5 local height = (amount*0.5) + 0.5
amount = amount + 1 amount = amount + 1
@ -67,7 +67,7 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
end end
end end
if cf.can_mod(name,team)==true then if ctf.can_mod(name,team)==true then
result = result .. "button[4,6;2,1;clear;Clear all]" result = result .. "button[4,6;2,1;clear;Clear all]"
end end
@ -78,15 +78,15 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
minetest.show_formspec(name, "ctf:board", minetest.show_formspec(name, "ctf:board",
"size[10,7]".. "size[10,7]"..
cf.gui.tabs(name,team).. ctf.gui.tabs(name,team)..
result result
) )
end end
-- Team interface -- Team interface
function cf.gui.team_flags(name,team) function ctf.gui.team_flags(name,team)
local result = "" local result = ""
local t = cf.team(team) local t = ctf.team(team)
if not t then if not t then
return return
@ -96,7 +96,7 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
local y = 2 local y = 2
result = result .. "label[1,1;Click a flag button to go there]" result = result .. "label[1,1;Click a flag button to go there]"
if cf.setting("spawn_in_flag_teleport_gui") and minetest.get_setting("static_spawnpoint") then if ctf.setting("spawn_in_flag_teleport_gui") and minetest.get_setting("static_spawnpoint") then
local x,y,z = string.match(minetest.get_setting("static_spawnpoint"),"(%d+),(%d+),(%d+)") local x,y,z = string.match(minetest.get_setting("static_spawnpoint"),"(%d+),(%d+),(%d+)")
result = result .. result = result ..
@ -134,25 +134,25 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
minetest.show_formspec(name, "ctf:flags", minetest.show_formspec(name, "ctf:flags",
"size[10,7]".. "size[10,7]"..
cf.gui.tabs(name,team).. ctf.gui.tabs(name,team)..
result result
) )
end end
-- Team interface -- Team interface
function cf.gui.team_dip(name,team) function ctf.gui.team_dip(name,team)
local result = "" local result = ""
local data = {} local data = {}
local amount = 0 local amount = 0
for key,value in pairs(cf.teams) do for key,value in pairs(ctf.teams) do
if key ~= team then if key ~= team then
table.insert(data,{ table.insert(data,{
team = key, team = key,
state = cf.diplo.get(team,key), state = ctf.diplo.get(team,key),
to = cf.diplo.check_requests(team,key), to = ctf.diplo.check_requests(team,key),
from = cf.diplo.check_requests(key,team) from = ctf.diplo.check_requests(key,team)
}) })
end end
end end
@ -171,7 +171,7 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
result = result .. "button[1.25,".. height ..";2,1;team_".. data[i].team ..";".. data[i].team .."]" result = result .. "button[1.25,".. height ..";2,1;team_".. data[i].team ..";".. data[i].team .."]"
result = result .. "label[3.75,".. height ..";".. data[i].state .."]" result = result .. "label[3.75,".. height ..";".. data[i].state .."]"
if cf.can_mod(name,team)==true and cf.player(name).team == team then if ctf.can_mod(name,team)==true and ctf.player(name).team == team then
if not data[i].from and not data[i].to then if not data[i].from and not data[i].to then
if data[i].state == "war" then if data[i].state == "war" then
result = result .. "button[7.5,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]" result = result .. "button[7.5,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
@ -192,34 +192,34 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
minetest.show_formspec(name, "ctf:dip", minetest.show_formspec(name, "ctf:dip",
"size[10,7]".. "size[10,7]"..
cf.gui.tabs(name,team).. ctf.gui.tabs(name,team)..
result result
) )
end end
-- Team interface -- Team interface
function cf.gui.team_settings(name,team) function ctf.gui.team_settings(name,team)
if not team or not cf.team(team) then if not team or not ctf.team(team) then
return return
end end
local color = "" local color = ""
if cf.team(team).data and cf.team(team).data.color then if ctf.team(team).data and ctf.team(team).data.color then
color = cf.team(team).data.color color = ctf.team(team).data.color
end end
local result = "field[3,2;4,1;color;Team Color;"..color.."]".. local result = "field[3,2;4,1;color;Team Color;"..color.."]"..
"button[4,6;2,1;save;Save]" "button[4,6;2,1;save;Save]"
if cf.can_mod(name,team) == false then if ctf.can_mod(name,team) == false then
result = "label[0.5,1;You do not own this team!" result = "label[0.5,1;You do not own this team!"
end end
minetest.show_formspec(name, "ctf:team_settings", minetest.show_formspec(name, "ctf:team_settings",
"size[10,7]".. "size[10,7]"..
cf.gui.tabs(name,team).. ctf.gui.tabs(name,team)..
result result
) )
end end
@ -227,46 +227,46 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
local name = player:get_player_name() local name = player:get_player_name()
if formname=="ctf:board" or formname=="ctf:flags" or formname=="ctf:dip" or formname=="ctf:team_settings" then if formname=="ctf:board" or formname=="ctf:flags" or formname=="ctf:dip" or formname=="ctf:team_settings" then
if fields.flags then if fields.flags then
if cf and cf.players and cf.players[name] and cf.players[name].team then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
cf.gui.team_flags(name,cf.players[name].team) ctf.gui.team_flags(name,ctf.players[name].team)
end end
return true return true
end end
if fields.board then if fields.board then
if cf and cf.players and cf.players[name] and cf.players[name].team then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
cf.gui.team_board(name,cf.players[name].team) ctf.gui.team_board(name,ctf.players[name].team)
end end
return true return true
end end
if fields.diplo then if fields.diplo then
if cf and cf.players and cf.players[name] and cf.players[name].team then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
cf.gui.team_dip(name,cf.players[name].team) ctf.gui.team_dip(name,ctf.players[name].team)
end end
return true return true
end end
if fields.admin then if fields.admin then
if cf and cf.players and cf.players[name] and cf.players[name].team then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
cf.gui.team_settings(name,cf.players[name].team) ctf.gui.team_settings(name,ctf.players[name].team)
end end
return true return true
end end
if fields.clear then if fields.clear then
if cf and cf.players and cf.players[name] and cf.players[name].team then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
cf.team(cf.players[name].team).log = {} ctf.team(ctf.players[name].team).log = {}
cf.save() ctf.save()
cf.gui.team_board(name,cf.players[name].team) ctf.gui.team_board(name,ctf.players[name].team)
end end
return true return true
end end
if fields.save and formname=="ctf:team_settings" then if fields.save and formname=="ctf:team_settings" then
if cf and cf.players and cf.players[name] and cf.players[name].team then if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
cf.gui.team_settings(name,cf.players[name].team) ctf.gui.team_settings(name,ctf.players[name].team)
end end
if cf and cf.team(cf.players[name].team) and cf.team(cf.players[name].team).data then 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_top_"..fields.color] then
print("Setting color...") print("Setting color...")
cf.team(cf.players[name].team).data.color = fields.color ctf.team(ctf.players[name].team).data.color = fields.color
cf.save() ctf.save()
else else
minetest.chat_send_player(name,"Color "..fields.color.." does not exist!") minetest.chat_send_player(name,"Color "..fields.color.." does not exist!")
end end
@ -282,17 +282,17 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
for key, field in pairs(fields) do for key, field in pairs(fields) do
local ok, id = string.match(key, "btn_([yn])([0123456789]+)") local ok, id = string.match(key, "btn_([yn])([0123456789]+)")
if ok and id then if ok and id then
if cf.player(name) and cf.player(name).team and cf.team(cf.player(name).team) then if ctf.player(name) and ctf.player(name).team and ctf.team(ctf.player(name).team) then
if ok == "y" then if ok == "y" then
cf.diplo.set(cf.player(name).team, cf.team(cf.player(name).team).log[tonumber(id)].team, cf.team(cf.player(name).team).log[tonumber(id)].msg) ctf.diplo.set(ctf.player(name).team, ctf.team(ctf.player(name).team).log[tonumber(id)].team, ctf.team(ctf.player(name).team).log[tonumber(id)].msg)
cf.post(cf.player(name).team,{msg="You have accepted the "..cf.team(cf.player(name).team).log[tonumber(id)].msg.." request from "..cf.team(cf.player(name).team).log[tonumber(id)].team}) ctf.post(ctf.player(name).team,{msg="You have accepted the "..ctf.team(ctf.player(name).team).log[tonumber(id)].msg.." request from "..ctf.team(ctf.player(name).team).log[tonumber(id)].team})
cf.post(cf.team(cf.player(name).team).log[tonumber(id)].team,{msg=cf.player(name).team.." has accepted your "..cf.team(cf.player(name).team).log[tonumber(id)].msg.." request"}) ctf.post(ctf.team(ctf.player(name).team).log[tonumber(id)].team,{msg=ctf.player(name).team.." has accepted your "..ctf.team(ctf.player(name).team).log[tonumber(id)].msg.." request"})
id = id + 1 id = id + 1
end end
table.remove(cf.team(cf.player(name).team).log,id) table.remove(ctf.team(ctf.player(name).team).log,id)
cf.save() ctf.save()
cf.gui.team_board(name,cf.player(name).team) ctf.gui.team_board(name,ctf.player(name).team)
return true return true
end end
end end
@ -319,63 +319,63 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
for key, field in pairs(fields) do for key, field in pairs(fields) do
local newteam = string.match(key, "team_(.+)") local newteam = string.match(key, "team_(.+)")
if newteam then if newteam then
cf.gui.team_dip(name,newteam) ctf.gui.team_dip(name,newteam)
return true return true
end end
newteam = string.match(key, "peace_(.+)") newteam = string.match(key, "peace_(.+)")
if newteam and cf.player(name) then if newteam and ctf.player(name) then
local team = cf.player(name).team local team = ctf.player(name).team
if team then if team then
if cf.diplo.get(team,newteam) == "war" then if ctf.diplo.get(team,newteam) == "war" then
cf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"}) ctf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"})
else else
cf.diplo.set(team,newteam,"peace") ctf.diplo.set(team,newteam,"peace")
cf.post(team,{msg="You have cancelled the alliance treaty with "..newteam}) ctf.post(team,{msg="You have cancelled the alliance treaty with "..newteam})
cf.post(newteam,{msg=team.." has cancelled the alliance treaty"}) ctf.post(newteam,{msg=team.." has cancelled the alliance treaty"})
end end
end end
cf.gui.team_dip(name,team) ctf.gui.team_dip(name,team)
return true return true
end end
newteam = string.match(key, "war_(.+)") newteam = string.match(key, "war_(.+)")
if newteam and cf.player(name) then if newteam and ctf.player(name) then
local team = cf.player(name).team local team = ctf.player(name).team
if team then if team then
cf.diplo.set(team,newteam,"war") ctf.diplo.set(team,newteam,"war")
cf.post(team,{msg="You have declared war on "..newteam}) ctf.post(team,{msg="You have declared war on "..newteam})
cf.post(newteam,{msg=team.." has declared war on you"}) ctf.post(newteam,{msg=team.." has declared war on you"})
end end
cf.gui.team_dip(name,team) ctf.gui.team_dip(name,team)
return true return true
end end
newteam = string.match(key, "alli_(.+)") newteam = string.match(key, "alli_(.+)")
if newteam and cf.player(name) then if newteam and ctf.player(name) then
local team = cf.player(name).team local team = ctf.player(name).team
if team then if team then
cf.post(newteam,{type="request",msg="alliance",team=team,mode="diplo"}) ctf.post(newteam,{type="request",msg="alliance",team=team,mode="diplo"})
end end
cf.gui.team_dip(name,team) ctf.gui.team_dip(name,team)
return true return true
end end
newteam = string.match(key, "cancel_(.+)") newteam = string.match(key, "cancel_(.+)")
if newteam and cf.player(name) then if newteam and ctf.player(name) then
local team = cf.player(name).team local team = ctf.player(name).team
if team then if team then
cf.diplo.cancel_requests(team,newteam) ctf.diplo.cancel_requests(team,newteam)
end end
cf.gui.team_dip(name,team) ctf.gui.team_dip(name,team)
return true return true
end end
end end
@ -384,8 +384,8 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e
end -- end of check if team guis are enabled end -- end of check if team guis are enabled
-- Flag interface -- Flag interface
function cf.gui.flag_board(name,pos) function ctf.gui.flag_board(name,pos)
local flag = cf.area.get_flag(pos) local flag = ctf.area.get_flag(pos)
if not flag then if not flag then
return return
end end
@ -395,21 +395,21 @@ function cf.gui.flag_board(name,pos)
return return
end end
if cf.can_mod(name,team) == false then if ctf.can_mod(name,team) == false then
if cf.player(name) and cf.player(name).team and cf.player(name).team == team then if ctf.player(name) and ctf.player(name).team and ctf.player(name).team == team then
cf.gui.team_board(name,team) ctf.gui.team_board(name,team)
end end
return return
end end
local flag_name = flag.name local flag_name = flag.name
if not cf.setting("flag_names") then if not ctf.setting("flag_names") then
flag.name = nil flag.name = nil
return return
end end
if not cf.setting("gui") then if not ctf.setting("gui") then
return return
end end
@ -417,11 +417,11 @@ function cf.gui.flag_board(name,pos)
flag_name = "" flag_name = ""
end end
if not cf.gui.flag_data then if not ctf.gui.flag_data then
cf.gui.flag_data = {} ctf.gui.flag_data = {}
end end
cf.gui.flag_data[name] = {pos=pos} ctf.gui.flag_data[name] = {pos=pos}
minetest.show_formspec(name, "ctf:flag_board", minetest.show_formspec(name, "ctf:flag_board",
"size[6,3]".. "size[6,3]"..
@ -438,7 +438,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.save and fields.flag_name then if fields.save and fields.flag_name then
local flag = cf.area.get_flag(cf.gui.flag_data[name].pos) local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos)
if not flag then if not flag then
return false return false
end end
@ -448,7 +448,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return false return false
end end
if cf.can_mod(name,team) == false then if ctf.can_mod(name,team) == false then
return false return false
end end
@ -462,18 +462,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local msg = flag_name.." was renamed to "..fields.flag_name local msg = flag_name.." was renamed to "..fields.flag_name
if flag_name=="" then if flag_name=="" then
msg = "A flag was named "..fields.flag_name.." at ("..cf.gui.flag_data[name].pos.x..","..cf.gui.flag_data[name].pos.z..")" msg = "A flag was named "..fields.flag_name.." at ("..ctf.gui.flag_data[name].pos.x..","..ctf.gui.flag_data[name].pos.z..")"
end end
print(msg) print(msg)
cf.post(team,{msg=msg,icon="flag_info"}) ctf.post(team,{msg=msg,icon="flag_info"})
return true return true
elseif fields.delete then elseif fields.delete then
local pos = cf.gui.flag_data[name].pos local pos = ctf.gui.flag_data[name].pos
local flag = cf.area.get_flag(cf.gui.flag_data[name].pos) local flag = ctf.area.get_flag(ctf.gui.flag_data[name].pos)
if not flag then if not flag then
print("No flag?!") print("No flag?!")
@ -484,11 +484,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return return
end end
if cf.can_mod(name,team) == false then if ctf.can_mod(name,team) == false then
return false return false
end end
cf.area.delete_flag(team,pos) ctf.area.delete_flag(team,pos)
minetest.env:set_node(pos,{name="air"}) minetest.env:set_node(pos,{name="air"})
pos.y=pos.y+1 pos.y=pos.y+1

View File

@ -2,7 +2,7 @@
-- by Andrew "rubenwardy" Ward -- by Andrew "rubenwardy" Ward
----------------------------------------- -----------------------------------------
cf = {} ctf = {}
-- Helpers -- Helpers
v3={} v3={}
@ -60,7 +60,7 @@ end
-- Load the core -- Load the core
dofile(minetest.get_modpath("ctf").."/core.lua") dofile(minetest.get_modpath("ctf").."/core.lua")
cf.init() ctf.init()
-- Modules -- Modules
dofile(minetest.get_modpath("ctf").."/diplomacy.lua") dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
@ -70,5 +70,5 @@ dofile(minetest.get_modpath("ctf").."/cli.lua")
dofile(minetest.get_modpath("ctf").."/flag.lua") dofile(minetest.get_modpath("ctf").."/flag.lua")
-- Init -- Init
cf.clean_player_lists() ctf.clean_player_lists()
cf.collect_claimed() ctf.collect_claimed()

View File

@ -1,14 +1,14 @@
-- This mod is used to protect nodes in the capture the flag game -- This mod is used to protect nodes in the capture the flag game
function stop_dig(name,pos) function stop_dig(name,pos)
local team = cf.area.get_area(pos) local team = ctf.area.get_area(pos)
if not team then if not team then
return false return false
end end
if cf.players and cf.player(name) and cf.player(name).team then if ctf.players and ctf.player(name) and ctf.player(name).team then
if cf.player(name).team == team then if ctf.player(name).team == team then
return false return false
end end
end end

View File

@ -29,8 +29,8 @@ minetest.register_node("ctf_turret:turret", {
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
if meta and cf.players and cf.player(placer:get_player_name()) and cf.player(placer:get_player_name()).team then if meta and ctf.players and ctf.player(placer:get_player_name()) and ctf.player(placer:get_player_name()).team then
local team = cf.player(placer:get_player_name()).team local team = ctf.player(placer:get_player_name()).team
meta:set_string("team", team) meta:set_string("team", team)
meta:set_string("infotext", "Owned by "..team) meta:set_string("infotext", "Owned by "..team)
else else
@ -54,7 +54,7 @@ minetest.register_abm({
return return
end end
local app = cf.area.get_area(pos) local app = ctf.area.get_area(pos)
if app and app~=team then if app and app~=team then
team = app team = app
meta:set_string("team",team) meta:set_string("team",team)
@ -69,9 +69,9 @@ minetest.register_abm({
for _,obj in ipairs(objects) do for _,obj in ipairs(objects) do
if ( if (
obj:is_player() and obj:is_player() and
cf.players and ctf.players and
cf.player(obj:get_player_name()) and ctf.player(obj:get_player_name()) and
cf.player(obj:get_player_name()).team ~= team ctf.player(obj:get_player_name()).team ~= team
)then )then
-- Calculate stuff -- Calculate stuff
local obj_p = obj:getpos() local obj_p = obj:getpos()