2018-01-27 18:45:52 +00:00
|
|
|
give_initial_stuff = {}
|
2018-01-21 22:10:37 +00:00
|
|
|
|
2018-01-27 18:45:52 +00:00
|
|
|
setmetatable(give_initial_stuff, {
|
|
|
|
__call = function(self, player)
|
2019-03-19 16:54:43 +00:00
|
|
|
minetest.log("action", "Giving initial stuff to player "
|
|
|
|
.. player:get_player_name())
|
2018-01-27 18:45:52 +00:00
|
|
|
local inv = player:get_inventory()
|
|
|
|
inv:set_list("main", {})
|
|
|
|
inv:set_list("craft", {})
|
|
|
|
|
2018-05-04 18:01:53 +00:00
|
|
|
inv:set_size("craft", 1)
|
|
|
|
inv:set_size("craftresult", 0)
|
|
|
|
inv:set_size("hand", 0)
|
|
|
|
|
2020-03-13 21:58:42 +00:00
|
|
|
local items = give_initial_stuff.get_stuff(player)
|
2018-01-27 18:45:52 +00:00
|
|
|
|
|
|
|
for _, item in pairs(items) do
|
|
|
|
inv:add_item("main", item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2020-03-13 21:58:42 +00:00
|
|
|
local registered_stuff_providers = {}
|
|
|
|
function give_initial_stuff.register_stuff_provider(func, priority)
|
|
|
|
table.insert(registered_stuff_providers,
|
|
|
|
priority or (#registered_stuff_providers + 1),
|
|
|
|
func)
|
|
|
|
end
|
|
|
|
|
|
|
|
function give_initial_stuff.get_stuff(player)
|
|
|
|
local stuff = {}
|
|
|
|
for i=1, #registered_stuff_providers do
|
|
|
|
local new_stuff = registered_stuff_providers[i](player)
|
|
|
|
assert(new_stuff)
|
|
|
|
|
|
|
|
for j=1, #new_stuff do
|
|
|
|
stuff[#stuff + 1] = new_stuff[j]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return stuff
|
2018-01-21 22:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
2019-03-21 01:36:59 +00:00
|
|
|
player:set_hp(player:get_properties().hp_max)
|
2018-01-21 22:10:37 +00:00
|
|
|
give_initial_stuff(player)
|
|
|
|
end)
|
|
|
|
minetest.register_on_respawnplayer(give_initial_stuff)
|