Changes with logging

master
rubenwardy 2015-02-24 20:09:21 +00:00
parent e54429a649
commit 4c3e623e93
7 changed files with 31 additions and 31 deletions

View File

@ -53,7 +53,6 @@ function ctf.area.delete_flag(team, pos)
return
end
print(dump(ctf.team(team).flags))
for i = 1, #ctf.team(team).flags do
if (
ctf.team(team).flags[i].x == pos.x and
@ -69,7 +68,7 @@ end
-- Gets the nearest flag in a 25 metre radius block
function ctf.area.nearest_flag(pos)
if not pos then
print ("No position provided to nearest_flag()")
ctf.error("No position provided to nearest_flag()")
return nil
end
@ -153,13 +152,14 @@ function ctf.area.asset_flags(team)
return false
end
print("Checking the flags of "..team)
ctf.log("utils", "Checking the flags of "..team)
local tmp = ctf.team(team).flags
local get_res = minetest.env:get_node(tmp[i])
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
print("Replacing flag...")
if tmp[i] and (not get_res or not get_res.name == "ctf:flag") then
ctf.log("utils", "Replacing flag...")
-- TODO: ctf.area.asset_flags
end
end
end

View File

@ -24,8 +24,6 @@ minetest.register_chatcommand("team", {
local create = string.match(param,"^add ([%a%d_]+)")
local tplayer,tteam = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)")
if test then
print("is a player request "..test)
if ctf.player(test) then
if ctf.player(test).team then
if ctf.player(test).auth then

View File

@ -20,7 +20,7 @@ function ctf.log(area, msg)
end
function ctf.warning(area, msg)
minetest.log("warning", "[CaptureTheFlag] (" .. area .. ") " .. msg)
print("WARNING: [CaptureTheFlag] (" .. area .. ") " .. msg)
end
function ctf.init()
@ -143,11 +143,11 @@ end
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 ctf.team")
ctf.error("Invalid table given to ctf.team")
return
end
print("Defining team "..name.name)
ctf.log("team", "Defining team "..name.name)
ctf.teams[name.name]={
data = name,
@ -403,12 +403,9 @@ minetest.register_on_newplayer(function(player)
return
end
local name = player:get_player_name()
-- TODO: make this work correctly. (ie no need for minetest.after)
minetest.after(1, function()
local team = ctf.autoalloc(name, alloc_mode)
if team then
ctf.log("autoalloc", name .. " was allocated to " .. team)
ctf.join(name, team)
end
end)
local team = ctf.autoalloc(name, alloc_mode)
if team then
ctf.log("autoalloc", name .. " was allocated to " .. team)
ctf.join(name, team)
end
end)

View File

@ -314,7 +314,6 @@ minetest.register_on_respawnplayer(function(player)
if player and ctf.player(player:get_player_name()) then
local team = ctf.player(player:get_player_name()).team
if team and ctf.team(team) and ctf.area.get_spawn(team)==true then
print("Player "..player:get_player_name().." moved to team spawn")
player:moveto(ctf.team(team).spawn, false)
return true
end
@ -337,7 +336,7 @@ minetest.register_abm({
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))
ctf.log("flag", "Flag does not exist! Deleting nodes. "..dump(pos))
minetest.env:set_node(pos,{name="air"})
minetest.env:set_node(top,{name="air"})
return

View File

@ -23,6 +23,7 @@ end
-- Team interface
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
return
end
@ -61,7 +62,6 @@ function ctf.gui.team_board(name,team)
local height = (amount*0.5)+0.5
if height > 5 then
print("break!")
break
end
@ -88,6 +88,7 @@ end
-- Team interface
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
return
end
@ -148,6 +149,7 @@ end
-- Team interface
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
return
end
@ -210,6 +212,7 @@ end
-- Team interface
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
return
end
@ -279,7 +282,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
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()
else
@ -399,6 +401,7 @@ end)
-- Flag interface
function ctf.gui.flag_board(name,pos)
ctf.log("gui", name .. " views team_board")
local flag = ctf.area.get_flag(pos)
if not flag then
return
@ -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..")"
end
print(msg)
ctf.post(team,{msg=msg,icon="flag_info"})
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)
if not flag then
print("No flag?!")
return
end
local team = flag.team

View File

@ -67,13 +67,12 @@ minetest.register_on_leaveplayer(function(player)
end)
function ctf.hud.update(player)
ctf.log("hud", "Updating player HUD")
if not player then
ctf.log("hud", " - player not emerged")
return
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
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", "number", color)
end
ctf.log("hud", " - Done.")
end
local count = 0

View File

@ -4,6 +4,14 @@
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
dofile(minetest.get_modpath("ctf").."/core.lua")
dofile(minetest.get_modpath("ctf").."/diplomacy.lua")