diff --git a/mods/capturetheflag/ctf/area.lua b/mods/capturetheflag/ctf/area.lua index dc5276c..71a3747 100644 --- a/mods/capturetheflag/ctf/area.lua +++ b/mods/capturetheflag/ctf/area.lua @@ -1,28 +1,28 @@ -cf.area = {} +ctf.area = {} -- 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 return end - if not cf.team(team).flags then - cf.team(team).flags = {} + if not ctf.team(team).flags then + ctf.team(team).flags = {} end pos.team = team - table.insert(cf.team(team).flags,pos) - cf.save() + table.insert(ctf.team(team).flags,pos) + ctf.save() end -- get a flag from a team -function cf.area.get_flag(pos) +function ctf.area.get_flag(pos) if not pos then return end local result = nil - for _, team in pairs(cf.teams) do + for _, team in pairs(ctf.teams) do for i = 1, #team.flags do if ( team.flags[i].x == pos.x and @@ -48,36 +48,36 @@ function cf.area.get_flag(pos) end -- 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 return end - print(dump(cf.team(team).flags)) - for i = 1, #cf.team(team).flags do + print(dump(ctf.team(team).flags)) + for i = 1, #ctf.team(team).flags do if ( - cf.team(team).flags[i].x == pos.x and - cf.team(team).flags[i].y == pos.y and - cf.team(team).flags[i].z == pos.z + ctf.team(team).flags[i].x == pos.x and + ctf.team(team).flags[i].y == pos.y and + ctf.team(team).flags[i].z == pos.z ) then - table.remove(cf.team(team).flags,i) + table.remove(ctf.team(team).flags,i) return end end end -- 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 print ("No position provided to nearest_flag()") return nil 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( - {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+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+ctf.setting("flag_protect_distance"),y=pos.y+ctf.setting("flag_protect_distance"),z=pos.z+ctf.setting("flag_protect_distance")}, {"group:is_flag"} ) @@ -99,12 +99,12 @@ function cf.area.nearest_flag(pos) end -- gets the name of the owner of that location -function cf.area.get_area(pos) - local closest = cf.area.nearest_flag(pos) +function ctf.area.get_area(pos) + local closest = ctf.area.nearest_flag(pos) if not closest then return false end - local flag = cf.area.get_flag(closest) + local flag = ctf.area.get_flag(closest) if flag then return flag.team @@ -113,12 +113,12 @@ function cf.area.get_area(pos) end -- updates the spawn position for a team -function cf.area.get_spawn(team) - cf.area.asset_flags(team) +function ctf.area.get_spawn(team) + ctf.area.asset_flags(team) - if team and cf.teams and cf.team(team) then - if cf.team(team).spawn and minetest.env:get_node(cf.team(team).spawn).name == "ctf:flag" then - local flag = cf.area.get_flag(cf.team(team).spawn) + 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 flag then return false @@ -133,22 +133,22 @@ function cf.area.get_spawn(team) end -- Get new spawn - if #cf.team(team).flags > 0 then - cf.team(team).spawn = cf.team(team).flags[1] + if #ctf.team(team).flags > 0 then + ctf.team(team).spawn = ctf.team(team).flags[1] return true end end return false end -function cf.area.asset_flags(team) - if not team or not cf.team(team) then +function ctf.area.asset_flags(team) + if not team or not ctf.team(team) then return false end print("Checking the flags of "..team) - local tmp = cf.team(team).flags + local tmp = ctf.team(team).flags 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 diff --git a/mods/capturetheflag/ctf/cli.lua b/mods/capturetheflag/ctf/cli.lua index bc5bd06..b5fdc66 100644 --- a/mods/capturetheflag/ctf/cli.lua +++ b/mods/capturetheflag/ctf/cli.lua @@ -22,12 +22,12 @@ minetest.register_chatcommand("team", { if test then print("is a player request "..test) - if cf.player(test) then - if cf.player(test).team then - if cf.player(test).auth then - minetest.chat_send_player(name,test.." is in team "..cf.player(test).team.." (team owner)",false) + if ctf.player(test) then + if ctf.player(test).team then + if ctf.player(test).auth then + minetest.chat_send_player(name,test.." is in team "..ctf.player(test).team.." (team owner)",false) 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 else 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 ( 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 ~= nil ) then @@ -53,7 +53,7 @@ minetest.register_chatcommand("team", { end elseif param == "all" then 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 local numItems = 0 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) end end - elseif cf.team(param) then + elseif ctf.team(param) then minetest.chat_send_player(name,"Team "..param..":",false) local count = 0 - for _,value in pairs(cf.team(param).players) do + for _,value in pairs(ctf.team(param).players) do count = count + 1 if value.aut == true then 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) local privs = minetest.get_player_privs(name) if privs and privs.team == true then - local player = cf.player(tplayer) + local player = ctf.player(tplayer) if not player then player = {name=tplayer} 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) end else @@ -101,22 +101,22 @@ minetest.register_chatcommand("team", { team_console_help(name) end if ( - cf and - cf.players and - cf.players[name] and - cf.players[name].team and - cf.setting("gui") + ctf and + ctf.players and + ctf.players[name] and + ctf.players[name].team and + ctf.setting("gui") ) then - if cf.setting("team_gui_initial") == "news" and cf.setting("news_gui") then - cf.gui.team_board(name,cf.players[name].team) - elseif cf.setting("team_gui_initial") == "flags" and cf.setting("flag_teleport_gui") then - cf.gui.team_flags(name,cf.players[name].team) - elseif cf.setting("team_gui_initial") == "diplo" and cf.setting("diplomacy") then - cf.gui.team_dip(name,cf.players[name].team) - elseif cf.setting("team_gui_initial") == "admin" then - cf.gui.team_settings(name,cf.players[name].team) - elseif cf.setting("news_gui") then - cf.gui.team_board(name,cf.players[name].team) + if ctf.setting("team_gui_initial") == "news" and ctf.setting("news_gui") then + ctf.gui.team_board(name,ctf.players[name].team) + elseif ctf.setting("team_gui_initial") == "flags" and ctf.setting("flag_teleport_gui") then + ctf.gui.team_flags(name,ctf.players[name].team) + elseif ctf.setting("team_gui_initial") == "diplo" and ctf.setting("diplomacy") then + ctf.gui.team_dip(name,ctf.players[name].team) + elseif ctf.setting("team_gui_initial") == "admin" then + ctf.gui.team_settings(name,ctf.players[name].team) + elseif ctf.setting("news_gui") then + ctf.gui.team_board(name,ctf.players[name].team) end end end @@ -127,7 +127,7 @@ minetest.register_chatcommand("join", { params = "team name", description = "Add to team", func = function(name, param) - cf.join(name, param, false) + ctf.join(name, param, false) end, }) minetest.register_chatcommand("list_teams", { @@ -136,7 +136,7 @@ minetest.register_chatcommand("list_teams", { 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, "Teams:") - for k,v in pairs(cf.teams) do + for k,v in pairs(ctf.teams) do if v and v.players then local numItems = 0 for k,v in pairs(v.players) do @@ -158,7 +158,7 @@ minetest.register_chatcommand("ateam", { privs = {team=true}, func = function(name, param) 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) else minetest.chat_send_player(name, "Error adding team "..param,false) @@ -170,8 +170,8 @@ minetest.register_chatcommand("ctf", { description = "Do admin cleaning stuff", privs = {team=true}, func = function(name, param) - cf.clean_player_lists() - cf.collect_claimed() + ctf.clean_player_lists() + ctf.collect_claimed() minetest.chat_send_player(name, "CTF cleaned!") end, }) @@ -180,8 +180,8 @@ minetest.register_chatcommand("reload_ctf", { description = "reload the ctf main frame and get settings", privs = {team=true}, func = function(name, param) - cf.save() - cf.init() + ctf.save() + ctf.init() minetest.chat_send_player(name, "CTF core reloaded!") end }) @@ -191,15 +191,15 @@ minetest.register_chatcommand("team_owner", { description = "Make player team owner", privs = {team=true}, 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 cf.player(param).auth == true then - cf.player(param).auth = false + if ctf and ctf.players and ctf.player(param) and ctf.player(param).team and ctf.team(ctf.player(param).team) then + if ctf.player(param).auth == true then + ctf.player(param).auth = false minetest.chat_send_player(name, param.." was downgraded from team admin status",false) else - cf.player(param).auth = true - minetest.chat_send_player(name, param.." was upgraded to an admin of "..cf.player(name).team,false) + ctf.player(param).auth = true + minetest.chat_send_player(name, param.." was upgraded to an admin of "..ctf.player(name).team,false) end - cf.save() + ctf.save() else minetest.chat_send_player(name, "Unable to do that :/ "..param.." does not exist, or is not part of a valid team.",false) end @@ -210,13 +210,13 @@ minetest.register_chatcommand("all", { params = "msg", description = "Send a message on the global channel", 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) return end - if cf.player(name) and cf.player(name).team then - minetest.chat_send_all(cf.player(name).team.." <"..name.."> "..param) + if ctf.player(name) and ctf.player(name).team then + minetest.chat_send_all(ctf.player(name).team.." <"..name.."> "..param) else minetest.chat_send_all("GLOBAL <"..name.."> "..param) end @@ -229,16 +229,16 @@ minetest.register_chatcommand("post", { description = "Post a message on your team's message board", 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 not cf.player(name).auth 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 ctf.player(name).auth then minetest.chat_send_player(name, "You do not own that team") end - if not cf.teams[cf.players[name].team].log then - cf.teams[cf.players[name].team].log = {} + if not ctf.teams[ctf.players[name].team].log then + ctf.teams[ctf.players[name].team].log = {} 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) else @@ -250,15 +250,15 @@ minetest.register_chatcommand("post", { -- Chat plus stuff if chatplus then chatplus.register_handler(function(from,to,msg) - if not cf.setting("team_channel") then + if not ctf.setting("team_channel") then return nil end - local fromp = cf.player(from) - local top = cf.player(to) + local fromp = ctf.player(from) + local top = ctf.player(to) 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) else minetest.chat_send_player(to,"GLOBAL <"..from.."> "..msg,false) diff --git a/mods/capturetheflag/ctf/core.lua b/mods/capturetheflag/ctf/core.lua index 37b58c3..241692d 100644 --- a/mods/capturetheflag/ctf/core.lua +++ b/mods/capturetheflag/ctf/core.lua @@ -1,60 +1,60 @@ -function cf.init() +function ctf.init() print("[CaptureTheFlag] Initialising...") -- Set up structures - cf._defsettings = {} - cf.teams = {} - cf.players = {} - cf.claimed = {} - cf.diplo = {diplo = {}} + ctf._defsettings = {} + ctf.teams = {} + ctf.players = {} + ctf.claimed = {} + ctf.diplo = {diplo = {}} -- Settings: Feature enabling - cf._set("node_ownership",true) - cf._set("multiple_flags",true) - cf._set("flag_capture_take",false) -- whether flags need to be taken to home flag when captured - cf._set("gui",true) -- whether GUIs are used - cf._set("team_gui",true) -- GUI on /team is used - cf._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 - cf._set("news_gui",true) -- news tab in /team - cf._set("diplomacy",true) - cf._set("flag_names",true) -- can flags be named - cf._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. - cf._set("players_can_change_team",true) + ctf._set("node_ownership",true) + ctf._set("multiple_flags",true) + ctf._set("flag_capture_take",false) -- whether flags need to be taken to home flag when captured + ctf._set("gui",true) -- whether GUIs are used + ctf._set("team_gui",true) -- GUI on /team is used + ctf._set("flag_teleport_gui",true) -- flag tab in /team + ctf._set("spawn_in_flag_teleport_gui",false) -- show spawn in the flag teleport team gui + ctf._set("news_gui",true) -- news tab in /team + ctf._set("diplomacy",true) + ctf._set("flag_names",true) -- can flags be named + ctf._set("team_channel",true) -- do teams have their own chat channel + ctf._set("global_channel",true) -- Can players chat with other teams on /all. If team_channel is false, this does nothing. + ctf._set("players_can_change_team",true) -- Settings: Teams - --cf._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) - --cf._setb("delete_teams",false) -- (COMING SOON):should teams be deleted when they are defeated? + --ctf._set("allocate_mode",0) -- (COMING SOON):how are players allocated to teams? + ctf._set("default_diplo_state","war") -- what is the default diplomatic state? (war/peace/alliance) + --ctf._setb("delete_teams",false) -- (COMING SOON):should teams be deleted when they are defeated? -- Settings: Misc - --cf._set("on_game_end",0) -- (COMING SOON):what happens when the game ends? - cf._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("on_game_end",0) -- (COMING SOON):what happens when the game ends? + ctf._set("flag_protect_distance",25) -- how far do flags protect? + ctf._set("team_gui_initial","news") -- [news/flags/diplo/admin] - the starting tab local file = io.open(minetest.get_worldpath().."/ctf.txt", "r") if file then local table = minetest.deserialize(file:read("*all")) if type(table) == "table" then - cf.teams = table.teams - cf.players = table.players - cf.diplo.diplo = table.diplo + ctf.teams = table.teams + ctf.players = table.players + ctf.diplo.diplo = table.diplo return end end end -- Set settings -function cf._set(setting,default) - cf._defsettings[setting] = default +function ctf._set(setting,default) + ctf._defsettings[setting] = default end -function cf.setting(name) +function ctf.setting(name) if minetest.setting_get("ctf_"..name) then return minetest.setting_get("ctf_"..name) - elseif cf._defsettings[name] ~= nil then - return cf._defsettings[name] + elseif ctf._defsettings[name] ~= nil then + return ctf._defsettings[name] else print("[CaptureTheFlag] Setting "..name.." not found!") return nil @@ -62,67 +62,67 @@ function cf.setting(name) end -- Save game -function cf.save() +function ctf.save() print("[CaptureTheFlag] Saving data...") local file = io.open(minetest.get_worldpath().."/ctf.txt", "w") if file then file:write(minetest.serialize({ - teams = cf.teams, - players = cf.players, - diplo = cf.diplo.diplo + teams = ctf.teams, + players = ctf.players, + diplo = ctf.diplo.diplo })) file:close() end end -- 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 not name.add_team then - error("Invalid table given to cf.team") + error("Invalid table given to ctf.team") return end print("Defining team "..name.name) - cf.teams[name.name]={ + ctf.teams[name.name]={ data = name, spawn=nil, players={}, flags = {} } - cf.save() + ctf.save() - return cf.teams[name.name] + return ctf.teams[name.name] else - return cf.teams[name] + return ctf.teams[name] end end -- get a player -function cf.player(name) - return cf.players[name] +function ctf.player(name) + return ctf.players[name] end -- 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 return false end - local player = cf.player(name) + local player = ctf.player(name) if not player then player = {name = name} 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!") return false 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) return true end @@ -130,19 +130,19 @@ function cf.join(name, team, force) end -- Add a player to a team in data structures -function cf.add_user(team, user) - local _team = cf.team(team) - local _user = cf.player(user.name) +function ctf.add_user(team, user) + local _team = ctf.team(team) + local _user = ctf.player(user.name) if _team and user and user.name then - if _user and _user.team and cf.team(_user.team) then - cf.teams[_user.team].players[user.name] = nil + if _user and _user.team and ctf.team(_user.team) then + ctf.teams[_user.team].players[user.name] = nil end user.team = team user.auth = false _team.players[user.name]=user - cf.players[user.name] = user - cf.save() + ctf.players[user.name] = user + ctf.save() return true else @@ -151,31 +151,31 @@ function cf.add_user(team, user) end -- Cleans up the player lists -function cf.clean_player_lists() - for _, str in pairs(cf.players) do - if str and str.team and cf.teams[str.team] then +function ctf.clean_player_lists() + for _, str in pairs(ctf.players) do + if str and str.team and ctf.teams[str.team] then 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 print("Skipping player "..str.name) end end end --- Get info for cf.claimed -function cf.collect_claimed() - cf.claimed = {} - for _, team in pairs(cf.teams) do +-- Get info for ctf.claimed +function ctf.collect_claimed() + ctf.claimed = {} + for _, team in pairs(ctf.teams) do for i = 1, #team.flags do if team.flags[i].claimed then - table.insert(cf.claimed, team.flags[i]) + table.insert(ctf.claimed, team.flags[i]) end end end end -- 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) if privs then @@ -184,8 +184,8 @@ function cf.can_mod(player,team) end end - if player and cf.teams[team] and cf.teams[team].players and cf.teams[team].players[player] then - if cf.teams[team].players[player].auth == true then + if player and ctf.teams[team] and ctf.teams[team].players and ctf.teams[team].players[player] then + if ctf.teams[team].players[player].auth == true then return true end end @@ -193,17 +193,17 @@ function cf.can_mod(player,team) end -- post a message to a team board -function cf.post(team,msg) - if not cf.team(team) then +function ctf.post(team,msg) + if not ctf.team(team) then return false end - if not cf.team(team).log then - cf.team(team).log = {} + if not ctf.team(team).log then + ctf.team(team).log = {} end - table.insert(cf.team(team).log,1,msg) - cf.save() + table.insert(ctf.team(team).log,1,msg) + ctf.save() return true end diff --git a/mods/capturetheflag/ctf/diplomacy.lua b/mods/capturetheflag/ctf/diplomacy.lua index af8ce36..1ecd658 100644 --- a/mods/capturetheflag/ctf/diplomacy.lua +++ b/mods/capturetheflag/ctf/diplomacy.lua @@ -1,27 +1,27 @@ -- diplo states: war, peace, alliance -cf.diplo = {} +ctf.diplo = {} -function cf.diplo.get(one,two) - if not cf.diplo.diplo then - return cf.setting("default_diplo_state") +function ctf.diplo.get(one,two) + if not ctf.diplo.diplo then + return ctf.setting("default_diplo_state") end - for i=1,#cf.diplo.diplo do - local dip = cf.diplo.diplo[i] + for i=1,#ctf.diplo.diplo do + local dip = ctf.diplo.diplo[i] if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then return dip.state end end - return cf.setting("default_diplo_state") + return ctf.setting("default_diplo_state") end -function cf.diplo.set(one,two,state) - if not cf.diplo.diplo then - cf.diplo.diplo = {} +function ctf.diplo.set(one,two,state) + if not ctf.diplo.diplo then + ctf.diplo.diplo = {} else - for i=1,#cf.diplo.diplo do - local dip = cf.diplo.diplo[i] + for i=1,#ctf.diplo.diplo do + local dip = ctf.diplo.diplo[i] if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then dip.state = state return @@ -29,12 +29,12 @@ function cf.diplo.set(one,two,state) 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 end -function cf.diplo.check_requests(one,two) - local team = cf.team(two) +function ctf.diplo.check_requests(one,two) + local team = ctf.team(two) if not team.log then return nil @@ -49,8 +49,8 @@ function cf.diplo.check_requests(one,two) return nil end -function cf.diplo.cancel_requests(one,two) - local team = cf.team(two) +function ctf.diplo.cancel_requests(one,two) + local team = ctf.team(two) if not team.log then return diff --git a/mods/capturetheflag/ctf/flag.lua b/mods/capturetheflag/ctf/flag.lua index 3b2fc11..981f9d7 100644 --- a/mods/capturetheflag/ctf/flag.lua +++ b/mods/capturetheflag/ctf/flag.lua @@ -1,19 +1,19 @@ -cf.flag_func = { +ctf.flag_func = { on_punch_top = function(pos, node, puncher) pos.y=pos.y-1 - cf.flag_func.on_punch(pos,node,puncher) + ctf.flag_func.on_punch(pos,node,puncher) end, on_rightclick_top = function(pos, node, clicker) pos.y=pos.y-1 - local flag = cf.area.get_flag(pos) + local flag = ctf.area.get_flag(pos) if not flag then return end 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,"who is a member of team "..flag.claimed.team) return @@ -23,16 +23,16 @@ cf.flag_func = { end end - cf.gui.flag_board(clicker:get_player_name(),pos) + ctf.gui.flag_board(clicker:get_player_name(),pos) end, on_rightclick = function(pos, node, clicker) - local flag = cf.area.get_flag(pos) + local flag = ctf.area.get_flag(pos) if not flag then return end 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,"who is a member of team "..flag.claimed.team) return @@ -41,7 +41,7 @@ cf.flag_func = { flag.claimed = nil end end - cf.gui.flag_board(clicker:get_player_name(),pos) + ctf.gui.flag_board(clicker:get_player_name(),pos) end, on_punch = function(pos, node, puncher) local player = puncher:get_player_name() @@ -49,13 +49,13 @@ cf.flag_func = { return end - local flag = cf.area.get_flag(pos) + local flag = ctf.area.get_flag(pos) if not flag then return end 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,"who is a member of team "..flag.claimed.team) return @@ -70,12 +70,12 @@ cf.flag_func = { return end - if cf.players and cf.team(team) and cf.player(player) and cf.player(player).team then - if cf.player(player).team ~= team then - local diplo = cf.diplo.get(team,cf.player(player).team) + if ctf.players and ctf.team(team) and ctf.player(player) and ctf.player(player).team then + if ctf.player(player).team ~= team then + local diplo = ctf.diplo.get(team,ctf.player(player).team) if not diplo then - diplo = cf.setting("default_diplo_state") + diplo = ctf.setting("default_diplo_state") end if diplo ~= "war" then @@ -83,51 +83,51 @@ cf.flag_func = { return end - --cf.post(team,{msg=flag_name.." has been captured by "..cf.player(player).team,icon="flag_red"}) - --cf.post(cf.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"}) - --cf.post(cf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) + --ctf.post(team,{msg=flag_name.." has been captured by "..ctf.player(player).team,icon="flag_red"}) + --ctf.post(ctf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"}) + --ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..ctf.player(player).team,icon="flag_red"}) + --ctf.post(ctf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) 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 - minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..cf.player(player).team..")") - cf.post(team,{msg=flag_name.." has been taken by "..cf.player(player).team,icon="flag_red"}) - cf.post(cf.player(player).team,{msg=player.." snatched '"..flag_name.."' from "..team,icon="flag_green"}) + 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"}) + ctf.post(ctf.player(player).team,{msg=player.." snatched '"..flag_name.."' from "..team,icon="flag_green"}) else - minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has taken by "..player.." (team "..cf.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"}) - cf.post(cf.player(player).team,{msg=player.." snatched flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) + minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has taken by "..player.." (team "..ctf.player(player).team..")") + ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been taken by "..ctf.player(player).team,icon="flag_red"}) + ctf.post(ctf.player(player).team,{msg=player.." snatched flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) end flag.claimed = { - team = cf.player(player).team, + team = ctf.player(player).team, player = player } - table.insert(cf.claimed, flag) + table.insert(ctf.claimed, flag) else 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..")") - cf.post(team,{msg=flag_name.." has been captured by "..cf.player(player).team,icon="flag_red"}) - cf.post(cf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"}) + 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 captured by "..ctf.player(player).team,icon="flag_red"}) + ctf.post(ctf.player(player).team,{msg=player.." captured '"..flag_name.."' from "..team,icon="flag_green"}) else - minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has been captured by "..player.." (team "..cf.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"}) - cf.post(cf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) + minetest.chat_send_all(team.."'s flag at ("..pos.x..","..pos.z..") has been captured by "..player.." (team "..ctf.player(player).team..")") + ctf.post(team,{msg="The flag at ("..pos.x..","..pos.z..") has been captured by "..ctf.player(player).team,icon="flag_red"}) + ctf.post(ctf.player(player).team,{msg=player.." captured flag ("..pos.x..","..pos.z..") from "..team,icon="flag_green"}) end - cf.team(team).spawn = nil - if cf.setting("multiple_flags") == true then - cf.area.delete_flag(team,pos) - cf.area.add_flag(cf.player(player).team,pos) + ctf.team(team).spawn = nil + if ctf.setting("multiple_flags") == true then + ctf.area.delete_flag(team,pos) + ctf.area.add_flag(ctf.player(player).team,pos) else minetest.env:set_node(pos,{name="air"}) - cf.area.delete_flag(team,pos) + ctf.area.delete_flag(team,pos) end end - cf.save() + ctf.save() else -- Clicking on their team's flag - if cf.setting("flag_capture_take") then - cf.flag_func._flagret(player) + if ctf.setting("flag_capture_take") then + ctf.flag_func._flagret(player) end end else @@ -136,30 +136,30 @@ cf.flag_func = { end, _flagret = function(player) minetest.chat_send_player(player,"Own flag") - for i=1, #cf.claimed do - if cf.claimed[i].claimed.player == player then + for i=1, #ctf.claimed do + if ctf.claimed[i].claimed.player == player then minetest.chat_send_player(player,"Returning flag") - local fteam = cf.team(cf.claimed[i].team) - local flag_name = cf.claimed[i].name + local fteam = ctf.team(ctf.claimed[i].team) + local flag_name = ctf.claimed[i].name 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..")") - cf.post(fteam,{msg=flag_name.." has been captured by "..cf.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"}) + 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..")") + ctf.post(fteam,{msg=flag_name.." has been captured by "..ctf.claimed[i].claimed.team,icon="flag_red"}) + ctf.post(ctf.claimed[i].claimed.team,{msg=player.." captured '"..flag_name.."' from "..fteam.data.name,icon="flag_green"}) 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..")") - 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"}) - 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"}) + 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..")") + 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"}) + 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 fteam.spawn = nil - local fpos = {x=cf.claimed[i].x,y=cf.claimed[i].y,z=cf.claimed[i].z} - if cf.setting("multiple_flags") == true then - cf.area.delete_flag(fteam.data.name,fpos) - cf.area.add_flag(cf.claimed[i].claimed.team,fpos) + local fpos = {x=ctf.claimed[i].x,y=ctf.claimed[i].y,z=ctf.claimed[i].z} + if ctf.setting("multiple_flags") == true then + ctf.area.delete_flag(fteam.data.name,fpos) + ctf.area.add_flag(ctf.claimed[i].claimed.team,fpos) else minetest.env:set_node(fpos,{name="air"}) - cf.area.delete_flag(fteam.data.name,fpos) + ctf.area.delete_flag(fteam.data.name,fpos) end - cf.collect_claimed() + ctf.collect_claimed() end end end, @@ -178,30 +178,30 @@ cf.flag_func = { return end - if cf.players and cf.players[placer:get_player_name()] and cf.players[placer:get_player_name()].team then - local team = cf.players[placer:get_player_name()].team + if ctf.players and ctf.players[placer:get_player_name()] and ctf.players[placer:get_player_name()].team then + local team = ctf.players[placer:get_player_name()].team meta:set_string("infotext", team.."'s 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 not cf.setting("multiple_flags") then + 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 -- send message 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({ - x=cf.team(team).spawn.x, - y=cf.team(team).spawn.y+1, - z=cf.team(team).spawn.z + x=ctf.team(team).spawn.x, + y=ctf.team(team).spawn.y+1, + z=ctf.team(team).spawn.z },{name="air"}) - cf.team(team).spawn = pos + ctf.team(team).spawn = pos end else - cf.area.get_spawn(team) + ctf.area.get_spawn(team) end - cf.save() + ctf.save() local pos2 = { x=pos.x, @@ -209,12 +209,12 @@ cf.flag_func = { z=pos.z } - if not cf.team(team).data.color then - cf.team(team).data.color = "red" - cf.save() + if not ctf.team(team).data.color then + ctf.team(team).data.color = "red" + ctf.save() 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) @@ -247,10 +247,10 @@ minetest.register_node("ctf:flag",{ } }, groups = {immortal=1,is_flag=1,flag_bottom=1}, - on_punch = cf.flag_func.on_punch, - on_rightclick = cf.flag_func.on_rightclick, - on_construct = cf.flag_func.on_construct, - after_place_node = cf.flag_func.after_place_node + 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 }) 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}, - on_punch = cf.flag_func.on_punch_top, - on_rightclick = cf.flag_func.on_rightclick_top + on_punch = ctf.flag_func.on_punch_top, + on_rightclick = ctf.flag_func.on_rightclick_top }) 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}, - on_punch = cf.flag_func.on_punch_top, - on_rightclick = cf.flag_func.on_rightclick_top + 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 cf.player(player:get_player_name()) then - local team = cf.player(player:get_player_name()).team - if team and cf.team(team) and cf.area.get_spawn(team)==true then + 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 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 end end @@ -332,8 +332,8 @@ minetest.register_abm({ return end - local flag_team_data = cf.area.get_flag(pos) - if not flag_team_data or not cf.team(flag_team_data.team)then + local flag_team_data = ctf.area.get_flag(pos) + if not flag_team_data or not ctf.team(flag_team_data.team)then print("Flag does not exist! "..dump(pos)) minetest.env:set_node(pos,{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") end - if not cf.team(flag_team_data.team).data.color then - cf.team(flag_team_data.team).data.color = "red" - cf.save() + 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_"..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 topmeta = minetest.env:get_meta(top) diff --git a/mods/capturetheflag/ctf/gui.lua b/mods/capturetheflag/ctf/gui.lua index 7991a4d..ee72e6f 100644 --- a/mods/capturetheflag/ctf/gui.lua +++ b/mods/capturetheflag/ctf/gui.lua @@ -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 - function cf.gui.tabs(name,team) + function ctf.gui.tabs(name,team) local result = "" local id = 1 local function addtab(name,text) result = result .. "button["..(id*2-1)..",0;2,1;"..name..";"..text.."]" id = id + 1 end - if cf.setting("news_gui") then + if ctf.setting("news_gui") then addtab("board","News") end - if cf.setting("flag_teleport_gui") then + if ctf.setting("flag_teleport_gui") then addtab("flags","Flags") end - if cf.setting("diplomacy") then + if ctf.setting("diplomacy") then addtab("diplo","Diplomacy") end addtab("admin","Settings") @@ -23,9 +23,9 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e end -- Team interface - function cf.gui.team_board(name,team) + function ctf.gui.team_board(name,team) local result = "" - local data = cf.teams[team].log + local data = ctf.teams[team].log if not data then 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 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 local height = (amount*0.5) + 0.5 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 - 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]" 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", "size[10,7]".. - cf.gui.tabs(name,team).. + ctf.gui.tabs(name,team).. result ) end -- Team interface - function cf.gui.team_flags(name,team) + function ctf.gui.team_flags(name,team) local result = "" - local t = cf.team(team) + local t = ctf.team(team) if not t then return @@ -96,7 +96,7 @@ if cf.setting("team_gui") and cf.setting("gui") then -- check if team guis are e local y = 2 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+)") 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", "size[10,7]".. - cf.gui.tabs(name,team).. + ctf.gui.tabs(name,team).. result ) end -- Team interface - function cf.gui.team_dip(name,team) + function ctf.gui.team_dip(name,team) local result = "" local data = {} local amount = 0 - for key,value in pairs(cf.teams) do + for key,value in pairs(ctf.teams) do if key ~= team then table.insert(data,{ team = key, - state = cf.diplo.get(team,key), - to = cf.diplo.check_requests(team,key), - from = cf.diplo.check_requests(key,team) + state = ctf.diplo.get(team,key), + to = ctf.diplo.check_requests(team,key), + from = ctf.diplo.check_requests(key,team) }) 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 .. "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 data[i].state == "war" then 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", "size[10,7]".. - cf.gui.tabs(name,team).. + ctf.gui.tabs(name,team).. result ) end -- Team interface - function cf.gui.team_settings(name,team) - if not team or not cf.team(team) then + function ctf.gui.team_settings(name,team) + if not team or not ctf.team(team) then return end local color = "" - if cf.team(team).data and cf.team(team).data.color then - color = cf.team(team).data.color + if ctf.team(team).data and ctf.team(team).data.color then + color = ctf.team(team).data.color end local result = "field[3,2;4,1;color;Team Color;"..color.."]".. "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!" end minetest.show_formspec(name, "ctf:team_settings", "size[10,7]".. - cf.gui.tabs(name,team).. + ctf.gui.tabs(name,team).. result ) 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() if formname=="ctf:board" or formname=="ctf:flags" or formname=="ctf:dip" or formname=="ctf:team_settings" then if fields.flags then - if cf and cf.players and cf.players[name] and cf.players[name].team then - cf.gui.team_flags(name,cf.players[name].team) + if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then + ctf.gui.team_flags(name,ctf.players[name].team) end return true end if fields.board then - if cf and cf.players and cf.players[name] and cf.players[name].team then - cf.gui.team_board(name,cf.players[name].team) + if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then + ctf.gui.team_board(name,ctf.players[name].team) end return true end if fields.diplo then - if cf and cf.players and cf.players[name] and cf.players[name].team then - cf.gui.team_dip(name,cf.players[name].team) + if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then + ctf.gui.team_dip(name,ctf.players[name].team) end return true end if fields.admin then - if cf and cf.players and cf.players[name] and cf.players[name].team then - cf.gui.team_settings(name,cf.players[name].team) + if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then + ctf.gui.team_settings(name,ctf.players[name].team) end return true end if fields.clear then - if cf and cf.players and cf.players[name] and cf.players[name].team then - cf.team(cf.players[name].team).log = {} - cf.save() - cf.gui.team_board(name,cf.players[name].team) + 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) end return true end if fields.save and formname=="ctf:team_settings" then - if cf and cf.players and cf.players[name] and cf.players[name].team then - cf.gui.team_settings(name,cf.players[name].team) + if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then + ctf.gui.team_settings(name,ctf.players[name].team) 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 print("Setting color...") - cf.team(cf.players[name].team).data.color = fields.color - cf.save() + ctf.team(ctf.players[name].team).data.color = fields.color + ctf.save() else minetest.chat_send_player(name,"Color "..fields.color.." does not exist!") 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 local ok, id = string.match(key, "btn_([yn])([0123456789]+)") 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 - 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) - 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}) - 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.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) + 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}) + 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 end - table.remove(cf.team(cf.player(name).team).log,id) - cf.save() - cf.gui.team_board(name,cf.player(name).team) + table.remove(ctf.team(ctf.player(name).team).log,id) + ctf.save() + ctf.gui.team_board(name,ctf.player(name).team) return true 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 local newteam = string.match(key, "team_(.+)") if newteam then - cf.gui.team_dip(name,newteam) + ctf.gui.team_dip(name,newteam) return true end newteam = string.match(key, "peace_(.+)") - if newteam and cf.player(name) then - local team = cf.player(name).team + if newteam and ctf.player(name) then + local team = ctf.player(name).team if team then - if cf.diplo.get(team,newteam) == "war" then - cf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"}) + if ctf.diplo.get(team,newteam) == "war" then + ctf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"}) else - cf.diplo.set(team,newteam,"peace") - cf.post(team,{msg="You have cancelled the alliance treaty with "..newteam}) - cf.post(newteam,{msg=team.." has cancelled the alliance treaty"}) + ctf.diplo.set(team,newteam,"peace") + ctf.post(team,{msg="You have cancelled the alliance treaty with "..newteam}) + ctf.post(newteam,{msg=team.." has cancelled the alliance treaty"}) end end - cf.gui.team_dip(name,team) + ctf.gui.team_dip(name,team) return true end newteam = string.match(key, "war_(.+)") - if newteam and cf.player(name) then - local team = cf.player(name).team + if newteam and ctf.player(name) then + local team = ctf.player(name).team if team then - cf.diplo.set(team,newteam,"war") - cf.post(team,{msg="You have declared war on "..newteam}) - cf.post(newteam,{msg=team.." has declared war on you"}) + ctf.diplo.set(team,newteam,"war") + ctf.post(team,{msg="You have declared war on "..newteam}) + ctf.post(newteam,{msg=team.." has declared war on you"}) end - cf.gui.team_dip(name,team) + ctf.gui.team_dip(name,team) return true end newteam = string.match(key, "alli_(.+)") - if newteam and cf.player(name) then - local team = cf.player(name).team + if newteam and ctf.player(name) then + local team = ctf.player(name).team 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 - cf.gui.team_dip(name,team) + ctf.gui.team_dip(name,team) return true end newteam = string.match(key, "cancel_(.+)") - if newteam and cf.player(name) then - local team = cf.player(name).team + if newteam and ctf.player(name) then + local team = ctf.player(name).team if team then - cf.diplo.cancel_requests(team,newteam) + ctf.diplo.cancel_requests(team,newteam) end - cf.gui.team_dip(name,team) + ctf.gui.team_dip(name,team) return true 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 -- Flag interface -function cf.gui.flag_board(name,pos) - local flag = cf.area.get_flag(pos) +function ctf.gui.flag_board(name,pos) + local flag = ctf.area.get_flag(pos) if not flag then return end @@ -395,21 +395,21 @@ function cf.gui.flag_board(name,pos) return end - if cf.can_mod(name,team) == false then - if cf.player(name) and cf.player(name).team and cf.player(name).team == team then - cf.gui.team_board(name,team) + 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 cf.setting("flag_names") then + if not ctf.setting("flag_names") then flag.name = nil return end - if not cf.setting("gui") then + if not ctf.setting("gui") then return end @@ -417,11 +417,11 @@ function cf.gui.flag_board(name,pos) flag_name = "" end - if not cf.gui.flag_data then - cf.gui.flag_data = {} + if not ctf.gui.flag_data then + ctf.gui.flag_data = {} end - cf.gui.flag_data[name] = {pos=pos} + ctf.gui.flag_data[name] = {pos=pos} minetest.show_formspec(name, "ctf:flag_board", "size[6,3]".. @@ -438,7 +438,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end 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 return false end @@ -448,7 +448,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) return false end - if cf.can_mod(name,team) == false then + if ctf.can_mod(name,team) == false then return false 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 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 print(msg) - cf.post(team,{msg=msg,icon="flag_info"}) + ctf.post(team,{msg=msg,icon="flag_info"}) return true 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 print("No flag?!") @@ -484,11 +484,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) return end - if cf.can_mod(name,team) == false then + if ctf.can_mod(name,team) == false then return false end - cf.area.delete_flag(team,pos) + ctf.area.delete_flag(team,pos) minetest.env:set_node(pos,{name="air"}) pos.y=pos.y+1 diff --git a/mods/capturetheflag/ctf/init.lua b/mods/capturetheflag/ctf/init.lua index 9849b3b..bcff44f 100644 --- a/mods/capturetheflag/ctf/init.lua +++ b/mods/capturetheflag/ctf/init.lua @@ -2,7 +2,7 @@ -- by Andrew "rubenwardy" Ward ----------------------------------------- -cf = {} +ctf = {} -- Helpers v3={} @@ -60,7 +60,7 @@ end -- Load the core dofile(minetest.get_modpath("ctf").."/core.lua") -cf.init() +ctf.init() -- Modules 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") -- Init -cf.clean_player_lists() -cf.collect_claimed() +ctf.clean_player_lists() +ctf.collect_claimed() diff --git a/mods/capturetheflag/ctf_protect/init.lua b/mods/capturetheflag/ctf_protect/init.lua index cbd8c4b..fef9ae3 100644 --- a/mods/capturetheflag/ctf_protect/init.lua +++ b/mods/capturetheflag/ctf_protect/init.lua @@ -1,14 +1,14 @@ -- This mod is used to protect nodes in the capture the flag game function stop_dig(name,pos) - local team = cf.area.get_area(pos) + local team = ctf.area.get_area(pos) if not team then return false end - if cf.players and cf.player(name) and cf.player(name).team then - if cf.player(name).team == team then + if ctf.players and ctf.player(name) and ctf.player(name).team then + if ctf.player(name).team == team then return false end end diff --git a/mods/capturetheflag/ctf_turret/init.lua b/mods/capturetheflag/ctf_turret/init.lua index 3a00b3e..3220065 100644 --- a/mods/capturetheflag/ctf_turret/init.lua +++ b/mods/capturetheflag/ctf_turret/init.lua @@ -29,8 +29,8 @@ minetest.register_node("ctf_turret:turret", { after_place_node = function(pos, placer) 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 - local team = cf.player(placer:get_player_name()).team + if meta and ctf.players and ctf.player(placer:get_player_name()) and ctf.player(placer:get_player_name()).team then + local team = ctf.player(placer:get_player_name()).team meta:set_string("team", team) meta:set_string("infotext", "Owned by "..team) else @@ -54,7 +54,7 @@ minetest.register_abm({ return end - local app = cf.area.get_area(pos) + local app = ctf.area.get_area(pos) if app and app~=team then team = app meta:set_string("team",team) @@ -69,9 +69,9 @@ minetest.register_abm({ for _,obj in ipairs(objects) do if ( obj:is_player() and - cf.players and - cf.player(obj:get_player_name()) and - cf.player(obj:get_player_name()).team ~= team + ctf.players and + ctf.player(obj:get_player_name()) and + ctf.player(obj:get_player_name()).team ~= team )then -- Calculate stuff local obj_p = obj:getpos()