Advertisement
Sungmingamerpro13

New BackpackGui (Break In Story)

Oct 11th, 2024
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 5.31 KB | None | 0 0
  1. -- SungExetior13RBLX --
  2.  
  3. -- [ SETTINGS ] --
  4.  
  5. local backgroundColor = Color3.fromRGB(0, 132, 255) -- The color of each circle
  6. local maxOnHotbar = 10 -- How many tools can be displayed. Setting this to more than 10 reverts to 10
  7.  
  8. -- [ END SETTINGS ] --
  9.  
  10. -- Don't edit if you don't know what you're doing --
  11.  
  12. local Players = game:GetService("Players")
  13. local StarterGui = game:GetService("StarterGui")
  14. local UserInputService = game:GetService("UserInputService")
  15. local TweenService = game:GetService("TweenService")
  16. local player = Players.LocalPlayer
  17. local Backpack = player.Backpack
  18. local Character = player.Character
  19. local Frame = script.Parent.Frame
  20. local Template = Frame.Contents.objTemplate
  21.  
  22. local COLOR_DARKER = 0.65
  23. local KEY_DICTIONARY = { Zero = 10, One = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9 }
  24. local EQUIP_TWEENINFO = TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
  25. local items = {}
  26. local tweens = {}
  27. local stackedItems = {}
  28.  
  29. local function handleStackingUI(toolCircle, tool)
  30.     if tool:FindFirstChild("stacks").Value then
  31.         tool.stacks:GetPropertyChangedSignal('Value'):Connect(function()
  32.             toolCircle.Stacks.Text = tool.stacks.Value
  33.         end)
  34.         toolCircle.Stacks.Text = tool.stacks.Value
  35.     end
  36. end
  37.  
  38. local function handleEquip(tool)
  39.     if tool.Parent == nil or tool.Parent == Backpack then
  40.         Character.Humanoid:EquipTool(tool)
  41.     elseif tool.Parent == Character then
  42.         Character.Humanoid:UnequipTools()
  43.     end
  44. end
  45.  
  46.  
  47. local function checkHotbar(removeIndex)
  48.     if removeIndex then
  49.         for _, toolCircle in pairs(Frame.Contents:GetChildren()) do
  50.             if toolCircle:IsA("GuiObject") then
  51.                 local circleName = tonumber(toolCircle.Name)
  52.                 if circleName and circleName >= removeIndex then
  53.                     local newIndex = (circleName == 11) and 0 or circleName - 1
  54.                     local isVisible = (maxOnHotbar == 10) and (newIndex <= 9 and true or false) or ((newIndex ~= 0 and newIndex <= maxOnHotbar) and true or false)
  55.  
  56.                     toolCircle.LayoutOrder -= 1
  57.                     toolCircle.Name = tostring(newIndex)
  58.                     toolCircle.Visible = isVisible
  59.                     toolCircle.Index.Text = tostring(newIndex)
  60.                 end
  61.             end
  62.         end
  63.     end
  64.  
  65.     local additionalIndex = Frame.AdditionalIndex
  66.     additionalIndex.Size = UDim2.new(0, Frame.Contents.UIListLayout.AbsoluteContentSize.X + Frame.Contents.AbsoluteSize.Y + 15, 0, 25)
  67.     additionalIndex.Text = "+" .. (#items - maxOnHotbar)
  68.     additionalIndex.Visible = (#items > maxOnHotbar)
  69.  
  70.     for index, tool in ipairs(items) do
  71.         local toolCircle = Frame.Contents:FindFirstChild(index)
  72.         local isEquipped = (tool.Parent == Character)
  73.  
  74.         if not toolCircle then
  75.             return
  76.         end
  77.  
  78.         if tweens[toolCircle] then
  79.             tweens[toolCircle]:Cancel()
  80.             tweens[toolCircle] = nil
  81.         end
  82.  
  83.         -- Adjust UIStroke Transparency based on whether the tool is equipped or not
  84.         toolCircle.Background.Out.UIStroke.Transparency = isEquipped and 0 or 1
  85.         -- Adjust BackgroundTransparency of the circle Frame based on the UIStroke Transparency
  86.         toolCircle.Background.Out.BackgroundTransparency = isEquipped and 0.7 or 0.7
  87.        
  88.         handleStackingUI(toolCircle, tool)
  89.     end
  90. end
  91.  
  92.  
  93.  
  94. local function create(tool)
  95.    
  96.     local nextIndex = (#items == 10) and 0 or #items
  97.     local isVisible = (maxOnHotbar == 10) and (nextIndex <= 9 and true or false) or ((nextIndex ~= 0 and nextIndex <= maxOnHotbar) and true or false)
  98.  
  99.     local toolCircle = Template:Clone()
  100.    
  101.     toolCircle.LayoutOrder = #items
  102.     toolCircle.Name = #items
  103.     toolCircle.Size = UDim2.new(1, -25,1, -25)
  104.     toolCircle.Visible = isVisible
  105.     toolCircle.Image.Image = tool.TextureId
  106.     toolCircle.Index.Text = nextIndex
  107.     toolCircle.FixedName.Text = tool.TextureId == "" and tool.Name or ""
  108.     toolCircle.Parent = Frame.Contents
  109.  
  110.     toolCircle.Image.MouseButton1Click:Connect(function()
  111.         local index = string.gmatch(toolCircle.Name,"%d+")
  112.         index = tonumber(index())
  113.         tool = items[index]
  114.         handleEquip(tool)
  115.     end)
  116.  
  117.     checkHotbar()
  118.    
  119. end
  120.  
  121. local function updateAdd(tool)
  122.     if not tool:IsA("Tool") then
  123.         return
  124.     end
  125.  
  126.     checkHotbar()
  127.  
  128.     if table.find(items, tool) then
  129.         return
  130.     end
  131.  
  132.     table.insert(items, tool)
  133.  
  134.     create(tool)
  135. end
  136.  
  137. local function updateRemove(tool)
  138.     if not tool:IsA("Tool") then
  139.         return
  140.     end
  141.  
  142.     if tool.Parent == Character or tool.Parent == Backpack then
  143.         return
  144.     end
  145.  
  146.     if table.find(items, tool) then
  147.         local index = table.find(items, tool)
  148.         local toolCircle = Frame.Contents:FindFirstChild(index)
  149.  
  150.         if toolCircle then
  151.             toolCircle:Destroy()
  152.         end
  153.  
  154.         table.remove(items, index)
  155.         checkHotbar(index)
  156.     end
  157. end
  158.  
  159. while true do
  160.     local success, err = pcall(function()
  161.         StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
  162.     end)
  163.     if success then
  164.         break
  165.     end
  166.     wait()
  167. end
  168.  
  169. if maxOnHotbar > 10 then
  170.     maxOnHotbar = 10
  171. end
  172.  
  173. Template.Visible = true
  174. Template.Parent = nil
  175.  
  176. for _, tool in pairs(Backpack:GetChildren()) do
  177.     updateAdd(tool)
  178. end
  179. Backpack.ChildAdded:Connect(updateAdd)
  180. Backpack.ChildRemoved:Connect(updateRemove)
  181.  
  182. Character.ChildAdded:Connect(updateAdd)
  183. Character.ChildRemoved:Connect(updateRemove)
  184.  
  185. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  186.     if gameProcessed then
  187.         return
  188.     end
  189.  
  190.     if KEY_DICTIONARY[input.KeyCode.Name] then
  191.         local index = KEY_DICTIONARY[input.KeyCode.Name]
  192.  
  193.         if items[index] then
  194.             handleEquip(items[index])
  195.         end
  196.     end
  197. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement