Advertisement
Pinkl

Untitled

Jan 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. function onSave()
  2. local data_to_save = {saved_count1 = countHP, saved_count2 = countMP}
  3. saved_data = JSON.encode(data_to_save)
  4. return saved_data
  5. end
  6.  
  7. --Loads the saved data then creates the buttons
  8. function onload(saved_data)
  9. generateButtonParamitersHP()
  10. --Checks if there is a saved data. If there is, it gets the saved value for 'count'
  11. if saved_data != '' then
  12. local loaded_data = JSON.decode(saved_data)
  13. countHP = loaded_data.saved_count1
  14.  
  15. else
  16. --If there wasn't saved data, the default value is set to 10.
  17.  
  18. countHP = 10
  19. end
  20.  
  21. generateButtonParamitersMP()
  22. --Checks if there is a saved data. If there is, it gets the saved value for 'count'
  23. if saved_data != '' then
  24. local loaded_data = JSON.decode(saved_data)
  25. countMP = loaded_data.saved_count2
  26.  
  27. else
  28. --If there wasn't saved data, the default value is set to 10.
  29.  
  30. countMP = 10
  31. end
  32.  
  33. b_displayHP.label = tostring(countHP)
  34. b_displayHP.font_size = 70
  35.  
  36.  
  37. b_displayMP.label = tostring(countMP)
  38. b_displayMP.font_size = 70
  39.  
  40. self.createButton(b_displayHP)
  41. self.createButton(b_plusHP)
  42. self.createButton(b_minusHP)
  43. self.createButton(b_plusHP5)
  44. self.createButton(b_minusHP5)
  45. self.createButton(b_displayMP)
  46. self.createButton(b_plusMP)
  47. self.createButton(b_minusMP)
  48. self.createButton(b_plusMP5)
  49. self.createButton(b_minusMP5)
  50. end
  51.  
  52. function increaseMP()
  53. countMP = countMP + 1
  54. updateDisplayMP()
  55. end
  56.  
  57.  
  58. function decreaseMP()
  59. --Prevents countMP from going below 0
  60. if countMP > 0 then
  61. countMP = countMP - 1
  62. updateDisplayMP()
  63. end
  64. end
  65.  
  66.  
  67. function increaseMP5()
  68. countMP = countMP + 5
  69. updateDisplayMP()
  70. end
  71.  
  72.  
  73. function decreaseMP5()
  74. --Prevents countMP from going below 0
  75. if countMP > 4 then
  76. countMP = countMP - 5
  77. else
  78. countMP = 0
  79. end
  80. updateDisplayMP()
  81. end
  82.  
  83. function customSetMP()
  84. local descriptionMP = self.getDescription()
  85. if descriptionMP != '' and type(tonumber(descriptionMP)) == 'number' then
  86. self.setDescription('')
  87. countMP = tonumber(descriptionMP)
  88. updateDisplayMP()
  89. end
  90. end
  91.  
  92.  
  93. function updateDisplayMP()
  94.  
  95.  
  96. b_displayMP.font_size = 70
  97. b_displayMP.label = tostring(countMP)
  98. self.editButton(b_displayMP)
  99. end
  100.  
  101. function increaseHP()
  102. countHP = countHP + 1
  103. updateDisplayHP()
  104. end
  105.  
  106.  
  107. function decreaseHP()
  108. --Prevents countHP from going below 0
  109. if countHP > 0 then
  110. countHP = countHP - 1
  111. updateDisplayHP()
  112. end
  113. end
  114.  
  115.  
  116. function increaseHP5()
  117. countHP = countHP + 5
  118. updateDisplayHP()
  119. end
  120.  
  121.  
  122. function decreaseHP5()
  123. --Prevents countHP from going below 0
  124. if countHP > 4 then
  125. countHP = countHP - 5
  126. else
  127. countHP = 0
  128. end
  129. updateDisplayHP()
  130. end
  131.  
  132. function customSetHP()
  133. local descriptionHP = self.getDescription()
  134. if descriptionHP != '' and type(tonumber(descriptionHP)) == 'number' then
  135. self.setDescription('')
  136. countHP = tonumber(descriptionHP)
  137. updateDisplayHP()
  138. end
  139. end
  140.  
  141.  
  142. function updateDisplayHP()
  143. b_displayHP.font_size = 70
  144. b_displayHP.label = tostring(countHP)
  145. self.editButton(b_displayHP)
  146. end
  147.  
  148.  
  149. function generateButtonParamitersHP()
  150. b_displayHP = {
  151. index = 0, click_function = 'customSetHP', function_owner = self, label = '',
  152. position = {0,0.1,0}, width = 600, height = 600, font_size = 500
  153. }
  154. b_plusHP = {
  155. click_function = 'increaseHP', function_owner = self, label = '+1',
  156. position = {0.75,0.1,0.26}, width = 150, height = 300, font_size = 100
  157. }
  158. b_minusHP = {
  159. click_function = 'decreaseHP', function_owner = self, label = '-1',
  160. position = {-0.75,0.1,0.26}, width = 150, height = 300, font_size = 100
  161. }
  162. b_plusHP5 = {
  163. click_function = 'increaseHP5', function_owner = self, label = '+5',
  164. position = {0.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
  165. }
  166. b_minusHP5 = {
  167. click_function = 'decreaseHP5', function_owner = self, label = '-5',
  168. position = {-0.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
  169. }
  170. end
  171. function generateButtonParamitersMP()
  172. b_displayMP = {
  173. index = 5, click_function = 'customSetMP', function_owner = self, label = '',
  174. position = {2,0.1,0}, width = 600, height = 600, font_size = 500
  175. }
  176. b_plusMP = {
  177. click_function = 'increaseMP', function_owner = self, label = '+1',
  178. position = {2.75,0.1,0.26}, width = 150, height = 300, font_size = 100
  179. }
  180. b_minusMP = {
  181. click_function = 'decreaseMP', function_owner = self, label = '-1',
  182. position = {-2.75,0.1,0.26}, width = 150, height = 300, font_size = 100
  183. }
  184. b_plusMP5 = {
  185. click_function = 'increaseMP5', function_owner = self, label = '+5',
  186. position = {2.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
  187. }
  188. b_minusMP5 = {
  189. click_function = 'decreaseMP5', function_owner = self, label = '-5',
  190. position = {-2.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
  191. }
  192. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement