Advertisement
NeonStranger

2

Aug 7th, 2022
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.62 KB | None | 0 0
  1. ----- Services -----
  2.  
  3. local CollectionService = game:GetService("CollectionService")
  4. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  5. local Players = game:GetService("Players")
  6.  
  7. ----- Modules -----
  8.  
  9. ----- Remotes -----
  10.  
  11. local Remotes = ReplicatedStorage:WaitForChild("Remotes")
  12. local RemoteFunctions = Remotes:WaitForChild("RemoteFunctions")
  13. local RemoteEvents = Remotes:WaitForChild("RemoteEvents")
  14. local BindableEvents = Remotes:WaitForChild("BindableEvents")
  15. local BindableFunctions = Remotes:WaitForChild("BindableFunctions")
  16.  
  17. local RequestData = RemoteFunctions:WaitForChild("RequestData")
  18. local EmployeeManage = RemoteEvents:WaitForChild("ManageEmployees")
  19. local ManageCampaigns = RemoteEvents:WaitForChild("ManageCampaigns")
  20.  
  21. ----- Instances -----
  22.  
  23. local Main = script.Parent
  24. local Templates = ReplicatedStorage:WaitForChild("UI"):WaitForChild("Templates")
  25. local PlayerGui = script.Parent
  26. local EmployeesGUI = Main:WaitForChild("Employees")
  27. local MainUI = Main:WaitForChild("UI")
  28. local MainBottom = MainUI:WaitForChild("Bottom")
  29.  
  30. ----- Tables and Information -----
  31.  
  32. local function ClearScreen()
  33.     for _, ScreenGui in pairs(script.Parent:GetChildren()) do
  34.         if ScreenGui:IsA("ScreenGui") and ScreenGui.Name ~= "UI" then
  35.             ScreenGui.Enabled = false
  36.         end
  37.     end
  38. end
  39.  
  40. local function OpenWindow(WindowName)
  41.     ClearScreen()
  42.     Main:FindFirstChild(WindowName).Enabled = true
  43. end
  44.  
  45. ----- Employees -----
  46.  
  47. --[[Employee = {
  48.     Name,
  49.     Age,
  50.     Salary,
  51.     Level,
  52.     Skill,
  53.     CON,
  54.     Gender
  55.     }
  56. ]]
  57.  
  58. local EmployeeFrameTemplate = Templates:WaitForChild("EmployeeList")
  59. local EmployeesMain = EmployeesGUI:WaitForChild("Main")
  60. local ListFrame = EmployeesMain:WaitForChild("List")
  61. local EmployeeButton = MainBottom:WaitForChild("Employees")
  62.  
  63. local function CreateEmployeeFrame(Employee)
  64.     local Frame = EmployeeFrameTemplate:Clone()
  65.     Frame.Name = Employee[1]
  66.     Frame.Username.Text = Employee[1]
  67.     Frame.Age.Text = Employee[2]
  68.     Frame.Salary.Text = Employee[3]
  69.     Frame.Level.Text = Employee[4]
  70.     Frame.Status.Text = "Working"
  71.     Frame.Visible = true
  72.     Frame.Parent = ListFrame
  73. end
  74.  
  75. local function RemoveEmployeeFrame(Employee)
  76.     local EmployeeName
  77.     print(typeof(Employee))
  78.     if typeof(Employee) == "table" then
  79.         EmployeeName = Employee[1]
  80.     end
  81.     if typeof(Employee) == "string" then
  82.         EmployeeName = Employee
  83.     end
  84.     print(EmployeeName)
  85.  
  86.     ListFrame:FindFirstChild(EmployeeName):Destroy()
  87.     print(EmployeeName .. " was fired for being a bad boy.")
  88. end
  89.  
  90. local function LoadEmployees(EmployeeList)
  91.     print("List is")
  92.     print(EmployeeList)
  93.     for _, Employee in pairs(EmployeeList) do
  94.         print(Employee)
  95.         CreateEmployeeFrame(Employee)
  96.     end
  97. end
  98.  
  99. local EmployeeActions = {
  100.     ["Load"] = LoadEmployees,
  101.     ["Hire"] = CreateEmployeeFrame,
  102.     ["Fire"] = RemoveEmployeeFrame
  103. }
  104.  
  105. local function ManageEmployees(Action, Employee)
  106.     EmployeeActions[Action](Employee)
  107. end
  108.  
  109. local function OnEmployeeButtonClicked()
  110.     OpenWindow("Employees")
  111. end
  112.  
  113. --- Connections ---
  114.  
  115. EmployeeManage.OnClientEvent:Connect(ManageEmployees)
  116. EmployeeButton.MouseButton1Click:Connect(OnEmployeeButtonClicked)
  117.  
  118. ----- Websites -----
  119.  
  120. local ManageWebsites = RemoteEvents:WaitForChild("ManageWebsites")
  121. local WebsiteGUI = PlayerGui:WaitForChild("Website")
  122. local WebsitePage = WebsiteGUI:WaitForChild("Main")
  123. local OpenWebsite = MainBottom:WaitForChild("Website")
  124. local WebsiteButtonList = MainUI:WaitForChild("WebsiteList")
  125. local ButtonTemplate = Templates:WaitForChild("WebsiteButtonTemplate")
  126.  
  127. local WebsiteList = {}
  128. local CurrentWebsite
  129. local CurrentPage
  130.  
  131. local function RemoveWebsite(Website)
  132.     WebsiteButtonList:FindFirstChild(Website[1]):Destroy()
  133. end
  134.  
  135.  
  136.  
  137.  
  138. --- Connections ---
  139.  
  140.  
  141. ----- Create Website -----
  142.  
  143. local CreateWebsiteGUI = Main:WaitForChild("CreateWebsite")
  144. local NameBox = CreateWebsiteGUI.Main.WebsiteName
  145. local CreateWebsiteWindowButton = MainUI:WaitForChild("CreateWebsite")
  146.  
  147.  
  148. local function CheckName(Name)
  149.     if string.len(Name) > 3 then
  150.         return Name
  151.     else
  152.         return false
  153.     end
  154. end
  155.  
  156.  
  157. local function OnCreateWebsite(ButtonName)
  158.     local WebsiteInfo = {}
  159.     warn(NameBox.Text)
  160.     local GoodName = CheckName(NameBox.Text)
  161.     if GoodName then
  162.         --Good Name
  163.         WebsiteInfo[1] = NameBox.Text
  164.         WebsiteInfo[2] = ButtonName
  165.         --Fire Event for website creation
  166.         ManageWebsites:FireServer("Create", WebsiteInfo)
  167.         --Close Creation Window
  168.         CreateWebsiteGUI.Enabled = false
  169.     else
  170.         --Bad Name
  171.         warn(NameBox.Text)
  172.         warn(GoodName)
  173.     end
  174.     --Clear Name Box
  175.     NameBox.Text = ""
  176. end
  177.  
  178.  
  179.  
  180. ----- Campaigns -----
  181.  
  182. --[[
  183.  
  184. Campaign = {
  185.  
  186.     [1] = Id
  187.     [2] = Type
  188.     [3] = Budget
  189.     [4] = TimeLeft
  190.    
  191. }
  192.  
  193. ]]
  194. local MarketingFrame = WebsitePage.Marketing
  195. local BudgetFrame = MarketingFrame.Top.Budget
  196. local CampaignList = MarketingFrame:WaitForChild("ActiveCampaigns")
  197. local CashBox = BudgetFrame:WaitForChild("CashBox")
  198. local CampaignTemplate = Templates:WaitForChild("CampaignTemplate")
  199.  
  200. local MarketingSelection
  201.  
  202. function CreateCampaign()
  203.     local MBudget = tonumber(CashBox.Text)
  204.     if MarketingSelection then
  205.         if type(MBudget) == "number" then
  206.             if MBudget % 1 == 0 then
  207.                 print("Creating " .. MarketingSelection .. " campaign.")
  208.                 local CampaignInfo = {}
  209.                 CampaignInfo[1] = CurrentWebsite
  210.                 CampaignInfo[2] = MarketingSelection
  211.                 CampaignInfo[3] = MBudget
  212.                 ManageCampaigns:FireServer("Create", CampaignInfo)
  213.             end
  214.         end
  215.     end
  216. end
  217. local function DeleteCampaign(Id)
  218.     print("deleting")
  219.     ManageCampaigns:FireServer("Delete",{CurrentWebsite, Id})
  220. end
  221.  
  222.  
  223. function CreateCampaignFrame(Campaign)
  224.     local Frame = CampaignTemplate:Clone()
  225.     Frame.Name = Campaign[1]
  226.     Frame.name.Text = Campaign[2] .. " Campaign"
  227.     Frame.Budget.Text = Campaign[3] .. "$"
  228.     Frame.TimeLeft.Text = 420
  229.     Frame.TimeLeft.Activated.Value = true
  230.     Frame.Visible = true
  231.     Frame.Parent = CampaignList
  232. end
  233.  
  234.  
  235. local CampaignActions = {
  236.     ["Create"] = CreateCampaignFrame
  237. }
  238.  
  239. local function ManageCampaign(Action, Campaign)
  240.     CampaignActions[Action](Campaign)
  241. end
  242.  
  243. ManageCampaigns.OnClientEvent:Connect(ManageCampaign)
  244. BudgetFrame.CreateCampaign.MouseButton1Click:Connect(CreateCampaign)
  245.  
  246.  
  247. local function WriteWebsitePage(Site, Page) -- Write Website Page
  248.     print(Site, Page)
  249.     CurrentWebsite = Site
  250.     CurrentPage = Page
  251.     --Clear the page
  252.     for _, Frame in pairs(WebsitePage:GetChildren()) do
  253.         if Frame:IsA("Frame") and Frame.Name ~= "Top" then
  254.             Frame.Visible = false
  255.         end
  256.     end
  257.     local Website
  258.     if typeof(Site) == "string" then
  259.         print("It's a string")
  260.         Website = WebsiteList[Site]
  261.         print(Website)
  262.     elseif typeof(Site) == "table" then
  263.         WebsiteList[Site[1]] = Site
  264.         Website = Site      
  265.     end
  266.     if Website ~= nil then
  267.         print(Website[1])
  268.         if not WebsiteButtonList:FindFirstChild(Website[1]) then
  269.             local Button = ButtonTemplate:Clone()
  270.             Button.Name = Website[1]
  271.             Button.Text = Website[1]
  272.             Button.Parent = WebsiteButtonList
  273.         end
  274.         local Pages = {
  275.             ["Stats"] = function()
  276.                 WebsitePage.Stats.Top.Left.OnlineUsers.Text = Website[3]
  277.                 WebsitePage.Stats.Top.Middle.Users.Text = Website[4]
  278.                 WebsitePage.Stats.Visible = true
  279.             end,
  280.             ["Features"] = function()
  281.                 local Features = {}
  282.                 local FeatureLevels = {}
  283.                 Features = Website[5]
  284.                 FeatureLevels = Website[6]
  285.  
  286.                 WebsitePage.Features["1"].FName.Text = Features[1] or ""
  287.                 WebsitePage.Features["2"].FName.Text = Features[2] or ""
  288.                 WebsitePage.Features["3"].FName.Text = Features[3] or ""
  289.                 WebsitePage.Features["1"].Level.Text = FeatureLevels[1] or ""
  290.                 WebsitePage.Features["2"].Level.Text = FeatureLevels[2] or ""
  291.                 WebsitePage.Features["3"].Level.Text = FeatureLevels[3] or ""
  292.                 WebsitePage.Features.Visible = true
  293.             end,
  294.             ["Marketing"] = function()
  295.                 for _, Frame in pairs(CampaignList:GetChildren()) do
  296.                     if Frame:IsA("Frame") then
  297.                         Frame:Destroy()
  298.                     end
  299.                 end
  300.                 WebsitePage.Marketing.Visible = true
  301.                 print(Website[9])
  302.                 for _, Campaign in pairs(Website[9]) do
  303.                     print(Campaign[2])
  304.                     CreateCampaignFrame(Campaign)
  305.                 end
  306.                 --Load active campaigns
  307.             end,
  308.         }
  309.         if Page then
  310.             Pages[Page]()
  311.         else
  312.             Pages["Stats"]()
  313.         end
  314.         WebsitePage.Name = Website[1]
  315.         WebsitePage.Top.WebsiteName.Text = Website[1]
  316.         WebsitePage.Visible = true
  317.         WebsiteGUI.Enabled = true
  318.     end
  319. end
  320.  
  321. ----- Debug -----
  322.  
  323. local function CheckButtons()
  324.     for _, Button in pairs(script.Parent:GetDescendants()) do
  325.         if Button:IsA("TextButton") then
  326.             Button.MouseButton1Click:Connect(function()
  327.                 local Name = Button.Name
  328.                 warn(Button.Name .. " was clicked.")
  329.                 if Button.Name == "Close" then
  330.                     ClearScreen()
  331.                 elseif Button.Parent == WebsiteButtonList then
  332.                     WebsitePage.Visible = true
  333.                     WriteWebsitePage(Name)
  334.                     CurrentWebsite = Name
  335.                 elseif Name == "Stats" or Name == "Features" or Name == "Marketing" then
  336.                     WriteWebsitePage(CurrentWebsite,Name)
  337.                 elseif Button == CreateWebsiteWindowButton then
  338.                     CreateWebsiteGUI.Enabled = true
  339.                 elseif Name == "Mobile Ads" or Name == "Text Ads" or Name == "Newspaper" then
  340.                     MarketingSelection = Name
  341.                     for _, Frame in pairs(Button.Parent.Parent:GetChildren()) do
  342.                         if Frame.Name == "Two" or Frame.Name == "Three" or Frame.Name == "Four" then
  343.                             Frame.BorderColor3 = Color3.fromRGB(27, 42, 53)
  344.                         end
  345.                     end            
  346.                     Button.Parent.BorderColor3 = Color3.fromRGB(0,255,0)
  347.                 elseif Name == "DeleteCampaign" then
  348.                     DeleteCampaign(Button.Parent.Id.Value)
  349.                     Button.Parent:Destroy()
  350.                 elseif Button.Text == "Select" then
  351.                     OnCreateWebsite(Name)
  352.                 end
  353.             end)
  354.         end
  355.     end
  356. end
  357.  
  358. CheckButtons()
  359.  
  360. WebsiteButtonList.ChildAdded:Connect(CheckButtons)
  361. CampaignList.ChildAdded:Connect(CheckButtons)
  362.  
  363.  
  364. local function CreateWebsite(Website)
  365.     WebsiteList[Website[1]] = Website
  366.     WriteWebsitePage(Website, "Stats")
  367.     CurrentWebsite = Website
  368. end
  369.  
  370.  
  371. local function OnUpdate(ServerList)
  372.     WebsiteList = ServerList
  373. end
  374.  
  375. local WebsiteActions =
  376.     {
  377.         ["Create"] = CreateWebsite,
  378.         ["Write"] = WriteWebsitePage,
  379.         ["Remove"] = RemoveWebsite,
  380.         ["List"] = OnUpdate
  381.     }
  382.  
  383.  
  384.  
  385. local function ManageWebsite(Action, Website, Page)
  386.     WebsiteActions[Action](Website, Page)
  387. end
  388.  
  389.  
  390. ManageWebsites.OnClientEvent:Connect(ManageWebsite)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement