init.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. local stuff_string = minetest.settings:get("initial_stuff") or
  2. "default:pick_steel,default:axe_steel,default:shovel_steel," ..
  3. "default:torch 99,default:cobble 99"
  4. give_initial_stuff = {
  5. items = {}
  6. }
  7. function give_initial_stuff.give(player)
  8. minetest.log("action",
  9. "Giving initial stuff to player " .. player:get_player_name())
  10. local inv = player:get_inventory()
  11. for _, stack in ipairs(give_initial_stuff.items) do
  12. inv:add_item("main", stack)
  13. end
  14. end
  15. function give_initial_stuff.add(stack)
  16. give_initial_stuff.items[#give_initial_stuff.items + 1] = ItemStack(stack)
  17. end
  18. function give_initial_stuff.clear()
  19. give_initial_stuff.items = {}
  20. end
  21. function give_initial_stuff.add_from_csv(str)
  22. local items = str:split(",")
  23. for _, itemname in ipairs(items) do
  24. give_initial_stuff.add(itemname)
  25. end
  26. end
  27. function give_initial_stuff.set_list(list)
  28. give_initial_stuff.items = list
  29. end
  30. function give_initial_stuff.get_list()
  31. return give_initial_stuff.items
  32. end
  33. give_initial_stuff.add_from_csv(stuff_string)
  34. if minetest.settings:get_bool("give_initial_stuff") then
  35. minetest.register_on_newplayer(give_initial_stuff.give)
  36. end