Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----- Services -----
- local CollectionService = game:GetService("CollectionService")
- local ServerScriptService = game:GetService("ServerScriptService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- ----- Modules -----
- local Modules = game:GetService("ServerScriptService"):WaitForChild("Modules")
- local ProfileService = require(Modules.ProfileService)
- ----- Remotes -----
- local Remotes = ReplicatedStorage:WaitForChild("Remotes")
- local RemoteFunctions = Remotes:WaitForChild("RemoteFunctions")
- local RemoteEvents = Remotes:WaitForChild("RemoteEvents")
- local BindableEvents = Remotes:WaitForChild("BindableEvents")
- local BindableFunctions = Remotes:WaitForChild("BindableFunctions")
- local RequestData = RemoteFunctions:WaitForChild("RequestData")
- local ManageEmployees = RemoteEvents:WaitForChild("ManageEmployees")
- local ManageWebsites = RemoteEvents:WaitForChild("ManageWebsites")
- local ManageCampaigns = RemoteEvents:WaitForChild("ManageCampaigns")
- ----- Tables and Information -----
- --[[EmployeeName = {
- Age,
- Salary,
- Level,
- Skill,
- CON,
- Gender
- }
- ]]
- local ProfileTemplate = {
- Cash = 0,
- Employees = {
- ["John Skywalker"] = {
- "John Skywalker",
- 19,
- 10000,
- 15,
- "Programmer"
- }
- },
- Websites = {},
- }
- ----- Profile Service -----
- local ProfileStore = ProfileService.GetProfileStore("randomkey" , ProfileTemplate)
- local Profiles = {}
- ----- Functions -----
- function UpdateCash(Profile, Amount)
- Profile.Data.Cash = Amount
- print(Profile.Data.Cash)
- end
- function HireEmployee(Player, Employee)
- table.insert(Profiles[Player].Data["Employees"], Employee)
- ManageEmployees:FireClient(Player, "Hire", Employee)
- end
- function FireEmployee(Player, Employee)
- table.remove(Profiles[Player].Data.Employees[Employee])
- ManageEmployees:FireClient(Player, "Fire", Employee)
- end
- local function LoadEmployees(Player)
- local EmployeeList = Profiles[Player].Data.Employees
- print("Loading " .. Player.Name .. "'s employees...")
- --Send list to client for loading on gui
- print(EmployeeList)
- local Employee = "John Skywalker"
- ManageEmployees:FireClient(Player, "Load", EmployeeList)
- --FireEmployee(Player, Employee)
- end
- ----- Website -----
- --[[
- local website = {
- [1] ["Name"] = DataGiven[1], -- Website Name
- [2] ["Type"] = DataGiven[2], -- Website Type - "Social Media", "Shopping Platform", "Browser Game"
- [3] ["OnlineUsers"] = 5,
- [4] ["Users"] = 69,
- [5] ["Features"] = {"feature1", "feature2"},
- [6] ["FeatureLevels"] = {10,10},
- [7] ["Framework"] = 1,
- [8] ["CloudServers"] = 1,
- [9] [Marketing Campaigns] = {{campaign1, 100buckaroos, newspaper, 19secsleft},{campaign2, newspaper, 100buckaroos, 19secsleft}}
- }
- ]]--
- ----- Website -----
- local function GetWebsite(Player, WebsiteName)
- return Profiles[Player].Data.Websites[WebsiteName]
- end
- local function LoadWebsites(Player)
- local WebsiteList = Profiles[Player].Data.Websites
- print("Loading " .. Player.Name .. "'s websites..")
- print(WebsiteList)
- for _, Website in pairs(WebsiteList) do
- ManageWebsites:FireClient(Player, "Write", Website)
- end
- end
- local function CreateWebsite(Player, WebsiteInfo)
- local Website = {
- WebsiteInfo[1],
- WebsiteInfo[2],
- 1,
- 1,
- {"Quinta do Tio Manel", "Quinta do Tio Jaquim"},
- {10,10},
- "DingDong",
- 1,
- {
- ["1312312312312"] = {
- "1312312312312",
- "Yo",
- "Noway",
- "420"
- }
- },
- }
- Profiles[Player].Data.Websites[Website[1]] = Website
- print("Created website " .. Website[1])
- ManageWebsites:FireClient(Player, "Create", Website)
- end
- local function RemoveWebsite(Player, WebsiteName)
- table.remove(Profiles[Player].Data.Websites[WebsiteName])
- end
- local WebsiteActions = {
- ["Create"] = CreateWebsite,
- ["Remove"] = RemoveWebsite,
- }
- local function ManageWebsite(Player, Action, Website)
- WebsiteActions[Action](Player, Website)
- end
- local function UpdateWebsiteList(Player)
- ManageWebsites:FireClient(Player, "List" ,Profiles[Player].Data.Websites)
- end
- ----- Connections -----
- ManageWebsites.OnServerEvent:Connect(ManageWebsite)
- ----- Campaigns -----
- local function CreateCampaign(Player, Info)
- local Campaign =
- {
- os.time(),
- Info[2],
- Info[3],
- 420
- }
- print("loading")
- print(Profiles[Player].Data.Websites[Info[1][1]][9])
- table.insert(Profiles[Player].Data.Websites[Info[1][1]][9], Campaign)
- ManageCampaigns:FireClient(Player, "Create", Campaign)
- end
- local function DeleteCampaign(Player, Info)
- local WebsiteName = Info[1]
- local CampaignId = Info[2]
- end
- local CampaignActions = {
- ["Create"] = CreateCampaign,
- ["Delete"] = DeleteCampaign,
- }
- local function ManageCampaign(Player, Action, Campaign)
- CampaignActions[Action](Player, Campaign)
- end
- ManageCampaigns.OnServerEvent:Connect(ManageCampaign)
- local DataActions = {
- ["Website"] = GetWebsite
- }
- local function DataRequest(Player, DataType, Data)
- return DataActions[DataType](Player, Data)
- end
- ----- Initialization -----
- local function LoadProfile(Player)
- local Profile = ProfileStore:LoadProfileAsync("Player_" .. Player.UserId)
- if Profile ~= nil then
- Profile:AddUserId(Player.UserId) -- GDPR compliance
- Profile:Reconcile() -- Fill in missing variables from ProfileTemplate (optional)
- Profile:ListenToRelease(
- function()
- Profiles[Player] = nil
- -- The profile could've been loaded on another Roblox server:
- Player:Kick("Please rejoin the experience.")
- end
- )
- if Player:IsDescendantOf(Players) == true then
- Profiles[Player] = Profile
- -- A profile has been successfully loaded:
- warn(Player.Name .. "'s profile was loaded successfully.")
- warn("Initializing Data")
- LoadEmployees(Player)
- else
- -- Player left before the profile loaded:
- Profile:Release()
- end
- else
- -- The profile couldn't be loaded possibly due to other
- -- Roblox servers trying to load this profile at the same time:
- Player:Kick("Please rejoin the experience.")
- end
- end
- local function PlayerAdded(Player)
- LoadProfile(Player)
- repeat wait() until Profiles[Player].Data.Websites ~= nil
- LoadWebsites(Player)
- end
- ----- Connections -----
- RequestData.OnServerInvoke = DataRequest
- Players.PlayerAdded:Connect(PlayerAdded)
- Players.PlayerRemoving:Connect(
- function(Player)
- local Profile = Profiles[Player]
- if Profile ~= nil then
- Profile:Release()
- warn(Player.Name .. "'s profile was released successfully.")
- end
- end
- )
- ----- Loops -----
- while task.wait(1) do
- for _, Player in pairs(Players:GetChildren()) do
- UpdateWebsiteList(Player)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement