Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local GUI = Game:GetService("Selection"):Get()[1]
- if (not GUI or GUI.Name ~= "ItemContainer") then
- error("Invalid inventory GUI selected")
- end
- local AbsoluteWindowSizeX = (GUI.AbsoluteWindowSize.X-20); -- We take away 20 for 10 pixel padding on both left and right sides
- local AmountOfGUIsPerRow = 3;
- local TotalGUIs = 30;
- local TotalRows = math.floor( (TotalGUIs/AmountOfGUIsPerRow) + 0.05)
- -- Here's an interesting part.
- -- Depending on how many GUIs in each row we have, we need an amount of spaces in between them equal to AmountOfGUIsPerRow-1.
- -- Then we need to determine how many pixels in between each one and also subtract that from the AbsoluteWindowSizeX
- local PaddingInBetweenGUIs = 10;
- local AbsoluteWindowSizeX = AbsoluteWindowSizeX - (PaddingInBetweenGUIs * (AmountOfGUIsPerRow-1));
- local SizeOfEachGUI = math.floor( (AbsoluteWindowSizeX/AmountOfGUIsPerRow) + 0.05);
- -- Should be it. Generate the GUIs in the selected container.
- for Row = 1, TotalRows do
- for Item = 1, AmountOfGUIsPerRow do
- local ShouldPadX, ShouldPadY = false, false;
- local ImageGUI = Instance.new("ImageLabel");
- ImageGUI.Size = UDim2.new(0,SizeOfEachGUI,0,SizeOfEachGUI);
- ImageGUI.BackgroundTransparency = 1;
- ImageGUI.Image = "";
- ImageGUI.ZIndex = 2
- local FallbackText = Instance.new("TextLabel");
- FallbackText.Size = UDim2.new(1,0,1,0);
- FallbackText.BackgroundColor3 = Color3.new(30/255,30/255,30/255);
- FallbackText.TextColor3 = BrickColor.White().Color;
- FallbackText.Text = "Inventory Item Name"
- FallbackText.TextWrapped = true;
- -- Do not pad first or last GUIs
- if (Row > 1) then
- ShouldPadY = true;
- end
- if (Item > 1) then
- ShouldPadX = true;
- end
- ImageGUI.Position = UDim2.new(0,10 + ((SizeOfEachGUI + (ShouldPadX and PaddingInBetweenGUIs or 0)) * (Item-1)),0, 10 + ((SizeOfEachGUI + (ShouldPadY and PaddingInBetweenGUIs or 0)) * (Row-1)))
- ImageGUI.Name = "[" .. tostring(Row) .. "," .. tostring(Item) .. "]"
- ImageGUI.Parent = GUI
- FallbackText.Parent = ImageGUI
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement