Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Inventory Controller
- -- By Sylvern and EmbeddedLua
- -- 4/15/2020
- --[[
- For equipping, make a remove event that fires.
- Same with de-equipping.
- Max pets for now is 5.
- ]]--
- local UI = script.Parent.Inventory
- local InvFolder = UI:WaitForChild("Inventory")
- local Template = script:WaitForChild("Template")
- local InventoryOpen = false
- local InventoryClosed = true
- local Players = game:GetService("Players")
- local Player = Players.LocalPlayer
- local MainFrame = InvFolder:WaitForChild('Frame')
- local SelectedItemFrame = MainFrame:WaitForChild('SelectedItemFrame')
- local SelectedImage = SelectedItemFrame:WaitForChild('SelectedItemImage')
- local CategoryLabel = SelectedItemFrame:WaitForChild('CategoryLabel')
- local NameLabel = SelectedItemFrame:WaitForChild('NameLabel')
- local InventoryBody = MainFrame:WaitForChild('InventoryBody')
- local ItemBox = InventoryBody:WaitForChild('ItemBox')
- local Equip = SelectedItemFrame:WaitForChild('Equip')
- local UnEquip = SelectedItemFrame:WaitForChild('UnEquip')
- local InventoryScrolling = ItemBox:WaitForChild('ScrollingFrame')
- local Storage = game:GetService("ReplicatedStorage")
- local PetsFolder = Storage:WaitForChild("Pets")
- local AllowedPets = Storage:WaitForChild("AllowedPets")
- local EquipEvent = Storage:WaitForChild("EquipPet")
- local Rarities = {
- ['Pet1'] = 'Common',
- ['Pet2'] = 'Uncommon',
- ['Pet3'] = 'Rare',
- }
- function displaySelection(name1, name2) -- Name1 is Normal Name and Name2 is specific name.
- local petsEquippedFolder = Player:WaitForChild('EquippedPetsFolder')
- if petsEquippedFolder:FindFirstChild(name2) then
- Equip.Visible = false
- UnEquip.Visible = true
- NameLabel.Text = name1
- CategoryLabel.Text = Rarities[name1]
- else
- Equip.Visible = true
- UnEquip.Visible = false
- NameLabel.Text = name1
- CategoryLabel.Text = Rarities[name1]
- end
- end
- function equipping(bool, petName, specificName)
- local petsEquippedFolder = Player:WaitForChild('EquippedPetsFolder')
- if bool == true then
- for i,v in pairs(petsEquippedFolder:GetChildren()) do
- if i == 10 then warn'Max pet slots' return end
- end
- if PetsFolder:FindFirstChild(petName) then
- EquipEvent:FireServer('Equip', petName, specificName)
- Equip.Visible = false
- UnEquip.Visible = true
- end
- end
- if bool == false then
- if PetsFolder:FindFirstChild(petName) then
- EquipEvent:FireServer('UnEquip', petName, specificName)
- UnEquip.Visible = false
- Equip.Visible = true
- end
- end
- end
- function refreshHUD()
- for _,assets in pairs(InventoryScrolling:GetChildren()) do
- if assets:IsA("TextButton") then
- assets:Destroy()
- end
- end
- Equip.Visible = true
- UnEquip.Visible = false
- NameLabel.Text = 'PetName'
- CategoryLabel.Text = 'Rarity'
- SelectedImage.Image = ''
- NameLabel.SpecificPetName.Value = ''
- end
- function updateHUD()
- refreshHUD()
- local plrInventory = Player:WaitForChild('Inventory')
- local equippedPetsFolder = Player:WaitForChild('EquippedPetsFolder')
- for i,pets in pairs(plrInventory:GetChildren()) do
- if not pets then warn'No pets currently' return end
- local PetsClone = Template:Clone()
- PetsClone.Name = i..pets.Name
- PetsClone.Parent = InventoryScrolling
- local newValue = Instance.new("StringValue", PetsClone)
- newValue.Name = 'PetName'
- newValue.Value = pets.Name
- PetsClone.MouseButton1Click:Connect(function()
- displaySelection(pets.Name, PetsClone.Name)
- NameLabel.SpecificPetName.Value = PetsClone.Name
- end)
- end
- end
- Equip.MouseButton1Click:Connect(function()
- equipping(true, NameLabel.Text, NameLabel.SpecificPetName.Value)
- end)
- UnEquip.MouseButton1Click:Connect(function()
- equipping(false, NameLabel.Text, NameLabel.SpecificPetName.Value)
- end)
- -- testing
- local s = game:GetService("ReplicatedStorage")
- local event = s:WaitForChild("PetEvent")
- event:FireServer('newTool', 'Pet2')
- event:FireServer('newTool', 'Pet1')
- event:FireServer('newTool', 'Pet3')
- event:FireServer('newTool', 'Pet2')
- event:FireServer('newTool', 'Pet1')
- event:FireServer('newTool', 'Pet3')
- --
- -- UI Opening and closings.
- -- By Fruitbarrel.
- function InventoryButtonClick()
- if not InventoryOpen then
- local GuiElement = script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.Body
- local TweeningInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, true, 0)
- local EndPosition = script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.Outline.Position
- local Tween = game.TweenService:Create(GuiElement, TweeningInfo, {Position = EndPosition})
- Tween:Play()
- updateHUD()
- game.SoundService.ClickButtonSound:Play()
- end
- end
- function OpenInventory()
- if not InventoryOpen then
- local GuiElement = script.Parent.Inventory.Inventory.Frame
- local TweeningInfo = TweenInfo.new(0.15, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
- local EndPosition = UDim2.new(0, 0, 0, 0)
- local Tween = game.TweenService:Create(GuiElement, TweeningInfo, {Position = EndPosition})
- updateHUD()
- wait(0.1)
- Tween:Play()
- game.SoundService.Woosh:Play()
- game.Lighting.Blur.Size = 24
- InventoryOpen = true
- wait(2)
- InventoryClosed = false
- end
- end
- function CloseInventory()
- if not InventoryClosed then
- updateHUD()
- local GuiElement = script.Parent.Inventory.Inventory.Frame
- local TweeningInfo = TweenInfo.new(0.15, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
- local EndPosition = UDim2.new(0, 0, -1.1, 0)
- local Tween = game.TweenService:Create(GuiElement, TweeningInfo, {Position = EndPosition})
- Tween:Play()
- game.SoundService.ClickXSound:Play()
- game.Lighting.Blur.Size = 0
- InventoryClosed = true
- wait(2)
- InventoryOpen = false
- end
- end
- script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.MouseButton1Click:Connect(InventoryButtonClick)
- script.Parent.SideButtons.SideBar.InventoryButton.InventoryButton.MouseButton1Click:Connect(OpenInventory)
- script.Parent.Inventory.Inventory.Frame.XButton.MouseButton1Click:Connect(CloseInventory)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement