Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rs = game:GetService("ReplicatedStorage")
- local itemDirectory = rs:WaitForChild("ItemDirectory")
- local inventory = script.Parent:WaitForChild("Inventory")
- local frame = inventory:WaitForChild("Frame")
- local bottom = frame:WaitForChild("Bottom")
- local dataLimit = bottom:WaitForChild("DataLimit")
- local limit = dataLimit:WaitForChild("Limit")
- local sorts = bottom:WaitForChild("Sorts")
- local sortTitle = sorts:WaitForChild("Title")
- local levelSort = sorts:WaitForChild("Level")
- local nameSort = sorts:WaitForChild("Name")
- local raritySort = sorts:WaitForChild("Rarity")
- local items = frame:WaitForChild("Items")
- local uiGridLayout = items:WaitForChild("UIGridLayout")
- local top = frame:WaitForChild("Top")
- local search = top:WaitForChild("Search")
- local title top:WaitForChild("Title")
- local itemInfoDisplay = script:WaitForChild("ItemInfo")
- local sampleItem = script:WaitForChild("SampleItem")
- local doubleHats = false
- local currentlyDisplayedInfo
- local clickEvents = {}
- local stats = {}
- stats.Armor = ""
- stats.Gamepasses = ""
- stats.Helmet = ""
- stats.Helmet2 = ""
- stats.Inventory = require(workspace.Inventory) --string.rep(require(workspace.Inventory), 37)
- stats.Level = math.huge
- stats.Weapon = ""
- local itemTable = {}
- local intValue = Instance.new("IntValue")
- local rarityColors = {
- {"Starter", Color3.fromRGB(255, 255, 255)}, -- white
- {"Common", Color3.fromRGB(255, 255, 255)}, -- white
- {"Uncommon", Color3.fromRGB(165, 165, 165)}, -- grey
- {"Rare", Color3.fromRGB(0, 0, 255)}, -- blue
- {"Epic", Color3.fromRGB(255, 127, 238)}, -- pink
- {"Unreal", Color3.fromRGB(170, 0, 255)}, -- purple
- {"Legendary", Color3.fromRGB(255, 170, 0)}, -- orange
- {"Fabled", Color3.fromRGB(0, 0, 0)}, -- black
- {"Event", Color3.fromRGB(255, 0, 0)}, -- red
- {"Staff", Color3.fromRGB(18, 237, 212)} -- teal
- }
- local statsToDestroy = {
- ["Buyable"] = true,
- ["Cost"] = true,
- ["ItemType"] = true,
- ["Picture"] = true
- }
- if string.find(stats.Gamepasses, ":Double Helmets:") then
- doubleHats = true
- end
- local function closeEvent(event)
- event:Disconnect()
- event = nil
- end
- local function formatNumber(num)
- if num < 1000 then
- return tostring(num)
- else
- return tostring(math.floor((num/1000) * 100)/100) .. "K"
- end
- end
- local function displayDataLimit(data)
- if data then
- limit.Text = formatNumber(data) .. "/150K"
- if data >= 145000 then
- limit.TextColor3 = Color3.fromRGB(255, 0, 0)
- elseif data < 145000 and data >= 100000 then
- limit.TextColor3 = Color3.fromRGB(255, 85, 0)
- elseif data < 100000 and data >= 75000 then
- limit.TextColor3 = Color3.fromRGB(255, 255, 0)
- else
- limit.TextColor3 = Color3.fromRGB(85, 255, 0)
- end
- end
- end
- local function inventoryTable()
- local pattern = "%p[%w%s]+%p"
- local items = {}
- local inventory = stats.Inventory
- for key, val in string.gmatch(inventory, pattern) do
- key = string.sub(key, 2, string.len(key) - 1)
- if not itemTable[key] then
- itemTable[key] = 1
- else
- itemTable[key] = itemTable[key] + 1
- end
- end
- end
- local function findItemInventoryTable(search)
- local item = itemDirectory:FindFirstChild(search, true)
- if item then
- return item, string.sub(item.Parent.Name, 1, #item.Parent.Name - 1)
- end
- end
- local function getRarityColor(rarity)
- local color = Color3.fromRGB(255, 255, 255)
- for i,v in pairs(rarityColors) do
- if v[1] == rarity then
- color = v[2]
- end
- end
- return color
- end
- local function onContentSizeChanged()
- local absoluteSize = uiGridLayout.AbsoluteContentSize
- items.CanvasSize = UDim2.new(0, absoluteSize.X, 0, absoluteSize.Y + 15)
- end
- local function getRarityWeight(rarity)
- for i,v in pairs(rarityColors) do
- if v[1] == rarity then
- return i
- end
- end
- end
- local function setUpStatDisplay(element)
- if element then
- currentlyDisplayedInfo = itemInfoDisplay:Clone()
- local viewItem = currentlyDisplayedInfo:FindFirstChild("ViewItem")
- if viewItem then
- local itemStats = element:FindFirstChild("Stats")
- if itemStats then
- local damage = itemStats:FindFirstChild("Damage")
- local speed = itemStats:FindFirstChild("Speed")
- local defense = itemStats:FindFirstChild("Defense")
- local description = itemStats:FindFirstChild("Description")
- local level = itemStats:FindFirstChild("Level")
- local rarity = itemStats:FindFirstChild("Rarity")
- local set = itemStats:FindFirstChild("Set")
- local title = viewItem:FindFirstChild("Title")
- local viewSet = viewItem:FindFirstChild("Set")
- local viewStats = viewItem:FindFirstChild("Stats")
- local viewDamage = viewStats:FindFirstChild("Damage")
- local viewDefense = viewStats:FindFirstChild("Defense")
- local viewSpeed = viewStats:FindFirstChild("Speed")
- local viewDescription = viewStats:FindFirstChild("Description")
- local additionalStats = viewStats:FindFirstChild("AdditionalStats")
- local viewLevel = additionalStats:FindFirstChild("Level")
- local viewRarity = additionalStats:FindFirstChild("Rarity")
- local extendDescriptionSize = 0
- if not damage then
- viewDamage:Destroy()
- extendDescriptionSize = extendDescriptionSize + 0.1
- else
- local value = viewDamage:FindFirstChild("Value")
- if value then
- value.Text = damage.Value
- end
- end
- if not speed then
- viewSpeed:Destroy()
- extendDescriptionSize = extendDescriptionSize + 0.1
- else
- local value = viewSpeed:FindFirstChild("Value")
- if value then
- value.Text = speed.Value
- end
- end
- if not defense then
- viewDefense:Destroy()
- extendDescriptionSize = extendDescriptionSize + 0.1
- else
- local defenseValue = viewDefense:FindFirstChild("Value")
- if defenseValue then
- defenseValue.Text = defense.Value
- end
- end
- if not set then
- viewSet:Destroy()
- viewSet = nil
- else
- viewSet.Text = set.Value
- end
- local descriptionSize = viewDescription.Size
- viewDescription.Size = UDim2.new(descriptionSize.X.Scale, descriptionSize.X.Offset, descriptionSize.Y.Scale + extendDescriptionSize, descriptionSize.Y.Offset)
- title.Text = element.Name
- viewDescription.Text = description.Value
- viewLevel.Text = "Level " .. level.Value
- viewRarity.Text = rarity.Value
- viewRarity.TextColor3 = getRarityColor(rarity.Value)
- local absolutePosition = element.AbsolutePosition
- currentlyDisplayedInfo.Position = UDim2.new(0, absolutePosition.X, 0, absolutePosition.Y)
- currentlyDisplayedInfo.Visible = true
- currentlyDisplayedInfo.Parent = script.Parent
- end
- end
- end
- end
- inventoryTable()
- local function loadInInventory(tab)
- if string.find(stats.Gamepasses, ":Double Helmets:") and not doubleHats then
- doubleHats = true
- end
- for i = 1, #clickEvents do
- clickEvents[i]:Disconnect()
- clickEvents[i] = nil
- end
- for i,v in pairs(items:GetChildren()) do
- if v:IsA("ImageButton") then
- v:Destroy()
- end
- end
- local myStuff = tab or itemTable
- --print(game.HttpService:JSONEncode(myStuff))
- displayDataLimit(string.len(stats.Inventory))
- local t = tick()
- for i,v in pairs(myStuff) do
- --spawn(function()
- local itemInfo, itemType = findItemInventoryTable(#myStuff == 0 and i or v)
- if itemInfo then
- local item = items:FindFirstChild(itemInfo.Name)
- if not item then
- local newItem = sampleItem:Clone()
- newItem.Name = itemInfo.Name
- newItem.Image = itemInfo.Picture.Value
- if newItem:FindFirstChild("Tier") then
- newItem.Tier.BackgroundColor3 = getRarityColor(itemInfo.Rarity.Value or "Common")
- end
- local itemStats = newItem:FindFirstChild("Stats")
- if itemStats then
- for i,v in pairs(itemInfo:GetChildren()) do
- if not statsToDestroy[v.Name] then
- v:Clone().Parent = itemStats
- end
- end
- local rarityWeight = intValue:Clone()
- rarityWeight.Name = "RarityWeight"
- rarityWeight.Value = 0
- rarityWeight.Parent = itemStats
- rarityWeight.Value = getRarityWeight(itemStats.Rarity.Value) or 1
- end
- newItem.Parent = items
- clickEvents[#clickEvents + 1] = newItem.MouseEnter:Connect(function()
- if newItem:FindFirstChild("ViewItem") then
- if currentlyDisplayedInfo then
- currentlyDisplayedInfo:Destroy()
- currentlyDisplayedInfo = nil
- end
- setUpStatDisplay(newItem)
- end
- end)
- clickEvents[#clickEvents + 1] = newItem.MouseLeave:Connect(function()
- if currentlyDisplayedInfo then
- currentlyDisplayedInfo:Destroy()
- currentlyDisplayedInfo = nil
- end
- end)
- end
- if item then
- if #myStuff == 0 then
- local amount = item:FindFirstChild("Amount")
- if amount then
- amount.Text = tostring(v)
- end
- end
- end
- end
- --end)
- end
- print(tick() - t)
- onContentSizeChanged()
- clickEvents[#clickEvents + 1] = uiGridLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(onContentSizeChanged)
- end
- local function sortedTable(mode, text)
- local clone = {}
- if mode == "name" then
- for i = 1, #items:GetChildren() do
- local item = items:GetChildren()[i]
- if item:IsA("ImageButton") then
- table.insert(clone, item.Name)
- end
- end
- table.sort(clone, function(a, b)
- return string.lower(a) < string.lower(b)
- end)
- elseif mode == "level" then
- for i = 1, #items:GetChildren() do
- local item = items:GetChildren()[i]
- if item:IsA("ImageButton") then
- if item:FindFirstChild("Stats") and item.Stats:FindFirstChild("Level") then
- table.insert(clone, item)
- end
- end
- end
- table.sort(clone, function(a, b)
- return a.Stats.Level.Value > b.Stats.Level.Value
- end)
- for i = 1, #clone do
- clone[i] = clone[i].Name
- end
- elseif mode == "rarity" then
- for i = 1, #items:GetChildren() do
- local item = items:GetChildren()[i]
- if item:IsA("ImageButton") then
- if item:FindFirstChild("Stats") and item.Stats:FindFirstChild("RarityWeight") then
- table.insert(clone, item)
- end
- end
- end
- table.sort(clone, function(a, b)
- return a.Stats.RarityWeight.Value > b.Stats.RarityWeight.Value
- end)
- for i = 1, #clone do
- clone[i] = clone[i].Name
- end
- elseif mode == "searched" then
- if text then
- local tab = itemTable
- for i,v in pairs(tab) do
- local itemInfo, itemType = findItemInventoryTable(i)
- if itemInfo and itemType then
- local rarityValue = itemInfo:FindFirstChild("Rarity")
- if rarityValue then
- if string.find(string.lower(rarityValue.Value), string.lower(text)) then
- clone[i] = v
- elseif string.find(string.lower(itemType), string.lower(text)) or string.find(string.lower(itemType .. "s"), string.lower(text)) then
- clone[i] = v
- else
- if string.find(string.lower(i), string.lower(text)) then
- clone[i] = v
- end
- end
- end
- end
- end
- end
- end
- loadInInventory(clone)
- end
- nameSort.MouseButton1Click:Connect(function()
- sortedTable("name")
- end)
- levelSort.MouseButton1Click:Connect(function()
- sortedTable("level")
- end)
- raritySort.MouseButton1Click:Connect(function()
- sortedTable("rarity")
- end)
- search:GetPropertyChangedSignal("Text"):Connect(function()
- sortedTable("searched", search.Text)
- end)
- loadInInventory()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement