init.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. refill = refill or {}
  2. refill.modpath = minetest.get_modpath("refill")
  3. function refill.refill_all(pname)
  4. local player = minetest.get_player_by_name(pname)
  5. if not player then
  6. return
  7. end
  8. local inv = player:get_inventory()
  9. local sz = inv:get_size("main")
  10. local total = 0
  11. for i = 1, sz, 1 do
  12. local stack = inv:get_stack("main", i)
  13. if stack:get_count() > 0 then
  14. stack:set_count(stack:get_stack_max())
  15. inv:set_stack("main", i, stack)
  16. total = total + 1
  17. end
  18. end
  19. minetest.chat_send_player(pname, "# Server: " .. total .. " inventory stack(s) refilled.")
  20. end
  21. function refill.refill_single(pname)
  22. local player = minetest.get_player_by_name(pname)
  23. if not player then
  24. return
  25. end
  26. local stack = player:get_wielded_item()
  27. if stack:get_count() > 0 then
  28. stack:set_count(stack:get_stack_max())
  29. player:set_wielded_item(stack)
  30. minetest.chat_send_player(pname, "# Server: Stack refilled.")
  31. else
  32. minetest.chat_send_player(pname, "# Server: No wielded stack!")
  33. easyvend.sound_error(pname)
  34. end
  35. end
  36. if not refill.run_once then
  37. minetest.register_privilege("refill", {
  38. description = "User is allowed infinite item stacks.",
  39. give_to_singleplayer = false,
  40. })
  41. minetest.register_chatcommand("refill", {
  42. params = "[all]",
  43. description = "Refill item stacks to max capacity.",
  44. privs = {refill = true},
  45. func = function(pname, param)
  46. param = string.trim(param)
  47. if param == "all" then
  48. refill.refill_all(pname)
  49. return true
  50. end
  51. refill.refill_single(pname)
  52. return true
  53. end,
  54. })
  55. local c = "refill:core"
  56. local f = refill.modpath .. "/init.lua"
  57. reload.register_file(c, f, false)
  58. refill.run_once = true
  59. end