Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.42 KB | None | 0 0
  1. local rs = game:GetService("ReplicatedStorage")
  2. local itemDirectory = rs:WaitForChild("ItemDirectory")
  3.  
  4. local inventory = script.Parent:WaitForChild("Inventory")
  5. local frame = inventory:WaitForChild("Frame")
  6. local bottom = frame:WaitForChild("Bottom")
  7.  
  8. local dataLimit = bottom:WaitForChild("DataLimit")
  9. local limit = dataLimit:WaitForChild("Limit")
  10.  
  11. local sorts = bottom:WaitForChild("Sorts")
  12. local sortTitle = sorts:WaitForChild("Title")
  13. local levelSort = sorts:WaitForChild("Level")
  14. local nameSort = sorts:WaitForChild("Name")
  15. local raritySort = sorts:WaitForChild("Rarity")
  16.  
  17. local items = frame:WaitForChild("Items")
  18. local uiGridLayout = items:WaitForChild("UIGridLayout")
  19.  
  20. local top = frame:WaitForChild("Top")
  21. local search = top:WaitForChild("Search")
  22. local title top:WaitForChild("Title")
  23.  
  24. local itemInfoDisplay = script:WaitForChild("ItemInfo")
  25.  
  26. local sampleItem = script:WaitForChild("SampleItem")
  27.  
  28. local doubleHats = false
  29.  
  30. local currentlyDisplayedInfo
  31.  
  32. local clickEvents = {}
  33.  
  34. local stats = {}
  35. stats.Armor = ""
  36. stats.Gamepasses = ""
  37. stats.Helmet = ""
  38. stats.Helmet2 = ""
  39. stats.Inventory = require(workspace.Inventory) --string.rep(require(workspace.Inventory), 37)
  40. stats.Level = math.huge
  41. stats.Weapon = ""
  42.  
  43. local itemTable = {}
  44.  
  45. local intValue = Instance.new("IntValue")
  46.  
  47. local rarityColors = {
  48. {"Starter", Color3.fromRGB(255, 255, 255)}, -- white
  49. {"Common", Color3.fromRGB(255, 255, 255)}, -- white
  50. {"Uncommon", Color3.fromRGB(165, 165, 165)}, -- grey
  51. {"Rare", Color3.fromRGB(0, 0, 255)}, -- blue
  52. {"Epic", Color3.fromRGB(255, 127, 238)}, -- pink
  53. {"Unreal", Color3.fromRGB(170, 0, 255)}, -- purple
  54. {"Legendary", Color3.fromRGB(255, 170, 0)}, -- orange
  55. {"Fabled", Color3.fromRGB(0, 0, 0)}, -- black
  56. {"Event", Color3.fromRGB(255, 0, 0)}, -- red
  57. {"Staff", Color3.fromRGB(18, 237, 212)} -- teal
  58. }
  59.  
  60. local statsToDestroy = {
  61. ["Buyable"] = true,
  62. ["Cost"] = true,
  63. ["ItemType"] = true,
  64. ["Picture"] = true
  65. }
  66.  
  67. if string.find(stats.Gamepasses, ":Double Helmets:") then
  68. doubleHats = true
  69. end
  70.  
  71. local function closeEvent(event)
  72. event:Disconnect()
  73. event = nil
  74. end
  75.  
  76. local function formatNumber(num)
  77. if num < 1000 then
  78. return tostring(num)
  79. else
  80. return tostring(math.floor((num/1000) * 100)/100) .. "K"
  81. end
  82. end
  83.  
  84. local function displayDataLimit(data)
  85. if data then
  86. limit.Text = formatNumber(data) .. "/150K"
  87. if data >= 145000 then
  88. limit.TextColor3 = Color3.fromRGB(255, 0, 0)
  89. elseif data < 145000 and data >= 100000 then
  90. limit.TextColor3 = Color3.fromRGB(255, 85, 0)
  91. elseif data < 100000 and data >= 75000 then
  92. limit.TextColor3 = Color3.fromRGB(255, 255, 0)
  93. else
  94. limit.TextColor3 = Color3.fromRGB(85, 255, 0)
  95. end
  96. end
  97. end
  98.  
  99. local function inventoryTable()
  100. local pattern = "%p[%w%s]+%p"
  101. local items = {}
  102. local inventory = stats.Inventory
  103. for key, val in string.gmatch(inventory, pattern) do
  104. key = string.sub(key, 2, string.len(key) - 1)
  105. if not itemTable[key] then
  106. itemTable[key] = 1
  107. else
  108. itemTable[key] = itemTable[key] + 1
  109. end
  110. end
  111. end
  112.  
  113. local function findItemInventoryTable(search)
  114. local item = itemDirectory:FindFirstChild(search, true)
  115. if item then
  116. return item, string.sub(item.Parent.Name, 1, #item.Parent.Name - 1)
  117. end
  118. end
  119.  
  120. local function getRarityColor(rarity)
  121. local color = Color3.fromRGB(255, 255, 255)
  122. for i,v in pairs(rarityColors) do
  123. if v[1] == rarity then
  124. color = v[2]
  125. end
  126. end
  127. return color
  128. end
  129.  
  130. local function onContentSizeChanged()
  131. local absoluteSize = uiGridLayout.AbsoluteContentSize
  132. items.CanvasSize = UDim2.new(0, absoluteSize.X, 0, absoluteSize.Y + 15)
  133. end
  134.  
  135. local function getRarityWeight(rarity)
  136. for i,v in pairs(rarityColors) do
  137. if v[1] == rarity then
  138. return i
  139. end
  140. end
  141. end
  142.  
  143. local function setUpStatDisplay(element)
  144. if element then
  145. currentlyDisplayedInfo = itemInfoDisplay:Clone()
  146. local viewItem = currentlyDisplayedInfo:FindFirstChild("ViewItem")
  147. if viewItem then
  148. local itemStats = element:FindFirstChild("Stats")
  149. if itemStats then
  150.  
  151. local damage = itemStats:FindFirstChild("Damage")
  152. local speed = itemStats:FindFirstChild("Speed")
  153. local defense = itemStats:FindFirstChild("Defense")
  154. local description = itemStats:FindFirstChild("Description")
  155. local level = itemStats:FindFirstChild("Level")
  156. local rarity = itemStats:FindFirstChild("Rarity")
  157. local set = itemStats:FindFirstChild("Set")
  158.  
  159. local title = viewItem:FindFirstChild("Title")
  160. local viewSet = viewItem:FindFirstChild("Set")
  161.  
  162. local viewStats = viewItem:FindFirstChild("Stats")
  163. local viewDamage = viewStats:FindFirstChild("Damage")
  164. local viewDefense = viewStats:FindFirstChild("Defense")
  165. local viewSpeed = viewStats:FindFirstChild("Speed")
  166. local viewDescription = viewStats:FindFirstChild("Description")
  167.  
  168. local additionalStats = viewStats:FindFirstChild("AdditionalStats")
  169. local viewLevel = additionalStats:FindFirstChild("Level")
  170. local viewRarity = additionalStats:FindFirstChild("Rarity")
  171.  
  172. local extendDescriptionSize = 0
  173.  
  174. if not damage then
  175. viewDamage:Destroy()
  176. extendDescriptionSize = extendDescriptionSize + 0.1
  177. else
  178. local value = viewDamage:FindFirstChild("Value")
  179. if value then
  180. value.Text = damage.Value
  181. end
  182. end
  183.  
  184. if not speed then
  185. viewSpeed:Destroy()
  186. extendDescriptionSize = extendDescriptionSize + 0.1
  187. else
  188. local value = viewSpeed:FindFirstChild("Value")
  189. if value then
  190. value.Text = speed.Value
  191. end
  192. end
  193.  
  194. if not defense then
  195. viewDefense:Destroy()
  196. extendDescriptionSize = extendDescriptionSize + 0.1
  197. else
  198. local defenseValue = viewDefense:FindFirstChild("Value")
  199. if defenseValue then
  200. defenseValue.Text = defense.Value
  201. end
  202. end
  203.  
  204. if not set then
  205. viewSet:Destroy()
  206. viewSet = nil
  207. else
  208. viewSet.Text = set.Value
  209. end
  210.  
  211. local descriptionSize = viewDescription.Size
  212. viewDescription.Size = UDim2.new(descriptionSize.X.Scale, descriptionSize.X.Offset, descriptionSize.Y.Scale + extendDescriptionSize, descriptionSize.Y.Offset)
  213.  
  214. title.Text = element.Name
  215. viewDescription.Text = description.Value
  216. viewLevel.Text = "Level " .. level.Value
  217. viewRarity.Text = rarity.Value
  218. viewRarity.TextColor3 = getRarityColor(rarity.Value)
  219.  
  220. local absolutePosition = element.AbsolutePosition
  221. currentlyDisplayedInfo.Position = UDim2.new(0, absolutePosition.X, 0, absolutePosition.Y)
  222. currentlyDisplayedInfo.Visible = true
  223.  
  224. currentlyDisplayedInfo.Parent = script.Parent
  225. end
  226. end
  227. end
  228. end
  229.  
  230. inventoryTable()
  231.  
  232. local function loadInInventory(tab)
  233. if string.find(stats.Gamepasses, ":Double Helmets:") and not doubleHats then
  234. doubleHats = true
  235. end
  236.  
  237. for i = 1, #clickEvents do
  238. clickEvents[i]:Disconnect()
  239. clickEvents[i] = nil
  240. end
  241.  
  242. for i,v in pairs(items:GetChildren()) do
  243. if v:IsA("ImageButton") then
  244. v:Destroy()
  245. end
  246. end
  247.  
  248. local myStuff = tab or itemTable
  249.  
  250. --print(game.HttpService:JSONEncode(myStuff))
  251.  
  252. displayDataLimit(string.len(stats.Inventory))
  253.  
  254. local t = tick()
  255. for i,v in pairs(myStuff) do
  256. --spawn(function()
  257. local itemInfo, itemType = findItemInventoryTable(#myStuff == 0 and i or v)
  258. if itemInfo then
  259. local item = items:FindFirstChild(itemInfo.Name)
  260. if not item then
  261.  
  262. local newItem = sampleItem:Clone()
  263. newItem.Name = itemInfo.Name
  264. newItem.Image = itemInfo.Picture.Value
  265. if newItem:FindFirstChild("Tier") then
  266. newItem.Tier.BackgroundColor3 = getRarityColor(itemInfo.Rarity.Value or "Common")
  267. end
  268.  
  269. local itemStats = newItem:FindFirstChild("Stats")
  270. if itemStats then
  271.  
  272. for i,v in pairs(itemInfo:GetChildren()) do
  273. if not statsToDestroy[v.Name] then
  274. v:Clone().Parent = itemStats
  275. end
  276. end
  277.  
  278. local rarityWeight = intValue:Clone()
  279. rarityWeight.Name = "RarityWeight"
  280. rarityWeight.Value = 0
  281. rarityWeight.Parent = itemStats
  282.  
  283. rarityWeight.Value = getRarityWeight(itemStats.Rarity.Value) or 1
  284. end
  285.  
  286. newItem.Parent = items
  287.  
  288. clickEvents[#clickEvents + 1] = newItem.MouseEnter:Connect(function()
  289. if newItem:FindFirstChild("ViewItem") then
  290. if currentlyDisplayedInfo then
  291. currentlyDisplayedInfo:Destroy()
  292. currentlyDisplayedInfo = nil
  293. end
  294.  
  295. setUpStatDisplay(newItem)
  296. end
  297. end)
  298.  
  299. clickEvents[#clickEvents + 1] = newItem.MouseLeave:Connect(function()
  300. if currentlyDisplayedInfo then
  301. currentlyDisplayedInfo:Destroy()
  302. currentlyDisplayedInfo = nil
  303. end
  304. end)
  305. end
  306.  
  307. if item then
  308. if #myStuff == 0 then
  309. local amount = item:FindFirstChild("Amount")
  310. if amount then
  311. amount.Text = tostring(v)
  312. end
  313. end
  314. end
  315. end
  316. --end)
  317. end
  318. print(tick() - t)
  319.  
  320. onContentSizeChanged()
  321. clickEvents[#clickEvents + 1] = uiGridLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(onContentSizeChanged)
  322. end
  323.  
  324. local function sortedTable(mode, text)
  325. local clone = {}
  326. if mode == "name" then
  327.  
  328. for i = 1, #items:GetChildren() do
  329. local item = items:GetChildren()[i]
  330. if item:IsA("ImageButton") then
  331. table.insert(clone, item.Name)
  332. end
  333. end
  334.  
  335. table.sort(clone, function(a, b)
  336. return string.lower(a) < string.lower(b)
  337. end)
  338. elseif mode == "level" then
  339.  
  340. for i = 1, #items:GetChildren() do
  341. local item = items:GetChildren()[i]
  342. if item:IsA("ImageButton") then
  343. if item:FindFirstChild("Stats") and item.Stats:FindFirstChild("Level") then
  344. table.insert(clone, item)
  345. end
  346. end
  347. end
  348.  
  349. table.sort(clone, function(a, b)
  350. return a.Stats.Level.Value > b.Stats.Level.Value
  351. end)
  352.  
  353. for i = 1, #clone do
  354. clone[i] = clone[i].Name
  355. end
  356. elseif mode == "rarity" then
  357.  
  358. for i = 1, #items:GetChildren() do
  359. local item = items:GetChildren()[i]
  360. if item:IsA("ImageButton") then
  361. if item:FindFirstChild("Stats") and item.Stats:FindFirstChild("RarityWeight") then
  362. table.insert(clone, item)
  363. end
  364. end
  365. end
  366.  
  367. table.sort(clone, function(a, b)
  368. return a.Stats.RarityWeight.Value > b.Stats.RarityWeight.Value
  369. end)
  370.  
  371. for i = 1, #clone do
  372. clone[i] = clone[i].Name
  373. end
  374. elseif mode == "searched" then
  375. if text then
  376. local tab = itemTable
  377. for i,v in pairs(tab) do
  378. local itemInfo, itemType = findItemInventoryTable(i)
  379. if itemInfo and itemType then
  380. local rarityValue = itemInfo:FindFirstChild("Rarity")
  381. if rarityValue then
  382. if string.find(string.lower(rarityValue.Value), string.lower(text)) then
  383. clone[i] = v
  384. elseif string.find(string.lower(itemType), string.lower(text)) or string.find(string.lower(itemType .. "s"), string.lower(text)) then
  385. clone[i] = v
  386. else
  387. if string.find(string.lower(i), string.lower(text)) then
  388. clone[i] = v
  389. end
  390. end
  391. end
  392. end
  393. end
  394. end
  395. end
  396. loadInInventory(clone)
  397. end
  398.  
  399. nameSort.MouseButton1Click:Connect(function()
  400. sortedTable("name")
  401. end)
  402.  
  403. levelSort.MouseButton1Click:Connect(function()
  404. sortedTable("level")
  405. end)
  406.  
  407. raritySort.MouseButton1Click:Connect(function()
  408. sortedTable("rarity")
  409. end)
  410.  
  411. search:GetPropertyChangedSignal("Text"):Connect(function()
  412. sortedTable("searched", search.Text)
  413. end)
  414.  
  415. loadInInventory()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement