Add per-map initial stuff

This commit is contained in:
rubenwardy 2018-01-21 22:10:37 +00:00
parent d2db81bf9b
commit 749bde3165
6 changed files with 34 additions and 27 deletions

View file

@ -1,17 +0,0 @@
function give_initial_stuff(player)
if minetest.setting_getbool("give_initial_stuff") then
minetest.log("action", "Giving initial stuff to player "..player:get_player_name())
local inv = player:get_inventory()
inv:set_list("main", {})
inv:set_list("craft", {})
inv:add_item('main', 'default:pick_wood')
inv:add_item('main', 'default:sword_wood')
inv:add_item('main', 'default:torch 3')
end
end
minetest.register_on_joinplayer(function(player)
player:set_hp(20)
give_initial_stuff(player)
end)
minetest.register_on_respawnplayer(give_initial_stuff)

View file

@ -41,5 +41,3 @@ sfinv.register_page("ctf_inventory:help", {
return sfinv.make_formspec(player, context, fs, false)
end
})
dofile(minetest.get_modpath("ctf_inventory") .. "/give_initial_stuff.lua")

View file

@ -0,0 +1,22 @@
function give_initial_stuff(player)
minetest.log("action", "Giving initial stuff to player "..player:get_player_name())
local inv = player:get_inventory()
inv:set_list("main", {})
inv:set_list("craft", {})
local items = ctf_map.map and ctf_map.map.initial_stuff or {
"default:pick_wood",
"default:sword_wood",
"default:torch 3",
}
for _, item in pairs(items) do
inv:add_item("main", item)
end
end
minetest.register_on_joinplayer(function(player)
player:set_hp(20)
give_initial_stuff(player)
end)
minetest.register_on_respawnplayer(give_initial_stuff)

View file

@ -7,6 +7,7 @@ dofile(minetest.get_modpath("ctf_map") .. "/barrier.lua")
if minetest.get_modpath("ctf") then
dofile(minetest.get_modpath("ctf_map") .. "/schem_map.lua")
dofile(minetest.get_modpath("ctf_map") .. "/give_initial_stuff.lua")
assert(ctf_match)
ctf_match.register_on_build_time_end(ctf_map.remove_middle_barrier)

View file

@ -3,6 +3,7 @@ author = rubenwardy
rotation = z
r = 115
h = 230
initial_stuff = default:pick_steel,default:sword_wood,default:torch 20
team.1 = red
team.1.color = red
team.1.pos = -20,-2,65

View file

@ -48,15 +48,17 @@ function ctf_match.load_map_meta(idx, name)
local offset = vector.new(600 * (idx - 1), 0, 0)
local meta = Settings(mapdir .. name .. ".conf")
local initial_stuff = meta:get("initial_stuff")
local map = {
idx = idx,
name = meta:get("name"),
author = meta:get("author"),
rotation = meta:get("rotation"),
schematic = name .. ".mts",
r = tonumber(meta:get("r")),
h = tonumber(meta:get("h")),
teams = {}
idx = idx,
name = meta:get("name"),
author = meta:get("author"),
rotation = meta:get("rotation"),
schematic = name .. ".mts",
r = tonumber(meta:get("r")),
h = tonumber(meta:get("h")),
teams = {},
initial_stuff = initial_stuff and initial_stuff:split(","),
}
assert(map.r <= max_r)