Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----- Services -----
- local CollectionService = game:GetService("CollectionService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- ----- Modules -----
- ----- 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 EmployeeManage = RemoteEvents:WaitForChild("ManageEmployees")
- local ManageCampaigns = RemoteEvents:WaitForChild("ManageCampaigns")
- ----- Instances -----
- local Main = script.Parent
- local Templates = ReplicatedStorage:WaitForChild("UI"):WaitForChild("Templates")
- local PlayerGui = script.Parent
- local EmployeesGUI = Main:WaitForChild("Employees")
- local MainUI = Main:WaitForChild("UI")
- local MainBottom = MainUI:WaitForChild("Bottom")
- ----- Tables and Information -----
- local function ClearScreen()
- for _, ScreenGui in pairs(script.Parent:GetChildren()) do
- if ScreenGui:IsA("ScreenGui") and ScreenGui.Name ~= "UI" then
- ScreenGui.Enabled = false
- end
- end
- end
- local function OpenWindow(WindowName)
- ClearScreen()
- Main:FindFirstChild(WindowName).Enabled = true
- end
- ----- Employees -----
- --[[Employee = {
- Name,
- Age,
- Salary,
- Level,
- Skill,
- CON,
- Gender
- }
- ]]
- local EmployeeFrameTemplate = Templates:WaitForChild("EmployeeList")
- local EmployeesMain = EmployeesGUI:WaitForChild("Main")
- local ListFrame = EmployeesMain:WaitForChild("List")
- local EmployeeButton = MainBottom:WaitForChild("Employees")
- local function CreateEmployeeFrame(Employee)
- local Frame = EmployeeFrameTemplate:Clone()
- Frame.Name = Employee[1]
- Frame.Username.Text = Employee[1]
- Frame.Age.Text = Employee[2]
- Frame.Salary.Text = Employee[3]
- Frame.Level.Text = Employee[4]
- Frame.Status.Text = "Working"
- Frame.Visible = true
- Frame.Parent = ListFrame
- end
- local function RemoveEmployeeFrame(Employee)
- local EmployeeName
- print(typeof(Employee))
- if typeof(Employee) == "table" then
- EmployeeName = Employee[1]
- end
- if typeof(Employee) == "string" then
- EmployeeName = Employee
- end
- print(EmployeeName)
- ListFrame:FindFirstChild(EmployeeName):Destroy()
- print(EmployeeName .. " was fired for being a bad boy.")
- end
- local function LoadEmployees(EmployeeList)
- print("List is")
- print(EmployeeList)
- for _, Employee in pairs(EmployeeList) do
- print(Employee)
- CreateEmployeeFrame(Employee)
- end
- end
- local EmployeeActions = {
- ["Load"] = LoadEmployees,
- ["Hire"] = CreateEmployeeFrame,
- ["Fire"] = RemoveEmployeeFrame
- }
- local function ManageEmployees(Action, Employee)
- EmployeeActions[Action](Employee)
- end
- local function OnEmployeeButtonClicked()
- OpenWindow("Employees")
- end
- --- Connections ---
- EmployeeManage.OnClientEvent:Connect(ManageEmployees)
- EmployeeButton.MouseButton1Click:Connect(OnEmployeeButtonClicked)
- ----- Websites -----
- local ManageWebsites = RemoteEvents:WaitForChild("ManageWebsites")
- local WebsiteGUI = PlayerGui:WaitForChild("Website")
- local WebsitePage = WebsiteGUI:WaitForChild("Main")
- local OpenWebsite = MainBottom:WaitForChild("Website")
- local WebsiteButtonList = MainUI:WaitForChild("WebsiteList")
- local ButtonTemplate = Templates:WaitForChild("WebsiteButtonTemplate")
- local WebsiteList = {}
- local CurrentWebsite
- local CurrentPage
- local function RemoveWebsite(Website)
- WebsiteButtonList:FindFirstChild(Website[1]):Destroy()
- end
- --- Connections ---
- ----- Create Website -----
- local CreateWebsiteGUI = Main:WaitForChild("CreateWebsite")
- local NameBox = CreateWebsiteGUI.Main.WebsiteName
- local CreateWebsiteWindowButton = MainUI:WaitForChild("CreateWebsite")
- local function CheckName(Name)
- if string.len(Name) > 3 then
- return Name
- else
- return false
- end
- end
- local function OnCreateWebsite(ButtonName)
- local WebsiteInfo = {}
- warn(NameBox.Text)
- local GoodName = CheckName(NameBox.Text)
- if GoodName then
- --Good Name
- WebsiteInfo[1] = NameBox.Text
- WebsiteInfo[2] = ButtonName
- --Fire Event for website creation
- ManageWebsites:FireServer("Create", WebsiteInfo)
- --Close Creation Window
- CreateWebsiteGUI.Enabled = false
- else
- --Bad Name
- warn(NameBox.Text)
- warn(GoodName)
- end
- --Clear Name Box
- NameBox.Text = ""
- end
- ----- Campaigns -----
- --[[
- Campaign = {
- [1] = Id
- [2] = Type
- [3] = Budget
- [4] = TimeLeft
- }
- ]]
- local MarketingFrame = WebsitePage.Marketing
- local BudgetFrame = MarketingFrame.Top.Budget
- local CampaignList = MarketingFrame:WaitForChild("ActiveCampaigns")
- local CashBox = BudgetFrame:WaitForChild("CashBox")
- local CampaignTemplate = Templates:WaitForChild("CampaignTemplate")
- local MarketingSelection
- function CreateCampaign()
- local MBudget = tonumber(CashBox.Text)
- if MarketingSelection then
- if type(MBudget) == "number" then
- if MBudget % 1 == 0 then
- print("Creating " .. MarketingSelection .. " campaign.")
- local CampaignInfo = {}
- CampaignInfo[1] = CurrentWebsite
- CampaignInfo[2] = MarketingSelection
- CampaignInfo[3] = MBudget
- ManageCampaigns:FireServer("Create", CampaignInfo)
- end
- end
- end
- end
- local function DeleteCampaign(Id)
- print("deleting")
- ManageCampaigns:FireServer("Delete",{CurrentWebsite, Id})
- end
- function CreateCampaignFrame(Campaign)
- local Frame = CampaignTemplate:Clone()
- Frame.Name = Campaign[1]
- Frame.name.Text = Campaign[2] .. " Campaign"
- Frame.Budget.Text = Campaign[3] .. "$"
- Frame.TimeLeft.Text = 420
- Frame.TimeLeft.Activated.Value = true
- Frame.Visible = true
- Frame.Parent = CampaignList
- end
- local CampaignActions = {
- ["Create"] = CreateCampaignFrame
- }
- local function ManageCampaign(Action, Campaign)
- CampaignActions[Action](Campaign)
- end
- ManageCampaigns.OnClientEvent:Connect(ManageCampaign)
- BudgetFrame.CreateCampaign.MouseButton1Click:Connect(CreateCampaign)
- local function WriteWebsitePage(Site, Page) -- Write Website Page
- print(Site, Page)
- CurrentWebsite = Site
- CurrentPage = Page
- --Clear the page
- for _, Frame in pairs(WebsitePage:GetChildren()) do
- if Frame:IsA("Frame") and Frame.Name ~= "Top" then
- Frame.Visible = false
- end
- end
- local Website
- if typeof(Site) == "string" then
- print("It's a string")
- Website = WebsiteList[Site]
- print(Website)
- elseif typeof(Site) == "table" then
- WebsiteList[Site[1]] = Site
- Website = Site
- end
- if Website ~= nil then
- print(Website[1])
- if not WebsiteButtonList:FindFirstChild(Website[1]) then
- local Button = ButtonTemplate:Clone()
- Button.Name = Website[1]
- Button.Text = Website[1]
- Button.Parent = WebsiteButtonList
- end
- local Pages = {
- ["Stats"] = function()
- WebsitePage.Stats.Top.Left.OnlineUsers.Text = Website[3]
- WebsitePage.Stats.Top.Middle.Users.Text = Website[4]
- WebsitePage.Stats.Visible = true
- end,
- ["Features"] = function()
- local Features = {}
- local FeatureLevels = {}
- Features = Website[5]
- FeatureLevels = Website[6]
- WebsitePage.Features["1"].FName.Text = Features[1] or ""
- WebsitePage.Features["2"].FName.Text = Features[2] or ""
- WebsitePage.Features["3"].FName.Text = Features[3] or ""
- WebsitePage.Features["1"].Level.Text = FeatureLevels[1] or ""
- WebsitePage.Features["2"].Level.Text = FeatureLevels[2] or ""
- WebsitePage.Features["3"].Level.Text = FeatureLevels[3] or ""
- WebsitePage.Features.Visible = true
- end,
- ["Marketing"] = function()
- for _, Frame in pairs(CampaignList:GetChildren()) do
- if Frame:IsA("Frame") then
- Frame:Destroy()
- end
- end
- WebsitePage.Marketing.Visible = true
- print(Website[9])
- for _, Campaign in pairs(Website[9]) do
- print(Campaign[2])
- CreateCampaignFrame(Campaign)
- end
- --Load active campaigns
- end,
- }
- if Page then
- Pages[Page]()
- else
- Pages["Stats"]()
- end
- WebsitePage.Name = Website[1]
- WebsitePage.Top.WebsiteName.Text = Website[1]
- WebsitePage.Visible = true
- WebsiteGUI.Enabled = true
- end
- end
- ----- Debug -----
- local function CheckButtons()
- for _, Button in pairs(script.Parent:GetDescendants()) do
- if Button:IsA("TextButton") then
- Button.MouseButton1Click:Connect(function()
- local Name = Button.Name
- warn(Button.Name .. " was clicked.")
- if Button.Name == "Close" then
- ClearScreen()
- elseif Button.Parent == WebsiteButtonList then
- WebsitePage.Visible = true
- WriteWebsitePage(Name)
- CurrentWebsite = Name
- elseif Name == "Stats" or Name == "Features" or Name == "Marketing" then
- WriteWebsitePage(CurrentWebsite,Name)
- elseif Button == CreateWebsiteWindowButton then
- CreateWebsiteGUI.Enabled = true
- elseif Name == "Mobile Ads" or Name == "Text Ads" or Name == "Newspaper" then
- MarketingSelection = Name
- for _, Frame in pairs(Button.Parent.Parent:GetChildren()) do
- if Frame.Name == "Two" or Frame.Name == "Three" or Frame.Name == "Four" then
- Frame.BorderColor3 = Color3.fromRGB(27, 42, 53)
- end
- end
- Button.Parent.BorderColor3 = Color3.fromRGB(0,255,0)
- elseif Name == "DeleteCampaign" then
- DeleteCampaign(Button.Parent.Id.Value)
- Button.Parent:Destroy()
- elseif Button.Text == "Select" then
- OnCreateWebsite(Name)
- end
- end)
- end
- end
- end
- CheckButtons()
- WebsiteButtonList.ChildAdded:Connect(CheckButtons)
- CampaignList.ChildAdded:Connect(CheckButtons)
- local function CreateWebsite(Website)
- WebsiteList[Website[1]] = Website
- WriteWebsitePage(Website, "Stats")
- CurrentWebsite = Website
- end
- local function OnUpdate(ServerList)
- WebsiteList = ServerList
- end
- local WebsiteActions =
- {
- ["Create"] = CreateWebsite,
- ["Write"] = WriteWebsitePage,
- ["Remove"] = RemoveWebsite,
- ["List"] = OnUpdate
- }
- local function ManageWebsite(Action, Website, Page)
- WebsiteActions[Action](Website, Page)
- end
- ManageWebsites.OnClientEvent:Connect(ManageWebsite)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement