local Gear = game:GetService('ReplicatedStorage').GiveGear
local Get = game:GetService('ReplicatedStorage').Get
-- Filter Functions
function Updated(val1,val2)
if val1 and val2 then
val1 = string.match(val1['UpdatedDate'],'%b()')
val1 = val1:sub(2,#val1-1)
val2 = string.match(val2['UpdatedDate'],'%b()')
val2 = val1:sub(2,#val2-1)
print(val1,val2)
return val1 < val2
elseif val1 then return false else return true
end
end
function Created(val1,val2)
if val1 and val2 then
val1 = string.match(val1['CreatedDate'],'%b()')
val1 = val1:sub(2,#val1-1)
val2 = string.match(val2['CreatedDate'],'%b()')
val2 = val1:sub(2,#val2-1)
print(val1,val2)
return val1 < val2
elseif val1 then return val1 elseif val2 then return val2
end
end
function Search(name)
local found = {}
for i,v in pairs(Catalog) do
if v.Name:lower():find(name:lower()) then
table.insert(found,v)
end
end
return found
end
local Container = script.Parent.Frame.Frame.Container
local SearchBar = script.Parent.Frame.Searchbox
local Filters = script.Parent.Frame.Filter
--v.Position = UDim2.new(i/(#stuff.Background)-(1/#stuff.Background),7,0,5)
function Add(tbl)
for i,v in pairs(tbl) do
Container.CanvasSize = UDim2.new(1,0,0,(180*math.floor(i/3))+180)
local Row = math.floor(#Container:GetChildren()/3)
local Pos = math.fmod(#Container:GetChildren(),3)
local CanMove = (Container.AbsoluteSize.X-30)/3
local Base = Instance.new('TextButton',Container)
Base.Size = UDim2.new(0,136,0,136)
Base.BackgroundColor3 = Color3.new(1,1,1)
Base.BorderColor3 = Color3.new(1,1,1)
Base.Position = UDim2.new(0,20+Pos*CanMove,0,Row*180)
Base.Text = ''
Base.ClipsDescendants = true
Base.BorderSizePixel = 2
Base.MouseButton1Click:connect(function()
Gear:FireServer(v['AssetId'])
spawn(function()
local x = Instance.new('Sound',workspace.CurrentCamera)
x.SoundId = 'rbxassetid://3359534883'
x.TimePosition = 1
x:Play()
end)
end)
local Image = Instance.new('ImageLabel',Base)
local Camera = Instance.new('Camera',Image)
if not game:GetService('ReplicatedStorage').Loaded:FindFirstChild(v['AssetId']) then
Get:FireServer(v['AssetId'])
end
Image.BackgroundTransparency = 1
Image.Size = UDim2.new(1,0,1,0)
local Tool = game:GetService('ReplicatedStorage').Loaded:WaitForChild(v['AssetId'])
Image.Image = Tool.TextureId
local Name = Instance.new('TextLabel',Base)
Name.Position = UDim2.new(0,0,1,-10)
Name.Size = UDim2.new(1,0,0,10)
Name.BackgroundTransparency = 1
Name.Text = v['Name']
Name.ZIndex = 2
if Name.TextBounds.X > Name.AbsoluteSize.X then
Name.Text = Name.Text:sub(1,#Name.Text-#Name.Text/3)..' ...'
end
if v["IsForSale"] then
local x = Instance.new('TextLabel',Base)
x.Size = UDim2.new(0,20,0,10)
x.BackgroundTransparency = 1
x.Text = 'OffSale'
x.TextColor3 = Color3.new(1,0,0)
x.TextXAlignment = 'Left'
end
local Roux = Instance.new('TextLabel',Base)
Roux.Size = UDim2.new(1,0,0,10)
Roux.TextXAlignment = 'Right'
Roux.BackgroundTransparency = 1
if not v["Price"] then
Roux.Text = 'Broken'
else
Roux.Text = v["Price"]
end
end
end
function rrandom()
local tbl = {Catalog[1]}
for i,v in pairs(Catalog) do
math.randomseed(tick())
table.insert(tbl,math.random(1,#tbl or 1),v)
end
print(#tbl)
Add(tbl)
end
function PriceToLow()
local tbl = {}
for i,v in pairs(Catalog) do
table.insert(tbl,v['Price'])
end
local sorted = {}
for i,v in pairs(tbl) do
end
Add(tbl)
end
-- Filter Events
Filters.MouseButton1Click:connect(function()
Filters.ClipsDescendants = not Filters.ClipsDescendants
end)
Filters.Random.MouseButton1Click:connect(function()
Container:ClearAllChildren()
rrandom()
end)
Filters.HighToLow.MouseButton1Click:connect(function()
Container:ClearAllChildren()
table.sort(Catalog,PriceToLow)
Add(Catalog)
end)
Filters.LowToHigh.MouseButton1Click:connect(function()
Container:ClearAllChildren()
PriceToLow()
end)
Filters.Updated.MouseButton1Click:connect(function()
Container:ClearAllChildren()
table.sort(Catalog,Updated)
Add(Catalog)
end)
Filters.Created.MouseButton1Click:connect(function()
Container:ClearAllChildren()
table.sort(Catalog,Created)
Add(Catalog)
end)
SearchBar.FocusLost:connect(function(enter)
if enter then
print'ne'
Container:ClearAllChildren()
else
print'ye'
end
Add(Search(SearchBar.Text))
end)
--print(#Catalog)