Advertisement
Sungmingamerpro13

stackHotBar 2

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