Better callback running and ctf.reset()
This commit is contained in:
parent
a7d5d29220
commit
b2cc033d1b
@ -1,22 +1,43 @@
|
|||||||
-- Registered
|
-- Registered
|
||||||
ctf.registered_on_load = {}
|
ctf.registered_on_load = {}
|
||||||
function ctf.register_on_load(func)
|
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)
|
table.insert(ctf.registered_on_load, func)
|
||||||
|
if ctf._loaddata then
|
||||||
|
func(ctf._loaddata)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ctf.registered_on_save = {}
|
ctf.registered_on_save = {}
|
||||||
function ctf.register_on_save(func)
|
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)
|
table.insert(ctf.registered_on_save, func)
|
||||||
end
|
end
|
||||||
ctf.registered_on_init = {}
|
ctf.registered_on_init = {}
|
||||||
function ctf.register_on_init(func)
|
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)
|
table.insert(ctf.registered_on_init, func)
|
||||||
|
if ctf._inited then
|
||||||
|
func()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
ctf.registered_on_new_team = {}
|
ctf.registered_on_new_team = {}
|
||||||
function ctf.register_on_new_team(func)
|
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)
|
table.insert(ctf.registered_on_new_team, func)
|
||||||
end
|
end
|
||||||
ctf.registered_on_territory_query = {}
|
ctf.registered_on_territory_query = {}
|
||||||
function ctf.register_on_territory_query(func)
|
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)
|
table.insert(ctf.registered_on_territory_query, func)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,9 +72,8 @@ function ctf.warning(area, msg)
|
|||||||
print("WARNING: [CaptureTheFlag] (" .. area .. ") " .. msg)
|
print("WARNING: [CaptureTheFlag] (" .. area .. ") " .. msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ctf.init()
|
function ctf.init()
|
||||||
|
ctf._inited = true
|
||||||
ctf.log("init", "Initialising!")
|
ctf.log("init", "Initialising!")
|
||||||
|
|
||||||
-- Set up structures
|
-- Set up structures
|
||||||
@ -81,6 +101,12 @@ function ctf.init()
|
|||||||
ctf.log("init", "Done!")
|
ctf.log("init", "Done!")
|
||||||
end
|
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
|
-- Set default setting value
|
||||||
function ctf._set(setting, default)
|
function ctf._set(setting, default)
|
||||||
ctf._defsettings[setting] = default
|
ctf._defsettings[setting] = default
|
||||||
@ -130,11 +156,17 @@ function ctf.load()
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
ctf._loaddata = table
|
||||||
else
|
else
|
||||||
ctf.log("io", "ctf.txt is not present in the world folder")
|
ctf.log("io", "ctf.txt is not present in the world folder")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.after(0, function()
|
||||||
|
ctf._loaddata = nil
|
||||||
|
ctf._mt_loaded = true
|
||||||
|
end)
|
||||||
|
|
||||||
function ctf.save()
|
function ctf.save()
|
||||||
ctf.log("io", "Saving CTF state...")
|
ctf.log("io", "Saving CTF state...")
|
||||||
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
|
local file = io.open(minetest.get_worldpath().."/ctf.txt", "w")
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
ctf_chat = {}
|
ctf.register_on_init(function()
|
||||||
function ctf_chat.init()
|
ctf.log("chat", "Initialising...")
|
||||||
|
|
||||||
-- Settings: Chat
|
-- Settings: Chat
|
||||||
ctf._set("chat.team_channel", true)
|
ctf._set("chat.team_channel", true)
|
||||||
ctf._set("chat.global_channel", true)
|
ctf._set("chat.global_channel", true)
|
||||||
ctf._set("chat.default", "global")
|
ctf._set("chat.default", "global")
|
||||||
end
|
end)
|
||||||
ctf_chat.init()
|
|
||||||
|
|
||||||
local function team_console_help(name)
|
local function team_console_help(name)
|
||||||
minetest.chat_send_player(name,"Try:", false)
|
minetest.chat_send_player(name,"Try:", false)
|
||||||
@ -126,9 +126,19 @@ minetest.register_chatcommand("ctf_clean", {
|
|||||||
end,
|
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", {
|
minetest.register_chatcommand("ctf_reload", {
|
||||||
description = "reload the ctf main frame and get settings",
|
description = "reload the ctf main frame and get settings",
|
||||||
privs = {team=true},
|
privs = {ctf_admin=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
ctf.save()
|
ctf.save()
|
||||||
ctf.init()
|
ctf.init()
|
||||||
@ -139,7 +149,7 @@ minetest.register_chatcommand("ctf_reload", {
|
|||||||
minetest.register_chatcommand("team_owner", {
|
minetest.register_chatcommand("team_owner", {
|
||||||
params = "player name",
|
params = "player name",
|
||||||
description = "Make player team owner",
|
description = "Make player team owner",
|
||||||
privs = {team=true},
|
privs = {ctf_admin=true},
|
||||||
func = function(name, param)
|
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 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
|
if ctf.player(param).auth == true then
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
-- Initialise
|
-- Initialise
|
||||||
function init()
|
ctf.register_on_init(function()
|
||||||
|
ctf.log("flag", "Initialising...")
|
||||||
ctf._set("flag.allow_multiple", true)
|
ctf._set("flag.allow_multiple", true)
|
||||||
ctf._set("flag.capture_take", false)
|
ctf._set("flag.capture_take", false)
|
||||||
ctf._set("flag.names", true)
|
ctf._set("flag.names", true)
|
||||||
@ -7,8 +8,7 @@ function init()
|
|||||||
ctf._set("gui.tab.flags", true)
|
ctf._set("gui.tab.flags", true)
|
||||||
ctf._set("gui.team.teleport_to_flag", true)
|
ctf._set("gui.team.teleport_to_flag", true)
|
||||||
ctf._set("gui.team.teleport_to_spawn", false)
|
ctf._set("gui.team.teleport_to_spawn", false)
|
||||||
end
|
end)
|
||||||
init()
|
|
||||||
ctf.register_on_new_team(function(team)
|
ctf.register_on_new_team(function(team)
|
||||||
team.flags = {}
|
team.flags = {}
|
||||||
end)
|
end)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
function init()
|
ctf.register_on_init(function()
|
||||||
|
ctf.log("turrets", "Initialising...")
|
||||||
|
|
||||||
ctf._set("turrets", true)
|
ctf._set("turrets", true)
|
||||||
end
|
end)
|
||||||
init()
|
|
||||||
|
|
||||||
if ctf.setting("turrets") then
|
if ctf.setting("turrets") then
|
||||||
ARROW_DAMAGE = 2
|
ARROW_DAMAGE = 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user