Fix dropondie not taking map's initial stuff into account

This commit is contained in:
rubenwardy 2018-01-27 18:45:52 +00:00
parent 7836ba78c2
commit 8cbceb9e4d
3 changed files with 31 additions and 29 deletions

View file

@ -1,18 +1,26 @@
function give_initial_stuff(player) give_initial_stuff = {}
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 { setmetatable(give_initial_stuff, {
__call = function(self, 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 = give_initial_stuff.get_stuff()
for _, item in pairs(items) do
inv:add_item("main", item)
end
end
})
function give_initial_stuff.get_stuff()
return ctf_map.map and ctf_map.map.initial_stuff or {
"default:pick_wood", "default:pick_wood",
"default:sword_wood", "default:sword_wood",
"default:torch 3", "default:torch 3",
} }
for _, item in pairs(items) do
inv:add_item("main", item)
end
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)

View file

@ -0,0 +1 @@
ctf_map

View file

@ -10,12 +10,7 @@ local function drop(pos, itemstack)
for _, item in pairs(blacklist_drop) do for _, item in pairs(blacklist_drop) do
if sname == item then if sname == item then
return minetest.log("error", "Not dropping " .. item)
end
end
if sname == "default:torch" then
it:take_item(3)
if it:get_count() <= 0 then
return return
end end
end end
@ -34,25 +29,23 @@ local function drop(pos, itemstack)
return itemstack return itemstack
end end
local function drop_all(player) local function drop_list(pos, inv, list)
if minetest.setting_getbool("creative_mode") then for i = 1, inv:get_size(list) do
return drop(pos, inv:get_stack(list, i))
inv:set_stack(list, i, nil)
end end
end
local function drop_all(player)
local pos = player:getpos() local pos = player:getpos()
pos.y = math.floor(pos.y + 0.5) pos.y = math.floor(pos.y + 0.5)
local player_inv = player:get_inventory() local inv = player:get_inventory()
for _, item in pairs(give_initial_stuff.get_stuff()) do
for i=1,player_inv:get_size("main") do inv:remove_item("main", ItemStack(item))
drop(pos, player_inv:get_stack("main", i))
player_inv:set_stack("main", i, nil)
end
for i=1,player_inv:get_size("craft") do
drop(pos, player_inv:get_stack("craft", i))
player_inv:set_stack("craft", i, nil)
end end
drop_list(pos, inv, "main")
drop_list(pos, inv, "craft")
end end
minetest.register_on_dieplayer(drop_all) minetest.register_on_dieplayer(drop_all)