Decouple core.lua
This commit is contained in:
parent
8c7381aa24
commit
6b1555ab4b
@ -1,3 +1,12 @@
|
|||||||
|
ctf.registered_on_load = {}
|
||||||
|
function ctf.register_on_load(func)
|
||||||
|
table.insert(ctf.registered_on_load, func)
|
||||||
|
end
|
||||||
|
ctf.registered_on_save = {}
|
||||||
|
function ctf.register_on_save(func)
|
||||||
|
table.insert(ctf.registered_on_save, func)
|
||||||
|
end
|
||||||
|
|
||||||
function ctf.init()
|
function ctf.init()
|
||||||
print("[CaptureTheFlag] Initialising...")
|
print("[CaptureTheFlag] Initialising...")
|
||||||
|
|
||||||
@ -6,7 +15,6 @@ function ctf.init()
|
|||||||
ctf.teams = {}
|
ctf.teams = {}
|
||||||
ctf.players = {}
|
ctf.players = {}
|
||||||
ctf.claimed = {}
|
ctf.claimed = {}
|
||||||
ctf.diplo = {diplo = {}}
|
|
||||||
|
|
||||||
-- Settings: Feature enabling
|
-- Settings: Feature enabling
|
||||||
ctf._set("node_ownership",true)
|
ctf._set("node_ownership",true)
|
||||||
@ -22,7 +30,7 @@ function ctf.init()
|
|||||||
ctf._set("team_channel",true) -- do teams have their own chat channel
|
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("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)
|
ctf._set("players_can_change_team",true)
|
||||||
|
|
||||||
-- Settings: Teams
|
-- Settings: Teams
|
||||||
ctf._set("allocate_mode", 0) -- how are players allocated to teams? 0: none, 1: random, 2: one of first two largest groups, 3 smallest group
|
ctf._set("allocate_mode", 0) -- how are players allocated to teams? 0: none, 1: random, 2: one of first two largest groups, 3 smallest group
|
||||||
ctf._set("maximum_in_team", -1) -- Maximum number in team, obeyed by allocation and /join. Admins don't obey this
|
ctf._set("maximum_in_team", -1) -- Maximum number in team, obeyed by allocation and /join. Admins don't obey this
|
||||||
@ -34,19 +42,10 @@ function ctf.init()
|
|||||||
ctf._set("flag_protect_distance", 25) -- how far do flags protect?
|
ctf._set("flag_protect_distance", 25) -- how far do flags protect?
|
||||||
ctf._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")
|
ctf.load()
|
||||||
if file then
|
|
||||||
local table = minetest.deserialize(file:read("*all"))
|
|
||||||
if type(table) == "table" then
|
|
||||||
ctf.teams = table.teams
|
|
||||||
ctf.players = table.players
|
|
||||||
ctf.diplo.diplo = table.diplo
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set settings
|
-- Set default setting value
|
||||||
function ctf._set(setting,default)
|
function ctf._set(setting,default)
|
||||||
ctf._defsettings[setting] = default
|
ctf._defsettings[setting] = default
|
||||||
end
|
end
|
||||||
@ -63,16 +62,42 @@ function ctf.setting(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save game
|
function ctf.load()
|
||||||
|
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
|
||||||
|
ctf.teams = table.teams
|
||||||
|
ctf.players = table.players
|
||||||
|
|
||||||
|
for i = 1, #ctf.registered_on_load do
|
||||||
|
ctf.registered_on_load[i](table)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ctf.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({
|
local out = {
|
||||||
teams = ctf.teams,
|
teams = ctf.teams,
|
||||||
players = ctf.players,
|
players = ctf.players
|
||||||
diplo = ctf.diplo.diplo
|
}
|
||||||
}))
|
|
||||||
|
for i = 1, #ctf.registered_on_save do
|
||||||
|
local res = ctf.registered_on_save[i]()
|
||||||
|
|
||||||
|
if res then
|
||||||
|
for key, value in pairs(res) do
|
||||||
|
out[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
file:write(minetest.serialize(out))
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -93,9 +118,9 @@ function ctf.team(name) -- get or add a team
|
|||||||
players={},
|
players={},
|
||||||
flags = {}
|
flags = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctf.save()
|
ctf.save()
|
||||||
|
|
||||||
return ctf.teams[name.name]
|
return ctf.teams[name.name]
|
||||||
else
|
else
|
||||||
return ctf.teams[name]
|
return ctf.teams[name]
|
||||||
@ -112,7 +137,7 @@ function ctf.count_players_in_team(team)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get a player
|
-- get a player
|
||||||
function ctf.player(name)
|
function ctf.player(name)
|
||||||
return ctf.players[name]
|
return ctf.players[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -123,11 +148,11 @@ function ctf.join(name, team, force)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local player = ctf.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 ctf.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
|
||||||
@ -188,7 +213,7 @@ end
|
|||||||
-- Sees if the player can change stuff in a team
|
-- Sees if the player can change stuff in a team
|
||||||
function ctf.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
|
||||||
if privs.team == true then
|
if privs.team == true then
|
||||||
return true
|
return true
|
||||||
@ -223,25 +248,25 @@ minetest.register_on_newplayer(function(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local max_players = ctf.setting("maximum_in_team")
|
local max_players = ctf.setting("maximum_in_team")
|
||||||
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
||||||
|
|
||||||
if alloc_mode == 0 then
|
if alloc_mode == 0 then
|
||||||
return
|
return
|
||||||
elseif alloc_mode == 1 then
|
elseif alloc_mode == 1 then
|
||||||
local index = {}
|
local index = {}
|
||||||
|
|
||||||
for key, team in pairs(ctf.teams) do
|
for key, team in pairs(ctf.teams) do
|
||||||
if max_players == -1 or ctf.count_players_in_team(key) < max_players then
|
if max_players == -1 or ctf.count_players_in_team(key) < max_players then
|
||||||
table.insert(index, key)
|
table.insert(index, key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if #index == 0 then
|
if #index == 0 then
|
||||||
minetest.log("error", "[CaptureTheFlag] No teams to join!")
|
minetest.log("error", "[CaptureTheFlag] No teams to join!")
|
||||||
else
|
else
|
||||||
local team = index[math.random(1, #index)]
|
local team = index[math.random(1, #index)]
|
||||||
|
|
||||||
print(name.." was allocated to "..team)
|
print(name.." was allocated to "..team)
|
||||||
|
|
||||||
ctf.join(name, team)
|
ctf.join(name, team)
|
||||||
end
|
end
|
||||||
elseif alloc_mode == 2 then
|
elseif alloc_mode == 2 then
|
||||||
@ -258,19 +283,19 @@ minetest.register_on_newplayer(function(player)
|
|||||||
one = key
|
one = key
|
||||||
one_count = count
|
one_count = count
|
||||||
end
|
end
|
||||||
|
|
||||||
if count > two_count then
|
if count > two_count then
|
||||||
two = key
|
two = key
|
||||||
two_count = count
|
two_count = count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not one and not two then
|
if not one and not two then
|
||||||
minetest.log("error", "[CaptureTheFlag] No teams to join!")
|
minetest.log("error", "[CaptureTheFlag] No teams to join!")
|
||||||
elseif one and two then
|
elseif one and two then
|
||||||
if math.random() > 0.5 then
|
if math.random() > 0.5 then
|
||||||
print(name.." was allocated to "..one)
|
print(name.." was allocated to "..one)
|
||||||
ctf.join(name, one)
|
ctf.join(name, one)
|
||||||
else
|
else
|
||||||
print(name.." was allocated to "..two)
|
print(name.." was allocated to "..two)
|
||||||
@ -278,9 +303,9 @@ minetest.register_on_newplayer(function(player)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if one then
|
if one then
|
||||||
print(name.." was allocated to "..one)
|
print(name.." was allocated to "..one)
|
||||||
ctf.join(name, one)
|
ctf.join(name, one)
|
||||||
else
|
else
|
||||||
print(name.." was allocated to "..two)
|
print(name.." was allocated to "..two)
|
||||||
ctf.join(name, two)
|
ctf.join(name, two)
|
||||||
end
|
end
|
||||||
@ -295,7 +320,7 @@ minetest.register_on_newplayer(function(player)
|
|||||||
smallest_count = count
|
smallest_count = count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not smallest then
|
if not smallest then
|
||||||
minetest.log("error", "[CaptureTheFlag] No teams to join!")
|
minetest.log("error", "[CaptureTheFlag] No teams to join!")
|
||||||
else
|
else
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
-- diplo states: war, peace, alliance
|
-- diplo states: war, peace, alliance
|
||||||
ctf.diplo = {}
|
ctf.diplo = {
|
||||||
|
diplo = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctf.register_on_load(function(table)
|
||||||
|
ctf.diplo.diplo = table.diplo
|
||||||
|
end)
|
||||||
|
|
||||||
|
ctf.register_on_save(function()
|
||||||
|
return { diplo = ctf.diplo.diplo }
|
||||||
|
end)
|
||||||
|
|
||||||
function ctf.diplo.get(one,two)
|
function ctf.diplo.get(one,two)
|
||||||
if not ctf.diplo.diplo then
|
if not ctf.diplo.diplo then
|
||||||
@ -28,40 +38,40 @@ function ctf.diplo.set(one,two,state)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(ctf.diplo.diplo,{one=one,two=two,state=state})
|
table.insert(ctf.diplo.diplo,{one=one,two=two,state=state})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctf.diplo.check_requests(one,two)
|
function ctf.diplo.check_requests(one,two)
|
||||||
local team = ctf.team(two)
|
local team = ctf.team(two)
|
||||||
|
|
||||||
if not team.log then
|
if not team.log then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for i=1,#team.log do
|
for i=1,#team.log do
|
||||||
if team.log[i].team == one and team.log[i].type=="request" and team.log[i].mode=="diplo" then
|
if team.log[i].team == one and team.log[i].type=="request" and team.log[i].mode=="diplo" then
|
||||||
return team.log[i].msg
|
return team.log[i].msg
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctf.diplo.cancel_requests(one,two)
|
function ctf.diplo.cancel_requests(one,two)
|
||||||
local team = ctf.team(two)
|
local team = ctf.team(two)
|
||||||
|
|
||||||
if not team.log then
|
if not team.log then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for i=1,#team.log do
|
for i=1,#team.log do
|
||||||
if team.log[i].team == one and team.log[i].type=="request" and team.log[i].mode=="diplo" then
|
if team.log[i].team == one and team.log[i].type=="request" and team.log[i].mode=="diplo" then
|
||||||
table.remove(team.log,i)
|
table.remove(team.log,i)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -1,387 +1,401 @@
|
|||||||
ctf.gui = {}
|
ctf.gui = {}
|
||||||
|
|
||||||
if ctf.setting("team_gui") and ctf.setting("gui") then -- check if team guis are enabled
|
-- Get tab buttons
|
||||||
-- Get tab buttons
|
function ctf.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
|
|
||||||
if ctf.setting("news_gui") then
|
|
||||||
addtab("board","News")
|
|
||||||
end
|
|
||||||
if ctf.setting("flag_teleport_gui") then
|
|
||||||
addtab("flags","Flags")
|
|
||||||
end
|
|
||||||
if ctf.setting("diplomacy") then
|
|
||||||
addtab("diplo","Diplomacy")
|
|
||||||
end
|
|
||||||
addtab("admin","Settings")
|
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
|
if ctf.setting("news_gui") then
|
||||||
-- Team interface
|
addtab("board","News")
|
||||||
function ctf.gui.team_board(name,team)
|
end
|
||||||
local result = ""
|
if ctf.setting("flag_teleport_gui") then
|
||||||
local data = ctf.teams[team].log
|
addtab("flags","Flags")
|
||||||
|
end
|
||||||
if not data then
|
if ctf.setting("diplomacy") then
|
||||||
data = {}
|
addtab("diplo","Diplomacy")
|
||||||
end
|
end
|
||||||
|
addtab("admin","Settings")
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
local amount = 0
|
-- Team interface
|
||||||
|
function ctf.gui.team_board(name,team)
|
||||||
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for i=1,#data do
|
local result = ""
|
||||||
if data[i].type == "request" then
|
local data = ctf.teams[team].log
|
||||||
if ctf.can_mod(name,team)==true then
|
|
||||||
amount = amount + 2
|
|
||||||
local height = (amount*0.5) + 0.5
|
|
||||||
amount = amount + 1
|
|
||||||
|
|
||||||
if data[i].mode == "diplo" then
|
if not data then
|
||||||
result = result .. "image[0.5,".. height ..";10.5,1;diplo_"..data[i].msg..".png]"
|
data = {}
|
||||||
if data[i].msg == "alliance" then
|
end
|
||||||
result = result .. "label[1,".. height ..";".. data[i].team .." offers an "..minetest.formspec_escape(data[i].msg).." treaty]"
|
|
||||||
else
|
local amount = 0
|
||||||
result = result .. "label[1,".. height ..";".. data[i].team .." offers a "..minetest.formspec_escape(data[i].msg).." treaty]"
|
|
||||||
end
|
for i=1,#data do
|
||||||
result = result .. "button[6,".. height ..";1,1;btn_y"..i..";Yes]"
|
if data[i].type == "request" then
|
||||||
result = result .. "button[7,".. height ..";1,1;btn_n"..i..";No]"
|
if ctf.can_mod(name,team)==true then
|
||||||
else
|
amount = amount + 2
|
||||||
result = result .. "label[0.5,".. height ..";RANDOM REQUEST TYPE]"
|
local height = (amount*0.5) + 0.5
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
amount = amount + 1
|
amount = amount + 1
|
||||||
local height = (amount*0.5)+0.5
|
|
||||||
|
|
||||||
if height > 5 then
|
if data[i].mode == "diplo" then
|
||||||
print("break!")
|
result = result .. "image[0.5,".. height ..";10.5,1;diplo_"..data[i].msg..".png]"
|
||||||
break
|
if data[i].msg == "alliance" then
|
||||||
|
result = result .. "label[1,".. height ..";".. data[i].team .." offers an "..minetest.formspec_escape(data[i].msg).." treaty]"
|
||||||
|
else
|
||||||
|
result = result .. "label[1,".. height ..";".. data[i].team .." offers a "..minetest.formspec_escape(data[i].msg).." treaty]"
|
||||||
|
end
|
||||||
|
result = result .. "button[6,".. height ..";1,1;btn_y"..i..";Yes]"
|
||||||
|
result = result .. "button[7,".. height ..";1,1;btn_n"..i..";No]"
|
||||||
|
else
|
||||||
|
result = result .. "label[0.5,".. height ..";RANDOM REQUEST TYPE]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
result = result .. "label[0.5,".. height ..";".. minetest.formspec_escape(data[i].msg) .."]"
|
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
amount = amount + 1
|
||||||
if ctf.can_mod(name,team)==true then
|
local height = (amount*0.5)+0.5
|
||||||
result = result .. "button[4,6;2,1;clear;Clear all]"
|
|
||||||
end
|
|
||||||
|
|
||||||
if amount == 0 then
|
|
||||||
result = "label[0.5,1;Welcome to the news panel]"..
|
|
||||||
"label[0.5,1.5;News such as attacks will appear here]"
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.show_formspec(name, "ctf:board",
|
|
||||||
"size[10,7]"..
|
|
||||||
ctf.gui.tabs(name,team)..
|
|
||||||
result
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Team interface
|
|
||||||
function ctf.gui.team_flags(name,team)
|
|
||||||
local result = ""
|
|
||||||
local t = ctf.team(team)
|
|
||||||
|
|
||||||
if not t then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local x = 1
|
|
||||||
local y = 2
|
|
||||||
result = result .. "label[1,1;Click a flag button to go there]"
|
|
||||||
|
|
||||||
if ctf.setting("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 ..
|
|
||||||
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
|
||||||
..f.x.."_"..f.y.."_"..f.z..";"
|
|
||||||
|
|
||||||
result = result .. "Spawn]"
|
|
||||||
x = x + 2
|
|
||||||
end
|
|
||||||
|
|
||||||
for i=1,#t.flags do
|
|
||||||
local f = t.flags[i]
|
|
||||||
|
|
||||||
if x > 8 then
|
|
||||||
x = 1
|
|
||||||
y = y + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if y > 6 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
result = result ..
|
|
||||||
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
|
||||||
..f.x.."_"..f.y.."_"..f.z..";"
|
|
||||||
|
|
||||||
if f.name then
|
|
||||||
result = result .. f.name .. "]"
|
|
||||||
else
|
|
||||||
result = result .. "("..f.x..","..f.y..","..f.z..")]"
|
|
||||||
end
|
|
||||||
|
|
||||||
x = x + 2
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.show_formspec(name, "ctf:flags",
|
|
||||||
"size[10,7]"..
|
|
||||||
ctf.gui.tabs(name,team)..
|
|
||||||
result
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Team interface
|
|
||||||
function ctf.gui.team_dip(name,team)
|
|
||||||
local result = ""
|
|
||||||
local data = {}
|
|
||||||
|
|
||||||
local amount = 0
|
|
||||||
|
|
||||||
for key,value in pairs(ctf.teams) do
|
|
||||||
if key ~= team then
|
|
||||||
table.insert(data,{
|
|
||||||
team = key,
|
|
||||||
state = ctf.diplo.get(team,key),
|
|
||||||
to = ctf.diplo.check_requests(team,key),
|
|
||||||
from = ctf.diplo.check_requests(key,team)
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
result = result .. "label[1,1;Diplomacy from the perspective of "..team.."]"
|
|
||||||
|
|
||||||
for i=1,#data do
|
|
||||||
amount = i
|
|
||||||
local height = (i*1)+0.5
|
|
||||||
|
|
||||||
if height > 5 then
|
if height > 5 then
|
||||||
|
print("break!")
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
result = result .. "image[1,".. height ..";10,1;diplo_"..data[i].state..".png]"
|
|
||||||
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 ctf.can_mod(name,team)==true and ctf.player(name).team == team then
|
result = result .. "label[0.5,".. height ..";".. minetest.formspec_escape(data[i].msg) .."]"
|
||||||
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]"
|
|
||||||
elseif data[i].state == "peace" then
|
|
||||||
result = result .. "button[6,".. height ..";1.5,1;war_".. data[i].team ..";War]"
|
|
||||||
result = result .. "button[7.5,".. height ..";1.5,1;alli_".. data[i].team ..";Alliance]"
|
|
||||||
elseif data[i].state == "alliance" then
|
|
||||||
result = result .. "button[6,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
|
|
||||||
end
|
|
||||||
elseif data[i].from ~= nil then
|
|
||||||
result = result .. "label[6,".. height ..";request recieved]"
|
|
||||||
elseif data[i].to ~= nil then
|
|
||||||
result = result .. "label[5.5,".. height ..";request sent]"
|
|
||||||
result = result .. "button[7.5,".. height ..";1.5,1;cancel_".. data[i].team ..";Cancel]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.show_formspec(name, "ctf:dip",
|
|
||||||
"size[10,7]"..
|
|
||||||
ctf.gui.tabs(name,team)..
|
|
||||||
result
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Team interface
|
|
||||||
function ctf.gui.team_settings(name,team)
|
|
||||||
if not team or not ctf.team(team) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local color = ""
|
|
||||||
|
|
||||||
if ctf.team(team).data and ctf.team(team).data.color then
|
if ctf.can_mod(name,team)==true then
|
||||||
color = ctf.team(team).data.color
|
result = result .. "button[4,6;2,1;clear;Clear all]"
|
||||||
end
|
|
||||||
|
|
||||||
local result = "field[3,2;4,1;color;Team Color;"..color.."]"..
|
|
||||||
"button[4,6;2,1;save;Save]"
|
|
||||||
|
|
||||||
|
|
||||||
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]"..
|
|
||||||
ctf.gui.tabs(name,team)..
|
|
||||||
result
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
local name = player:get_player_name()
|
if amount == 0 then
|
||||||
if formname=="ctf:board" or formname=="ctf:flags" or formname=="ctf:dip" or formname=="ctf:team_settings" then
|
result = "label[0.5,1;Welcome to the news panel]"..
|
||||||
if fields.flags then
|
"label[0.5,1.5;News such as attacks will appear here]"
|
||||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
end
|
||||||
ctf.gui.team_flags(name,ctf.players[name].team)
|
|
||||||
|
minetest.show_formspec(name, "ctf:board",
|
||||||
|
"size[10,7]"..
|
||||||
|
ctf.gui.tabs(name,team)..
|
||||||
|
result
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Team interface
|
||||||
|
function ctf.gui.team_flags(name,team)
|
||||||
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = ""
|
||||||
|
local t = ctf.team(team)
|
||||||
|
|
||||||
|
if not t then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local x = 1
|
||||||
|
local y = 2
|
||||||
|
result = result .. "label[1,1;Click a flag button to go there]"
|
||||||
|
|
||||||
|
if ctf.setting("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 ..
|
||||||
|
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
||||||
|
..f.x.."_"..f.y.."_"..f.z..";"
|
||||||
|
|
||||||
|
result = result .. "Spawn]"
|
||||||
|
x = x + 2
|
||||||
|
end
|
||||||
|
|
||||||
|
for i=1,#t.flags do
|
||||||
|
local f = t.flags[i]
|
||||||
|
|
||||||
|
if x > 8 then
|
||||||
|
x = 1
|
||||||
|
y = y + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if y > 6 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
result = result ..
|
||||||
|
"button[" .. x .. "," .. y .. ";2,1;goto_"
|
||||||
|
..f.x.."_"..f.y.."_"..f.z..";"
|
||||||
|
|
||||||
|
if f.name then
|
||||||
|
result = result .. f.name .. "]"
|
||||||
|
else
|
||||||
|
result = result .. "("..f.x..","..f.y..","..f.z..")]"
|
||||||
|
end
|
||||||
|
|
||||||
|
x = x + 2
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.show_formspec(name, "ctf:flags",
|
||||||
|
"size[10,7]"..
|
||||||
|
ctf.gui.tabs(name,team)..
|
||||||
|
result
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Team interface
|
||||||
|
function ctf.gui.team_dip(name,team)
|
||||||
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = ""
|
||||||
|
local data = {}
|
||||||
|
|
||||||
|
local amount = 0
|
||||||
|
|
||||||
|
for key,value in pairs(ctf.teams) do
|
||||||
|
if key ~= team then
|
||||||
|
table.insert(data,{
|
||||||
|
team = key,
|
||||||
|
state = ctf.diplo.get(team,key),
|
||||||
|
to = ctf.diplo.check_requests(team,key),
|
||||||
|
from = ctf.diplo.check_requests(key,team)
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
result = result .. "label[1,1;Diplomacy from the perspective of "..team.."]"
|
||||||
|
|
||||||
|
for i=1,#data do
|
||||||
|
amount = i
|
||||||
|
local height = (i*1)+0.5
|
||||||
|
|
||||||
|
if height > 5 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
result = result .. "image[1,".. height ..";10,1;diplo_"..data[i].state..".png]"
|
||||||
|
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 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]"
|
||||||
|
elseif data[i].state == "peace" then
|
||||||
|
result = result .. "button[6,".. height ..";1.5,1;war_".. data[i].team ..";War]"
|
||||||
|
result = result .. "button[7.5,".. height ..";1.5,1;alli_".. data[i].team ..";Alliance]"
|
||||||
|
elseif data[i].state == "alliance" then
|
||||||
|
result = result .. "button[6,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
|
||||||
end
|
end
|
||||||
return true
|
elseif data[i].from ~= nil then
|
||||||
|
result = result .. "label[6,".. height ..";request recieved]"
|
||||||
|
elseif data[i].to ~= nil then
|
||||||
|
result = result .. "label[5.5,".. height ..";request sent]"
|
||||||
|
result = result .. "button[7.5,".. height ..";1.5,1;cancel_".. data[i].team ..";Cancel]"
|
||||||
end
|
end
|
||||||
if fields.board then
|
end
|
||||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
end
|
||||||
ctf.gui.team_board(name,ctf.players[name].team)
|
|
||||||
end
|
minetest.show_formspec(name, "ctf:dip",
|
||||||
return true
|
"size[10,7]"..
|
||||||
|
ctf.gui.tabs(name,team)..
|
||||||
|
result
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Team interface
|
||||||
|
function ctf.gui.team_settings(name,team)
|
||||||
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not team or not ctf.team(team) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local 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 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]"..
|
||||||
|
ctf.gui.tabs(name,team)..
|
||||||
|
result
|
||||||
|
)
|
||||||
|
end
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
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 ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
||||||
|
ctf.gui.team_flags(name,ctf.players[name].team)
|
||||||
end
|
end
|
||||||
if fields.diplo then
|
return true
|
||||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
end
|
||||||
ctf.gui.team_dip(name,ctf.players[name].team)
|
if fields.board then
|
||||||
end
|
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
||||||
return true
|
ctf.gui.team_board(name,ctf.players[name].team)
|
||||||
end
|
end
|
||||||
if fields.admin then
|
return true
|
||||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
end
|
||||||
ctf.gui.team_settings(name,ctf.players[name].team)
|
if fields.diplo then
|
||||||
end
|
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
||||||
return true
|
ctf.gui.team_dip(name,ctf.players[name].team)
|
||||||
end
|
end
|
||||||
if fields.clear then
|
return true
|
||||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
end
|
||||||
ctf.team(ctf.players[name].team).log = {}
|
if fields.admin then
|
||||||
|
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
||||||
|
ctf.gui.team_settings(name,ctf.players[name].team)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if fields.clear then
|
||||||
|
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 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 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...")
|
||||||
|
ctf.team(ctf.players[name].team).data.color = fields.color
|
||||||
ctf.save()
|
ctf.save()
|
||||||
ctf.gui.team_board(name,ctf.players[name].team)
|
else
|
||||||
|
minetest.chat_send_player(name,"Color "..fields.color.." does not exist!")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if formname=="ctf:board" then
|
||||||
|
for key, field in pairs(fields) do
|
||||||
|
local ok, id = string.match(key, "btn_([yn])([0123456789]+)")
|
||||||
|
if ok and id then
|
||||||
|
if ctf.player(name) and ctf.player(name).team and ctf.team(ctf.player(name).team) then
|
||||||
|
if ok == "y" then
|
||||||
|
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(ctf.team(ctf.player(name).team).log,id)
|
||||||
|
ctf.save()
|
||||||
|
ctf.gui.team_board(name,ctf.player(name).team)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if formname=="ctf:flags" then
|
||||||
|
for key, field in pairs(fields) do
|
||||||
|
local x,y,z = string.match(key, "goto_(%d+)_(%d+)_(%d+)")
|
||||||
|
if x and y and x then
|
||||||
|
player:setpos({x=x,y=y,z=z})
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if fields.save and formname=="ctf:team_settings" then
|
end
|
||||||
if ctf and ctf.players and ctf.players[name] and ctf.players[name].team then
|
end
|
||||||
ctf.gui.team_settings(name,ctf.players[name].team)
|
end)
|
||||||
end
|
|
||||||
if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if minetest.registered_items["ctf:flag_top_"..fields.color] then
|
local name = player:get_player_name()
|
||||||
print("Setting color...")
|
if formname=="ctf:dip" then
|
||||||
ctf.team(ctf.players[name].team).data.color = fields.color
|
for key, field in pairs(fields) do
|
||||||
ctf.save()
|
local newteam = string.match(key, "team_(.+)")
|
||||||
|
if newteam then
|
||||||
|
ctf.gui.team_dip(name,newteam)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
newteam = string.match(key, "peace_(.+)")
|
||||||
|
if newteam and ctf.player(name) then
|
||||||
|
local team = ctf.player(name).team
|
||||||
|
|
||||||
|
if team then
|
||||||
|
if ctf.diplo.get(team,newteam) == "war" then
|
||||||
|
ctf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"})
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name,"Color "..fields.color.." does not exist!")
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ctf.gui.team_dip(name,team)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
newteam = string.match(key, "war_(.+)")
|
||||||
|
if newteam and ctf.player(name) then
|
||||||
|
local team = ctf.player(name).team
|
||||||
|
|
||||||
|
if team then
|
||||||
|
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
|
||||||
|
|
||||||
|
ctf.gui.team_dip(name,team)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
newteam = string.match(key, "alli_(.+)")
|
||||||
|
if newteam and ctf.player(name) then
|
||||||
|
local team = ctf.player(name).team
|
||||||
|
|
||||||
|
if team then
|
||||||
|
ctf.post(newteam,{type="request",msg="alliance",team=team,mode="diplo"})
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf.gui.team_dip(name,team)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
newteam = string.match(key, "cancel_(.+)")
|
||||||
|
if newteam and ctf.player(name) then
|
||||||
|
local team = ctf.player(name).team
|
||||||
|
|
||||||
|
if team then
|
||||||
|
ctf.diplo.cancel_requests(team,newteam)
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf.gui.team_dip(name,team)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
end)
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if formname=="ctf:board" then
|
|
||||||
for key, field in pairs(fields) do
|
|
||||||
local ok, id = string.match(key, "btn_([yn])([0123456789]+)")
|
|
||||||
if ok and id then
|
|
||||||
if ctf.player(name) and ctf.player(name).team and ctf.team(ctf.player(name).team) then
|
|
||||||
if ok == "y" then
|
|
||||||
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(ctf.team(ctf.player(name).team).log,id)
|
|
||||||
ctf.save()
|
|
||||||
ctf.gui.team_board(name,ctf.player(name).team)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if formname=="ctf:flags" then
|
|
||||||
for key, field in pairs(fields) do
|
|
||||||
local x,y,z = string.match(key, "goto_(%d+)_(%d+)_(%d+)")
|
|
||||||
if x and y and x then
|
|
||||||
player:setpos({x=x,y=y,z=z})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
if formname=="ctf:dip" then
|
|
||||||
for key, field in pairs(fields) do
|
|
||||||
local newteam = string.match(key, "team_(.+)")
|
|
||||||
if newteam then
|
|
||||||
ctf.gui.team_dip(name,newteam)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
newteam = string.match(key, "peace_(.+)")
|
|
||||||
if newteam and ctf.player(name) then
|
|
||||||
local team = ctf.player(name).team
|
|
||||||
|
|
||||||
if team then
|
|
||||||
if ctf.diplo.get(team,newteam) == "war" then
|
|
||||||
ctf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"})
|
|
||||||
else
|
|
||||||
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
|
|
||||||
|
|
||||||
ctf.gui.team_dip(name,team)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
newteam = string.match(key, "war_(.+)")
|
|
||||||
if newteam and ctf.player(name) then
|
|
||||||
local team = ctf.player(name).team
|
|
||||||
|
|
||||||
if team then
|
|
||||||
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
|
|
||||||
|
|
||||||
ctf.gui.team_dip(name,team)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
newteam = string.match(key, "alli_(.+)")
|
|
||||||
if newteam and ctf.player(name) then
|
|
||||||
local team = ctf.player(name).team
|
|
||||||
|
|
||||||
if team then
|
|
||||||
ctf.post(newteam,{type="request",msg="alliance",team=team,mode="diplo"})
|
|
||||||
end
|
|
||||||
|
|
||||||
ctf.gui.team_dip(name,team)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
newteam = string.match(key, "cancel_(.+)")
|
|
||||||
if newteam and ctf.player(name) then
|
|
||||||
local team = ctf.player(name).team
|
|
||||||
|
|
||||||
if team then
|
|
||||||
ctf.diplo.cancel_requests(team,newteam)
|
|
||||||
end
|
|
||||||
|
|
||||||
ctf.gui.team_dip(name,team)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end -- end of check if team guis are enabled
|
|
||||||
|
|
||||||
-- Flag interface
|
-- Flag interface
|
||||||
function ctf.gui.flag_board(name,pos)
|
function ctf.gui.flag_board(name,pos)
|
||||||
@ -408,7 +422,7 @@ function ctf.gui.flag_board(name,pos)
|
|||||||
flag.name = nil
|
flag.name = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ctf.setting("gui") then
|
if not ctf.setting("gui") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -416,7 +430,7 @@ function ctf.gui.flag_board(name,pos)
|
|||||||
if not flag_name then
|
if not flag_name then
|
||||||
flag_name = ""
|
flag_name = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ctf.gui.flag_data then
|
if not ctf.gui.flag_data then
|
||||||
ctf.gui.flag_data = {}
|
ctf.gui.flag_data = {}
|
||||||
end
|
end
|
||||||
@ -432,7 +446,7 @@ function ctf.gui.flag_board(name,pos)
|
|||||||
end
|
end
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if not formname=="ctf:flag_board" then
|
if not formname=="ctf:flag_board" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -447,7 +461,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if not team then
|
if not team then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctf.can_mod(name,team) == false then
|
if ctf.can_mod(name,team) == false then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -466,15 +480,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
|
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
ctf.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 = ctf.gui.flag_data[name].pos
|
local pos = ctf.gui.flag_data[name].pos
|
||||||
|
|
||||||
local flag = ctf.area.get_flag(ctf.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?!")
|
||||||
end
|
end
|
||||||
@ -483,17 +497,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if not team then
|
if not team then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctf.can_mod(name,team) == false then
|
if ctf.can_mod(name,team) == false then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf.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
|
||||||
minetest.env:set_node(pos,{name="air"})
|
minetest.env:set_node(pos,{name="air"})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -58,11 +58,8 @@ function v3.get_direction(pos1,pos2)
|
|||||||
return {x=x_raw,y=y_raw,z=z_raw}
|
return {x=x_raw,y=y_raw,z=z_raw}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Load the core
|
|
||||||
dofile(minetest.get_modpath("ctf").."/core.lua")
|
|
||||||
ctf.init()
|
|
||||||
|
|
||||||
-- Modules
|
-- Modules
|
||||||
|
dofile(minetest.get_modpath("ctf").."/core.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/area.lua")
|
dofile(minetest.get_modpath("ctf").."/area.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/gui.lua")
|
dofile(minetest.get_modpath("ctf").."/gui.lua")
|
||||||
@ -70,5 +67,6 @@ dofile(minetest.get_modpath("ctf").."/cli.lua")
|
|||||||
dofile(minetest.get_modpath("ctf").."/flag.lua")
|
dofile(minetest.get_modpath("ctf").."/flag.lua")
|
||||||
|
|
||||||
-- Init
|
-- Init
|
||||||
|
ctf.init()
|
||||||
ctf.clean_player_lists()
|
ctf.clean_player_lists()
|
||||||
ctf.collect_claimed()
|
ctf.collect_claimed()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user