Advertisement
Scripting_King

Request For Hire

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