init.lua 1.1 KB

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