ctf.join() bug fixes and ctf.register_on_new_game()
This commit is contained in:
parent
1aa85c35b8
commit
60f9060bd5
@ -40,6 +40,16 @@ function ctf.register_on_territory_query(func)
|
|||||||
end
|
end
|
||||||
table.insert(ctf.registered_on_territory_query, func)
|
table.insert(ctf.registered_on_territory_query, func)
|
||||||
end
|
end
|
||||||
|
ctf.registered_on_new_game = {}
|
||||||
|
function ctf.register_on_new_game(func)
|
||||||
|
if ctf._mt_loaded then
|
||||||
|
error("You can't register callbacks at game time!")
|
||||||
|
end
|
||||||
|
table.insert(ctf.registered_on_new_game, func)
|
||||||
|
if ctf._new_game then
|
||||||
|
func()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function vector.distanceSQ(p1, p2)
|
function vector.distanceSQ(p1, p2)
|
||||||
local x = p1.x - p2.x
|
local x = p1.x - p2.x
|
||||||
@ -159,6 +169,10 @@ function ctf.load()
|
|||||||
ctf._loaddata = table
|
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")
|
||||||
|
ctf._new_game = true
|
||||||
|
for i = 1, #ctf.registered_on_new_game do
|
||||||
|
ctf.registered_on_new_game[i]()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ end
|
|||||||
|
|
||||||
-- Player joins team
|
-- Player joins team
|
||||||
-- Called by /join, /team join or auto allocate.
|
-- Called by /join, /team join or auto allocate.
|
||||||
function ctf.join(name, team, force)
|
function ctf.join(name, team, force, by)
|
||||||
if not name or name == "" or not team or team == "" then
|
if not name or name == "" or not team or team == "" then
|
||||||
ctf.log("team", "Missing parameters to ctf.join")
|
ctf.log("team", "Missing parameters to ctf.join")
|
||||||
return false
|
return false
|
||||||
@ -109,17 +109,36 @@ function ctf.join(name, team, force)
|
|||||||
|
|
||||||
if not force and not ctf.setting("players_can_change_team")
|
if not force and not ctf.setting("players_can_change_team")
|
||||||
and not player.team then
|
and not player.team then
|
||||||
|
if by then
|
||||||
|
if by == name then
|
||||||
ctf.action("teams", name .. " attempted to change to " .. team)
|
ctf.action("teams", name .. " attempted to change to " .. team)
|
||||||
minetest.chat_send_player(name, "You are not allowed to switch teams, traitor!")
|
minetest.chat_send_player(by, "You are not allowed to switch teams, traitor!")
|
||||||
|
else
|
||||||
|
ctf.action("teams", by .. " attempted to change " .. name .. " to " .. team)
|
||||||
|
minetest.chat_send_player(by, "Failed to add " .. name .. " to " .. team ..
|
||||||
|
" as players_can_change_team = false")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ctf.log("teams", "failed to add " .. name .. " to " .. team ..
|
||||||
|
" as players_can_change_team = false")
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local team_data = ctf.team(team)
|
local team_data = ctf.team(team)
|
||||||
if team_data then
|
if not team_data then
|
||||||
|
if by then
|
||||||
|
minetest.chat_send_player(by, "No such team.")
|
||||||
|
ctf.list_teams(by)
|
||||||
|
if by == name then
|
||||||
|
minetest.log("action", by .. " tried to move " .. name .. " to " .. team .. ", which doesn't exist")
|
||||||
|
else
|
||||||
minetest.log("action", name .. " attempted to join " .. team .. ", which doesn't exist")
|
minetest.log("action", name .. " attempted to join " .. team .. ", which doesn't exist")
|
||||||
minetest.chat_send_player(name, "No such team.")
|
end
|
||||||
ctf.list_teams(name)
|
else
|
||||||
|
ctf.log("teams", "failed to add " .. name .. " to " .. team ..
|
||||||
|
" as team does not exist")
|
||||||
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -287,6 +306,11 @@ minetest.register_on_newplayer(function(player)
|
|||||||
if team then
|
if team then
|
||||||
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
||||||
ctf.join(name, team)
|
ctf.join(name, team)
|
||||||
|
|
||||||
|
local spawn = ctf.get_spawn(team)
|
||||||
|
if spawn then
|
||||||
|
player:moveto(spawn, false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ minetest.register_chatcommand("team", {
|
|||||||
"' to team '" .. tteam .. "'",false)
|
"' to team '" .. tteam .. "'",false)
|
||||||
local privs = minetest.get_player_privs(name)
|
local privs = minetest.get_player_privs(name)
|
||||||
if privs and privs.ctf_admin == true then
|
if privs and privs.ctf_admin == true then
|
||||||
if ctf.join(tplayer, tteam, true) then
|
if ctf.join(tplayer, tteam, true, name) then
|
||||||
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
||||||
else
|
else
|
||||||
minetest.char_send_player(name, "Failed to add player to team.")
|
minetest.char_send_player(name, "Failed to add player to team.")
|
||||||
@ -107,7 +107,7 @@ minetest.register_chatcommand("join", {
|
|||||||
params = "team name",
|
params = "team name",
|
||||||
description = "Add to team",
|
description = "Add to team",
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
ctf.join(name, param, false)
|
ctf.join(name, param, false, name)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -42,18 +42,30 @@ ctf_flag.register_on_capture(function(attname, flag)
|
|||||||
minetest.chat_send_all("Team " .. winner .. " won!")
|
minetest.chat_send_all("Team " .. winner .. " won!")
|
||||||
minetest.chat_send_all("Resetting the map, this may take a few moments...")
|
minetest.chat_send_all("Resetting the map, this may take a few moments...")
|
||||||
minetest.after(0.5, function()
|
minetest.after(0.5, function()
|
||||||
ctf.reset()
|
|
||||||
minetest.delete_area(vector.new(-16*3, -16*3, -16*3), vector.new(16*3, 16*3, 16*3))
|
minetest.delete_area(vector.new(-16*3, -16*3, -16*3), vector.new(16*3, 16*3, 16*3))
|
||||||
|
|
||||||
|
minetest.after(1, function()
|
||||||
|
ctf.reset()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
ctf.register_on_new_game(function()
|
||||||
|
ctf.log("endgame", "Setting up new game!")
|
||||||
|
|
||||||
ctf.team({name="red", color="red", add_team=true})
|
ctf.team({name="red", color="red", add_team=true})
|
||||||
ctf.team({name="blue", color="blue", add_team=true})
|
ctf.team({name="blue", color="blue", add_team=true})
|
||||||
|
|
||||||
minetest.after(1, function()
|
|
||||||
local fred = {x=15, y=7, z=39, team="red"}
|
local fred = {x=15, y=7, z=39, team="red"}
|
||||||
local fblue = {x=-9,y=9,z=-50, team="blue"}
|
local fblue = {x=-9, y=9, z=-50, team="blue"}
|
||||||
ctf_flag.add("red", fred)
|
ctf_flag.add("red", fred)
|
||||||
ctf_flag.add("blue", fblue)
|
ctf_flag.add("blue", fblue)
|
||||||
|
|
||||||
|
minetest.after(0, function()
|
||||||
safe_place(fred, {name="ctf_flag:flag"})
|
safe_place(fred, {name="ctf_flag:flag"})
|
||||||
safe_place(fblue, {name="ctf_flag:flag"})
|
safe_place(fblue, {name="ctf_flag:flag"})
|
||||||
|
end)
|
||||||
|
|
||||||
for i, player in pairs(minetest.get_connected_players()) do
|
for i, player in pairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
@ -74,12 +86,11 @@ ctf_flag.register_on_capture(function(attname, flag)
|
|||||||
team = ctf.player(name).team
|
team = ctf.player(name).team
|
||||||
if ctf.team(team) then
|
if ctf.team(team) then
|
||||||
local spawn = ctf.get_spawn(team)
|
local spawn = ctf.get_spawn(team)
|
||||||
|
if spawn then
|
||||||
player:moveto(spawn, false)
|
player:moveto(spawn, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.log("endgame", "reset done")
|
|
||||||
minetest.chat_send_all("All done! Next round!")
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
minetest.log("endgame", "reset done")
|
||||||
|
minetest.chat_send_all("Next round!")
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user