diff --git a/public/asset/1 b/public/asset/1 index 72ff10f..3f9bba4 100644 --- a/public/asset/1 +++ b/public/asset/1 @@ -70,26 +70,28 @@ else end if game.CoreGui.Version >= 3 then - -- Backpack Builder, creates most of the backpack gui - scriptContext:AddCoreScript(12,screenGui,"CoreScripts/BackpackScripts/BackpackBuilder") - + waitForProperty(game,"PlaceId") + local inRightPlace = true + for i,v in ipairs(backpackTestPlaces) do + if v == game.PlaceId then + inRightPlace = true + break + end + end + + waitForChild(game,"Players") + waitForProperty(game.Players,"LocalPlayer") + if game.Players.LocalPlayer.userId == 7210880 or game.Players.LocalPlayer.userId == 0 then inRightPlace = true end + + if not inRightPlace then return end -- restricting availability of backpack + + -- Backpack Builder + scriptContext:AddCoreScript(12,screenGui,"BackpackBuilder") waitForChild(screenGui,"CurrentLoadout") - waitForChild(screenGui,"Backpack") - local Backpack = screenGui.Backpack - - -- Manager handles all big backpack state changes, other scripts subscribe to this and do things accordingly - if game.CoreGui.Version >= 7 then - scriptContext:AddCoreScript(13,Backpack,"CoreScripts/BackpackScripts/BackpackManager") - end - - -- Backpack Gear (handles all backpack gear tab stuff) - game:GetService("ScriptContext"):AddCoreScript(14,Backpack,"CoreScripts/BackpackScripts/BackpackGear") - -- Loadout Script, used for gear hotkeys - scriptContext:AddCoreScript(15,screenGui.CurrentLoadout,"CoreScripts/BackpackScripts/LoadoutScript") - if game.CoreGui.Version >= 8 then - -- Wardrobe script handles all character dressing operations - scriptContext:AddCoreScript(-1,Backpack,"CoreScripts/BackpackScripts/BackpackWardrobe") - end + waitForChild(screenGui.CurrentLoadout,"TempSlot") + waitForChild(screenGui.CurrentLoadout.TempSlot,"SlotNumber") + -- Backpack Script + scriptContext:AddCoreScript(13,screenGui.CurrentLoadout,"BackpackScript") end local IsPersonalServer = not not game.Workspace:FindFirstChild("PSVariable") diff --git a/public/asset/12 b/public/asset/12 index cded2ee..007a8c9 100644 --- a/public/asset/12 +++ b/public/asset/12 @@ -1,15 +1,15 @@ %12% --- This script manages context switches in the backpack (Gear to Wardrobe, etc.) and player state changes. Also manages global functions across different tabs (currently only search) -print("mamanger") -if game.CoreGui.Version < 7 then return end -- peace out if we aren't using the right client -print("made it past gui version check") +--- ATTENTION!!! There are site-specific ids at the end of this script!!!!!!!!!!!!!!!!!!!! --- basic functions +if game.CoreGui.Version < 3 then return end -- peace out if we aren't using the right client + +local gui = script.Parent + +-- A couple of necessary functions local function waitForChild(instance, name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end - return instance:FindFirstChild(name) end local function waitForProperty(instance, property) while not instance[property] do @@ -17,347 +17,461 @@ local function waitForProperty(instance, property) end end --- don't do anything if we are in an empty game waitForChild(game,"Players") -if #game.Players:GetChildren() < 1 then - game.Players.ChildAdded:wait() -end --- make sure everything is loaded in before we do anything --- get our local player waitForProperty(game.Players,"LocalPlayer") local player = game.Players.LocalPlayer +-- First up is the current loadout +local CurrentLoadout = Instance.new("Frame") +CurrentLoadout.Name = "CurrentLoadout" +CurrentLoadout.Position = UDim2.new(0.5, -240, 1, -85) +CurrentLoadout.Size = UDim2.new(0, 480, 0, 48) +CurrentLoadout.BackgroundTransparency = 1 +CurrentLoadout.RobloxLocked = true +CurrentLoadout.Parent = gui +local Debounce = Instance.new("BoolValue") +Debounce.Name = "Debounce" +Debounce.RobloxLocked = true +Debounce.Parent = CurrentLoadout ------------------------- Locals ------------------------------ -local backpack = script.Parent -waitForChild(backpack,"Gear") +local BackpackButton = Instance.new("ImageButton") +BackpackButton.RobloxLocked = true +BackpackButton.Visible = false +BackpackButton.Name = "BackpackButton" +BackpackButton.BackgroundTransparency = 1 +BackpackButton.Image = "rbxasset://textures/ui/backpackButton.png" +BackpackButton.Position = UDim2.new(0.5, -195, 1, -30) +BackpackButton.Size = UDim2.new(0,107,0,26) +waitForChild(gui,"ControlFrame") +BackpackButton.Parent = gui.ControlFrame -local screen = script.Parent.Parent -assert(screen:IsA("ScreenGui")) - -waitForChild(backpack, "Tabs") -waitForChild(backpack.Tabs, "CloseButton") -local closeButton = backpack.Tabs.CloseButton - -waitForChild(backpack.Tabs, "InventoryButton") -local inventoryButton = backpack.Tabs.InventoryButton -if game.CoreGui.Version >= 8 then - waitForChild(backpack.Tabs, "WardrobeButton") - local wardrobeButton = backpack.Tabs.WardrobeButton -end -waitForChild(backpack.Parent,"ControlFrame") -local backpackButton = waitForChild(backpack.Parent.ControlFrame,"BackpackButton") -local currentTab = "gear" - -local searchFrame = waitForChild(backpack,"SearchFrame") -waitForChild(backpack.SearchFrame,"SearchBoxFrame") -local searchBox = waitForChild(backpack.SearchFrame.SearchBoxFrame,"SearchBox") -local searchButton = waitForChild(backpack.SearchFrame,"SearchButton") -local resetButton = waitForChild(backpack.SearchFrame,"ResetButton") - -local canToggle = true -local readyForNextEvent = true -local backpackIsOpen = false -local active = true - -local humanoidDiedCon = nil - -local guiTweenSpeed = 0.25 -- how quickly we open/close the backpack - -local searchDefaultText = "Search..." -local tilde = "~" -local backquote = "`" - ------------------------- End Locals --------------------------- - - ----------------------------------------- Public Event Setup ---------------------------------------- - -function createPublicEvent(eventName) - assert(eventName, "eventName is nil") - assert(tostring(eventName),"eventName is not a string") - - local newEvent = Instance.new("BindableEvent") - newEvent.Name = tostring(eventName) - newEvent.Parent = script - - return newEvent -end - -function createPublicFunction(funcName, invokeFunc) - assert(funcName, "funcName is nil") - assert(tostring(funcName), "funcName is not a string") - assert(invokeFunc, "invokeFunc is nil") - assert(type(invokeFunc) == "function", "invokeFunc should be of type 'function'") - - local newFunction = Instance.new("BindableFunction") - newFunction.Name = tostring(funcName) - newFunction.OnInvoke = invokeFunc - newFunction.Parent = script - - return newFunction -end - --- Events -local resizeEvent = createPublicEvent("ResizeEvent") -local backpackOpenEvent = createPublicEvent("BackpackOpenEvent") -local backpackCloseEvent = createPublicEvent("BackpackCloseEvent") -local tabClickedEvent = createPublicEvent("TabClickedEvent") -local searchRequestedEvent = createPublicEvent("SearchRequestedEvent") ----------------------------------------- End Public Event Setup ---------------------------------------- - - - ---------------------------- Internal Functions ---------------------------------------- - -function deactivateBackpack() - backpack.Visible = false - active = false -end - -function activateBackpack() - initHumanoidDiedConnections() - active = true - backpack.Visible = backpackIsOpen -end - -function initHumanoidDiedConnections() - if humanoidDiedCon then - humanoidDiedCon:disconnect() - end - waitForProperty(game.Players.LocalPlayer,"Character") - waitForChild(game.Players.LocalPlayer.Character,"Humanoid") - humanoidDiedCon = game.Players.LocalPlayer.Character.Humanoid.Died:connect(deactivateBackpack) -end - -local hideBackpack = function() - backpackIsOpen = false - readyForNextEvent = false - backpackButton.Selected = false - resetSearch() - backpackCloseEvent:Fire(currentTab) - backpack.Tabs.Visible = false - searchFrame.Visible = false - backpack:TweenSizeAndPosition(UDim2.new(0,0,0,0),UDim2.new(0.5,0,0.5,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, guiTweenSpeed, true, - function() - game.GuiService:RemoveCenterDialog(backpack) - backpack.Visible = false - backpackButton.Selected = false - end) - delay(guiTweenSpeed,function() - game.GuiService:RemoveCenterDialog(backpack) - backpack.Visible = false - backpackButton.Selected = false - canToggle = true - end) -end - -function showBackpack() - game.GuiService:AddCenterDialog(backpack, Enum.CenterDialogType.PlayerInitiatedDialog, - function() - backpack.Visible = true - backpackButton.Selected = true - end, - function() - backpack.Visible = false - backpackButton.Selected = false - end) - backpack.Visible = true - backpackButton.Selected = true - backpack:TweenSizeAndPosition(UDim2.new(0.55, 0, 0.76, 0),UDim2.new(0.225, 0, 0.09, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, guiTweenSpeed, true) - delay(guiTweenSpeed,function() - backpack.Tabs.Visible = true - searchFrame.Visible = true - backpackOpenEvent:Fire(currentTab) - canToggle = true - end) -end - -function toggleBackpack() - if not game.Players.LocalPlayer then return end - if not game.Players.LocalPlayer["Character"] then return end - - if not canToggle then return end - if not readyForNextEvent then return end - readyForNextEvent = false - canToggle = false - - backpackIsOpen = not backpackIsOpen - - if backpackIsOpen then - showBackpack() +for i = 0, 9 do + local slotFrame = Instance.new("Frame") + slotFrame.RobloxLocked = true + slotFrame.BackgroundColor3 = Color3.new(0,0,0) + slotFrame.BackgroundTransparency = 1 + slotFrame.BorderColor3 = Color3.new(1,1,1) + slotFrame.Name = "Slot" .. tostring(i) + if i == 0 then + slotFrame.Position = UDim2.new(0.9,0,0,0) else - backpackButton.Selected = false - hideBackpack() + slotFrame.Position = UDim2.new((i - 1) * 0.1,0,0,0) end + slotFrame.Size = UDim2.new(0.1,0,1,0) + slotFrame.Parent = CurrentLoadout end -function closeBackpack() - if backpackIsOpen then - toggleBackpack() - end -end +local TempSlot = Instance.new("ImageButton") +TempSlot.Name = "TempSlot" +TempSlot.Active = true +TempSlot.Size = UDim2.new(1,0,1,0) +TempSlot.Style = Enum.ButtonStyle.RobloxButton +TempSlot.Visible = false +TempSlot.RobloxLocked = true +TempSlot.Parent = CurrentLoadout -function setSelected(tab) - assert(tab) - assert(tab:IsA("TextButton")) + -- TempSlot Children + local GearReference = Instance.new("ObjectValue") + GearReference.Name = "GearReference" + GearReference.RobloxLocked = true + GearReference.Parent = TempSlot + + local Kill = Instance.new("BoolValue") + Kill.Name = "Kill" + Kill.RobloxLocked = true + Kill.Parent = TempSlot + + local GearImage = Instance.new("ImageLabel") + GearImage.Name = "GearImage" + GearImage.BackgroundTransparency = 1 + GearImage.Position = UDim2.new(0,-7,0,-7) + GearImage.Size = UDim2.new(1,14,1,14) + GearImage.ZIndex = 2 + GearImage.RobloxLocked = true + GearImage.Parent = TempSlot + + local SlotNumber = Instance.new("TextLabel") + SlotNumber.Name = "SlotNumber" + SlotNumber.BackgroundTransparency = 1 + SlotNumber.BorderSizePixel = 0 + SlotNumber.Font = Enum.Font.ArialBold + SlotNumber.FontSize = Enum.FontSize.Size18 + SlotNumber.Position = UDim2.new(0,-7,0,-7) + SlotNumber.Size = UDim2.new(0,10,0,15) + SlotNumber.TextColor3 = Color3.new(1,1,1) + SlotNumber.TextTransparency = 0 + SlotNumber.TextXAlignment = Enum.TextXAlignment.Left + SlotNumber.TextYAlignment = Enum.TextYAlignment.Bottom + SlotNumber.ZIndex = 4 + SlotNumber.RobloxLocked = true + SlotNumber.Parent = TempSlot - tab.BackgroundColor3 = Color3.new(1,1,1) - tab.TextColor3 = Color3.new(0,0,0) - tab.Selected = true - tab.ZIndex = 3 -end - -function setUnselected(tab) - assert(tab) - assert(tab:IsA("TextButton")) + local SlotNumberDownShadow = SlotNumber:clone() + SlotNumberDownShadow.Name = "SlotNumberDownShadow" + SlotNumberDownShadow.TextColor3 = Color3.new(0,0,0) + SlotNumberDownShadow.ZIndex = 3 + SlotNumberDownShadow.Position = UDim2.new(0,-6,0,-6) + SlotNumberDownShadow.Parent = TempSlot - tab.BackgroundColor3 = Color3.new(0,0,0) - tab.TextColor3 = Color3.new(1,1,1) - tab.Selected = false - tab.ZIndex = 1 -end + local SlotNumberUpShadow = SlotNumberDownShadow:clone() + SlotNumberUpShadow.Name = "SlotNumberUpShadow" + SlotNumberUpShadow.Position = UDim2.new(0,-8,0,-8) + SlotNumberUpShadow.Parent = TempSlot -function updateTabGui(selectedTab) - assert(selectedTab) + local GearText = Instance.new("TextLabel") + GearText.RobloxLocked = true + GearText.Name = "GearText" + GearText.BackgroundTransparency = 1 + GearText.Font = Enum.Font.Arial + GearText.FontSize = Enum.FontSize.Size14 + GearText.Position = UDim2.new(0,-8,0,-8) + GearText.ZIndex = 2 + GearText.Size = UDim2.new(1,16,1,16) + GearText.Text = "" + GearText.TextColor3 = Color3.new(1,1,1) + GearText.TextWrap = true + GearText.Parent = TempSlot + +--- Great, now lets make the inventory! + +local Backpack = Instance.new("Frame") +Backpack.Visible = false +Backpack.Name = "Backpack" +Backpack.Position = UDim2.new(0.5,0,0.5,0) +Backpack.Size = UDim2.new(0,0,0,0) +Backpack.Style = Enum.FrameStyle.RobloxSquare +Backpack.RobloxLocked = true +Backpack.Parent = gui +Backpack.Active = true + + -- Backpack Children + local SwapSlot = Instance.new("BoolValue") + SwapSlot.RobloxLocked = true + SwapSlot.Name = "SwapSlot" + SwapSlot.Parent = Backpack + + -- SwapSlot Children + local Slot = Instance.new("IntValue") + Slot.RobloxLocked = true + Slot.Name = "Slot" + Slot.Parent = SwapSlot + + local GearButton = Instance.new("ObjectValue") + GearButton.RobloxLocked = true + GearButton.Name = "GearButton" + GearButton.Parent = SwapSlot - if selectedTab == "gear" then - setSelected(inventoryButton) - setUnselected(wardrobeButton) - elseif selectedTab == "wardrobe" then - setSelected(wardrobeButton) - setUnselected(inventoryButton) - end -end - -function mouseLeaveTab(button) - assert(button) - assert(button:IsA("TextButton")) + local Tabs = Instance.new("Frame") + Tabs.Name = "Tabs" + Tabs.Visible = false + Tabs.RobloxLocked = true + Tabs.BackgroundColor3 = Color3.new(0,0,0) + Tabs.BackgroundTransparency = 0.5 + Tabs.BorderSizePixel = 0 + Tabs.Position = UDim2.new(0,-8,-0.1,-8) + Tabs.Size = UDim2.new(1,16,0.1,0) + Tabs.Parent = Backpack - if button.Selected then return end + -- Tabs Children + local InventoryButton = Instance.new("ImageButton") + InventoryButton.RobloxLocked = true + InventoryButton.Name = "InventoryButton" + InventoryButton.Size = UDim2.new(0.12,0,1,0) + InventoryButton.Style = Enum.ButtonStyle.RobloxButton + InventoryButton.Selected = true + InventoryButton.Parent = Tabs + + -- InventoryButton Children + local InventoryText = Instance.new("TextLabel") + InventoryText.RobloxLocked = true + InventoryText.Name = "InventoryText" + InventoryText.BackgroundTransparency = 1 + InventoryText.Font = Enum.Font.ArialBold + InventoryText.FontSize = Enum.FontSize.Size18 + InventoryText.Position = UDim2.new(0,-7,0,-7) + InventoryText.Size = UDim2.new(1,14,1,14) + InventoryText.Text = "Gear" + InventoryText.TextColor3 = Color3.new(1,1,1) + InventoryText.Parent = InventoryButton + + local closeButton = Instance.new("TextButton") + closeButton.RobloxLocked = true + closeButton.Name = "CloseButton" + closeButton.Font = Enum.Font.ArialBold + closeButton.FontSize = Enum.FontSize.Size24 + closeButton.Position = UDim2.new(1,-33,0,2) + closeButton.Size = UDim2.new(0,30,0,30) + closeButton.Style = Enum.ButtonStyle.RobloxButton + closeButton.Text = "X" + closeButton.TextColor3 = Color3.new(1,1,1) + closeButton.Parent = Tabs - button.BackgroundColor3 = Color3.new(0,0,0) -end + local Gear = Instance.new("Frame") + Gear.Name = "Gear" + Gear.RobloxLocked = true + Gear.BackgroundTransparency = 1 + Gear.Size = UDim2.new(1,0,1,0) + Gear.Parent = Backpack -function mouseOverTab(button) - assert(button) - assert(button:IsA("TextButton")) + -- Gear Children + local GearGrid = Instance.new("Frame") + GearGrid.RobloxLocked = true + GearGrid.Name = "GearGrid" + GearGrid.Size = UDim2.new(0.69,0,1,0) + GearGrid.Style = Enum.FrameStyle.RobloxSquare + GearGrid.Parent = Gear + + -- GearGrid Children + local ResetFrame = Instance.new("Frame") + ResetFrame.RobloxLocked = true + ResetFrame.Name = "ResetFrame" + ResetFrame.Visible = false + ResetFrame.BackgroundTransparency = 1 + ResetFrame.Size = UDim2.new(0,32,0,64) + ResetFrame.Parent = GearGrid + + -- ResetFrame Children + local ResetImageLabel = Instance.new("ImageLabel") + ResetImageLabel.RobloxLocked = true + ResetImageLabel.Name = "ResetImageLabel" + ResetImageLabel.Image = "rbxasset://textures/ui/ResetIcon.png" + ResetImageLabel.BackgroundTransparency = 1 + ResetImageLabel.Position = UDim2.new(0,0,0,-12) + ResetImageLabel.Size = UDim2.new(0.8,0,0.79,0) + ResetImageLabel.ZIndex = 2 + ResetImageLabel.Parent = ResetFrame + + local ResetButtonBorder = Instance.new("TextButton") + ResetButtonBorder.RobloxLocked = true + ResetButtonBorder.Name = "ResetButtonBorder" + ResetButtonBorder.Position = UDim2.new(0,-3,0,-7) + ResetButtonBorder.Size = UDim2.new(1,0,0.64,0) + ResetButtonBorder.Style = Enum.ButtonStyle.RobloxButton + ResetButtonBorder.Text = "" + ResetButtonBorder.Parent = ResetFrame + + + local SearchFrame = Instance.new("Frame") + SearchFrame.RobloxLocked = true + SearchFrame.Name = "SearchFrame" + SearchFrame.BackgroundTransparency = 1 + SearchFrame.Position = UDim2.new(1,-150,0,0) + SearchFrame.Size = UDim2.new(0,150,0,25) + SearchFrame.Parent = GearGrid + + -- SearchFrame Children + local SearchButton = Instance.new("ImageButton") + SearchButton.RobloxLocked = true + SearchButton.Name = "SearchButton" + SearchButton.Size = UDim2.new(0,25,0,25) + SearchButton.BackgroundTransparency = 1 + SearchButton.Image = "rbxasset://textures/ui/SearchIcon.png" + SearchButton.Parent = SearchFrame + + local SearchBoxFrame = Instance.new("TextButton") + SearchBoxFrame.RobloxLocked = true + SearchBoxFrame.Position = UDim2.new(0,26,0,0) + SearchBoxFrame.Size = UDim2.new(0,121,0,25) + SearchBoxFrame.Name = "SearchBoxFrame" + SearchBoxFrame.Text = "" + SearchBoxFrame.Style = Enum.ButtonStyle.RobloxButton + SearchBoxFrame.Parent = SearchFrame + + -- SearchBoxFrame Children + local SearchBox = Instance.new("TextBox") + SearchBox.RobloxLocked = true + SearchBox.Name = "SearchBox" + SearchBox.BackgroundTransparency = 1 + SearchBox.Font = Enum.Font.ArialBold + SearchBox.FontSize = Enum.FontSize.Size12 + SearchBox.Position = UDim2.new(0,-5,0,-5) + SearchBox.Size = UDim2.new(1,10,1,10) + SearchBox.TextColor3 = Color3.new(1,1,1) + SearchBox.TextXAlignment = Enum.TextXAlignment.Left + SearchBox.ZIndex = 2 + SearchBox.TextWrap = true + SearchBox.Text = "Search..." + SearchBox.Parent = SearchBoxFrame + + local GearButton = Instance.new("ImageButton") + GearButton.RobloxLocked = true + GearButton.Visible = false + GearButton.Name = "GearButton" + GearButton.Size = UDim2.new(0,64,0,64) + GearButton.Style = Enum.ButtonStyle.RobloxButton + GearButton.Parent = GearGrid + + -- GearButton Children + local GearReference = Instance.new("ObjectValue") + GearReference.RobloxLocked = true + GearReference.Name = "GearReference" + GearReference.Parent = GearButton + + local GreyOutButton = Instance.new("Frame") + GreyOutButton.RobloxLocked = true + GreyOutButton.Name = "GreyOutButton" + GreyOutButton.BackgroundTransparency = 0.5 + GreyOutButton.Size = UDim2.new(1,0,1,0) + GreyOutButton.Active = true + GreyOutButton.Visible = false + GreyOutButton.ZIndex = 3 + GreyOutButton.Parent = GearButton + + local GearText = Instance.new("TextLabel") + GearText.RobloxLocked = true + GearText.Name = "GearText" + GearText.BackgroundTransparency = 1 + GearText.Font = Enum.Font.Arial + GearText.FontSize = Enum.FontSize.Size14 + GearText.Position = UDim2.new(0,-8,0,-8) + GearText.Size = UDim2.new(1,16,1,16) + GearText.Text = "" + GearText.ZIndex = 2 + GearText.TextColor3 = Color3.new(1,1,1) + GearText.TextWrap = true + GearText.Parent = GearButton + + local GearGridScrollingArea = Instance.new("Frame") + GearGridScrollingArea.RobloxLocked = true + GearGridScrollingArea.Name = "GearGridScrollingArea" + GearGridScrollingArea.Position = UDim2.new(0.7,0,0,0) + GearGridScrollingArea.Size = UDim2.new(0,17,1,0) + GearGridScrollingArea.BackgroundTransparency = 1 + GearGridScrollingArea.Parent = Gear + + local GearLoadouts = Instance.new("Frame") + GearLoadouts.RobloxLocked = true + GearLoadouts.Name = "GearLoadouts" + GearLoadouts.BackgroundTransparency = 1 + GearLoadouts.Position = UDim2.new(0.7,23,0.5,1) + GearLoadouts.Size = UDim2.new(0.3,-23,0.5,-1) + GearLoadouts.Parent = Gear + GearLoadouts.Visible = false + + -- GearLoadouts Children + local GearLoadoutsHeader = Instance.new("Frame") + GearLoadoutsHeader.RobloxLocked = true + GearLoadoutsHeader.Name = "GearLoadoutsHeader" + GearLoadoutsHeader.BackgroundColor3 = Color3.new(0,0,0) + GearLoadoutsHeader.BackgroundTransparency = 0.2 + GearLoadoutsHeader.BorderColor3 = Color3.new(1,0,0) + GearLoadoutsHeader.Size = UDim2.new(1,2,0.15,-1) + GearLoadoutsHeader.Parent = GearLoadouts + + -- GearLoadoutsHeader Children + local LoadoutsHeaderText = Instance.new("TextLabel") + LoadoutsHeaderText.RobloxLocked = true + LoadoutsHeaderText.Name = "LoadoutsHeaderText" + LoadoutsHeaderText.BackgroundTransparency = 1 + LoadoutsHeaderText.Font = Enum.Font.ArialBold + LoadoutsHeaderText.FontSize = Enum.FontSize.Size18 + LoadoutsHeaderText.Size = UDim2.new(1,0,1,0) + LoadoutsHeaderText.Text = "Loadouts" + LoadoutsHeaderText.TextColor3 = Color3.new(1,1,1) + LoadoutsHeaderText.Parent = GearLoadoutsHeader - if button.Selected then return end + local GearLoadoutsScrollingArea = GearGridScrollingArea:clone() + GearLoadoutsScrollingArea.RobloxLocked = true + GearLoadoutsScrollingArea.Name = "GearLoadoutsScrollingArea" + GearLoadoutsScrollingArea.Position = UDim2.new(1,-15,0.15,2) + GearLoadoutsScrollingArea.Size = UDim2.new(0,17,0.85,-2) + GearLoadoutsScrollingArea.Parent = GearLoadouts + + local LoadoutsList = Instance.new("Frame") + LoadoutsList.RobloxLocked = true + LoadoutsList.Name = "LoadoutsList" + LoadoutsList.Position = UDim2.new(0,0,0.15,2) + LoadoutsList.Size = UDim2.new(1,-17,0.85,-2) + LoadoutsList.Style = Enum.FrameStyle.RobloxSquare + LoadoutsList.Parent = GearLoadouts + + + local GearPreview = Instance.new("Frame") + GearPreview.RobloxLocked = true + GearPreview.Name = "GearPreview" + GearPreview.Position = UDim2.new(0.7,23,0,0) + GearPreview.Size = UDim2.new(0.3,-23,0.5,-1) + GearPreview.Style = Enum.FrameStyle.RobloxRound + GearPreview.Parent = Gear + + -- GearPreview Children + local GearStats = Instance.new("Frame") + GearStats.RobloxLocked = true + GearStats.Name = "GearStats" + GearStats.BackgroundTransparency = 1 + GearStats.Position = UDim2.new(0,0,0.75,0) + GearStats.Size = UDim2.new(1,0,0.25,0) + GearStats.Parent = GearPreview + + -- GearStats Children + local GearName = Instance.new("TextLabel") + GearName.RobloxLocked = true + GearName.Name = "GearName" + GearName.BackgroundTransparency = 1 + GearName.Font = Enum.Font.ArialBold + GearName.FontSize = Enum.FontSize.Size18 + GearName.Position = UDim2.new(0,-3,0,0) + GearName.Size = UDim2.new(1,6,1,5) + GearName.Text = "" + GearName.TextColor3 = Color3.new(1,1,1) + GearName.TextWrap = true + GearName.Parent = GearStats + + local GearImage = Instance.new("ImageLabel") + GearImage.RobloxLocked = true + GearImage.Name = "GearImage" + GearImage.Image = "" + GearImage.BackgroundTransparency = 1 + GearImage.Position = UDim2.new(0.125,0,0,0) + GearImage.Size = UDim2.new(0.75,0,0.75,0) + GearImage.Parent = GearPreview + + --GearImage Children + local GearIcons = Instance.new("Frame") + GearIcons.BackgroundColor3 = Color3.new(0,0,0) + GearIcons.BackgroundTransparency = 0.5 + GearIcons.BorderSizePixel = 0 + GearIcons.RobloxLocked = true + GearIcons.Name = "GearIcons" + GearIcons.Position = UDim2.new(0.4,2,0.85,-2) + GearIcons.Size = UDim2.new(0.6,0,0.15,0) + GearIcons.Visible = false + GearIcons.Parent = GearImage + + -- GearIcons Children + local GenreImage = Instance.new("ImageLabel") + GenreImage.RobloxLocked = true + GenreImage.Name = "GenreImage" + GenreImage.BackgroundColor3 = Color3.new(102/255,153/255,1) + GenreImage.BackgroundTransparency = 0.5 + GenreImage.BorderSizePixel = 0 + GenreImage.Size = UDim2.new(0.25,0,1,0) + GenreImage.Parent = GearIcons + + local AttributeOneImage = GenreImage:clone() + AttributeOneImage.RobloxLocked = true + AttributeOneImage.Name = "AttributeOneImage" + AttributeOneImage.BackgroundColor3 = Color3.new(1,51/255,0) + AttributeOneImage.Position = UDim2.new(0.25,0,0,0) + AttributeOneImage.Parent = GearIcons + + local AttributeTwoImage = GenreImage:clone() + AttributeTwoImage.RobloxLocked = true + AttributeTwoImage.Name = "AttributeTwoImage" + AttributeTwoImage.BackgroundColor3 = Color3.new(153/255,1,153/255) + AttributeTwoImage.Position = UDim2.new(0.5,0,0,0) + AttributeTwoImage.Parent = GearIcons + + local AttributeThreeImage = GenreImage:clone() + AttributeThreeImage.RobloxLocked = true + AttributeThreeImage.Name = "AttributeThreeImage" + AttributeThreeImage.BackgroundColor3 = Color3.new(0,0.5,0.5) + AttributeThreeImage.Position = UDim2.new(0.75,0,0,0) + AttributeThreeImage.Parent = GearIcons + + +-- Backpack Resizer (handles all backpack resizing junk) +game:GetService("ScriptContext"):AddCoreScript(11,Backpack,"BackpackResizer") - button.BackgroundColor3 = Color3.new(39/255,39/255,39/255) -end - -function newTabClicked(tabName) - assert(tabName) - tabName = string.lower(tabName) - currentTab = tabName - - updateTabGui(tabName) - tabClickedEvent:Fire(tabName) - resetSearch() -end - -function trim(s) - return (s:gsub("^%s*(.-)%s*$", "%1")) -end - -function splitByWhitespace(text) - if type(text) ~= "string" then return nil end - - local terms = {} - for token in string.gmatch(text, "[^%s]+") do - if string.len(token) > 0 then - table.insert(terms,token) - end - end - return terms -end - -function resetSearchBoxGui() - resetButton.Visible = false - searchBox.Text = searchDefaultText -end - -function doSearch() - local searchText = searchBox.Text - if searchText == "" then - resetSearch() - return - end - searchText = trim(searchText) - resetButton.Visible = true - termTable = splitByWhitespace(searchText) - searchRequestedEvent:Fire(searchText) -- todo: replace this with termtable when table passing is possible -end - -function resetSearch() - resetSearchBoxGui() - searchRequestedEvent:Fire() -end - -local backpackReady = function() - readyForNextEvent = true -end - ---------------------------- End Internal Functions ------------------------------------- - - ------------------------------- Public Functions Setup ------------------------------------- -createPublicFunction("CloseBackpack", hideBackpack) -createPublicFunction("BackpackReady", backpackReady) ------------------------------- End Public Functions Setup --------------------------------- - - ------------------------- Connections/Script Main ------------------------------------------- - -inventoryButton.MouseButton1Click:connect(function() newTabClicked("gear") end) -inventoryButton.MouseEnter:connect(function() mouseOverTab(inventoryButton) end) -inventoryButton.MouseLeave:connect(function() mouseLeaveTab(inventoryButton) end) - -if game.CoreGui.Version >= 8 then - wardrobeButton.MouseButton1Click:connect(function() newTabClicked("wardrobe") end) - wardrobeButton.MouseEnter:connect(function() mouseOverTab(wardrobeButton) end) - wardrobeButton.MouseLeave:connect(function() mouseLeaveTab(wardrobeButton) end) -end - -closeButton.MouseButton1Click:connect(closeBackpack) - -screen.Changed:connect(function(prop) - if prop == "AbsoluteSize" then - resizeEvent:Fire(screen.AbsoluteSize) - end -end) - --- GuiService key setup -game:GetService("GuiService"):AddKey(tilde) -game:GetService("GuiService"):AddKey(backquote) -game:GetService("GuiService").KeyPressed:connect(function(key) - if not active then return end - if key == tilde or key == backquote then - toggleBackpack() - end -end) -backpackButton.MouseButton1Click:connect(function() - if not active then return end - toggleBackpack() -end) - -if game.Players.LocalPlayer["Character"] then - activateBackpack() -end -game.Players.LocalPlayer.CharacterAdded:connect(activateBackpack) - --- search functions -searchBox.FocusLost:connect(function(enterPressed) - if enterPressed or searchBox.Text ~= "" then - doSearch() - elseif searchBox.Text == "" then - resetSearch() - end -end) -searchButton.MouseButton1Click:connect(doSearch) -resetButton.MouseButton1Click:connect(resetSearch) - -backpackButton.Visible = true +script:remove() \ No newline at end of file diff --git a/public/asset/13 b/public/asset/13 index 5d2f3e2..84cdf31 100644 --- a/public/asset/13 +++ b/public/asset/13 @@ -1,843 +1,828 @@ %13% +if game.CoreGui.Version < 3 then return end -- peace out if we aren't using the right client + -- A couple of necessary functions local function waitForChild(instance, name) - assert(instance) - assert(name) while not instance:FindFirstChild(name) do instance.ChildAdded:wait() end - return instance:FindFirstChild(name) end local function waitForProperty(instance, property) - assert(instance) - assert(property) while not instance[property] do instance.Changed:wait() end end + + + + +--- Begin Locals waitForChild(game,"Players") waitForProperty(game.Players,"LocalPlayer") local player = game.Players.LocalPlayer -local RbxGui, msg = LoadLibrary("RbxGui") -if not RbxGui then print("could not find RbxGui!") return end +waitForChild(game, "LocalBackpack") +game.LocalBackpack:SetOldSchoolBackpack(false) ---- Begin Locals -local StaticTabName = "gear" +local currentLoadout = script.Parent +local maxNumLoadoutItems = 10 -local backpack = script.Parent -local screen = script.Parent.Parent - -local backpackItems = {} -local buttons = {} - -local debounce = false -local browsingMenu = false - -local mouseEnterCons = {} -local mouseClickCons = {} +waitForChild(currentLoadout.Parent,"Backpack") +local guiBackpack = currentLoadout.Parent.Backpack local characterChildAddedCon = nil -local characterChildRemovedCon = nil -local backpackAddCon = nil +local backpackChildCon = nil -local playerBackpack = waitForChild(player,"Backpack") +local debounce = script.Parent.Debounce -waitForChild(backpack,"Tabs") +local waitingOnEnlarge = nil -waitForChild(backpack,"Gear") -local gearPreview = waitForChild(backpack.Gear,"GearPreview") +local canSaveLoadout = true -local scroller = waitForChild(backpack.Gear,"GearGridScrollingArea") +local enlargeFactor = 1.18 +local buttonSizeEnlarge = UDim2.new(1 * enlargeFactor,0,1 * enlargeFactor,0) +local buttonSizeNormal = UDim2.new(1,0,1,0) +local enlargeOverride = true -local currentLoadout = waitForChild(backpack.Parent,"CurrentLoadout") +local guiTweenSpeed = 0.5 -local grid = waitForChild(backpack.Gear,"GearGrid") -local gearButton = waitForChild(grid,"GearButton") +for i = 0, 9 do + game:GetService("GuiService"):AddKey(tostring(i)) -- register our keys +end -local swapSlot = waitForChild(script.Parent,"SwapSlot") +local gearSlots = {} +for i = 1, maxNumLoadoutItems do + gearSlots[i] = "empty" +end -local backpackManager = waitForChild(script.Parent,"CoreScripts/BackpackScripts/BackpackManager") -local backpackOpenEvent = waitForChild(backpackManager,"BackpackOpenEvent") -local backpackCloseEvent = waitForChild(backpackManager,"BackpackCloseEvent") -local tabClickedEvent = waitForChild(backpackManager,"TabClickedEvent") -local resizeEvent = waitForChild(backpackManager,"ResizeEvent") -local searchRequestedEvent = waitForChild(backpackManager,"SearchRequestedEvent") -local tellBackpackReadyFunc = waitForChild(backpackManager,"BackpackReady") +local inventory = {} +local lastLoadout = {} +--- End Locals --- creating scroll bar early as to make sure items get placed correctly -local scrollFrame, scrollUp, scrollDown, recalculateScroll = RbxGui.CreateScrollingFrame(nil,"grid") -scrollFrame.Position = UDim2.new(0,0,0,30) -scrollFrame.Size = UDim2.new(1,0,1,-30) -scrollFrame.Parent = backpack.Gear.GearGrid -local scrollBar = Instance.new("Frame") -scrollBar.Name = "ScrollBar" -scrollBar.BackgroundTransparency = 0.9 -scrollBar.BackgroundColor3 = Color3.new(1,1,1) -scrollBar.BorderSizePixel = 0 -scrollBar.Size = UDim2.new(0, 17, 1, -36) -scrollBar.Position = UDim2.new(0,0,0,18) -scrollBar.Parent = scroller -scrollDown.Position = UDim2.new(0,0,1,-17) - -scrollUp.Parent = scroller -scrollDown.Parent = scroller - -local scrollFrameLoadout, scrollUpLoadout, scrollDownLoadout, recalculateScrollLoadout = RbxGui.CreateScrollingFrame() - -scrollFrameLoadout.Position = UDim2.new(0,0,0,0) -scrollFrameLoadout.Size = UDim2.new(1,0,1,0) -scrollFrameLoadout.Parent = backpack.Gear.GearLoadouts.LoadoutsList - -local LoadoutButton = Instance.new("TextButton") -LoadoutButton.RobloxLocked = true -LoadoutButton.Name = "LoadoutButton" -LoadoutButton.Font = Enum.Font.ArialBold -LoadoutButton.FontSize = Enum.FontSize.Size14 -LoadoutButton.Position = UDim2.new(0,0,0,0) -LoadoutButton.Size = UDim2.new(1,0,0,32) -LoadoutButton.Style = Enum.ButtonStyle.RobloxButton -LoadoutButton.Text = "Loadout #1" -LoadoutButton.TextColor3 = Color3.new(1,1,1) -LoadoutButton.Parent = scrollFrameLoadout - -local LoadoutButtonTwo = LoadoutButton:clone() -LoadoutButtonTwo.Text = "Loadout #2" -LoadoutButtonTwo.Parent = scrollFrameLoadout - -local LoadoutButtonThree = LoadoutButton:clone() -LoadoutButtonThree.Text = "Loadout #3" -LoadoutButtonThree.Parent = scrollFrameLoadout - -local LoadoutButtonFour = LoadoutButton:clone() -LoadoutButtonFour.Text = "Loadout #4" -LoadoutButtonFour.Parent = scrollFrameLoadout - -local scrollBarLoadout = Instance.new("Frame") -scrollBarLoadout.Name = "ScrollBarLoadout" -scrollBarLoadout.BackgroundTransparency = 0.9 -scrollBarLoadout.BackgroundColor3 = Color3.new(1,1,1) -scrollBarLoadout.BorderSizePixel = 0 -scrollBarLoadout.Size = UDim2.new(0, 17, 1, -36) -scrollBarLoadout.Position = UDim2.new(0,0,0,18) -scrollBarLoadout.Parent = backpack.Gear.GearLoadouts.GearLoadoutsScrollingArea - -scrollDownLoadout.Position = UDim2.new(0,0,1,-17) - -scrollUpLoadout.Parent = backpack.Gear.GearLoadouts.GearLoadoutsScrollingArea -scrollDownLoadout.Parent = backpack.Gear.GearLoadouts.GearLoadoutsScrollingArea -- Begin Functions -function removeFromMap(map,object) - for i = 1, #map do - if map[i] == object then - table.remove(map,i) +local function kill(prop,con,gear) + if con then con:disconnect() end + if prop == true and gear then + reorganizeLoadout(gear,false) + end +end + +function removeGear(gear) + local emptySlot = nil + for i = 1, #gearSlots do + if gearSlots[i] == gear and gear.Parent ~= nil then + emptySlot = i break end end -end + if emptySlot then + if gearSlots[emptySlot].GearReference.Value then + if gearSlots[emptySlot].GearReference.Value.Parent == game.Players.LocalPlayer.Character then -- if we currently have this equipped, unequip it + gearSlots[emptySlot].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack + end -function robloxLock(instance) - instance.RobloxLocked = true - children = instance:GetChildren() - if children then - for i, child in ipairs(children) do - robloxLock(child) - end - end -end - -function resize() - local size = 0 - if gearPreview.AbsoluteSize.Y > gearPreview.AbsoluteSize.X then - size = gearPreview.AbsoluteSize.X * 0.75 - else - size = gearPreview.AbsoluteSize.Y * 0.75 - end - - waitForChild(gearPreview,"GearImage") - gearPreview.GearImage.Size = UDim2.new(0,size,0,size) - gearPreview.GearImage.Position = UDim2.new(0,gearPreview.AbsoluteSize.X/2 - size/2,0.75,-size) - - resizeGrid() -end - -function addToGrid(child) - if not child:IsA("Tool") then - if not child:IsA("HopperBin") then - return - end - end - if child:FindFirstChild("RobloxBuildTool") then return end - - for i,v in pairs(backpackItems) do -- check to see if we already have this gear registered - if v == child then return end - end - - table.insert(backpackItems,child) - - local changeCon = child.Changed:connect(function(prop) - if prop == "Name" then - if buttons[child] then - if buttons[child].Image == "" then - buttons[child].GearText.Text = child.Name - end + if gearSlots[emptySlot].GearReference.Value:IsA("HopperBin") and gearSlots[emptySlot].GearReference.Value.Active then -- this is an active hopperbin + gearSlots[emptySlot].GearReference.Value:Disable() + gearSlots[emptySlot].GearReference.Value.Active = false end end - end) - local ancestryCon = nil - ancestryCon = child.AncestryChanged:connect(function(theChild,theParent) - local thisObject = nil - for k,v in pairs(backpackItems) do - if v == child then - thisObject = v + + gearSlots[emptySlot] = "empty" + + local centerizeX = gear.Size.X.Scale/2 + local centerizeY = gear.Size.Y.Scale/2 + gear:TweenSizeAndPosition(UDim2.new(0,0,0,0), + UDim2.new(gear.Position.X.Scale + centerizeX,gear.Position.X.Offset,gear.Position.Y.Scale + centerizeY,gear.Position.Y.Offset), + Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/4,true) + delay(guiTweenSpeed/2, + function() + gear:remove() + end) + end +end + +function insertGear(gear, addToSlot) + local pos = nil + if not addToSlot then + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then + pos = i break end end - - waitForProperty(player,"Character") - waitForChild(player,"Backpack") - if (child.Parent ~= player.Backpack and child.Parent ~= player.Character) then - if ancestryCon then ancestryCon:disconnect() end - if changeCon then changeCon:disconnect() end - - for k,v in pairs(backpackItems) do - if v == thisObject then - if mouseEnterCons[buttons[v]] then mouseEnterCons[buttons[v]]:disconnect() end - if mouseClickCons[buttons[v]] then mouseClickCons[buttons[v]]:disconnect() end - buttons[v].Parent = nil - buttons[v] = nil - break - end - end - removeFromMap(backpackItems,thisObject) - - resizeGrid() - else - resizeGrid() - end - updateGridActive() - end) - resizeGrid() -end - -function buttonClick(button) - if button:FindFirstChild("UnequipContextMenu") and not button.Active then - button.UnequipContextMenu.Visible = true - browsingMenu = true - end -end - -function previewGear(button) - if not browsingMenu then - gearPreview.GearImage.Image = button.Image - gearPreview.GearStats.GearName.Text = button.GearReference.Value.Name - end -end - -function findEmptySlot() - local smallestNum = nil - local loadout = currentLoadout:GetChildren() - for i = 1, #loadout do - if loadout[i]:IsA("Frame") and #loadout[i]:GetChildren() <= 0 then - local frameNum = tonumber(string.sub(loadout[i].Name,5)) - if frameNum == 0 then frameNum = 10 end - if not smallestNum or (smallestNum > frameNum) then - smallestNum = frameNum - end - end - end - if smallestNum == 10 then smallestNum = 0 end - return smallestNum -end - -function checkForSwap(button,x,y) - local loadoutChildren = currentLoadout:GetChildren() - for i = 1, #loadoutChildren do - if loadoutChildren[i]:IsA("Frame") and string.find(loadoutChildren[i].Name,"Slot") then - if x >= loadoutChildren[i].AbsolutePosition.x and x <= (loadoutChildren[i].AbsolutePosition.x + loadoutChildren[i].AbsoluteSize.x) then - if y >= loadoutChildren[i].AbsolutePosition.y and y <= (loadoutChildren[i].AbsolutePosition.y + loadoutChildren[i].AbsoluteSize.y) then - local slot = tonumber(string.sub(loadoutChildren[i].Name,5)) - swapGearSlot(slot,button) - return true - end - end - end - end - return false -end - -function resizeGrid() - for k,v in pairs(backpackItems) do - if not v:FindFirstChild("RobloxBuildTool") then - if not buttons[v] then - local buttonClone = gearButton:clone() - buttonClone.Parent = grid.ScrollingFrame - buttonClone.Visible = true - buttonClone.Image = v.TextureId - if buttonClone.Image == "" then - buttonClone.GearText.Text = v.Name - end - - buttonClone.GearReference.Value = v - buttonClone.Draggable = true - buttons[v] = buttonClone - - local unequipMenu = getGearContextMenu() - - unequipMenu.Visible = false - unequipMenu.Parent = buttonClone - - local beginPos = nil - buttonClone.DragBegin:connect(function(value) - buttonClone.ZIndex = 9 - beginPos = value - end) - buttonClone.DragStopped:connect(function(x,y) - buttonClone.ZIndex = 1 - if beginPos ~= buttonClone.Position then - if not checkForSwap(buttonClone,x,y) then - buttonClone:TweenPosition(beginPos,Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.5, true) - buttonClone.Draggable = false - delay(0.5,function() - buttonClone.Draggable = true - end) - else - buttonClone.Position = beginPos - end - end - end) - local clickTime = tick() - mouseEnterCons[buttonClone] = buttonClone.MouseEnter:connect(function() previewGear(buttonClone) end) - mouseClickCons[buttonClone] = buttonClone.MouseButton1Click:connect(function() - local newClickTime = tick() - if buttonClone.Active and (newClickTime - clickTime) < 0.5 then - local slot = findEmptySlot() - if slot then - buttonClone.ZIndex = 1 - swapGearSlot(slot,buttonClone) - end - else - buttonClick(buttonClone) - end - clickTime = newClickTime - end) - end - end - end - recalculateScroll() -end - -function showPartialGrid(subset) - for k,v in pairs(buttons) do - v.Parent = nil - end - if subset then - for k,v in pairs(subset) do - v.Parent = grid.ScrollingFrame - end - end - recalculateScroll() -end - -function showEntireGrid() - for k,v in pairs(buttons) do - v.Parent = grid.ScrollingFrame - end - recalculateScroll() -end - -function inLoadout(gear) - local children = currentLoadout:GetChildren() - for i = 1, #children do - if children[i]:IsA("Frame") then - local button = children[i]:GetChildren() - if #button > 0 then - if button[1].GearReference.Value and button[1].GearReference.Value == gear then - return true - end - end - end - end - return false -end - -function updateGridActive() - for k,v in pairs(backpackItems) do - if buttons[v] then - local gear = nil - local gearRef = buttons[v]:FindFirstChild("GearReference") - - if gearRef then gear = gearRef.Value end - - if not gear then - buttons[v].Active = false - elseif inLoadout(gear) then - buttons[v].Active = false - else - buttons[v].Active = true - end - end - end -end - -function centerGear(loadoutChildren) - local gearButtons = {} - local lastSlotAdd = nil - for i = 1, #loadoutChildren do - if loadoutChildren[i]:IsA("Frame") and #loadoutChildren[i]:GetChildren() > 0 then - if loadoutChildren[i].Name == "Slot0" then - lastSlotAdd = loadoutChildren[i] - else - table.insert(gearButtons, loadoutChildren[i]) - end - end - end - if lastSlotAdd then table.insert(gearButtons,lastSlotAdd) end - - local startPos = ( 1 - (#gearButtons * 0.1) ) / 2 - for i = 1, #gearButtons do - gearButtons[i]:TweenPosition(UDim2.new(startPos + ((i - 1) * 0.1),0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.25, true) - end -end - -function tabClickHandler(tabName) - if tabName == StaticTabName then - backpackOpenHandler(tabName) + if pos == 1 and gearSlots[1] ~= "empty" then gear:remove() return end -- we are currently full, can't add in else - backpackCloseHandler(tabName) - end -end - -function backpackOpenHandler(currentTab) - if currentTab and currentTab ~= StaticTabName then - backpack.Gear.Visible = false - return - end - - backpack.Gear.Visible = true - updateGridActive() - - resizeGrid() - resize() - tellBackpackReadyFunc:Invoke() -end - -function backpackCloseHandler(currentTab) - if currentTab and currentTab ~= StaticTabName then - backpack.Gear.Visible = false - return - end - - backpack.Gear.Visible = false - - resizeGrid() - resize() - tellBackpackReadyFunc:Invoke() -end - -function loadoutCheck(child, selectState) - if not child:IsA("ImageButton") then return end - for k,v in pairs(backpackItems) do - if buttons[v] then - if child:FindFirstChild("GearReference") and buttons[v]:FindFirstChild("GearReference") then - if buttons[v].GearReference.Value == child.GearReference.Value then - buttons[v].Active = selectState - break - end + pos = addToSlot + -- push all gear down one slot + local start = 1 + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then + start = i + break + end + end + for i = start, pos + 1, -1 do + gearSlots[i] = gearSlots[i - 1] + if i == 10 then + gearSlots[i].SlotNumber.Text = "0" + gearSlots[i].SlotNumberDownShadow.Text = "0" + gearSlots[i].SlotNumberUpShadow.Text = "0" + else + gearSlots[i].SlotNumber.Text = i + gearSlots[i].SlotNumberDownShadow.Text = i + gearSlots[i].SlotNumberUpShadow.Text = i end end end + + gearSlots[pos] = gear + if pos ~= maxNumLoadoutItems then + if(type(tostring(pos)) == "string") then + local posString = tostring(pos) + gear.SlotNumber.Text = posString + gear.SlotNumberDownShadow.Text = posString + gear.SlotNumberUpShadow.Text = posString + end + else -- tenth gear doesn't follow mathematical pattern :( + gear.SlotNumber.Text = "0" + gear.SlotNumberDownShadow.Text = "0" + gear.SlotNumberUpShadow.Text = "0" + end + gear.Visible = true + + local con = nil + con = gear.Kill.Changed:connect(function(prop) kill(prop,con,gear) end) end -function clearPreview() - gearPreview.GearImage.Image = "" - gearPreview.GearStats.GearName.Text = "" + +function reorganizeLoadout(gear, inserting, equipped, addToSlot) + if inserting then -- add in gear + insertGear(gear, addToSlot) + else + removeGear(gear) + end + if gear ~= "empty" then gear.ZIndex = 1 end +end + +function checkToolAncestry(child,parent) + if child:IsA("Tool") or child:IsA("HopperBin") then + for i = 1, #gearSlots do + if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then + if parent == nil then + gearSlots[i].Kill.Value = true + return false + elseif child.Parent == player.Character then + gearSlots[i].Selected = true + return true + elseif child.Parent == player.Backpack then + if child:IsA("Tool") or child:IsA("HopperBin") then gearSlots[i].Selected = false end + return true + else + gearSlots[i].Kill.Value = true + return false + end + return true + end + end + end end function removeAllEquippedGear(physGear) local stuff = player.Character:GetChildren() for i = 1, #stuff do if ( stuff[i]:IsA("Tool") or stuff[i]:IsA("HopperBin") ) and stuff[i] ~= physGear then - stuff[i].Parent = playerBackpack - end - end -end - -function equipGear(physGear) - removeAllEquippedGear(physGear) - physGear.Parent = player.Character - updateGridActive() -end - -function unequipGear(physGear) - physGear.Parent = playerBackpack - updateGridActive() -end - -function highlight(button) - button.TextColor3 = Color3.new(0,0,0) - button.BackgroundColor3 = Color3.new(0.8,0.8,0.8) -end -function clearHighlight(button) - button.TextColor3 = Color3.new(1,1,1) - button.BackgroundColor3 = Color3.new(0,0,0) -end - -function swapGearSlot(slot,gearButton) - if not swapSlot.Value then -- signal loadout to swap a gear out - swapSlot.Slot.Value = slot - swapSlot.GearButton.Value = gearButton - swapSlot.Value = true - updateGridActive() - end -end - - -local UnequipGearMenuClick = function(element, menu) - if type(element.Action) ~= "number" then return end - local num = element.Action - if num == 1 then -- remove from loadout - unequipGear(menu.Parent.GearReference.Value) - local inventoryButton = menu.Parent - local gearToUnequip = inventoryButton.GearReference.Value - local loadoutChildren = currentLoadout:GetChildren() - local slot = -1 - for i = 1, #loadoutChildren do - if loadoutChildren[i]:IsA("Frame") then - local button = loadoutChildren[i]:GetChildren() - if button[1] and button[1].GearReference.Value == gearToUnequip then - slot = button[1].SlotNumber.Text - break - end - end - end - swapGearSlot(slot,nil) - end -end - -function setupCharacterConnections() - - if backpackAddCon then backpackAddCon:disconnect() end - backpackAddCon = game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(child) addToGrid(child) end) - - -- make sure we get all the children - local backpackChildren = game.Players.LocalPlayer.Backpack:GetChildren() - for i = 1, #backpackChildren do - addToGrid(backpackChildren[i]) - end - - if characterChildAddedCon then characterChildAddedCon:disconnect() end - characterChildAddedCon = - game.Players.LocalPlayer.Character.ChildAdded:connect(function(child) - addToGrid(child) - updateGridActive() - end) - - if characterChildRemovedCon then characterChildRemovedCon:disconnect() end - characterChildRemovedCon = - game.Players.LocalPlayer.Character.ChildRemoved:connect(function(child) - updateGridActive() - end) - - wait() - centerGear(currentLoadout:GetChildren()) -end - -function removeCharacterConnections() - if characterChildAddedCon then characterChildAddedCon:disconnect() end - if characterChildRemovedCon then characterChildRemovedCon:disconnect() end - if backpackAddCon then backpackAddCon:disconnect() end -end - -function trim(s) - return (s:gsub("^%s*(.-)%s*$", "%1")) -end - -function filterGear(terms) - local filteredGear = {} - for k,v in pairs(backpackItems) do - if buttons[v] then - local gearString = string.lower(buttons[v].GearReference.Value.Name) - gearString = trim(gearString) - for i = 1, #terms do - if string.match(gearString,terms[i]) then - table.insert(filteredGear,buttons[v]) - break - end + if stuff[i]:IsA("Tool") then stuff[i].Parent = player.Backpack end + if stuff[i]:IsA("HopperBin") then + stuff[i]:Disable() end end end - - return filteredGear end -function splitByWhitespace(text) - if type(text) ~= "string" then return nil end - - local terms = {} - for token in string.gmatch(text, "[^%s]+") do - if string.len(token) > 0 then - table.insert(terms,token) - end - end - return terms -end -function showSearchGear(searchTerms) - if not backpack.Gear.Visible then return end -- currently not active tab - local searchTermTable = splitByWhitespace(searchTerms) - if searchTermTable and (#searchTermTable > 0) then - currSearchTerms = searchTermTable +function hopperBinSwitcher(numKey, physGear) + if not physGear then return end + + physGear:ToggleSelect() + + if gearSlots[numKey] == "empty" then return end + + if not physGear.Active then + gearSlots[numKey].Selected = false + normalizeButton(gearSlots[numKey]) else - currSearchTerms = nil + gearSlots[numKey].Selected = true + enlargeButton(gearSlots[numKey]) + end +end + +function toolSwitcher(numKey) + + if not gearSlots[numKey] then return end + local physGear = gearSlots[numKey].GearReference.Value + if physGear == nil then return end + + removeAllEquippedGear(physGear) -- we don't remove this gear, as then we get a double switcheroo + + local key = numKey + if numKey == 0 then key = 10 end + + for i = 1, #gearSlots do + if gearSlots[i] and gearSlots[i] ~= "empty" and i ~= key then + normalizeButton(gearSlots[i]) + gearSlots[i].Selected = false + if gearSlots[i].GearReference and gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value:IsA("HopperBin") and gearSlots[i].GearReference.Value.Active then + gearSlots[i].GearReference.Value:ToggleSelect() + end + end end - if searchTermTable == nil then - showEntireGrid() + if physGear:IsA("HopperBin") then + hopperBinSwitcher(numKey,physGear) + else + if physGear.Parent == player.Character then + physGear.Parent = player.Backpack + + if gearSlots[numKey] ~= "empty" then + gearSlots[numKey].Selected = false + normalizeButton(gearSlots[numKey]) + end + else + physGear.Parent = player.Character + gearSlots[numKey].Selected = true + + enlargeButton(gearSlots[numKey]) + end + end +end + + +function activateGear(num) + local numKey = nil + if num == "0" then + numKey = 10 -- why do lua indexes have to start at 1? :( + else + numKey = tonumber(num) + end + + if(numKey == nil) then return end + + if gearSlots[numKey] ~= "empty" then + toolSwitcher(numKey) + end +end + + +enlargeButton = function(button) + if button.Size.Y.Scale > 1 then return end + if not button.Parent then return end + if not button.Selected then return end + + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then break end + if gearSlots[i] ~= button then + normalizeButton(gearSlots[i]) + end + end + + if not enlargeOverride then + waitingOnEnlarge = button return end - local filteredButtons = filterGear(currSearchTerms) - showPartialGrid(filteredButtons) -end - -function nukeBackpack() - while #buttons > 0 do - table.remove(buttons) - end - buttons = {} - while #backpackItems > 0 do - table.remove(backpackItems) - end - backpackItems = {} - local scrollingFrameChildren = grid.ScrollingFrame:GetChildren() - for i = 1, #scrollingFrameChildren do - scrollingFrameChildren[i]:remove() + if button:IsA("ImageButton") or button:IsA("TextButton") then + button.ZIndex = 2 + local centerizeX = -(buttonSizeEnlarge.X.Scale - button.Size.X.Scale)/2 + local centerizeY = -(buttonSizeEnlarge.Y.Scale - button.Size.Y.Scale)/2 + button:TweenSizeAndPosition(buttonSizeEnlarge, + UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), + Enum.EasingDirection.Out, Enum.EasingStyle.Quad,guiTweenSpeed/5,enlargeOverride) end end -function getGearContextMenu() - local gearContextMenu = Instance.new("Frame") - gearContextMenu.Active = true - gearContextMenu.Name = "UnequipContextMenu" - gearContextMenu.Size = UDim2.new(0,115,0,70) - gearContextMenu.Position = UDim2.new(0,-16,0,-16) - gearContextMenu.BackgroundTransparency = 1 - gearContextMenu.Visible = false - - local gearContextMenuButton = Instance.new("TextButton") - gearContextMenuButton.Name = "UnequipContextMenuButton" - gearContextMenuButton.Text = "" - gearContextMenuButton.Style = Enum.ButtonStyle.RobloxButtonDefault - gearContextMenuButton.ZIndex = 8 - gearContextMenuButton.Size = UDim2.new(1, 0, 1, -20) - gearContextMenuButton.Visible = true - gearContextMenuButton.Parent = gearContextMenu - - local elementHeight = 12 - - local contextMenuElements = {} - local contextMenuElementsName = {"Remove Hotkey"} - - for i = 1, #contextMenuElementsName do - local element = {} - element.Type = "Button" - element.Text = contextMenuElementsName[i] - element.Action = i - element.DoIt = UnequipGearMenuClick - table.insert(contextMenuElements,element) +normalizeAllButtons = function() + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then break end + if gearSlots[i] ~= button then + normalizeButton(gearSlots[i],0.1) + end end +end - for i, contextElement in ipairs(contextMenuElements) do - local element = contextElement - if element.Type == "Button" then - local button = Instance.new("TextButton") - button.Name = "UnequipContextButton" .. i - button.BackgroundColor3 = Color3.new(0,0,0) - button.BorderSizePixel = 0 - button.TextXAlignment = Enum.TextXAlignment.Left - button.Text = " " .. contextElement.Text - button.Font = Enum.Font.Arial - button.FontSize = Enum.FontSize.Size14 - button.Size = UDim2.new(1, 8, 0, elementHeight) - button.Position = UDim2.new(0,0,0,elementHeight * i) - button.TextColor3 = Color3.new(1,1,1) - button.ZIndex = 9 - button.Parent = gearContextMenuButton - button.MouseButton1Click:connect(function() - if button.Active and not gearContextMenu.Parent.Active then - local success, result = pcall(function() element.DoIt(element, gearContextMenu) end) - browsingMenu = false - gearContextMenu.Visible = false - clearHighlight(button) - clearPreview() - end - end) - - button.MouseEnter:connect(function() - if button.Active and gearContextMenu.Parent.Active then - highlight(button) - end - end) - button.MouseLeave:connect(function() - if button.Active and gearContextMenu.Parent.Active then - clearHighlight(button) - end - end) - - contextElement.Button = button - contextElement.Element = button - elseif element.Type == "Label" then - local frame = Instance.new("Frame") - frame.Name = "ContextLabel" .. i - frame.BackgroundTransparency = 1 - frame.Size = UDim2.new(1, 8, 0, elementHeight) +normalizeButton = function(button, speed) + if not button then return end + if button.Size.Y.Scale <= 1 then return end + if button.Selected then return end + if not button.Parent then return end - local label = Instance.new("TextLabel") - label.Name = "Text1" - label.BackgroundTransparency = 1 - label.BackgroundColor3 = Color3.new(1,1,1) - label.BorderSizePixel = 0 - label.TextXAlignment = Enum.TextXAlignment.Left - label.Font = Enum.Font.ArialBold - label.FontSize = Enum.FontSize.Size14 - label.Position = UDim2.new(0.0, 0, 0, 0) - label.Size = UDim2.new(0.5, 0, 1, 0) - label.TextColor3 = Color3.new(1,1,1) - label.ZIndex = 9 - label.Parent = frame - element.Label1 = label - - if element.GetText2 then - label = Instance.new("TextLabel") - label.Name = "Text2" - label.BackgroundTransparency = 1 - label.BackgroundColor3 = Color3.new(1,1,1) - label.BorderSizePixel = 0 - label.TextXAlignment = Enum.TextXAlignment.Right - label.Font = Enum.Font.Arial - label.FontSize = Enum.FontSize.Size14 - label.Position = UDim2.new(0.5, 0, 0, 0) - label.Size = UDim2.new(0.5, 0, 1, 0) - label.TextColor3 = Color3.new(1,1,1) - label.ZIndex = 9 - label.Parent = frame - element.Label2 = label + local moveSpeed = speed + if moveSpeed == nil or type(moveSpeed) ~= "number" then moveSpeed = guiTweenSpeed/5 end + + if button:IsA("ImageButton") or button:IsA("TextButton") then + button.ZIndex = 1 + local inverseEnlarge = 1/enlargeFactor + local centerizeX = -(buttonSizeNormal.X.Scale - button.Size.X.Scale)/2 + local centerizeY = -(buttonSizeNormal.Y.Scale - button.Size.Y.Scale)/2 + button:TweenSizeAndPosition(buttonSizeNormal, + UDim2.new(button.Position.X.Scale + centerizeX,button.Position.X.Offset,button.Position.Y.Scale + centerizeY,button.Position.Y.Offset), + Enum.EasingDirection.Out, Enum.EasingStyle.Quad,moveSpeed,enlargeOverride) + end +end + +waitForDebounce = function() + if debounce.Value then + debounce.Changed:wait() + end +end + +function pointInRectangle(point,rectTopLeft,rectSize) + if point.x > rectTopLeft.x and point.x < (rectTopLeft.x + rectSize.x) then + if point.y > rectTopLeft.y and point.y < (rectTopLeft.y + rectSize.y) then + return true + end + end + return false +end + +function swapGear(gearClone,toFrame) + local toFrameChildren = toFrame:GetChildren() + if #toFrameChildren == 1 then + if toFrameChildren[1]:FindFirstChild("SlotNumber") then + + local toSlot = tonumber(toFrameChildren[1].SlotNumber.Text) + local gearCloneSlot = tonumber(gearClone.SlotNumber.Text) + if toSlot == 0 then toSlot = 10 end + if gearCloneSlot == 0 then gearCloneSlot = 10 end + + gearSlots[toSlot] = gearClone + gearSlots[gearCloneSlot] = toFrameChildren[1] + + toFrameChildren[1].SlotNumber.Text = gearClone.SlotNumber.Text + toFrameChildren[1].SlotNumberDownShadow.Text = gearClone.SlotNumber.Text + toFrameChildren[1].SlotNumberUpShadow.Text = gearClone.SlotNumber.Text + + local subString = string.sub(toFrame.Name,5) + gearClone.SlotNumber.Text = subString + gearClone.SlotNumberDownShadow.Text = subString + gearClone.SlotNumberUpShadow.Text = subString + + gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) + toFrameChildren[1].Position = UDim2.new(toFrameChildren[1].Position.X.Scale,0,toFrameChildren[1].Position.Y.Scale,0) + + toFrameChildren[1].Parent = gearClone.Parent + gearClone.Parent = toFrame + end + else + local slotNum = tonumber(gearClone.SlotNumber.Text) + if slotNum == 0 then slotNum = 10 end + gearSlots[slotNum] = "empty" -- reset this gear slot + + local subString = string.sub(toFrame.Name,5) + gearClone.SlotNumber.Text = subString + gearClone.SlotNumberDownShadow.Text = subString + gearClone.SlotNumberUpShadow.Text = subString + + local toSlotNum = tonumber(gearClone.SlotNumber.Text) + if toSlotNum == 0 then toSlotNum = 10 end + gearSlots[toSlotNum] = gearClone + gearClone.Position = UDim2.new(gearClone.Position.X.Scale,0,gearClone.Position.Y.Scale,0) + gearClone.Parent = toFrame + end +end + +function resolveDrag(gearClone,x,y) + local mousePoint = Vector2.new(x,y) + + local frame = gearClone.Parent + local frames = frame.Parent:GetChildren() + + for i = 1, #frames do + if frames[i]:IsA("Frame") then + if pointInRectangle(mousePoint, frames[i].AbsolutePosition,frames[i].AbsoluteSize) then + swapGear(gearClone,frames[i]) + --saveGearPositions() + return true end - frame.Parent = gearContextMenuButton - element.Label = frame - element.Element = frame end end - gearContextMenu.ZIndex = 4 - gearContextMenu.MouseLeave:connect(function() - browsingMenu = false - gearContextMenu.Visible = false - clearPreview() + if x < frame.AbsolutePosition.x or x > ( frame.AbsolutePosition.x + frame.AbsoluteSize.x ) then + reorganizeLoadout(gearClone,false) + --saveGearPositions() + return false + elseif y < frame.AbsolutePosition.y or y > ( frame.AbsolutePosition.y + frame.AbsoluteSize.y ) then + reorganizeLoadout(gearClone,false) + --saveGearPositions() + return false + else + if dragBeginPos then gearClone.Position = dragBeginPos end + return -1 + end +end + +function saveGearPositions() + if not canSaveLoadout then return end + + lastLoadout = {} + for i = 1, #gearSlots do + if gearSlots[i] and gearSlots[i] ~= "empty" then + lastLoadout[i] = gearSlots[i] + end + end +end + +function unequipAllItems(dontEquipThis) + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then break end + if gearSlots[i].GearReference.Value and gearSlots[i].GearReference.Value ~= dontEquipThis then + if gearSlots[i].GearReference.Value:IsA("HopperBin") then + gearSlots[i].GearReference.Value:Disable() + elseif gearSlots[i].GearReference.Value:IsA("Tool") then + gearSlots[i].GearReference.Value.Parent = game.Players.LocalPlayer.Backpack + end + gearSlots[i].Selected = false + end + end +end + +function showToolTip(button, tip) + if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then + button.ToolTipLabel.Text = tostring(tip) + local xSize = button.ToolTipLabel.TextBounds.X + 6 + button.ToolTipLabel.Size = UDim2.new(0,xSize,0,20) + button.ToolTipLabel.Position = UDim2.new(0.5,-xSize/2,0,-30) + button.ToolTipLabel.Visible = true + end +end + +function hideToolTip(button, tip) + if button and button:FindFirstChild("ToolTipLabel") and button.ToolTipLabel:IsA("TextLabel") then + button.ToolTipLabel.Visible = false + end +end + +local addingPlayerChild = function(child, equipped, addToSlot, inventoryGearButton) + waitForDebounce() + debounce.Value = true + + if not child:IsA("Tool") then + if not child:IsA("HopperBin") then + debounce.Value = false + return -- we don't care about anything besides tools (sigh...) + end + end + + if not addToSlot then + for i = 1, #gearSlots do + if gearSlots[i] ~= "empty" and gearSlots[i].GearReference.Value == child then -- we already have gear, do nothing + debounce.Value = false + return + end + end + end + + + local gearClone = currentLoadout.TempSlot:clone() + gearClone.Name = child.Name + gearClone.GearImage.Image = child.TextureId + if gearClone.GearImage.Image == "" then + gearClone.GearText.Text = child.Name + end + gearClone.GearReference.Value = child + + gearClone.MouseEnter:connect(function() + pcall(function() if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then + showToolTip(gearClone, gearClone.GearReference.Value.ToolTip) + end + end) end) - robloxLock(gearContextMenu) - return gearContextMenu + gearClone.MouseLeave:connect(function() + pcall(function() if gearClone.GearReference and gearClone.GearReference.Value["ToolTip"] and gearClone.GearReference.Value.ToolTip ~= "" then + hideToolTip(gearClone, gearClone.GearReference.Value.ToolTip) + end + end) + end) + + gearClone.RobloxLocked = true + + local slotToMod = -1 + + if not addToSlot then + for i = 1, #gearSlots do + if gearSlots[i] == "empty" then + slotToMod = i + break + end + end + else + slotToMod = addToSlot + end + + if slotToMod == - 1 then -- No available slot to add in! + debounce.Value = false + return + end + + local slotNum = slotToMod % 10 + local parent = currentLoadout:FindFirstChild("Slot"..tostring(slotNum)) + gearClone.Parent = parent + + if inventoryGearButton then + local absolutePositionFinal = inventoryGearButton.AbsolutePosition + local currentAbsolutePosition = gearClone.AbsolutePosition + local diff = absolutePositionFinal - currentAbsolutePosition + gearClone.Position = UDim2.new(gearClone.Position.X.Scale,diff.x,gearClone.Position.Y.Scale,diff.y) + gearClone.ZIndex = 4 + end + + if addToSlot then + reorganizeLoadout(gearClone, true, equipped, addToSlot) + else + reorganizeLoadout(gearClone, true) + end + + if gearClone.Parent == nil then debounce.Value = false return end -- couldn't fit in (hopper is full!) + + if equipped then + gearClone.Selected = true + unequipAllItems(child) + delay(guiTweenSpeed + 0.01,function() -- if our gear is equipped, we will want to enlarge it when done moving + if gearClone:FindFirstChild("GearReference") and ( (gearClone.GearReference.Value:IsA("Tool") and gearClone.GearReference.Value.Parent == player.Character) or + (gearClone.GearReference.Value:IsA("HopperBin") and gearClone.GearReference.Value.Active == true) ) then + enlargeButton(gearClone) + end + end) + end + + local dragBeginPos = nil + local clickCon, buttonDeleteCon, mouseEnterCon, mouseLeaveCon, dragStop, dragBegin = nil + clickCon = gearClone.MouseButton1Click:connect(function() if not gearClone.Draggable then activateGear(gearClone.SlotNumber.Text) end end) + mouseEnterCon = gearClone.MouseEnter:connect(function() + if guiBackpack.Visible then + gearClone.Draggable = true + end + end) + dragBegin = gearClone.DragBegin:connect(function(pos) + dragBeginPos = pos + gearClone.ZIndex = 7 + local children = gearClone:GetChildren() + for i = 1, #children do + if children[i]:IsA("TextLabel") then + if string.find(children[i].Name,"Shadow") then + children[i].ZIndex = 8 + else + children[i].ZIndex = 9 + end + elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then + children[i].ZIndex = 7 + end + end + end) + dragStop = gearClone.DragStopped:connect(function(x,y) + if gearClone.Selected then + gearClone.ZIndex = 2 + else + gearClone.ZIndex = 1 + end + local children = gearClone:GetChildren() + for i = 1, #children do + if children[i]:IsA("TextLabel") then + if string.find(children[i].Name,"Shadow") then + children[i].ZIndex = 3 + else + children[i].ZIndex = 4 + end + elseif children[i]:IsA("Frame") or children[i]:IsA("ImageLabel") then + children[i].ZIndex = 2 + end + end + resolveDrag(gearClone,x,y) + end) + mouseLeaveCon = gearClone.MouseLeave:connect(function() + gearClone.Draggable = false + end) + buttonDeleteCon = gearClone.AncestryChanged:connect(function() + if gearClone.Parent and gearClone.Parent.Parent == currentLoadout then return end + if clickCon then clickCon:disconnect() end + if buttonDeleteCon then buttonDeleteCon:disconnect() end + if mouseEnterCon then mouseEnterCon:disconnect() end + if mouseLeaveCon then mouseLeaveCon:disconnect() end + if dragStop then dragStop:disconnect() end + if dragBegin then dragBegin:disconnect() end + end) -- this probably isn't necessary since objects are being deleted (probably), but this might still leak just in case + + local childCon = nil + local childChangeCon = nil + childCon = child.AncestryChanged:connect(function(newChild,parent) + if not checkToolAncestry(newChild,parent) then + if childCon then childCon:disconnect() end + if childChangeCon then childChangeCon:disconnect() end + removeFromInventory(child) + elseif parent == game.Players.LocalPlayer.Backpack then + normalizeButton(gearClone) + end + end) + + childChangeCon = child.Changed:connect(function(prop) + if prop == "Name" then + if gearClone and gearClone.GearImage.Image == "" then + gearClone.GearText.Text = child.Name + end + elseif prop == "Active" then + if child and child:IsA("HopperBin") then + if not child.Active then + gearClone.Selected = false + normalizeButton(gearClone) + end + end + end + end) + + debounce.Value = false + end +function addToInventory(child) + if not child:IsA("Tool") or not child:IsA("HopperBin") then return end + + local slot = nil + for i = 1, #inventory do + if inventory[i] and inventory[i] == child then return end + if not inventory[i] then slot = i end + end + if slot then + inventory[slot] = child + elseif #inventory < 1 then + inventory[1] = child + else + inventory[#inventory + 1] = child + end +end + +function removeFromInventory(child) + for i = 1, #inventory do + if inventory[i] == child then + table.remove(inventory,i) + inventory[i] = nil + end + end +end + +-- these next two functions are used for safe guarding +-- when we are waiting for character to come back after dying +function activateLoadout() + currentLoadout.Visible = true +end + +function deactivateLoadout() + currentLoadout.Visible = false +end + +function setupBackpackListener() + if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end + backpackChildCon = player.Backpack.ChildAdded:connect(function(child) + addingPlayerChild(child) + addToInventory(child) + + -- now store info in case of death + --saveGearPositions() + end) +end + +function playerCharacterChildAdded(child) + addingPlayerChild(child,true) + addToInventory(child) + + -- now store info in case of death + --saveGearPositions() +end +-- End Functions + + + + + + +-- Begin Script +wait() -- let stuff initialize incase this is first heartbeat... + +waitForChild(player,"Backpack") +waitForProperty(player,"Character") local backpackChildren = player.Backpack:GetChildren() -for i = 1, #backpackChildren do - addToGrid(backpackChildren[i]) +local size = math.min(10,#backpackChildren) +for i = 1, size do + addingPlayerChild(backpackChildren[i],false) + + -- now store info in case of death + --saveGearPositions() end +setupBackpackListener() -------------------------- Start Lifelong Connections ----------------------- +waitForProperty(player,"Character") +for i,v in ipairs(player.Character:GetChildren()) do + playerCharacterChildAdded(v) +end +characterChildAddedCon = player.Character.ChildAdded:connect(function(child) playerCharacterChildAdded(child) end) - -resizeEvent.Event:connect(function(absSize) - if debounce then return end - - debounce = true - wait() - resize() - resizeGrid() - debounce = false +waitForChild(player.Character,"Humanoid") +humanoidDiedCon = player.Character.Humanoid.Died:connect(function() + if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end + deactivateLoadout() + if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end end) -currentLoadout.ChildAdded:connect(function(child) loadoutCheck(child, false) end) -currentLoadout.ChildRemoved:connect(function(child) loadoutCheck(child, true) end) - -currentLoadout.DescendantAdded:connect(function(descendant) - if not backpack.Visible and ( descendant:IsA("ImageButton") or descendant:IsA("TextButton") ) then - centerGear(currentLoadout:GetChildren()) - end -end) -currentLoadout.DescendantRemoving:connect(function(descendant) - if not backpack.Visible and ( descendant:IsA("ImageButton") or descendant:IsA("TextButton") ) then - wait() - centerGear(currentLoadout:GetChildren()) - end -end) - -grid.MouseEnter:connect(function() clearPreview() end) -grid.MouseLeave:connect(function() clearPreview() end) - player.CharacterRemoving:connect(function() - removeCharacterConnections() - nukeBackpack() -end) -player.CharacterAdded:connect(function() setupCharacterConnections() end) - -player.ChildAdded:connect(function(child) - if child:IsA("Backpack") then - playerBackpack = child - if backpackAddCon then backpackAddCon:disconnect() end - backpackAddCon = game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(child) addToGrid(child) end) + for i = 1, #gearSlots do + if gearSlots[i] ~= "empty" then + gearSlots[i].Parent = nil + gearSlots[i] = "empty" + end end end) -swapSlot.Changed:connect(function() - if not swapSlot.Value then - updateGridActive() - end -end) +player.CharacterAdded:connect(function() + --canSaveLoadout = false -- we need to save loadout table until we check it out + + waitForProperty(game.Players,"LocalPlayer") + player = game.Players.LocalPlayer -- make sure we are still looking at the correct character + waitForChild(player,"Backpack") -local loadoutChildren = currentLoadout:GetChildren() -for i = 1, #loadoutChildren do - if loadoutChildren[i]:IsA("Frame") and string.find(loadoutChildren[i].Name,"Slot") then - loadoutChildren[i].ChildRemoved:connect(function() - updateGridActive() + --[[local loadoutCount = 0 + + local backpackChildren = player.Backpack:GetChildren() + -- Make sure we put gear back in where we last had them + for i = 1, #backpackChildren do + for pos,v in pairs(lastLoadout) do + if v["Name"] and v.Name == backpackChildren[i].Name then + addingPlayerChild(backpackChildren[i],false,pos) + lastLoadout[pos] = nil + loadoutCount = loadoutCount + 1 + break + end + end + if loadoutCount >= 10 then -- we've accounted for all slots, no need to go thru rest of gear + break + end + end]] + --canSaveLoadout = true -- used loadout table, allow script to edit this again + + local backpackChildren = player.Backpack:GetChildren() + local size = math.min(10,#backpackChildren) + for i = 1, size do + addingPlayerChild(backpackChildren[i],false) + end + + setupBackpackListener() + + if characterChildAddedCon then + characterChildAddedCon:disconnect() + characterChildAddedCon = nil + end + + characterChildAddedCon = + player.Character.ChildAdded:connect(function(child) + addingPlayerChild(child,true) + + -- now store info in case of death + -- saveGearPositions() end) - loadoutChildren[i].ChildAdded:connect(function() - updateGridActive() + + waitForChild(player.Character,"Humanoid") + humanoidDiedCon = + player.Character.Humanoid.Died:connect(function() + deactivateLoadout() + + if humanoidDiedCon then humanoidDiedCon:disconnect() humanoidDiedCon = nil end + if backpackChildCon then backpackChildCon:disconnect() backpackChildCon = nil end end) + activateLoadout() +end) + +waitForChild(guiBackpack,"SwapSlot") +guiBackpack.SwapSlot.Changed:connect(function() + if guiBackpack.SwapSlot.Value then + local swapSlot = guiBackpack.SwapSlot + local pos = swapSlot.Slot.Value + if pos == 0 then pos = 10 end + if gearSlots[pos] then + reorganizeLoadout(gearSlots[pos],false) + end + if swapSlot.GearButton.Value then + addingPlayerChild(swapSlot.GearButton.Value.GearReference.Value,false,pos) + + -- now store info in case of death + --saveGearPositions() + end + guiBackpack.SwapSlot.Value = false end -end -------------------------- End Lifelong Connections ----------------------- +end) -resize() -resizeGrid() - --- make sure any items in the loadout are accounted for in inventory -local loadoutChildren = currentLoadout:GetChildren() -for i = 1, #loadoutChildren do - loadoutCheck(loadoutChildren[i], false) -end -if not backpack.Visible then centerGear(currentLoadout:GetChildren()) end - --- make sure that inventory is listening to gear reparenting -if characterChildAddedCon == nil and game.Players.LocalPlayer["Character"] then - setupCharacterConnections() -end -if not backpackAddCon then - backpackAddCon = game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(child) addToGrid(child) end) -end - -backpackOpenEvent.Event:connect(backpackOpenHandler) -backpackCloseEvent.Event:connect(backpackCloseHandler) -tabClickedEvent.Event:connect(tabClickHandler) -searchRequestedEvent.Event:connect(showSearchGear) - -recalculateScrollLoadout() \ No newline at end of file +game:GetService("GuiService").KeyPressed:connect(function(key) activateGear(key) end)