Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the Booth type which seems to have Claim and Edit proximity prompts
- type Booth = Model & {Claim: ProximityPrompt, Edit: ProximityPrompt}
- -- Import necessary Roblox services and modules
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local AvatarEditorService = game:GetService("AvatarEditorService")
- local AssetService = game:GetService("AssetService")
- local Players = game:GetService("Players")
- local Player = Players.LocalPlayer
- -- Initialize variables and references
- local Modules = ReplicatedStorage.Modules
- local ClaimedBooth: Model | nil = nil
- local Remotes = ReplicatedStorage.Remotes
- local boothCommunication = Remotes.BoothRemotes.boothCommunication
- local avatarEditor = Remotes.BoothRemotes.avatarEditor
- local publishAvatar = Remotes.BoothRemotes.publishAvatar
- local removeAvatar = Remotes.BoothRemotes.removeAvatar
- local AssetTypes = require(Modules.AssetTypes)
- local CatagoryTable = require(Modules.CatagoryTable)
- local getFilterType = require(Modules.getFilterType)
- local LayeredClothingOrder = require(Modules.LayeredClothingOrder)
- local SelectedStand = nil
- -- UI
- local PlayerGui = Player.PlayerGui
- local Core = PlayerGui:WaitForChild("Core")
- local Pages = Core:WaitForChild("Pages")
- local EditBooth = Pages:WaitForChild("EditBooth")
- local CatalogEditor = Pages:WaitForChild("NEW_CatalogEditor")
- local AvatarLeft = CatalogEditor.LeftSide.Top.ViewportFrame.WorldModel.HazelUGC
- local Booths = workspace.Booths
- local HumanoidDescription = Instance.new("HumanoidDescription")
- local FilterCatagory = nil
- local FilterSubCatagory = nil
- -- Define a function to toggle proximity prompts on or off for all booths except a specified one
- local function toggleProximitys(on: boolean, except: Model | nil)
- -- Loop through each booth in the workspace
- for _, Booth in pairs(Booths:GetChildren()) do
- if Booth == except then
- continue
- end
- local Claim: ProximityPrompt = Booth:FindFirstChild("Claim", true)
- if Claim then
- Claim.Enabled = on
- return
- end
- end
- end
- -- Define a function to set up booth interactions
- local function setupBooth(Booth)
- local Claim: ProximityPrompt = Booth:FindFirstChild("Claim", true)
- local Edit: ProximityPrompt = Booth:FindFirstChild("Edit", true)
- -- Connect actions to Claim and Edit proximity prompts
- Claim.Triggered:Connect(function()
- if not Claim.Enabled then return end
- boothCommunication:FireServer(Booth, "Claim")
- end)
- Edit.Triggered:Connect(function()
- if not Edit.Enabled then return end
- PlayerGui.Core.Pages.EditBooth.Visible = not PlayerGui.Core.Pages.EditBooth.Visible
- end)
- end
- -- Iterate through each booth and set up interactions
- for _, Booth in pairs(Booths:GetChildren()) do
- setupBooth(Booth)
- end
- -- Define a function to add proximity prompts for editing accessories in a booth
- local function addProximitys(Booth)
- local ProximityTable = {}
- local Stands = Booth.Stands
- for _, Stand in pairs(Stands:GetChildren()) do
- local Main = Stand:FindFirstChild("Main", true)
- if Main then
- local ProximityPrompt = Instance.new("ProximityPrompt")
- ProximityPrompt.Name = "EditProx"
- ProximityPrompt.RequiresLineOfSight = false
- ProximityPrompt.UIOffset = Vector2.new(0,150)
- ProximityPrompt.Parent = Main
- ProximityTable[Stand] = ProximityPrompt
- end
- end
- return ProximityTable
- end
- -- Define a function to set up interactions for proximity prompts
- local function setupProximitys(Proximitys)
- for _, Proximity in pairs(Proximitys) do
- local Stand = Proximity.Parent.Parent
- Proximity.Triggered:Connect(function()
- SelectedStand = Stand
- CatalogEditor.Visible = not CatalogEditor.Visible
- end)
- end
- end
- -- Connect to the boothCommunication event to handle booth status changes
- boothCommunication.OnClientEvent:Connect(function(Booth: Booth, Claimed: boolean, Message: string)
- local Claim: ProximityPrompt = Booth:FindFirstChild("Claim", true) :: Booth
- local Edit: ProximityPrompt = Booth:FindFirstChild("Edit", true) :: Booth
- local BoothProximitys = {}
- if Message == "Claimed!" then
- ClaimedBooth = Booth
- Claim.Enabled = false
- Edit.Enabled = true
- local Proximitys = addProximitys(Booth)
- setupProximitys(Proximitys)
- toggleProximitys(false, Booth)
- elseif Message == "Unclaimed!" then
- ClaimedBooth = nil
- setupBooth(Booth)
- toggleProximitys(true, nil)
- end
- end)
- -- EditBooth
- EditBooth.Container.TextSignBox.Confirm.MouseButton1Click:Connect(function()
- boothCommunication:FireServer(ClaimedBooth, "Edit", {
- ["TextSign"] = EditBooth.Container.TextSignBox.EnterTextBox.EnterText.Text
- })
- end)
- EditBooth.Container.Unclaim.MouseButton1Click:Connect(function()
- boothCommunication:FireServer(ClaimedBooth, "Unclaim")
- EditBooth.Visible = false
- end)
- EditBooth.Close.MouseButton1Click:Connect(function()
- EditBooth.Visible = false
- end)
- -- CatalogEditor
- -- Initialize variables
- local currentCost = 0
- -- Define paths to UI elements
- local Banner = CatalogEditor.LeftSide.Top.Banner
- local CatalogScroll = CatalogEditor.RightSide.BrowseCatalog.Container.Main.Catalog.CatalogScroll
- local CatalogTemplate = CatalogScroll.UIGridLayout.Template
- local CurrentWearing = CatalogEditor.LeftSide.CurrentlyWearing.WearingScroll
- local CurrentWearingTemplate = CurrentWearing.UIListLayout.Template
- local ColorFrame = CatalogEditor.RightSide.BrowseCatalog.Container.Main.Colors
- local CharacterViewport = CatalogEditor.LeftSide.Top.ViewportFrame
- -- Initialize page navigation and filtering variables
- local CurrentPageNum = 1
- local CurrentColorAim = "All"
- -- Define UI elements for page navigation
- local PageNext = CatalogEditor.RightSide.BrowseCatalog.Container.PageNext
- local nextButton = PageNext.NextButton
- local backButton = PageNext.BackButton
- local pageNumber = PageNext.PageNumber
- -- Create a search parameter object
- local SearchParams = CatalogSearchParams.new()
- -- Initialize a cache for pages
- local PageCache = {}
- -- Initialize data storage for humanoids
- local HumanoidData = {}
- -- Clear all items from the Currently Wearing scroll
- local function clearWearingScroll()
- for _, Item in pairs(CurrentWearing:GetChildren()) do
- if Item:IsA("ImageButton") then
- Item:Destroy()
- end
- end
- end
- -- Remove a specific item from Currently Wearing scroll
- local function removeWearingScroll(ID)
- local Wearing = CurrentWearing:FindFirstChild(ID)
- if Wearing then
- Wearing:Destroy()
- end
- end
- -- Add an item to the Currently Wearing scroll
- local function addWearingScroll(ItemFrame, ID, Price, BundleType)
- local Wearing = CurrentWearingTemplate:Clone()
- Wearing.Parent = CurrentWearing
- Wearing.Icon.Image = ItemFrame.Box.Image
- Wearing.Name = ID
- -- Connect a function when the item is clicked in Currently Wearing scroll
- Wearing.MouseButton1Click:Connect(function()
- if ItemFrame:FindFirstChild("Box") then
- ItemFrame.Box.Equipped.Visible = false
- end
- if BundleType then
- HumanoidData["BUNDLE"] = nil
- end
- HumanoidData[ID] = nil
- avatarEditor:FireServer(HumanoidData)
- currentCost -= Price
- Banner.Cost.Text = ""..tostring(currentCost)
- Wearing:Destroy()
- end)
- end
- -- Clear all items from the Catalog scroll
- local function clearCatalogScroll()
- for _, Item in pairs(CatalogScroll:GetChildren()) do
- if Item:IsA("Frame") then
- Item:Destroy()
- end
- end
- end
- -- Update the Catalog scroll based on search and page
- local function updateCatalogScroll(Search, Page)
- local CurrentPage
- -- If a specific page is provided, clear and use that page
- if Page then
- clearCatalogScroll()
- CurrentPage = Page
- else
- -- Otherwise, clear the Catalog scroll and get the current page from the search
- clearCatalogScroll()
- CurrentPage = Search:GetCurrentPage()
- table.insert(PageCache, {Search, CurrentPage})
- end
- -- Loop through items on the page and create UI elements for each
- for _, item in pairs(CurrentPage) do
- local AssetType = item.AssetType
- local BundleType = item.BundleType
- local ID = tostring(item.Id)
- local Price = item.Price or "Limited"
- local Name = item.Name
- local Image
- -- Determine the image URL based on the item type
- if AssetType then
- Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. ID .."&width=420&height=420&format=png"
- elseif BundleType then
- Image = "rbxthumb://type=BundleThumbnail&id="..ID.."&w=420&h=420"
- end
- -- Determine the humanoid asset type based on the AssetType
- local HumanoidAssetType = AssetTypes[AssetType]
- -- If HumanoidAssetType is not directly defined, create a default structure
- if typeof(HumanoidAssetType) == "EnumItem" then
- HumanoidAssetType = {
- ["AccessoryType"] = HumanoidAssetType;
- ["AssetId"] = ID;
- ["Order"] = 1; -- set this later TODO
- }
- end
- -- Create a new frame for the catalog item
- local ItemFrame = CatalogTemplate:Clone()
- ItemFrame.InfoDisplay.PriceBox.ItemPrice.Text = Price
- ItemFrame.InfoDisplay.ItemName.Text = Name
- ItemFrame.Box.Image = Image
- ItemFrame.Parent = CatalogScroll
- -- Check if the item is already equipped
- if HumanoidData[ID] then
- ItemFrame.Box.Equipped.Visible = true
- end
- -- Function to add an accessory to Currently Wearing
- local function addAccessory(Bundle)
- local equipAmount = #CurrentWearing:GetChildren()
- -- Check if the maximum number of accessories is equipped
- if equipAmount >= 20 then
- warn("Max accessories equipped!")
- return
- end
- HumanoidData[ID] = HumanoidAssetType
- if Bundle then
- HumanoidData["BUNDLE"] = Bundle
- end
- avatarEditor:FireServer(HumanoidData)
- if tonumber(Price) then
- currentCost += Price
- end
- addWearingScroll(ItemFrame, ID, Price, BundleType)
- Banner.Cost.Text = ""..tostring(currentCost)
- end
- -- Connect a function when the Catalog item is clicked
- ItemFrame.Box.MouseButton1Click:Connect(function()
- local equipAmount = #CurrentWearing:GetChildren() - 2
- -- Check if the maximum number of accessories is equipped
- if equipAmount >= 20 then
- warn("Max accessories equipped!")
- return
- end
- -- Toggle the equipped state of the item
- ItemFrame.Box.Equipped.Visible = not ItemFrame.Box.Equipped.Visible
- -- If equipped, process the accessory addition
- if ItemFrame.Box.Equipped.Visible then
- if HumanoidAssetType then
- addAccesory()
- elseif BundleType then
- local Details = AssetService:GetBundleDetailsAsync(tonumber(ID))
- for _, Item in pairs(Details.Items) do
- if Item.Type == "UserOutfit" then
- addAccesory(Item.Id)
- break
- end
- end
- else
- else warn player the player
- warn("Missing Type for: "..AssetType)
- end
- else
- HumanoidData[ID] = nil
- removeWearingScroll(ID)
- if BundleType then
- HumanoidData["BUNDLE"] = nil
- end
- if tonumber(Price) then
- currentCost -= Price
- Banner.Cost.Text = ""..tostring(currentCost)
- end
- avatarEditor:FireServer(HumanoidData)
- end
- end)
- end
- end --TODO clean tree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement