multiskin.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. MULTISKIN_DEFAULT_SKIN = "character.png"
  2. MULTISKIN_TRANS = "lottarmor_trans.png"
  3. multiskin = {}
  4. local skin_mod = nil
  5. if minetest.get_modpath("skins") then
  6. skin_mod = "skins"
  7. elseif minetest.get_modpath("simple_skins") then
  8. skin_mod = "simple_skins"
  9. elseif minetest.get_modpath("u_skins") then
  10. skin_mod = "u_skins"
  11. elseif minetest.get_modpath("wardrobe") then
  12. skin_mod = "wardrobe"
  13. end
  14. function multiskin:init(player)
  15. default.player_set_model(player, "lottarmor_player_character.b3d")
  16. local name = player:get_player_name()
  17. multiskin[name] = {
  18. skin = MULTISKIN_DEFAULT_SKIN,
  19. armor = MULTISKIN_TRANS,
  20. wielditem = MULTISKIN_TRANS,
  21. clothing = MULTISKIN_TRANS,
  22. }
  23. if skin_mod == "skins" then
  24. local skin = skins.skins[name]
  25. if skin and skins.get_type(skin) == skins.type.MODEL then
  26. multiskin[name].skin = skin..".png"
  27. end
  28. elseif skin_mod == "simple_skins" then
  29. local skin = skins.skins[name]
  30. if skin then
  31. multiskin[name].skin = skin..".png"
  32. end
  33. elseif skin_mod == "u_skins" then
  34. local skin = u_skins.u_skins[name]
  35. if skin and u_skins.get_type(skin) == u_skins.type.MODEL then
  36. multiskin[name].skin = skin..".png"
  37. end
  38. elseif skin_mod == "wardrobe" then
  39. local skin = wardrobe.playerSkins[name]
  40. if skin then
  41. multiskin[name].skin = skin
  42. end
  43. end
  44. if minetest.get_modpath("player_textures") then
  45. local filename = minetest.get_modpath("player_textures").."/textures/player_"..name
  46. local f = io.open(filename..".png")
  47. if f then
  48. f:close()
  49. multiskin[name].skin = "player_"..name..".png"
  50. end
  51. end
  52. end
  53. function multiskin:update_player_visuals(player)
  54. if not player then
  55. return
  56. end
  57. local name = player:get_player_name()
  58. if multiskin[name] then
  59. default.player_set_textures(player, {
  60. multiskin[name].skin,
  61. multiskin[name].armor,
  62. multiskin[name].wielditem,
  63. multiskin[name].clothing,
  64. })
  65. end
  66. end
  67. function multiskin:get_skin_name(name)
  68. local skin = nil
  69. if skin_mod == "skins" or skin_mod == "simple_skins" then
  70. skin = skins.skins[name]
  71. elseif skin_mod == "u_skins" then
  72. skin = u_skins.u_skins[name]
  73. elseif skin_mod == "wardrobe" then
  74. skin = string.gsub(wardrobe.playerSkins[name], "%.png$","")
  75. end
  76. return skin or MULTISKIN_DEFAULT_SKIN
  77. end
  78. function multiskin:get_preview(name)
  79. if skin_mod == "u_skins" then
  80. return multiskin:get_skin_name(name).."_preview.png"
  81. end
  82. end
  83. minetest.register_on_player_receive_fields(function(player, formname, fields)
  84. local name = player:get_player_name()
  85. for field, _ in pairs(fields) do
  86. if string.find(field, "skins_set") then
  87. minetest.after(0, function(player)
  88. local skin = multiskin:get_skin_name(name)
  89. if skin then
  90. multiskin[name].skin = skin..".png"
  91. multiskin:update_player_visuals(player)
  92. end
  93. end, player)
  94. end
  95. end
  96. end)
  97. default.player_register_model("lottarmor_player_character.b3d", {
  98. animation_speed = 30,
  99. textures = {
  100. MULTISKIN_DEFAULT_SKIN,
  101. MULTISKIN_TRANS,
  102. MULTISKIN_TRANS,
  103. MULTISKIN_TRANS,
  104. },
  105. animations = {
  106. stand = {x=0, y=79},
  107. lay = {x=162, y=166},
  108. walk = {x=168, y=187},
  109. mine = {x=189, y=198},
  110. walk_mine = {x=200, y=219},
  111. sit = {x=81, y=160},
  112. },
  113. })