Add random map selection
This commit is contained in:
parent
b4ed07cee3
commit
a3f5e065e3
1 changed files with 19 additions and 3 deletions
|
@ -19,10 +19,26 @@ function ctf_map.place_map(map)
|
||||||
return res ~= nil
|
return res ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local mapdir = minetest.get_modpath("ctf_map") .. "/maps/"
|
||||||
|
|
||||||
|
do
|
||||||
|
local files_hash = {}
|
||||||
|
local files = minetest.get_dir_list(mapdir, false)
|
||||||
|
for i=1, #files do
|
||||||
|
files_hash[files[i]:split(".")[1]] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
ctf_map.available_maps = {}
|
||||||
|
for key, _ in pairs(files_hash) do
|
||||||
|
table.insert(ctf_map.available_maps, key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
ctf_map.map = nil
|
ctf_map.map = nil
|
||||||
|
|
||||||
function ctf_match.load_map_meta(name)
|
function ctf_match.load_map_meta(name)
|
||||||
local meta = Settings(minetest.get_modpath("ctf_map") .. "/maps/" .. name .. ".conf")
|
local meta = Settings(mapdir .. name .. ".conf")
|
||||||
local map = {
|
local map = {
|
||||||
name = meta:get("name"),
|
name = meta:get("name"),
|
||||||
author = meta:get("author"),
|
author = meta:get("author"),
|
||||||
|
@ -51,8 +67,8 @@ function ctf_match.load_map_meta(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
ctf_match.register_on_new_match(function()
|
ctf_match.register_on_new_match(function()
|
||||||
ctf_map.map = ctf_match.load_map_meta("01_two_hills")
|
local name = ctf_map.available_maps[math.random(#ctf_map.available_maps)]
|
||||||
print(dump(ctf_map.map))
|
ctf_map.map = ctf_match.load_map_meta(name)
|
||||||
ctf_map.place_map(ctf_map.map)
|
ctf_map.place_map(ctf_map.map)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue