Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. local Player = game.Players.LocalPlayer
  2.  
  3.  
  4.  
  5.  
  6.  
  7. --Inventory Handling
  8. local currentPlayerInventory = nil;
  9. local currentSection = "Weapons"
  10. local inventoryOpened = true
  11. local InventoryUI = script.Parent:WaitForChild("Inventory")
  12. local InventoryEvent = game.ReplicatedStorage:WaitForChild("Remotes").Inventory
  13. local Module3D = require(game.ReplicatedStorage:WaitForChild("Modules").Module3D)
  14. function model(tool)
  15.     local newModel = Instance.new("Model")
  16.     newModel.Name = tool.Name
  17.     for x, a in pairs(tool:GetChildren()) do
  18.         if a:IsA("BasePart") then
  19.             a:Clone().Parent = newModel
  20.         end
  21.     end
  22.     return newModel
  23. end
  24.  
  25. function place3DHandler(slot,item)
  26.     if item.Type == "Weapon" then
  27.         if game.ReplicatedStorage.Tools:FindFirstChild(item.Name) then
  28.             local newTool = model(game.ReplicatedStorage.Tools:FindFirstChild(item.Name))
  29.             local new3DHandler = Module3D:Attach3D(slot,newTool)
  30.             new3DHandler:SetActive(true)
  31.             if game.ReplicatedStorage.Tools:FindFirstChild(item.Name):FindFirstChild("Rotation") then
  32.                 local newRotation = game.ReplicatedStorage.Tools:FindFirstChild(item.Name):FindFirstChild("Rotation")
  33.                 new3DHandler:SetCFrame(new3DHandler:GetCFrame() * CFrame.Angles(math.rad(newRotation.Value.X),math.rad(newRotation.Value.Y),math.rad(newRotation.Value.Z)))
  34.             end
  35.             return new3DHandler
  36.         end
  37.     end
  38. end
  39.  
  40. local destroy = {}
  41.  
  42. function refreshInventory(Section)
  43.     if inventoryOpened == true and currentPlayerInventory ~= nil then
  44.         if currentPlayerInventory[Section] ~= nil then
  45.             for x, Slot in pairs(InventoryUI.Scene.Container:GetChildren()) do
  46.                 if Slot:IsA("UIGridLayout") == false then
  47.                     Slot:Destroy();
  48.                 end
  49.             end
  50.             for x,y in pairs(destroy) do
  51.                 y:End()
  52.             end
  53.             if currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)] ~= nil and currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)] ~= "None" then
  54.                 local newSlot = InventoryUI:WaitForChild("Slot"):Clone()
  55.                 newSlot.ItemName.Text = currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)].Name
  56.                 newSlot.Parent = InventoryUI.Scene.Container
  57.                 newSlot.Visible = true
  58.                 local new3DHandler = place3DHandler(newSlot.ImageLabel,currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)])
  59.                 table.insert(destroy,new3DHandler)
  60.                 newSlot.Equip.MouseButton1Click:Connect(function()
  61.                     InventoryEvent:FireServer("Unequip",currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)])
  62.                 end)
  63.             end
  64.             for x, invSlot in pairs(currentPlayerInventory[Section]) do
  65.                 local newSlot = InventoryUI:WaitForChild("Slot"):Clone()
  66.                 newSlot.ItemName.Text = invSlot.Name
  67.                 newSlot.Parent = InventoryUI.Scene.Container
  68.                 newSlot.Visible = true 
  69.                 local new3DHandler = place3DHandler(newSlot.ImageLabel,currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)])
  70.                 table.insert(destroy,new3DHandler)
  71.                 newSlot.Equip.MouseButton1Click:Connect(function()
  72.                     InventoryEvent:FireServer("Equip",invSlot)
  73.                 end)
  74.             end
  75.         end
  76.     end
  77. end
  78. InventoryEvent.OnClientEvent:connect(function(Action,...)
  79.     local Args = {...}
  80.     if Action == "Update" then
  81.         currentPlayerInventory = Args[1]
  82.         if inventoryOpened == true then
  83.             refreshInventory(currentSection)
  84.         end
  85.     end
  86. end)
  87.  
  88. -- // SHOP BUTTON // --
  89. --[[script.Parent.Icons.Inventory.MouseButton1Down:Connect(function()
  90.     if inventoryOpened == true then
  91.         InventoryUI:TweenPosition(UDim2.new(-.5,0,.2,0),"Out","Quint",.15,true)
  92.         refreshInventory(currentSection)
  93.         inventoryOpened = false
  94.     else
  95.         InventoryUI:TweenPosition(UDim2.new(.25,0,.2,0),"Out","Quint",.15,true)
  96.         inventoryOpened = true
  97.     end
  98. end)]]
  99.  
  100. for x, Button in pairs(InventoryUI.Menu:GetChildren()) do
  101.     if Button:IsA("ImageButton") or Button:IsA("TextButton") then
  102.         Button.MouseButton1Click:connect(function()
  103.             if inventoryOpened == true then
  104.                 currentSection = Button.Name
  105.                 refreshInventory(Button.Name)
  106.             end
  107.         end)
  108.     end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement