Advertisement
NeonStranger

1

Aug 7th, 2022
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.33 KB | None | 0 0
  1. ----- Services -----
  2.  
  3. local CollectionService = game:GetService("CollectionService")
  4. local ServerScriptService = game:GetService("ServerScriptService")
  5. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  6. local Players = game:GetService("Players")
  7.  
  8. ----- Modules -----
  9.  
  10. local Modules = game:GetService("ServerScriptService"):WaitForChild("Modules")
  11. local ProfileService = require(Modules.ProfileService)
  12.  
  13. ----- Remotes -----
  14.  
  15. local Remotes = ReplicatedStorage:WaitForChild("Remotes")
  16. local RemoteFunctions = Remotes:WaitForChild("RemoteFunctions")
  17. local RemoteEvents = Remotes:WaitForChild("RemoteEvents")
  18. local BindableEvents = Remotes:WaitForChild("BindableEvents")
  19. local BindableFunctions = Remotes:WaitForChild("BindableFunctions")
  20.  
  21. local RequestData = RemoteFunctions:WaitForChild("RequestData")
  22. local ManageEmployees = RemoteEvents:WaitForChild("ManageEmployees")
  23. local ManageWebsites = RemoteEvents:WaitForChild("ManageWebsites")
  24. local ManageCampaigns = RemoteEvents:WaitForChild("ManageCampaigns")
  25.  
  26. ----- Tables and Information -----
  27.  
  28. --[[EmployeeName = {
  29.     Age,
  30.     Salary,
  31.     Level,
  32.     Skill,
  33.     CON,
  34.     Gender
  35.     }
  36. ]]
  37.  
  38. local ProfileTemplate = {
  39.     Cash = 0,
  40.     Employees = {
  41.         ["John Skywalker"] = {
  42.             "John Skywalker",
  43.             19,
  44.             10000,
  45.             15,
  46.             "Programmer"
  47.         }
  48.     },
  49.     Websites = {},
  50. }
  51.  
  52. ----- Profile Service -----
  53.  
  54. local ProfileStore = ProfileService.GetProfileStore("randomkey" , ProfileTemplate)
  55.  
  56. local Profiles = {}
  57.  
  58.  
  59. ----- Functions -----
  60.  
  61. function UpdateCash(Profile, Amount)
  62.     Profile.Data.Cash = Amount
  63.     print(Profile.Data.Cash)
  64. end
  65.  
  66. function HireEmployee(Player, Employee)
  67.     table.insert(Profiles[Player].Data["Employees"], Employee)
  68.     ManageEmployees:FireClient(Player, "Hire", Employee)
  69. end
  70.  
  71. function FireEmployee(Player, Employee)
  72.     table.remove(Profiles[Player].Data.Employees[Employee])
  73.     ManageEmployees:FireClient(Player, "Fire", Employee)
  74. end
  75.  
  76. local function LoadEmployees(Player)
  77.     local EmployeeList = Profiles[Player].Data.Employees
  78.  
  79.     print("Loading " .. Player.Name .. "'s employees...")
  80.  
  81.     --Send list to client for loading on gui
  82.     print(EmployeeList)
  83.     local Employee = "John Skywalker"
  84.     ManageEmployees:FireClient(Player, "Load", EmployeeList)
  85.     --FireEmployee(Player, Employee)    
  86. end
  87.  
  88. ----- Website -----
  89.  
  90.     --[[
  91.     local website = {
  92.    
  93.     [1] ["Name"] = DataGiven[1], -- Website Name
  94.     [2] ["Type"] = DataGiven[2], -- Website Type - "Social Media", "Shopping Platform", "Browser Game"
  95.     [3] ["OnlineUsers"] = 5,
  96.     [4] ["Users"] = 69,
  97.     [5] ["Features"] = {"feature1", "feature2"},
  98.     [6] ["FeatureLevels"] = {10,10},
  99.     [7] ["Framework"] = 1,
  100.     [8] ["CloudServers"] = 1,
  101.     [9] [Marketing Campaigns] = {{campaign1, 100buckaroos, newspaper, 19secsleft},{campaign2, newspaper, 100buckaroos, 19secsleft}}
  102.     }
  103.     ]]--
  104.  
  105. ----- Website -----
  106.  
  107. local function GetWebsite(Player, WebsiteName)
  108.     return Profiles[Player].Data.Websites[WebsiteName]
  109. end
  110.  
  111. local function LoadWebsites(Player)
  112.    
  113.     local WebsiteList = Profiles[Player].Data.Websites
  114.  
  115.     print("Loading " .. Player.Name .. "'s websites..")
  116.  
  117.     print(WebsiteList)
  118.     for _, Website in pairs(WebsiteList) do
  119.         ManageWebsites:FireClient(Player, "Write", Website)
  120.     end
  121. end
  122.  
  123. local function CreateWebsite(Player, WebsiteInfo)
  124.     local Website = {
  125.         WebsiteInfo[1],
  126.         WebsiteInfo[2],
  127.         1,
  128.         1,
  129.         {"Quinta do Tio Manel", "Quinta do Tio Jaquim"},
  130.         {10,10},
  131.         "DingDong",
  132.         1,
  133.         {
  134.             ["1312312312312"] = {
  135.                 "1312312312312",
  136.                 "Yo",
  137.                 "Noway",
  138.                 "420"
  139.             }
  140.         },
  141.     }
  142.     Profiles[Player].Data.Websites[Website[1]] = Website
  143.     print("Created website " .. Website[1])
  144.     ManageWebsites:FireClient(Player, "Create", Website)
  145. end
  146.  
  147. local function RemoveWebsite(Player, WebsiteName)
  148.     table.remove(Profiles[Player].Data.Websites[WebsiteName])
  149. end
  150.  
  151. local WebsiteActions = {
  152.     ["Create"] = CreateWebsite,
  153.     ["Remove"] = RemoveWebsite,
  154. }
  155.  
  156. local function ManageWebsite(Player, Action, Website)
  157.     WebsiteActions[Action](Player, Website)
  158. end
  159.  
  160. local function UpdateWebsiteList(Player)
  161.     ManageWebsites:FireClient(Player, "List" ,Profiles[Player].Data.Websites)
  162. end
  163.  
  164. ----- Connections -----
  165.  
  166. ManageWebsites.OnServerEvent:Connect(ManageWebsite)
  167.  
  168. ----- Campaigns -----
  169.  
  170. local function CreateCampaign(Player, Info)
  171.     local Campaign =
  172.         {
  173.             os.time(),
  174.             Info[2],
  175.             Info[3],
  176.             420
  177.         }
  178.     print("loading")
  179.     print(Profiles[Player].Data.Websites[Info[1][1]][9])
  180.     table.insert(Profiles[Player].Data.Websites[Info[1][1]][9], Campaign)
  181.     ManageCampaigns:FireClient(Player, "Create", Campaign)
  182. end
  183.  
  184. local function DeleteCampaign(Player, Info)
  185.     local WebsiteName = Info[1]
  186.     local CampaignId = Info[2]
  187.    
  188. end
  189.  
  190. local CampaignActions = {
  191.     ["Create"] = CreateCampaign,
  192.     ["Delete"] = DeleteCampaign,    
  193. }
  194.  
  195. local function ManageCampaign(Player, Action, Campaign)
  196.     CampaignActions[Action](Player, Campaign)
  197. end
  198.  
  199. ManageCampaigns.OnServerEvent:Connect(ManageCampaign)
  200.  
  201. local DataActions = {
  202.     ["Website"] = GetWebsite
  203. }
  204.  
  205.  
  206. local function DataRequest(Player, DataType, Data)
  207.     return DataActions[DataType](Player, Data)
  208. end
  209.  
  210. ----- Initialization -----
  211. local function LoadProfile(Player)
  212.     local Profile = ProfileStore:LoadProfileAsync("Player_" .. Player.UserId)
  213.     if Profile ~= nil then
  214.         Profile:AddUserId(Player.UserId) -- GDPR compliance
  215.         Profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
  216.         Profile:ListenToRelease(
  217.             function()
  218.                 Profiles[Player] = nil
  219.                 -- The profile could've been loaded on another Roblox server:
  220.                 Player:Kick("Please rejoin the experience.")
  221.             end
  222.         )
  223.         if Player:IsDescendantOf(Players) == true then
  224.             Profiles[Player] = Profile
  225.             -- A profile has been successfully loaded:
  226.             warn(Player.Name .. "'s profile was loaded successfully.")
  227.             warn("Initializing Data")
  228.             LoadEmployees(Player)
  229.         else
  230.             -- Player left before the profile loaded:
  231.             Profile:Release()
  232.         end
  233.     else
  234.         -- The profile couldn't be loaded possibly due to other
  235.         -- Roblox servers trying to load this profile at the same time:
  236.         Player:Kick("Please rejoin the experience.")
  237.     end
  238. end
  239.  
  240.  
  241. local function PlayerAdded(Player)
  242.     LoadProfile(Player)
  243.     repeat wait() until Profiles[Player].Data.Websites ~= nil
  244.     LoadWebsites(Player)
  245. end
  246.  
  247. ----- Connections -----
  248. RequestData.OnServerInvoke = DataRequest
  249.  
  250. Players.PlayerAdded:Connect(PlayerAdded)
  251.  
  252. Players.PlayerRemoving:Connect(
  253.     function(Player)
  254.         local Profile = Profiles[Player]
  255.         if Profile ~= nil then
  256.             Profile:Release()
  257.             warn(Player.Name .. "'s profile was released successfully.")
  258.         end
  259.     end
  260. )
  261.  
  262. ----- Loops -----
  263. while task.wait(1) do
  264.     for _, Player in pairs(Players:GetChildren()) do
  265.         UpdateWebsiteList(Player)
  266.     end
  267. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement