Advertisement
Scripting_King

Request For Hire

Aug 18th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.76 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. -- Initialize variables
  168. local currentCost = 0
  169.  
  170. -- Define paths to UI elements
  171. local Banner = CatalogEditor.LeftSide.Top.Banner
  172. local CatalogScroll = CatalogEditor.RightSide.BrowseCatalog.Container.Main.Catalog.CatalogScroll
  173. local CatalogTemplate = CatalogScroll.UIGridLayout.Template
  174. local CurrentWearing = CatalogEditor.LeftSide.CurrentlyWearing.WearingScroll
  175. local CurrentWearingTemplate = CurrentWearing.UIListLayout.Template
  176. local ColorFrame = CatalogEditor.RightSide.BrowseCatalog.Container.Main.Colors
  177. local CharacterViewport = CatalogEditor.LeftSide.Top.ViewportFrame
  178.  
  179. -- Initialize page navigation and filtering variables
  180. local CurrentPageNum = 1
  181. local CurrentColorAim = "All"
  182.  
  183. -- Define UI elements for page navigation
  184. local PageNext = CatalogEditor.RightSide.BrowseCatalog.Container.PageNext
  185. local nextButton = PageNext.NextButton
  186. local backButton = PageNext.BackButton
  187. local pageNumber = PageNext.PageNumber
  188.  
  189. -- Create a search parameter object
  190. local SearchParams = CatalogSearchParams.new()
  191.  
  192. -- Initialize a cache for pages
  193. local PageCache = {}
  194.  
  195. -- Initialize data storage for humanoids
  196. local HumanoidData = {}
  197.  
  198. -- Clear all items from the Currently Wearing scroll
  199. local function clearWearingScroll()
  200. for _, Item in pairs(CurrentWearing:GetChildren()) do
  201. if Item:IsA("ImageButton") then
  202. Item:Destroy()
  203. end
  204. end
  205. end
  206.  
  207. -- Remove a specific item from Currently Wearing scroll
  208. local function removeWearingScroll(ID)
  209. local Wearing = CurrentWearing:FindFirstChild(ID)
  210.  
  211. if Wearing then
  212. Wearing:Destroy()
  213. end
  214. end
  215.  
  216. -- Add an item to the Currently Wearing scroll
  217. local function addWearingScroll(ItemFrame, ID, Price, BundleType)
  218. local Wearing = CurrentWearingTemplate:Clone()
  219. Wearing.Parent = CurrentWearing
  220. Wearing.Icon.Image = ItemFrame.Box.Image
  221. Wearing.Name = ID
  222.  
  223. -- Connect a function when the item is clicked in Currently Wearing scroll
  224. Wearing.MouseButton1Click:Connect(function()
  225. if ItemFrame:FindFirstChild("Box") then
  226. ItemFrame.Box.Equipped.Visible = false
  227. end
  228.  
  229. if BundleType then
  230. HumanoidData["BUNDLE"] = nil
  231. end
  232.  
  233. HumanoidData[ID] = nil
  234. avatarEditor:FireServer(HumanoidData)
  235.  
  236. currentCost -= Price
  237. Banner.Cost.Text = ""..tostring(currentCost)
  238. Wearing:Destroy()
  239. end)
  240. end
  241.  
  242. -- Clear all items from the Catalog scroll
  243. local function clearCatalogScroll()
  244. for _, Item in pairs(CatalogScroll:GetChildren()) do
  245. if Item:IsA("Frame") then
  246. Item:Destroy()
  247. end
  248. end
  249. end
  250.  
  251. -- Update the Catalog scroll based on search and page
  252. local function updateCatalogScroll(Search, Page)
  253. local CurrentPage
  254.  
  255. -- If a specific page is provided, clear and use that page
  256. if Page then
  257. clearCatalogScroll()
  258. CurrentPage = Page
  259. else
  260. -- Otherwise, clear the Catalog scroll and get the current page from the search
  261. clearCatalogScroll()
  262. CurrentPage = Search:GetCurrentPage()
  263. table.insert(PageCache, {Search, CurrentPage})
  264. end
  265.  
  266. -- Loop through items on the page and create UI elements for each
  267. for _, item in pairs(CurrentPage) do
  268. local AssetType = item.AssetType
  269. local BundleType = item.BundleType
  270. local ID = tostring(item.Id)
  271. local Price = item.Price or "Limited"
  272. local Name = item.Name
  273.  
  274. local Image
  275.  
  276. -- Determine the image URL based on the item type
  277. if AssetType then
  278. Image = "https://www.roblox.com/asset-thumbnail/image?assetId=".. ID .."&width=420&height=420&format=png"
  279. elseif BundleType then
  280. Image = "rbxthumb://type=BundleThumbnail&id="..ID.."&w=420&h=420"
  281. end
  282.  
  283. -- Determine the humanoid asset type based on the AssetType
  284. local HumanoidAssetType = AssetTypes[AssetType]
  285.  
  286. -- If HumanoidAssetType is not directly defined, create a default structure
  287. if typeof(HumanoidAssetType) == "EnumItem" then
  288. HumanoidAssetType = {
  289. ["AccessoryType"] = HumanoidAssetType;
  290. ["AssetId"] = ID;
  291. ["Order"] = 1; -- set this later TODO
  292. }
  293. end
  294.  
  295. -- Create a new frame for the catalog item
  296. local ItemFrame = CatalogTemplate:Clone()
  297. ItemFrame.InfoDisplay.PriceBox.ItemPrice.Text = Price
  298. ItemFrame.InfoDisplay.ItemName.Text = Name
  299. ItemFrame.Box.Image = Image
  300. ItemFrame.Parent = CatalogScroll
  301.  
  302. -- Check if the item is already equipped
  303. if HumanoidData[ID] then
  304. ItemFrame.Box.Equipped.Visible = true
  305. end
  306.  
  307. -- Function to add an accessory to Currently Wearing
  308. local function addAccessory(Bundle)
  309. local equipAmount = #CurrentWearing:GetChildren()
  310.  
  311. -- Check if the maximum number of accessories is equipped
  312. if equipAmount >= 20 then
  313. warn("Max accessories equipped!")
  314. return
  315. end
  316.  
  317. HumanoidData[ID] = HumanoidAssetType
  318.  
  319. if Bundle then
  320. HumanoidData["BUNDLE"] = Bundle
  321. end
  322.  
  323. avatarEditor:FireServer(HumanoidData)
  324.  
  325. if tonumber(Price) then
  326. currentCost += Price
  327. end
  328.  
  329. addWearingScroll(ItemFrame, ID, Price, BundleType)
  330.  
  331. Banner.Cost.Text = ""..tostring(currentCost)
  332. end
  333.  
  334. -- Connect a function when the Catalog item is clicked
  335. ItemFrame.Box.MouseButton1Click:Connect(function()
  336. local equipAmount = #CurrentWearing:GetChildren() - 2
  337.  
  338. -- Check if the maximum number of accessories is equipped
  339. if equipAmount >= 20 then
  340. warn("Max accessories equipped!")
  341. return
  342. end
  343.  
  344. -- Toggle the equipped state of the item
  345. ItemFrame.Box.Equipped.Visible = not ItemFrame.Box.Equipped.Visible
  346.  
  347. -- If equipped, process the accessory addition
  348. if ItemFrame.Box.Equipped.Visible then
  349. if HumanoidAssetType then
  350. addAccesory()
  351. elseif BundleType then
  352. local Details = AssetService:GetBundleDetailsAsync(tonumber(ID))
  353. for _, Item in pairs(Details.Items) do
  354. if Item.Type == "UserOutfit" then
  355. addAccesory(Item.Id)
  356. break
  357. end
  358. end
  359. else
  360. else warn player the player
  361. warn("Missing Type for: "..AssetType)
  362. end
  363. else
  364. HumanoidData[ID] = nil
  365. removeWearingScroll(ID)
  366.  
  367. if BundleType then
  368. HumanoidData["BUNDLE"] = nil
  369. end
  370.  
  371. if tonumber(Price) then
  372. currentCost -= Price
  373. Banner.Cost.Text = ""..tostring(currentCost)
  374. end
  375.  
  376. avatarEditor:FireServer(HumanoidData)
  377. end
  378.  
  379. end)
  380. end
  381. end --TODO clean tree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement