init.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. clear_inventory = clear_inventory or {}
  2. clear_inventory.modpath = minetest.get_modpath("clear_inventory")
  3. function clear_inventory.clear_primary_inventories(player)
  4. local inv = player:get_inventory()
  5. inv:set_list("craft", {})
  6. inv:set_list("craftpreview", {})
  7. inv:set_list("craftresult", {})
  8. local main = inv:get_list("main")
  9. for k, v in ipairs(main) do
  10. if not passport.is_passport(v:get_name()) then
  11. v:set_count(0)
  12. v:set_name("")
  13. end
  14. end
  15. inv:set_list("main", main)
  16. map.update_inventory_info(player:get_player_name())
  17. end
  18. function clear_inventory.clear(name, param)
  19. local player
  20. if not param or param == "" then
  21. player = minetest.get_player_by_name(name)
  22. elseif param and param ~= "" then
  23. player = minetest.get_player_by_name(param)
  24. else
  25. return
  26. end
  27. if not player then
  28. minetest.chat_send_player(name, "# Server: Player not found!")
  29. return
  30. end
  31. -- Actually clear the player's inventory!
  32. clear_inventory.clear_primary_inventories(player)
  33. -- Report to player.
  34. minetest.chat_send_player(name, "# Server: Player <" .. rename.gpn(player:get_player_name()) .. ">'s inventory cleared!")
  35. end
  36. if not clear_inventory.registered then
  37. minetest.register_privilege("clear_inventory", {
  38. description = "Player can trash all items in their inventory.",
  39. give_to_singleplayer = false,
  40. })
  41. minetest.register_chatcommand("clearinv", {
  42. params = "";
  43. description = "Clear your inventory or another player's inventory.",
  44. privs = {clear_inventory=true},
  45. func = function(...)
  46. return clear_inventory.clear(...)
  47. end,
  48. })
  49. local c = "clear_inventory:core"
  50. local f = clear_inventory.modpath .. "/init.lua"
  51. reload.register_file(c, f, false)
  52. clear_inventory.registered = true
  53. end