Changes with logging
This commit is contained in:
parent
e54429a649
commit
4c3e623e93
@ -53,7 +53,6 @@ function ctf.area.delete_flag(team, pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print(dump(ctf.team(team).flags))
|
|
||||||
for i = 1, #ctf.team(team).flags do
|
for i = 1, #ctf.team(team).flags do
|
||||||
if (
|
if (
|
||||||
ctf.team(team).flags[i].x == pos.x and
|
ctf.team(team).flags[i].x == pos.x and
|
||||||
@ -69,7 +68,7 @@ end
|
|||||||
-- Gets the nearest flag in a 25 metre radius block
|
-- Gets the nearest flag in a 25 metre radius block
|
||||||
function ctf.area.nearest_flag(pos)
|
function ctf.area.nearest_flag(pos)
|
||||||
if not pos then
|
if not pos then
|
||||||
print ("No position provided to nearest_flag()")
|
ctf.error("No position provided to nearest_flag()")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -153,13 +152,14 @@ function ctf.area.asset_flags(team)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Checking the flags of "..team)
|
ctf.log("utils", "Checking the flags of "..team)
|
||||||
|
|
||||||
local tmp = ctf.team(team).flags
|
local tmp = ctf.team(team).flags
|
||||||
|
local get_res = minetest.env:get_node(tmp[i])
|
||||||
for i=1,#tmp do
|
for i=1,#tmp do
|
||||||
if tmp[i] and (not minetest.env:get_node(tmp[i]) or not minetest.env:get_node(tmp[i]).name == "ctf:flag") then
|
if tmp[i] and (not get_res or not get_res.name == "ctf:flag") then
|
||||||
print("Replacing flag...")
|
ctf.log("utils", "Replacing flag...")
|
||||||
|
-- TODO: ctf.area.asset_flags
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,8 +24,6 @@ minetest.register_chatcommand("team", {
|
|||||||
local create = string.match(param,"^add ([%a%d_]+)")
|
local create = string.match(param,"^add ([%a%d_]+)")
|
||||||
local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)")
|
local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)")
|
||||||
if test then
|
if test then
|
||||||
print("is a player request "..test)
|
|
||||||
|
|
||||||
if ctf.player(test) then
|
if ctf.player(test) then
|
||||||
if ctf.player(test).team then
|
if ctf.player(test).team then
|
||||||
if ctf.player(test).auth then
|
if ctf.player(test).auth then
|
||||||
|
@ -20,7 +20,7 @@ function ctf.log(area, msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ctf.warning(area, msg)
|
function ctf.warning(area, msg)
|
||||||
minetest.log("warning", "[CaptureTheFlag] (" .. area .. ") " .. msg)
|
print("WARNING: [CaptureTheFlag] (" .. area .. ") " .. msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ctf.init()
|
function ctf.init()
|
||||||
@ -143,11 +143,11 @@ end
|
|||||||
function ctf.team(name) -- get or add a team
|
function ctf.team(name) -- get or add a team
|
||||||
if type(name) == "table" then
|
if type(name) == "table" then
|
||||||
if not name.add_team then
|
if not name.add_team then
|
||||||
error("Invalid table given to ctf.team")
|
ctf.error("Invalid table given to ctf.team")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Defining team "..name.name)
|
ctf.log("team", "Defining team "..name.name)
|
||||||
|
|
||||||
ctf.teams[name.name]={
|
ctf.teams[name.name]={
|
||||||
data = name,
|
data = name,
|
||||||
@ -403,12 +403,9 @@ minetest.register_on_newplayer(function(player)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
-- TODO: make this work correctly. (ie no need for minetest.after)
|
local team = ctf.autoalloc(name, alloc_mode)
|
||||||
minetest.after(1, function()
|
if team then
|
||||||
local team = ctf.autoalloc(name, alloc_mode)
|
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
||||||
if team then
|
ctf.join(name, team)
|
||||||
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
end
|
||||||
ctf.join(name, team)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end)
|
end)
|
||||||
|
@ -314,7 +314,6 @@ minetest.register_on_respawnplayer(function(player)
|
|||||||
if player and ctf.player(player:get_player_name()) then
|
if player and ctf.player(player:get_player_name()) then
|
||||||
local team = ctf.player(player:get_player_name()).team
|
local team = ctf.player(player:get_player_name()).team
|
||||||
if team and ctf.team(team) and ctf.area.get_spawn(team)==true then
|
if team and ctf.team(team) and ctf.area.get_spawn(team)==true then
|
||||||
print("Player "..player:get_player_name().." moved to team spawn")
|
|
||||||
player:moveto(ctf.team(team).spawn, false)
|
player:moveto(ctf.team(team).spawn, false)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -337,7 +336,7 @@ minetest.register_abm({
|
|||||||
|
|
||||||
local flag_team_data = ctf.area.get_flag(pos)
|
local flag_team_data = ctf.area.get_flag(pos)
|
||||||
if not flag_team_data or not ctf.team(flag_team_data.team)then
|
if not flag_team_data or not ctf.team(flag_team_data.team)then
|
||||||
print("Flag does not exist! "..dump(pos))
|
ctf.log("flag", "Flag does not exist! Deleting nodes. "..dump(pos))
|
||||||
minetest.env:set_node(pos,{name="air"})
|
minetest.env:set_node(pos,{name="air"})
|
||||||
minetest.env:set_node(top,{name="air"})
|
minetest.env:set_node(top,{name="air"})
|
||||||
return
|
return
|
||||||
|
@ -23,6 +23,7 @@ end
|
|||||||
|
|
||||||
-- Team interface
|
-- Team interface
|
||||||
function ctf.gui.team_board(name,team)
|
function ctf.gui.team_board(name,team)
|
||||||
|
ctf.log("gui", name .. " views team_board")
|
||||||
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -61,7 +62,6 @@ function ctf.gui.team_board(name,team)
|
|||||||
local height = (amount*0.5)+0.5
|
local height = (amount*0.5)+0.5
|
||||||
|
|
||||||
if height > 5 then
|
if height > 5 then
|
||||||
print("break!")
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -88,6 +88,7 @@ end
|
|||||||
|
|
||||||
-- Team interface
|
-- Team interface
|
||||||
function ctf.gui.team_flags(name,team)
|
function ctf.gui.team_flags(name,team)
|
||||||
|
ctf.log("gui", name .. " views team_flags")
|
||||||
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -148,6 +149,7 @@ end
|
|||||||
|
|
||||||
-- Team interface
|
-- Team interface
|
||||||
function ctf.gui.team_dip(name,team)
|
function ctf.gui.team_dip(name,team)
|
||||||
|
ctf.log("gui", name .. " views team_dip")
|
||||||
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -210,6 +212,7 @@ end
|
|||||||
|
|
||||||
-- Team interface
|
-- Team interface
|
||||||
function ctf.gui.team_settings(name,team)
|
function ctf.gui.team_settings(name,team)
|
||||||
|
ctf.log("gui", name .. " views team_settings")
|
||||||
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
if not ctf.setting("team_gui") or not ctf.setting("gui") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -279,7 +282,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end
|
end
|
||||||
if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then
|
if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then
|
||||||
if minetest.registered_items["ctf:flag_top_"..fields.color] then
|
if minetest.registered_items["ctf:flag_top_"..fields.color] then
|
||||||
print("Setting color...")
|
|
||||||
ctf.team(ctf.players[name].team).data.color = fields.color
|
ctf.team(ctf.players[name].team).data.color = fields.color
|
||||||
ctf.save()
|
ctf.save()
|
||||||
else
|
else
|
||||||
@ -399,6 +401,7 @@ end)
|
|||||||
|
|
||||||
-- Flag interface
|
-- Flag interface
|
||||||
function ctf.gui.flag_board(name,pos)
|
function ctf.gui.flag_board(name,pos)
|
||||||
|
ctf.log("gui", name .. " views team_board")
|
||||||
local flag = ctf.area.get_flag(pos)
|
local flag = ctf.area.get_flag(pos)
|
||||||
if not flag then
|
if not flag then
|
||||||
return
|
return
|
||||||
@ -479,8 +482,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
msg = "A flag was named "..fields.flag_name.." at ("..ctf.gui.flag_data[name].pos.x..","..ctf.gui.flag_data[name].pos.z..")"
|
msg = "A flag was named "..fields.flag_name.." at ("..ctf.gui.flag_data[name].pos.x..","..ctf.gui.flag_data[name].pos.z..")"
|
||||||
end
|
end
|
||||||
|
|
||||||
print(msg)
|
|
||||||
|
|
||||||
ctf.post(team,{msg=msg,icon="flag_info"})
|
ctf.post(team,{msg=msg,icon="flag_info"})
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -490,7 +491,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
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?!")
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local team = flag.team
|
local team = flag.team
|
||||||
|
@ -67,13 +67,12 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
function ctf.hud.update(player)
|
function ctf.hud.update(player)
|
||||||
ctf.log("hud", "Updating player HUD")
|
|
||||||
if not player then
|
if not player then
|
||||||
ctf.log("hud", " - player not emerged")
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_data = ctf.player(player:get_player_name())
|
local name = player:get_player_name()
|
||||||
|
local player_data = ctf.player(name)
|
||||||
|
|
||||||
if not player_data or not player_data.team or not ctf.team(player_data.team) then
|
if not player_data or not player_data.team or not ctf.team(player_data.team) then
|
||||||
return
|
return
|
||||||
@ -97,8 +96,6 @@ function ctf.hud.update(player)
|
|||||||
ctf.hud:change(player, "ctf:hud_team", "text", player_data.team)
|
ctf.hud:change(player, "ctf:hud_team", "text", player_data.team)
|
||||||
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
ctf.hud:change(player, "ctf:hud_team", "number", color)
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf.log("hud", " - Done.")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = 0
|
local count = 0
|
||||||
|
@ -4,6 +4,14 @@
|
|||||||
|
|
||||||
ctf = {}
|
ctf = {}
|
||||||
|
|
||||||
|
-- Fix for https://github.com/minetest/minetest/issues/2383
|
||||||
|
local csa = minetest.chat_send_all
|
||||||
|
function minetest.chat_send_all(msg)
|
||||||
|
minetest.after(0, function()
|
||||||
|
csa(msg)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- Modules
|
-- Modules
|
||||||
dofile(minetest.get_modpath("ctf").."/core.lua")
|
dofile(minetest.get_modpath("ctf").."/core.lua")
|
||||||
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user