From c7c95a757e5ec14da9f8c1121909d915362a1798 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 2 Jan 2016 21:10:26 +0000 Subject: [PATCH] Random spawn locations --- mods/ctf_team_base/init.lua | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/mods/ctf_team_base/init.lua b/mods/ctf_team_base/init.lua index 72425ef..ce946b4 100644 --- a/mods/ctf_team_base/init.lua +++ b/mods/ctf_team_base/init.lua @@ -1,3 +1,41 @@ +local old = ctf.get_spawn +function ctf.get_spawn(tname) + local team = ctf.team(tname) + if team and #team.flags >= 1 then + local flag = team.flags[1] + local i = 0 + local r = 6 + while i < 6 do + i = i + 1 + local pos = {x=0, z=0} + pos.x = flag.x + math.random() * 40 - 20 + pos.z = math.random() * 30 + 49 + if pos.x < -99 then + pos.x = -99 + end + if pos.x > 99 then + pos.x = 99 + end + if team.flags[1].z < 0 then + pos.z = -pos.z + end + local res = minetest.find_nodes_in_area_under_air( + { x = pos.x - r, y = 2, z = pos.z - r}, + { x = pos.x + r, y = 17, z = pos.z + r}, + {"default:dirt_with_grass"}) + if #res > 0 then + res[1].y = res[1].y + 1 + team.spawn = res[1] + return res[1] + end + end + return team.spawn or old(tname) + else + return team.spawn + end +end + + local chest_formspec = "size[8,9]" .. default.gui_bg ..