change_skin.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. gamer.temp_tone = {}
  2. gamer.temp_eyes = {}
  3. gamer.temp_mouth = {}
  4. local function skin_selection(tone, eyes, mouth)
  5. local formspec =
  6. 'formspec_version[3]'..
  7. 'size[9,7]'..
  8. 'textarea[4,.5;4.5,2;;;Use the arrows to adjust switch between tones/colors. Initial setup is free, changes thereafter cost 500XP.]'..
  9. 'model[.5,.5;3,6;player model;gamer_model.b3d;gamer_skin_'..tone..'.png^gamer_eyes_'..eyes..'.png^gamer_mouth_'..mouth..'.png,clothing_briefs.png,blank.png,blank.png;0,180]'..
  10. 'button[4,2.75;1,.5;skin_sub;<]'..
  11. 'button[5,2.75;1,.5;skin_add;>]'..
  12. 'label[6.5,3;Skin Tone]'..
  13. 'button[4,3.75;1,.5;eyes_sub;<]'..
  14. 'button[5,3.75;1,.5;eyes_add;>]'..
  15. 'label[6.5,4;Eyes]'..
  16. 'button[4,4.75;1,.5;mouth_sub;<]'..
  17. 'button[5,4.75;1,.5;mouth_add;>]'..
  18. 'label[6.5,5;Mouth]'..
  19. 'button_exit[4,5.5;2,1;exit;Close]'..
  20. 'button_exit[6.5,5.5;2,1;save;Save]'
  21. return formspec
  22. end
  23. minetest.register_chatcommand('skin', {
  24. description = 'Change your skin.',
  25. func = function(name)
  26. local player = minetest.get_player_by_name(name)
  27. local player_attributes = player:get_meta()
  28. local tone = player_attributes:get_int('tone')
  29. local eyes = player_attributes:get_int('eyes')
  30. local mouth = player_attributes:get_int('mouth')
  31. if tone == 0 then
  32. gamer.temp_tone[name] = 4
  33. else
  34. gamer.temp_tone[name] = tone
  35. end
  36. if eyes == 0 then
  37. gamer.temp_eyes[name] = 1
  38. else
  39. gamer.temp_eyes[name] = eyes
  40. end
  41. if mouth == 0 then
  42. gamer.temp_mouth[name] = 1
  43. else
  44. gamer.temp_mouth[name] = mouth
  45. end
  46. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  47. end
  48. })
  49. minetest.register_on_player_receive_fields(function(player, formname, fields)
  50. if formname == 'gamer:skin_selection' then
  51. local name = player:get_player_name()
  52. local player_attributes = player:get_meta()
  53. local tone = gamer.temp_tone[name]
  54. local eyes = gamer.temp_eyes[name]
  55. local mouth = gamer.temp_mouth[name]
  56. if fields.skin_sub then
  57. if tone > 1 then
  58. gamer.temp_tone[name] = gamer.temp_tone[name] - 1
  59. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  60. end
  61. elseif fields.skin_add then
  62. if tone < 7 then
  63. gamer.temp_tone[name] = gamer.temp_tone[name] + 1
  64. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  65. end
  66. elseif fields.eyes_sub then
  67. if eyes > 1 then
  68. gamer.temp_eyes[name] = gamer.temp_eyes[name] - 1
  69. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  70. end
  71. elseif fields.eyes_add then
  72. if eyes < 6 then
  73. gamer.temp_eyes[name] = gamer.temp_eyes[name] + 1
  74. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  75. end
  76. elseif fields.mouth_sub then
  77. if mouth > 1 then
  78. gamer.temp_mouth[name] = gamer.temp_mouth[name] - 1
  79. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  80. end
  81. elseif fields.mouth_add then
  82. if mouth < 8 then
  83. gamer.temp_mouth[name] = gamer.temp_mouth[name] + 1
  84. minetest.show_formspec(name, 'gamer:skin_selection', skin_selection(gamer.temp_tone[name], gamer.temp_eyes[name], gamer.temp_mouth[name]))
  85. end
  86. elseif fields.save then
  87. local old_tone = player_attributes:get_int('tone')
  88. if old_tone ~= 0 then
  89. if lobby.take_xp(player, 500) then
  90. local tone = gamer.temp_tone[name]
  91. local eyes = gamer.temp_eyes[name]
  92. local mouth = gamer.temp_mouth[name]
  93. local skin_col = 'gamer_skin_'..tone..'.png^gamer_eyes_'..eyes..'.png^gamer_mouth_'..mouth..'.png'
  94. player_attributes:set_int('tone', tone)
  95. player_attributes:set_int('eyes', eyes)
  96. player_attributes:set_int('mouth', mouth)
  97. gamer.player_textures[name] = skin_col
  98. gamer.get_clothes(player)
  99. minetest.chat_send_player(name, 'Skin tone updated! Now buy some clothes from the shop.')
  100. gamer.save_skins()
  101. else
  102. minetest.chat_send_player(name, 'You need more XP!')
  103. end
  104. else
  105. local tone = gamer.temp_tone[name]
  106. local eyes = gamer.temp_eyes[name]
  107. local mouth = gamer.temp_mouth[name]
  108. local skin_col = 'gamer_skin_'..tone..'.png^gamer_eyes_'..eyes..'.png^gamer_mouth_'..mouth..'.png'
  109. player_attributes:set_int('tone', tone)
  110. player_attributes:set_int('eyes', eyes)
  111. player_attributes:set_int('mouth', mouth)
  112. gamer.player_textures[name] = skin_col
  113. gamer.get_clothes(player)
  114. minetest.chat_send_player(name, 'Skin tone updated! Now buy some clothes from the shop.')
  115. gamer.save_skins()
  116. end
  117. end
  118. end
  119. end)