diff --git a/mods/ctf/ctf_classes/items.lua b/mods/ctf/ctf_classes/items.lua index 35fc344..dc76613 100644 --- a/mods/ctf/ctf_classes/items.lua +++ b/mods/ctf/ctf_classes/items.lua @@ -54,7 +54,7 @@ ctf_classes.register_on_changed(function(player, old, new) local items = new.properties.initial_stuff for i = 1, #items do - inv:add_item("main", ItemStack(items[i])) + give_initial_stuff.give_item(inv, ItemStack(items[i])) end end end) diff --git a/mods/other/give_initial_stuff/init.lua b/mods/other/give_initial_stuff/init.lua index bd1936c..992bd69 100644 --- a/mods/other/give_initial_stuff/init.lua +++ b/mods/other/give_initial_stuff/init.lua @@ -1,5 +1,15 @@ give_initial_stuff = {} +-- Add item to inv. Split item if count > stack_max using recursion +function give_initial_stuff.give_item(inv, item) + inv:add_item("main", item:take_item(item:get_stack_max())) + + -- If item isn't empty, add the leftovers again + if not item:is_empty() then + give_initial_stuff.give_item(inv, item) + end +end + setmetatable(give_initial_stuff, { __call = function(self, player) minetest.log("action", "Giving initial stuff to player " @@ -15,7 +25,7 @@ setmetatable(give_initial_stuff, { local items = give_initial_stuff.get_stuff(player) for _, item in pairs(items) do - inv:add_item("main", item) + give_initial_stuff.give_item(inv, ItemStack(item)) end end })