Advertisement
Scripting_King

Request For Hire

Aug 15th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.28 KB | Source Code | 0 0
  1. -- Define the Booth type which seems to have Claim and Edit proximity prompts
  2. type Booth = Model & {Claim: ProximityPrompt, Edit: ProximityPrompt}
  3.  
  4. -- Import necessary Roblox services and modules
  5. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  6. local AvatarEditorService = game:GetService("AvatarEditorService")
  7. local AssetService = game:GetService("AssetService")
  8. local Players = game:GetService("Players")
  9. local Player = Players.LocalPlayer
  10.  
  11.  -- Initialize variables and references
  12. local Modules = ReplicatedStorage.Modules
  13.  
  14. local ClaimedBooth: Model | nil = nil
  15. local Remotes = ReplicatedStorage.Remotes
  16.  
  17.  
  18. local boothCommunication = Remotes.BoothRemotes.boothCommunication
  19. local avatarEditor = Remotes.BoothRemotes.avatarEditor
  20. local publishAvatar = Remotes.BoothRemotes.publishAvatar
  21. local removeAvatar = Remotes.BoothRemotes.removeAvatar
  22.  
  23. local AssetTypes = require(Modules.AssetTypes)
  24. local CatagoryTable = require(Modules.CatagoryTable)
  25. local getFilterType = require(Modules.getFilterType)
  26. local LayeredClothingOrder = require(Modules.LayeredClothingOrder)
  27.  
  28.  
  29. local SelectedStand = nil
  30.  
  31. -- UI
  32. local PlayerGui = Player.PlayerGui
  33. local Core = PlayerGui:WaitForChild("Core")
  34. local Pages = Core:WaitForChild("Pages")
  35. local EditBooth = Pages:WaitForChild("EditBooth")
  36. local CatalogEditor = Pages:WaitForChild("NEW_CatalogEditor")
  37.  
  38. local AvatarLeft = CatalogEditor.LeftSide.Top.ViewportFrame.WorldModel.HazelUGC
  39.  
  40. local Booths = workspace.Booths
  41.  
  42. local HumanoidDescription = Instance.new("HumanoidDescription")
  43.  
  44. local FilterCatagory = nil
  45. local FilterSubCatagory = nil
  46.  
  47. -- Define a function to toggle proximity prompts on or off for all booths except a specified one
  48. local function toggleProximitys(on: boolean, except: Model | nil)
  49.     -- Loop through each booth in the workspace
  50.     for _, Booth in pairs(Booths:GetChildren()) do
  51.         if Booth == except then
  52.             continue
  53.         end
  54.        
  55.         local Claim: ProximityPrompt = Booth:FindFirstChild("Claim", true)
  56.        
  57.         if Claim then
  58.             Claim.Enabled = on
  59.             return
  60.         end
  61.     end
  62. end
  63.  
  64.  
  65. -- Define a function to set up booth interactions
  66. local function setupBooth(Booth)
  67.     local Claim: ProximityPrompt = Booth:FindFirstChild("Claim", true)
  68.     local Edit: ProximityPrompt = Booth:FindFirstChild("Edit", true)
  69.  
  70.     -- Connect actions to Claim and Edit proximity prompts
  71.     Claim.Triggered:Connect(function()
  72.         if not Claim.Enabled then return end
  73.         boothCommunication:FireServer(Booth, "Claim")
  74.     end)
  75.  
  76.     Edit.Triggered:Connect(function()
  77.         if not Edit.Enabled then return end
  78.         PlayerGui.Core.Pages.EditBooth.Visible = not PlayerGui.Core.Pages.EditBooth.Visible
  79.     end)
  80. end
  81.  
  82.  -- Iterate through each booth and set up interactions
  83. for _, Booth in pairs(Booths:GetChildren()) do
  84.     setupBooth(Booth)
  85. end
  86.  
  87. -- Define a function to add proximity prompts for editing accessories in a booth
  88. local function addProximitys(Booth)
  89.  
  90.     local ProximityTable = {}
  91.    
  92.     local Stands = Booth.Stands
  93.  
  94.     for _, Stand in pairs(Stands:GetChildren()) do
  95.         local Main = Stand:FindFirstChild("Main", true)
  96.  
  97.         if Main then
  98.             local ProximityPrompt = Instance.new("ProximityPrompt")
  99.            
  100.             ProximityPrompt.Name = "EditProx"
  101.            
  102.             ProximityPrompt.RequiresLineOfSight = false
  103.             ProximityPrompt.UIOffset = Vector2.new(0,150)
  104.             ProximityPrompt.Parent = Main
  105.            
  106.             ProximityTable[Stand] = ProximityPrompt
  107.         end
  108.     end
  109.    
  110.     return ProximityTable
  111. end
  112.  
  113. -- Define a function to set up interactions for proximity prompts
  114. local function setupProximitys(Proximitys)
  115.     for _, Proximity in pairs(Proximitys) do
  116.         local Stand = Proximity.Parent.Parent
  117.        
  118.         Proximity.Triggered:Connect(function()
  119.             SelectedStand = Stand
  120.             CatalogEditor.Visible = not CatalogEditor.Visible
  121.         end)
  122.     end
  123. end
  124.  
  125. -- Connect to the boothCommunication event to handle booth status changes
  126. boothCommunication.OnClientEvent:Connect(function(Booth: Booth, Claimed: boolean, Message: string)
  127.     local Claim: ProximityPrompt = Booth:FindFirstChild("Claim", true) :: Booth
  128.     local Edit: ProximityPrompt = Booth:FindFirstChild("Edit", true) :: Booth
  129.    
  130.     local BoothProximitys = {}
  131.    
  132.     if Message == "Claimed!" then
  133.         ClaimedBooth = Booth
  134.         Claim.Enabled = false
  135.         Edit.Enabled = true
  136.         local Proximitys = addProximitys(Booth)
  137.         setupProximitys(Proximitys)
  138.         toggleProximitys(false, Booth)
  139.     elseif Message == "Unclaimed!" then
  140.         ClaimedBooth = nil
  141.         setupBooth(Booth)
  142.         toggleProximitys(true, nil)
  143.     end
  144.    
  145. end)
  146.  
  147. -- EditBooth
  148.  
  149. EditBooth.Container.TextSignBox.Confirm.MouseButton1Click:Connect(function()
  150.     boothCommunication:FireServer(ClaimedBooth, "Edit", {
  151.         ["TextSign"] = EditBooth.Container.TextSignBox.EnterTextBox.EnterText.Text
  152.     })
  153. end)
  154.  
  155. EditBooth.Container.Unclaim.MouseButton1Click:Connect(function()
  156.     boothCommunication:FireServer(ClaimedBooth, "Unclaim")
  157.     EditBooth.Visible = false
  158. end)
  159.  
  160. EditBooth.Close.MouseButton1Click:Connect(function()
  161.     EditBooth.Visible = false
  162. end)
  163.  
  164.  
  165. -- CatalogEditor
  166.  
  167. local currentCost = 0
  168.  
  169. local Banner = CatalogEditor.LeftSide.Top.Banner
  170.  
  171. local CatalogScroll = CatalogEditor.RightSide.BrowseCatalog.Container.Main.Catalog.CatalogScroll
  172. local CatalogTemplate = CatalogScroll.UIGridLayout.Template
  173.  
  174. local CurrentWearing = CatalogEditor.LeftSide.CurrentlyWearing.WearingScroll
  175. local CurrentWearingTemplate = CurrentWearing.UIListLayout.Template
  176.  
  177. local ColorFrame = CatalogEditor.RightSide.BrowseCatalog.Container.Main.Colors
  178.  
  179. local CurrentPageNum = 1
  180. local CurrentColorAim = "All"
  181.  
  182. local PageNext = CatalogEditor.RightSide.BrowseCatalog.Container.PageNext
  183. local nextButton = PageNext.NextButton
  184. local backButton = PageNext.BackButton
  185. local pageNumber = PageNext.PageNumber
  186.  
  187. local CharacterViewport = CatalogEditor.LeftSide.Top.ViewportFrame
  188.  
  189. local SearchParams = CatalogSearchParams.new()
  190.  
  191. local PageCache = {}
  192.  
  193. local HumanoidData = {}
  194.  
  195. local function clearWearingScroll()
  196.     for _, Item in pairs(CurrentWearing:GetChildren()) do
  197.         if Item:IsA("ImageButton") then
  198.             Item:Destroy()
  199.         end
  200.     end
  201. end
  202.  
  203. local function removeWearingScroll(ID)
  204.     local Wearing = CurrentWearing:FindFirstChild(ID)
  205.    
  206.     if Wearing then
  207.         Wearing:Destroy()
  208.     end
  209. end
  210.  
  211. local function addWearingScroll(ItemFrame, ID, Price, BundleType)
  212.     local Wearing = CurrentWearingTemplate:Clone()
  213.     Wearing.Parent = CurrentWearing
  214.     Wearing.Icon.Image = ItemFrame.Box.Image
  215.     Wearing.Name = ID
  216.    
  217.     Wearing.MouseButton1Click:Connect(function()
  218.         if ItemFrame:FindFirstChild("Box") then
  219.             ItemFrame.Box.Equipped.Visible = false
  220.         end
  221.        
  222.         if BundleType then
  223.             HumanoidData["BUNDLE"] = nil
  224.         end
  225.        
  226.         HumanoidData[ID] = nil
  227.         avatarEditor:FireServer(HumanoidData)
  228.        
  229.         currentCost -= Price
  230.         Banner.Cost.Text = ""..tostring(currentCost)
  231.         Wearing:Destroy()
  232.     end)
  233. end
  234.  
  235. local function clearCatalogScroll()
  236.     for _, Item in pairs(CatalogScroll:GetChildren()) do
  237.         if Item:IsA("Frame") then
  238.             Item:Destroy()
  239.         end
  240.     end
  241. end
  242.  
  243. local function updateCatalogScroll(Search, Page)
  244.     local CurrentPage
  245.    
  246.     if Page then
  247.         clearCatalogScroll()
  248.         CurrentPage = Page
  249.     else
  250.         clearCatalogScroll()
  251.         CurrentPage = Search:GetCurrentPage()
  252.         table.insert(PageCache, {Search, CurrentPage})
  253.     end
  254.  
  255.     for _, item in pairs(CurrentPage) do
  256.         local AssetType = item.AssetType
  257.         local BundleType = item.BundleType
  258.         local ID = tostring(item.Id)
  259.         local Price = item.Price or "Limited"
  260.         local Name = item.Name
  261.        
  262.         local Image
  263.        
  264.         if AssetType then
  265.             Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. ID .."&width=420&height=420&format=png"
  266.         elseif BundleType then
  267.             Image = "rbxthumb://type=BundleThumbnail&id="..ID.."&w=420&h=420"
  268.         end
  269.        
  270.    
  271.         local HumanoidAssetType = AssetTypes[AssetType]
  272.        
  273.         if typeof(HumanoidAssetType) == "EnumItem" then
  274.             HumanoidAssetType = {
  275.                 ["AccessoryType"] = HumanoidAssetType;
  276.                 ["AssetId"] = ID;
  277.                 ["Order"] = 1; -- set this lateer TODO
  278.             }
  279.         end
  280.        
  281.         local ItemFrame = CatalogTemplate:Clone()
  282.         ItemFrame.InfoDisplay.PriceBox.ItemPrice.Text = Price
  283.         ItemFrame.InfoDisplay.ItemName.Text = Name
  284.         ItemFrame.Box.Image = Image
  285.        
  286.         ItemFrame.Parent = CatalogScroll
  287.        
  288.         if HumanoidData[ID] then
  289.             ItemFrame.Box.Equipped.Visible = true
  290.         end
  291.        
  292.         local function addAccesory(Bundle)
  293.             local equipAmount = #CurrentWearing:GetChildren()
  294.            
  295.             if equipAmount >= 20 then
  296.                 warn("Max accessories equipped!")
  297.                 return
  298.             end
  299.            
  300.             HumanoidData[ID] = HumanoidAssetType
  301.            
  302.             if Bundle then
  303.                 HumanoidData["BUNDLE"] = Bundle
  304.             end
  305.            
  306.             avatarEditor:FireServer(HumanoidData)
  307.            
  308.             if tonumber(Price) then
  309.                 currentCost += Price
  310.             end
  311.            
  312.             addWearingScroll(ItemFrame, ID, Price, BundleType)
  313.            
  314.             Banner.Cost.Text = ""..tostring(currentCost)
  315.         end
  316.        
  317.         ItemFrame.Box.MouseButton1Click:Connect(function()
  318.             local equipAmount = #CurrentWearing:GetChildren() - 2
  319.            
  320.             if equipAmount >= 20 then
  321.                 warn("Max accessories equipped!")
  322.                 return
  323.             end
  324.            
  325.             ItemFrame.Box.Equipped.Visible = not ItemFrame.Box.Equipped.Visible
  326.            
  327.             if ItemFrame.Box.Equipped.Visible then
  328.                 if HumanoidAssetType then
  329.                     addAccesory()
  330.                 elseif BundleType then
  331.                     local Details = AssetService:GetBundleDetailsAsync(tonumber(ID))
  332.                     for _, Item in pairs(Details.Items) do
  333.                         if Item.Type == "UserOutfit" then
  334.                             addAccesory(Item.Id)
  335.                             break
  336.                         end
  337.                     end
  338.                 else
  339.                     warn("Missing Type for: "..AssetType)
  340.                 end
  341.             else                
  342.                 HumanoidData[ID] = nil
  343.                 removeWearingScroll(ID)
  344.                
  345.                 if BundleType then
  346.                     HumanoidData["BUNDLE"] = nil
  347.                 end
  348.                
  349.                 if tonumber(Price) then
  350.                     currentCost -= Price
  351.                     Banner.Cost.Text = ""..tostring(currentCost)
  352.                 end
  353.                
  354.                 avatarEditor:FireServer(HumanoidData)
  355.             end
  356.            
  357.         end)
  358.     end
  359. end --TODO clean tree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement