Player skin mod, supporting unified_inventory, sfinv and smart_inventory https://content.minetest.net/packages/bell07/skinsdb/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1KB

  1. local S = minetest.get_translator("skinsdb")
  2. local function show_selection_formspec(player)
  3. local context = skins.get_formspec_context(player)
  4. local name = player:get_player_name()
  5. local skin = skins.get_player_skin(player)
  6. local formspec = "size[8,8]"..skins.get_skin_info_formspec(skin)
  7. formspec = formspec..skins.get_skin_selection_formspec(player, context, 3.5)
  8. minetest.show_formspec(name, 'skinsdb_show_ui', formspec)
  9. end
  10. minetest.register_chatcommand("skinsdb", {
  11. params = "[set] <skin key> | show [<skin key>] | list | list private | list public | [ui]",
  12. description = S("Show, list or set player's skin"),
  13. func = function(name, param)
  14. local player = minetest.get_player_by_name(name)
  15. if not player then
  16. return false, S("Player not found")
  17. end
  18. -- parse command line
  19. local command, parameter
  20. local words = param:split(" ")
  21. local word = words[1]
  22. if word == 'set' or word == 'list' or word == 'show' or word == 'ui' then
  23. command = word
  24. parameter = words[2]
  25. elseif skins.get(word) then
  26. command = 'set'
  27. parameter = word
  28. elseif not word then
  29. command = 'ui'
  30. else
  31. return false, S("unknown command").." "..word..", "..S("see /help skinsdb for supported parameters")
  32. end
  33. if command == "set" then
  34. if parameter then
  35. local success = skins.set_player_skin(player, parameter)
  36. if success then
  37. return true, S("skin set to").." "..parameter
  38. else
  39. return false, S("invalid skin").." "..parameter
  40. end
  41. else return false, S("Requires skin key")
  42. end
  43. elseif command == "list" then
  44. local list
  45. if parameter == "private" then
  46. list = skins.get_skinlist_with_meta("playername", name)
  47. elseif parameter == "public" then
  48. list = skins.get_skinlist_for_player()
  49. elseif not parameter then
  50. list = skins.get_skinlist_for_player(name)
  51. else
  52. return false, S("unknown parameter"), parameter
  53. end
  54. local current_skin_key = skins.get_player_skin(player):get_key()
  55. for _, skin in ipairs(list) do
  56. local info = skin:get_key().." - "
  57. ..S("Name").."="..skin:get_meta_string("name").." "
  58. ..S("Author").."="..skin:get_meta_string("author").." "
  59. ..S("License").."="..skin:get_meta_string("license")
  60. if skin:get_key() == current_skin_key then
  61. info = minetest.colorize("#00FFFF", info)
  62. end
  63. minetest.chat_send_player(name, info)
  64. end
  65. elseif command == "show" then
  66. local skin
  67. if parameter then
  68. skin = skins.get(parameter)
  69. else
  70. skin = skins.get_player_skin(player)
  71. end
  72. if not skin then
  73. return false, S("invalid skin")
  74. end
  75. local formspec = "size[8,3]"..skins.get_skin_info_formspec(skin)
  76. minetest.show_formspec(name, 'skinsdb_show_skin', formspec)
  77. elseif command == "ui" then
  78. show_selection_formspec(player)
  79. end
  80. end,
  81. })
  82. minetest.register_on_player_receive_fields(function(player, formname, fields)
  83. if formname ~= "skinsdb_show_ui" then
  84. return
  85. end
  86. local context = skins.get_formspec_context(player)
  87. local action = skins.on_skin_selection_receive_fields(player, context, fields)
  88. if action == 'set' then
  89. minetest.close_formspec(player:get_player_name(), formname)
  90. elseif action == 'page' then
  91. show_selection_formspec(player)
  92. end
  93. end)