Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local HttpService = game:GetService("HttpService")
- local DataStore = game:GetService("DataStoreService")
- local Fleet_Array = DataStore:GetDataStore("The_Fleet24")
- local remote_function1 = Instance.new("RemoteFunction")
- remote_function1.Name = "Array_Giver"
- remote_function1.Parent = game.Workspace
- local remote_function2 = Instance.new("RemoteFunction")
- remote_function2.Name = "Check_Vacancies"
- remote_function2.Parent = game.Workspace
- local remote_function3 = Instance.new("RemoteFunction")
- remote_function3.Name = "Revival_DataStore"
- remote_function3.Parent = game.Workspace
- local remote_function4 = Instance.new("RemoteFunction")
- remote_function4.Name = "Ship_Savior"
- remote_function4.Parent = game.Workspace
- local remote_function5 = Instance.new("RemoteFunction")
- remote_function5.Name = "Add_Ship"
- remote_function5.Parent = game.Workspace
- local remote_function6 = Instance.new("RemoteFunction")
- remote_function6.Name = "Add_Slot"
- remote_function6.Parent = game.Workspace
- function get_ship_number()
- local count = 0
- local folder = game.ReplicatedStorage:WaitForChild("Ship_Customization"):GetChildren()
- for i=1, #folder do
- local ship = folder[i]:GetChildren()
- for k=1, #ship do
- if ship[k].ClassName == "Folder" then
- count = count+1
- end
- end
- end
- return count
- end
- function re_arrange(r_a_rep)
- if r_a_rep[1][1] == nil then
- local holder1 = nil
- local count = nil
- for i=1, #r_a_rep do
- if r_a_rep[i][1] ~= nil then
- holder1 = r_a_rep[i][1]
- count = i
- end
- end
- r_a_rep[1][1] = holder1
- if count ~= nil then
- r_a_rep[count][1] = nil
- end
- end
- return r_a_rep
- end
- function remote_function1.OnServerInvoke(player)--return fleet array
- local key = "user_" .. player.userId
- local fleet = Fleet_Array:GetAsync(key)
- local ourJSON = HttpService:JSONDecode(fleet)
- fleet = ourJSON
- fleet = re_arrange(fleet)
- ourJSON = HttpService:JSONEncode(fleet)
- fleet = ourJSON
- return fleet
- end
- function remote_function2.OnServerInvoke(player, fleet)--return number of vacancies
- local key = "user_" .. player.userId
- local fleet = Fleet_Array:GetAsync(key)
- local ourJSON = HttpService:JSONDecode(fleet)
- fleet = ourJSON
- local free_slot_count = 0
- local complimentary_slots = get_ship_number()
- local temp_count = 0
- --check if owed any new slots
- for i=1, #fleet do
- if fleet[i][2] == "Free" then
- temp_count = temp_count + 1
- end
- end
- if temp_count < complimentary_slots then
- local slot = {nil, "Free"} --{{ship_array, "Free"},}
- table.insert(fleet, slot)
- end
- temp_count = 0
- --find how many free slots are left
- for i=1, #fleet do
- if fleet[i][1] == nil then
- temp_count = temp_count + 1
- end
- end
- free_slot_count = temp_count
- return free_slot_count
- end
- function remote_function3.OnServerInvoke(player, aydee, value) --undestroy ships
- --print(ship_array[9])
- local key = "user_" .. player.userId
- local fleet = Fleet_Array:GetAsync(key)
- local ourJSON = HttpService:JSONDecode(fleet)
- fleet = ourJSON
- local chosen_ship_index = nil
- for i=1, #fleet do
- if fleet[i] ~= nil then
- if fleet[i][1] ~= nil then
- if fleet[i][1][18] ~= nil then
- if fleet[i][1][18] == aydee then
- fleet[i][1][16] = value
- end
- end
- end
- end
- end
- ourJSON = HttpService:JSONEncode(fleet)
- Fleet_Array:SetAsync(key, ourJSON)
- return nil
- end
- function remote_function4.OnServerInvoke(player, ship_array, kill) --update a current ship
- --print(index)
- if ship_array ~= nil then
- local myJson = HttpService:JSONDecode(ship_array)
- ship_array = myJson
- end
- --print(ship_array[9])
- local key = "user_" .. player.userId
- local fleet = Fleet_Array:GetAsync(key)
- local ourJSON = HttpService:JSONDecode(fleet)
- fleet = ourJSON
- local index = 0
- --print("0")
- for i=1, #fleet do
- if ship_array ~= nil then
- --Hanprint("1")
- if ship_array[1]~= nil then
- --print("1.5")
- if ship_array[1][18] ~= nil then
- --print("2")
- if fleet ~= nil then
- if fleet[i] ~= nil then
- --print("2.5")
- if fleet[i][1] ~= nil then
- --print("3")
- if ship_array[1][18] == fleet[i][1][18] then
- --print("MADE IT!")
- fleet[i][1] = ship_array[1]
- if kill == true then
- fleet[i][1] = nil
- end
- --print("Loaded Level: "..ship_array[1][6][2])
- --print("Other value: "..ship_array[1][6][1])
- break
- end
- end
- end
- end
- end
- --else
- -- fleet[i][1] = ship_array
- -- break
- end
- end
- end
- --print("Wah"..fleet[index][1][1])
- ourJSON = HttpService:JSONEncode(fleet)
- Fleet_Array:SetAsync(key, ourJSON)
- return nil
- end
- function remote_function5.OnServerInvoke(player, ship_array) --save a new ship
- local myJson = HttpService:JSONDecode(ship_array)
- ship_array = myJson
- --print("'Hi")
- local freedom_number = get_ship_number()
- local key = "user_" .. player.userId
- local fleet = Fleet_Array:GetAsync(key)
- local ourJSON = HttpService:JSONDecode(fleet)
- fleet = ourJSON
- --print("You don't gotta go to")
- for i=1, #fleet do
- if fleet[i][1] == nil then
- --print("Work")
- --if kill == false then
- fleet[i][1] = ship_array
- --else
- -- fleet[i][1] = nil
- --end
- break
- end
- end
- --print("You can work from home")
- local myJson = HttpService:JSONEncode(fleet)
- fleet = myJson
- Fleet_Array:SetAsync(key, fleet)
- --print("Ohhh ohhh")
- end
- function remote_function6.OnServerInvoke(player) --add a new slot
- local key = "user_" .. player.userId
- local fleet = Fleet_Array:GetAsync(key)
- local ourJSON = HttpService:JSONDecode(fleet)
- fleet = ourJSON
- local slot = {nil, "Purchased"} --{{ship_array, "Free"},}
- table.insert(fleet, slot)
- local myJson = HttpService:JSONEncode(fleet)
- fleet = myJson
- Fleet_Array:SetAsync(key, fleet)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement