Advertisement
Aquarius_Raverus

Hehehe

Apr 16th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.03 KB | None | 0 0
  1. -- Inventory Controller
  2. -- By Sylvern and EmbeddedLua
  3. -- 4/15/2020
  4.  
  5. --[[
  6.    
  7.     For equipping, make a remove event that fires.
  8.     Same with de-equipping.
  9.     Max pets for now is 5.
  10.    
  11. ]]--
  12.  
  13. local UI = script.Parent.Inventory
  14. local InvFolder = UI:WaitForChild("Inventory")
  15. local Template = script:WaitForChild("Template")
  16.  
  17. local InventoryOpen = false
  18. local InventoryClosed = true
  19.  
  20. local Players = game:GetService("Players")
  21. local Player = Players.LocalPlayer
  22.  
  23. local MainFrame = InvFolder:WaitForChild('Frame')
  24.  
  25. local SelectedItemFrame = MainFrame:WaitForChild('SelectedItemFrame')
  26. local SelectedImage = SelectedItemFrame:WaitForChild('SelectedItemImage')
  27. local CategoryLabel = SelectedItemFrame:WaitForChild('CategoryLabel')
  28. local NameLabel = SelectedItemFrame:WaitForChild('NameLabel')
  29.  
  30. local InventoryBody = MainFrame:WaitForChild('InventoryBody')
  31. local ItemBox = InventoryBody:WaitForChild('ItemBox')
  32.  
  33. local Equip = SelectedItemFrame:WaitForChild('Equip')
  34. local UnEquip = SelectedItemFrame:WaitForChild('UnEquip')
  35.  
  36. local InventoryScrolling = ItemBox:WaitForChild('ScrollingFrame')
  37.  
  38. local Storage = game:GetService("ReplicatedStorage")
  39. local PetsFolder = Storage:WaitForChild("Pets")
  40. local AllowedPets = Storage:WaitForChild("AllowedPets")
  41.  
  42. local EquipEvent = Storage:WaitForChild("EquipPet")
  43.  
  44. local Rarities = {
  45.  
  46.     ['Pet1'] = 'Common',
  47.     ['Pet2'] = 'Uncommon',
  48.     ['Pet3'] = 'Rare',
  49.  
  50.  
  51. }
  52.  
  53.  
  54. function displaySelection(name1, name2) -- Name1 is Normal Name and Name2 is specific name.
  55.     local petsEquippedFolder = Player:WaitForChild('EquippedPetsFolder')
  56.    
  57.     if petsEquippedFolder:FindFirstChild(name2) then
  58.         Equip.Visible = false
  59.         UnEquip.Visible = true
  60.         NameLabel.Text = name1
  61.         CategoryLabel.Text = Rarities[name1]
  62.     else
  63.         Equip.Visible = true
  64.         UnEquip.Visible = false
  65.         NameLabel.Text = name1
  66.         CategoryLabel.Text = Rarities[name1]
  67.     end
  68. end
  69.  
  70. function equipping(bool, petName, specificName)
  71.     local petsEquippedFolder = Player:WaitForChild('EquippedPetsFolder')
  72.  
  73.     if bool == true then
  74.         for i,v in pairs(petsEquippedFolder:GetChildren()) do
  75.             if  i == 10 then warn'Max pet slots' return end
  76.         end
  77.        
  78.         if PetsFolder:FindFirstChild(petName)  then
  79.             EquipEvent:FireServer('Equip', petName, specificName)
  80.             Equip.Visible = false
  81.             UnEquip.Visible = true
  82.         end
  83.     end
  84.    
  85.     if bool == false then
  86.         if PetsFolder:FindFirstChild(petName) then
  87.             EquipEvent:FireServer('UnEquip', petName, specificName)
  88.             UnEquip.Visible = false
  89.             Equip.Visible = true
  90.         end
  91.     end
  92. end
  93.  
  94.  
  95. function refreshHUD()  
  96.     for _,assets in pairs(InventoryScrolling:GetChildren()) do
  97.         if assets:IsA("TextButton") then
  98.             assets:Destroy()
  99.         end
  100.     end
  101.    
  102.     Equip.Visible = true
  103.     UnEquip.Visible = false
  104.    
  105.     NameLabel.Text = 'PetName'
  106.     CategoryLabel.Text = 'Rarity'
  107.     SelectedImage.Image = ''
  108.     NameLabel.SpecificPetName.Value = ''
  109. end
  110.  
  111. function updateHUD()
  112.     refreshHUD()
  113.     local plrInventory = Player:WaitForChild('Inventory')
  114.     local equippedPetsFolder = Player:WaitForChild('EquippedPetsFolder')
  115.    
  116.     for i,pets in pairs(plrInventory:GetChildren()) do
  117.         if not pets then warn'No pets currently' return end
  118.            
  119.         local PetsClone = Template:Clone()
  120.         PetsClone.Name = i..pets.Name
  121.         PetsClone.Parent = InventoryScrolling
  122.        
  123.         local newValue = Instance.new("StringValue", PetsClone)
  124.         newValue.Name = 'PetName'
  125.         newValue.Value = pets.Name
  126.                
  127.         PetsClone.MouseButton1Click:Connect(function()
  128.             displaySelection(pets.Name, PetsClone.Name)
  129.             NameLabel.SpecificPetName.Value = PetsClone.Name
  130.         end)
  131.     end
  132. end
  133.  
  134. Equip.MouseButton1Click:Connect(function()
  135.     equipping(true, NameLabel.Text, NameLabel.SpecificPetName.Value)
  136. end)
  137.  
  138. UnEquip.MouseButton1Click:Connect(function()
  139.     equipping(false, NameLabel.Text, NameLabel.SpecificPetName.Value)
  140. end)
  141.  
  142. -- testing
  143.  
  144. local s = game:GetService("ReplicatedStorage")
  145. local event = s:WaitForChild("PetEvent")
  146. event:FireServer('newTool', 'Pet2')
  147. event:FireServer('newTool', 'Pet1')
  148. event:FireServer('newTool', 'Pet3')
  149. event:FireServer('newTool', 'Pet2')
  150. event:FireServer('newTool', 'Pet1')
  151. event:FireServer('newTool', 'Pet3')
  152.  
  153.  
  154. --
  155.  
  156.  
  157. -- UI Opening and closings.
  158. -- By Fruitbarrel.
  159.  
  160.  
  161. function InventoryButtonClick()
  162.     if not InventoryOpen then
  163.         local GuiElement = script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.Body
  164.         local TweeningInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, true, 0)
  165.         local EndPosition = script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.Outline.Position
  166.         local Tween = game.TweenService:Create(GuiElement, TweeningInfo, {Position = EndPosition})
  167.         Tween:Play()
  168.         updateHUD()
  169.         game.SoundService.ClickButtonSound:Play()
  170.     end
  171. end
  172.  
  173.  
  174.  
  175. function OpenInventory()
  176.     if not InventoryOpen then
  177.         local GuiElement = script.Parent.Inventory.Inventory.Frame
  178.         local TweeningInfo = TweenInfo.new(0.15, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
  179.         local EndPosition = UDim2.new(0, 0, 0, 0)
  180.         local Tween = game.TweenService:Create(GuiElement, TweeningInfo, {Position = EndPosition})
  181.         updateHUD()
  182.         wait(0.1)
  183.         Tween:Play()
  184.         game.SoundService.Woosh:Play()
  185.         game.Lighting.Blur.Size = 24
  186.         InventoryOpen = true
  187.         wait(2)
  188.         InventoryClosed = false
  189.     end
  190. end
  191.  
  192.  
  193.  
  194. function CloseInventory()  
  195.     if not InventoryClosed then
  196.         updateHUD()
  197.         local GuiElement = script.Parent.Inventory.Inventory.Frame
  198.         local TweeningInfo = TweenInfo.new(0.15, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
  199.         local EndPosition = UDim2.new(0, 0, -1.1, 0)
  200.         local Tween = game.TweenService:Create(GuiElement, TweeningInfo, {Position = EndPosition})
  201.         Tween:Play()
  202.         game.SoundService.ClickXSound:Play()
  203.         game.Lighting.Blur.Size = 0
  204.         InventoryClosed = true
  205.         wait(2)
  206.         InventoryOpen = false
  207.     end
  208. end
  209.  
  210. script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.MouseButton1Click:Connect(InventoryButtonClick)
  211. script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.MouseButton1Click:Connect(OpenInventory)
  212. script.Parent.Inventory.Inventory.Frame.XButton.MouseButton1Click:Connect(CloseInventory)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement