diff --git a/mods/capturetheflag/ctf/core.lua b/mods/capturetheflag/ctf/core.lua index 1f1847f..e9a4a82 100644 --- a/mods/capturetheflag/ctf/core.lua +++ b/mods/capturetheflag/ctf/core.lua @@ -1,22 +1,43 @@ -- Registered ctf.registered_on_load = {} function ctf.register_on_load(func) + if ctf._mt_loaded then + error("You can't register callbacks at game time!") + end table.insert(ctf.registered_on_load, func) + if ctf._loaddata then + func(ctf._loaddata) + end end ctf.registered_on_save = {} function ctf.register_on_save(func) + if ctf._mt_loaded then + error("You can't register callbacks at game time!") + end table.insert(ctf.registered_on_save, func) end ctf.registered_on_init = {} function ctf.register_on_init(func) + if ctf._mt_loaded then + error("You can't register callbacks at game time!") + end table.insert(ctf.registered_on_init, func) + if ctf._inited then + func() + end end ctf.registered_on_new_team = {} function ctf.register_on_new_team(func) + if ctf._mt_loaded then + error("You can't register callbacks at game time!") + end table.insert(ctf.registered_on_new_team, func) end ctf.registered_on_territory_query = {} function ctf.register_on_territory_query(func) + if ctf._mt_loaded then + error("You can't register callbacks at game time!") + end table.insert(ctf.registered_on_territory_query, func) end @@ -51,9 +72,8 @@ function ctf.warning(area, msg) print("WARNING: [CaptureTheFlag] (" .. area .. ") " .. msg) end - - function ctf.init() + ctf._inited = true ctf.log("init", "Initialising!") -- Set up structures @@ -81,6 +101,12 @@ function ctf.init() ctf.log("init", "Done!") end +function ctf.reset() + ctf.log("io", "Deleting CTF save data...") + os.remove(minetest.get_worldpath().."/ctf.txt") + ctf.init() +end + -- Set default setting value function ctf._set(setting, default) ctf._defsettings[setting] = default @@ -130,11 +156,17 @@ function ctf.load() end return end + ctf._loaddata = table else ctf.log("io", "ctf.txt is not present in the world folder") end end +minetest.after(0, function() + ctf._loaddata = nil + ctf._mt_loaded = true +end) + function ctf.save() ctf.log("io", "Saving CTF state...") local file = io.open(minetest.get_worldpath().."/ctf.txt", "w") diff --git a/mods/capturetheflag/ctf_chat/init.lua b/mods/capturetheflag/ctf_chat/init.lua index c0ca06a..6af6004 100644 --- a/mods/capturetheflag/ctf_chat/init.lua +++ b/mods/capturetheflag/ctf_chat/init.lua @@ -1,11 +1,11 @@ -ctf_chat = {} -function ctf_chat.init() +ctf.register_on_init(function() + ctf.log("chat", "Initialising...") + -- Settings: Chat - ctf._set("chat.team_channel", true) - ctf._set("chat.global_channel", true) + ctf._set("chat.team_channel", true) + ctf._set("chat.global_channel", true) ctf._set("chat.default", "global") -end -ctf_chat.init() +end) local function team_console_help(name) minetest.chat_send_player(name,"Try:", false) @@ -126,9 +126,19 @@ minetest.register_chatcommand("ctf_clean", { end, }) +minetest.register_chatcommand("ctf_reset", { + description = "Delete all CTF saved states and start again.", + privs = {ctf_admin=true}, + func = function(name, param) + minetest.chat_send_all("The CTF core was reset. All team memberships," .. + "flags, land ownerships etc have been deleted.") + ctf.reset() + end, +}) + minetest.register_chatcommand("ctf_reload", { description = "reload the ctf main frame and get settings", - privs = {team=true}, + privs = {ctf_admin=true}, func = function(name, param) ctf.save() ctf.init() @@ -139,7 +149,7 @@ minetest.register_chatcommand("ctf_reload", { minetest.register_chatcommand("team_owner", { params = "player name", description = "Make player team owner", - privs = {team=true}, + privs = {ctf_admin=true}, func = function(name, param) 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 diff --git a/mods/capturetheflag/ctf_flag/init.lua b/mods/capturetheflag/ctf_flag/init.lua index ab70428..c666826 100644 --- a/mods/capturetheflag/ctf_flag/init.lua +++ b/mods/capturetheflag/ctf_flag/init.lua @@ -1,5 +1,6 @@ -- Initialise -function init() +ctf.register_on_init(function() + ctf.log("flag", "Initialising...") ctf._set("flag.allow_multiple", true) ctf._set("flag.capture_take", false) ctf._set("flag.names", true) @@ -7,8 +8,7 @@ function init() ctf._set("gui.tab.flags", true) ctf._set("gui.team.teleport_to_flag", true) ctf._set("gui.team.teleport_to_spawn", false) -end -init() +end) ctf.register_on_new_team(function(team) team.flags = {} end) diff --git a/mods/capturetheflag/ctf_turret/init.lua b/mods/capturetheflag/ctf_turret/init.lua index 9368858..347544d 100644 --- a/mods/capturetheflag/ctf_turret/init.lua +++ b/mods/capturetheflag/ctf_turret/init.lua @@ -1,7 +1,8 @@ -function init() +ctf.register_on_init(function() + ctf.log("turrets", "Initialising...") + ctf._set("turrets", true) -end -init() +end) if ctf.setting("turrets") then ARROW_DAMAGE = 2