From 9a6e6a5c55336daa1a35c7f6eb9e19678480bd1d Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 30 Mar 2016 00:24:12 +0100 Subject: [PATCH] Better team creation code, update ctf_pvp_engine --- minetest.conf | 8 ++++++- mods/ctf_match/matches.lua | 44 ++++++++++++++++++-------------------- mods/ctf_pvp_engine | 2 +- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/minetest.conf b/minetest.conf index f0132eb..0ef0578 100644 --- a/minetest.conf +++ b/minetest.conf @@ -31,7 +31,13 @@ ctf.friendly_fire = false ctf.autoalloc_on_joinplayer = true ctf.match = true -ctf.match.teams = red, red, 7, 65, 93; blue, blue, -22, 66, -78 +match.teams = 2 +match.team.1 = red +match.team.1.color = red +match.team.1.pos = 7,65,93 +match.team.2 = blue +match.team.2.color = blue +match.team.2.pos = -22,66,-78 ctf.match.build_time = 240 ctf.match.clear_inv = true ctf.match.destroy_team = true diff --git a/mods/ctf_match/matches.lua b/mods/ctf_match/matches.lua index 64c98d1..b83c143 100644 --- a/mods/ctf_match/matches.lua +++ b/mods/ctf_match/matches.lua @@ -2,7 +2,13 @@ ctf.register_on_init(function() ctf._set("match", false) ctf._set("match.destroy_team", false) ctf._set("match.break_alliances", true) - ctf._set("match.teams", "") + ctf._set("match.teams", 2) + ctf._set("match.team.1", "red") + ctf._set("match.team.1.color", "red") + ctf._set("match.team.1.pos", "7,65,93") + ctf._set("match.team.2", "blue") + ctf._set("match.team.2.color", "blue") + ctf._set("match.team.2.pos", "-22,66,-78") ctf._set("match.clear_inv", false) end) @@ -61,28 +67,18 @@ function ctf_match.check_for_winner() end end -ctf.register_on_new_game(function() - local teams = ctf.setting("match.teams") - if teams:trim() == "" then - return - end - ctf.log("match", "Setting up new game!") +function ctf_match.create_teams() + local number = ctf.setting("match.teams") - teams = teams:split(";") - for i, v in pairs(teams) do - local team = v:split(",") - if #team == 5 then - local name = team[1]:trim() - local color = team[2]:trim() - local x = tonumber(team[3]:trim()) - local y = tonumber(team[4]:trim()) - local z = tonumber(team[5]:trim()) - local flag = { - x = x, - y = y, - z = z - } + for i = 1, number do + print("Creating team #" .. i) + local name = ctf.setting("match.team." .. i) + local color = ctf.setting("match.team." .. i .. ".color") + local pos = ctf.setting("match.team." .. i .. ".pos") + local flag = minetest.string_to_pos(pos) + if name and color and pos and flag then + print(" - Success in getting settings") ctf.team({ name = name, color = color, @@ -94,10 +90,12 @@ ctf.register_on_new_game(function() minetest.after(0, function() ctf_flag.assert_flag(flag) end) - else - ctf.warning("match", "Invalid team setup: " .. dump(v)) end end +end + +ctf.register_on_new_game(function() + ctf_match.create_teams() for i, player in pairs(minetest.get_connected_players()) do local name = player:get_player_name() diff --git a/mods/ctf_pvp_engine b/mods/ctf_pvp_engine index cddcf97..8c073e1 160000 --- a/mods/ctf_pvp_engine +++ b/mods/ctf_pvp_engine @@ -1 +1 @@ -Subproject commit cddcf972743ac679b2520f5ce816d1e526e3e43c +Subproject commit 8c073e1b0d2f8b9c182f91b595dee52486e90462