Advertisement
DevelopingLaw

Rockport developer

Dec 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. local HttpService = game:GetService("HttpService")
  2.  
  3. local DataStore = game:GetService("DataStoreService")
  4. local Fleet_Array = DataStore:GetDataStore("The_Fleet24")
  5.  
  6. local remote_function1 = Instance.new("RemoteFunction")
  7. remote_function1.Name = "Array_Giver"
  8. remote_function1.Parent = game.Workspace
  9.  
  10. local remote_function2 = Instance.new("RemoteFunction")
  11. remote_function2.Name = "Check_Vacancies"
  12. remote_function2.Parent = game.Workspace
  13.  
  14. local remote_function3 = Instance.new("RemoteFunction")
  15. remote_function3.Name = "Revival_DataStore"
  16. remote_function3.Parent = game.Workspace
  17.  
  18. local remote_function4 = Instance.new("RemoteFunction")
  19. remote_function4.Name = "Ship_Savior"
  20. remote_function4.Parent = game.Workspace
  21.  
  22. local remote_function5 = Instance.new("RemoteFunction")
  23. remote_function5.Name = "Add_Ship"
  24. remote_function5.Parent = game.Workspace
  25.  
  26. local remote_function6 = Instance.new("RemoteFunction")
  27. remote_function6.Name = "Add_Slot"
  28. remote_function6.Parent = game.Workspace
  29.  
  30. function get_ship_number()
  31. local count = 0
  32. local folder = game.ReplicatedStorage:WaitForChild("Ship_Customization"):GetChildren()
  33. for i=1, #folder do
  34. local ship = folder[i]:GetChildren()
  35. for k=1, #ship do
  36. if ship[k].ClassName == "Folder" then
  37. count = count+1
  38. end
  39. end
  40. end
  41. return count
  42. end
  43.  
  44. function re_arrange(r_a_rep)
  45. if r_a_rep[1][1] == nil then
  46. local holder1 = nil
  47. local count = nil
  48. for i=1, #r_a_rep do
  49. if r_a_rep[i][1] ~= nil then
  50. holder1 = r_a_rep[i][1]
  51. count = i
  52. end
  53. end
  54. r_a_rep[1][1] = holder1
  55. if count ~= nil then
  56. r_a_rep[count][1] = nil
  57. end
  58. end
  59. return r_a_rep
  60. end
  61.  
  62. function remote_function1.OnServerInvoke(player)--return fleet array
  63. local key = "user_" .. player.userId
  64. local fleet = Fleet_Array:GetAsync(key)
  65. local ourJSON = HttpService:JSONDecode(fleet)
  66. fleet = ourJSON
  67. fleet = re_arrange(fleet)
  68. ourJSON = HttpService:JSONEncode(fleet)
  69. fleet = ourJSON
  70. return fleet
  71. end
  72.  
  73. function remote_function2.OnServerInvoke(player, fleet)--return number of vacancies
  74. local key = "user_" .. player.userId
  75. local fleet = Fleet_Array:GetAsync(key)
  76. local ourJSON = HttpService:JSONDecode(fleet)
  77. fleet = ourJSON
  78.  
  79. local free_slot_count = 0
  80. local complimentary_slots = get_ship_number()
  81. local temp_count = 0
  82. --check if owed any new slots
  83. for i=1, #fleet do
  84. if fleet[i][2] == "Free" then
  85. temp_count = temp_count + 1
  86. end
  87. end
  88. if temp_count < complimentary_slots then
  89. local slot = {nil, "Free"} --{{ship_array, "Free"},}
  90. table.insert(fleet, slot)
  91. end
  92.  
  93. temp_count = 0
  94.  
  95. --find how many free slots are left
  96.  
  97. for i=1, #fleet do
  98. if fleet[i][1] == nil then
  99. temp_count = temp_count + 1
  100. end
  101. end
  102. free_slot_count = temp_count
  103. return free_slot_count
  104. end
  105.  
  106. function remote_function3.OnServerInvoke(player, aydee, value) --undestroy ships
  107.  
  108. --print(ship_array[9])
  109. local key = "user_" .. player.userId
  110. local fleet = Fleet_Array:GetAsync(key)
  111. local ourJSON = HttpService:JSONDecode(fleet)
  112. fleet = ourJSON
  113.  
  114. local chosen_ship_index = nil
  115. for i=1, #fleet do
  116. if fleet[i] ~= nil then
  117. if fleet[i][1] ~= nil then
  118. if fleet[i][1][18] ~= nil then
  119. if fleet[i][1][18] == aydee then
  120. fleet[i][1][16] = value
  121. end
  122. end
  123. end
  124. end
  125. end
  126.  
  127. ourJSON = HttpService:JSONEncode(fleet)
  128. Fleet_Array:SetAsync(key, ourJSON)
  129. return nil
  130. end
  131.  
  132. function remote_function4.OnServerInvoke(player, ship_array, kill) --update a current ship
  133.  
  134. --print(index)
  135. if ship_array ~= nil then
  136. local myJson = HttpService:JSONDecode(ship_array)
  137. ship_array = myJson
  138. end
  139. --print(ship_array[9])
  140. local key = "user_" .. player.userId
  141. local fleet = Fleet_Array:GetAsync(key)
  142. local ourJSON = HttpService:JSONDecode(fleet)
  143. fleet = ourJSON
  144. local index = 0
  145. --print("0")
  146. for i=1, #fleet do
  147. if ship_array ~= nil then
  148. --Hanprint("1")
  149. if ship_array[1]~= nil then
  150. --print("1.5")
  151. if ship_array[1][18] ~= nil then
  152. --print("2")
  153. if fleet ~= nil then
  154. if fleet[i] ~= nil then
  155. --print("2.5")
  156. if fleet[i][1] ~= nil then
  157. --print("3")
  158. if ship_array[1][18] == fleet[i][1][18] then
  159. --print("MADE IT!")
  160. fleet[i][1] = ship_array[1]
  161. if kill == true then
  162. fleet[i][1] = nil
  163. end
  164. --print("Loaded Level: "..ship_array[1][6][2])
  165. --print("Other value: "..ship_array[1][6][1])
  166. break
  167. end
  168. end
  169. end
  170. end
  171. end
  172. --else
  173. -- fleet[i][1] = ship_array
  174. -- break
  175. end
  176. end
  177. end
  178. --print("Wah"..fleet[index][1][1])
  179. ourJSON = HttpService:JSONEncode(fleet)
  180. Fleet_Array:SetAsync(key, ourJSON)
  181. return nil
  182. end
  183.  
  184. function remote_function5.OnServerInvoke(player, ship_array) --save a new ship
  185. local myJson = HttpService:JSONDecode(ship_array)
  186. ship_array = myJson
  187. --print("'Hi")
  188. local freedom_number = get_ship_number()
  189.  
  190. local key = "user_" .. player.userId
  191. local fleet = Fleet_Array:GetAsync(key)
  192. local ourJSON = HttpService:JSONDecode(fleet)
  193. fleet = ourJSON
  194. --print("You don't gotta go to")
  195. for i=1, #fleet do
  196. if fleet[i][1] == nil then
  197. --print("Work")
  198. --if kill == false then
  199. fleet[i][1] = ship_array
  200. --else
  201. -- fleet[i][1] = nil
  202. --end
  203. break
  204. end
  205. end
  206. --print("You can work from home")
  207. local myJson = HttpService:JSONEncode(fleet)
  208. fleet = myJson
  209. Fleet_Array:SetAsync(key, fleet)
  210. --print("Ohhh ohhh")
  211. end
  212.  
  213. function remote_function6.OnServerInvoke(player) --add a new slot
  214. local key = "user_" .. player.userId
  215.  
  216. local fleet = Fleet_Array:GetAsync(key)
  217. local ourJSON = HttpService:JSONDecode(fleet)
  218. fleet = ourJSON
  219.  
  220. local slot = {nil, "Purchased"} --{{ship_array, "Free"},}
  221. table.insert(fleet, slot)
  222.  
  223. local myJson = HttpService:JSONEncode(fleet)
  224. fleet = myJson
  225. Fleet_Array:SetAsync(key, fleet)
  226. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement