mckaygerhard ee86fb1c41 * document, configure and improve the give_initial_stuff
* This mod provides some stuff per player at initial play when first join only
* set initial_stuff = default:wood 2,farming:bread 2,default:furnace 1,default:torch 5
* the initial_stuff is only configured per config files not at menu
* cherry-picked from 18aed0219b
2021-12-13 20:27:13 -06:00

50 lines
1.2 KiB
Lua

-- gave_initial_stuff/init.lua
local stuff_string = minetest.settings:get("initial_stuff") or
"default:wood 2,farming:bread 2,default:furnace 1," ..
"default:torch 5"
local modname = "give_initial_stuff"
local modlogn = "["..modname.."]"
give_initial_stuff = {
items = {}
}
function give_initial_stuff.give(player)
minetest.log("action",modlogn.." Giving initial stuff to player " .. player:get_player_name())
local inv = player:get_inventory()
for _, stack in ipairs(give_initial_stuff.items) do
inv:add_item("main", stack)
end
end
function give_initial_stuff.add(stack)
give_initial_stuff.items[#give_initial_stuff.items + 1] = ItemStack(stack)
end
function give_initial_stuff.clear()
give_initial_stuff.items = {}
end
function give_initial_stuff.add_from_csv(str)
local items = str:split(",")
for _, itemname in ipairs(items) do
give_initial_stuff.add(itemname)
end
end
function give_initial_stuff.set_list(list)
give_initial_stuff.items = list
end
function give_initial_stuff.get_list()
return give_initial_stuff.items
end
give_initial_stuff.add_from_csv(stuff_string)
if minetest.settings:get_bool("give_initial_stuff") then
minetest.register_on_newplayer(give_initial_stuff.give)
end