Advertisement
fartfart1555

roblox battle

Dec 9th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. local ASSET_URL = 'http://www.roblox.com/asset?id='
  2. --[[local STATIC_DATA_NAMES = {
  3. Armor = true,
  4. Name = true,
  5. Desc = true,
  6. Slot = true,
  7. Thumbnail = true
  8. }]]
  9. local MESSAGE_DEBRIS_TIME = 3
  10. local PURCHASE_DEBOUNCE_TIME = 1
  11.  
  12. --local MORE_COINS_ID = (Game.PlaceId == 96623001) and 19518348 or 19518905
  13.  
  14. local LightingService = Game:GetService('Lighting')
  15. local DebrisService = Game:GetService('Debris')
  16. local MarketplaceService = Game:GetService('MarketplaceService')
  17.  
  18. local ArmorDataModel = LightingService:WaitForChild('ArmorData')
  19. local CoinServiceScript = Workspace:WaitForChild('CoinService')
  20.  
  21. local QueueUpdateArmorData = Workspace:WaitForChild('ArmorService'):WaitForChild('QueueUpdateArmorData')
  22.  
  23. local ShopGui = script.Parent
  24. local PlayerGui = ShopGui.Parent
  25. local Player = PlayerGui.Parent
  26. local OpenedObject = ShopGui:WaitForChild('Opened')
  27. local ShopFrame = ShopGui:WaitForChild('ShopFrame')
  28. local ExitButton = ShopFrame:WaitForChild('Exit')
  29. local PreviewFrame = ShopFrame:WaitForChild('PreviewPanel')
  30. local PreviewImage = PreviewFrame:WaitForChild('Image')
  31. local PreviewName = PreviewFrame:WaitForChild('Name')
  32. local PreviewDescription = PreviewFrame:WaitForChild('Description')
  33. local GridFrame = ShopFrame:WaitForChild('Grid')
  34. local HeadFrame = GridFrame:WaitForChild('Left')
  35. local BodyFrame = GridFrame:WaitForChild('Middle')
  36. local LegsFrame = GridFrame:WaitForChild('Right')
  37. local BaseGridItem = GridFrame:WaitForChild('BaseGridItem')
  38. --local MoreCoinsButton = GridFrame:WaitForChild('MORECOINS')
  39. local BuyButton = PreviewFrame:WaitForChild('Buy')
  40. local BeforeBuyFrame = BuyButton:WaitForChild('Before')
  41. local BeforeBuyText = BeforeBuyFrame:WaitForChild('Text')
  42. local AfterBuyFrame = BuyButton:WaitForChild('After')
  43.  
  44. local GridItems = {}
  45. local PreviewArmor = nil
  46. local JustAttemptedPurchase = false
  47.  
  48. local function OnGridItemClicked(gridItemTable)
  49. if gridItemTable then
  50. local gridItem, armor = gridItemTable[1], gridItemTable[2]
  51. if gridItem and armor then
  52. local nameObject = armor:FindFirstChild('Name')
  53. local descriptionObject = armor:FindFirstChild('Desc')
  54. local costObject = armor:FindFirstChild('Cost')
  55. if nameObject and descriptionObject and costObject then
  56. PreviewImage.Image = gridItem.Image
  57. PreviewName.Text = nameObject.Value
  58. PreviewDescription.Text = descriptionObject.Value
  59. PreviewArmor = armor
  60. BeforeBuyText.Text = costObject.Value
  61. BeforeBuyFrame.Visible = true
  62. end
  63. end
  64. end
  65. BuyButton.Selected = false
  66. AfterBuyFrame.Visible = false
  67. JustAttemptedPurchase = false
  68. end
  69.  
  70. local function PopulateGrid()
  71. -- Clear any existing grid items
  72. for _, gridItemTable in pairs(GridItems) do
  73. local gridItem = gridItemTable[1]
  74. if gridItem then
  75. gridItem:Destroy()
  76. end
  77. end
  78. GridItems = {}
  79.  
  80. -- Make new grid items
  81. for _, child in pairs(ArmorDataModel:GetChildren()) do
  82. local thumbnailObject = child:FindFirstChild('Thumbnail')
  83. local slotObject = child:FindFirstChild('Slot')
  84. local costObject = child:FindFirstChild('Cost')
  85. if thumbnailObject and slotObject and costObject and costObject.Value > 0 then
  86. local gridItem = BaseGridItem:Clone()
  87. gridItem.Name = "GridItem"
  88. gridItem.Image = ASSET_URL .. thumbnailObject.Value
  89. local slotName = slotObject.Value
  90. local slot = slotName == 'Head' and HeadFrame or slotName == 'Body' and BodyFrame or slotName == 'Legs' and LegsFrame or nil
  91. gridItem.Parent = slot
  92. local slotChildCount = #slot:GetChildren()
  93. if slotChildCount-3 > 4 then
  94. gridItem.Position = UDim2.new(0, 65, 0, BaseGridItem.Position.Y.Offset + (65 * (slotChildCount - 3 - 5)))
  95. else
  96. gridItem.Position = UDim2.new(0, 0, 0, BaseGridItem.Position.Y.Offset + (65 * (slotChildCount - 3)))
  97. end
  98. gridItem.Size = UDim2.new(0, 65, 0, 65)
  99. local gridItemTable = {gridItem, child}
  100. gridItem.MouseButton1Click:connect(function()
  101. OnGridItemClicked(gridItemTable)
  102. end)
  103. table.insert(GridItems, gridItemTable)
  104. gridItem.Visible = true
  105. end
  106. end
  107. end
  108.  
  109. local function OnPurchase()
  110. if BeforeBuyFrame.Visible and PreviewArmor then
  111. local persistentModel = Player:FindFirstChild('PersistentModel')
  112. local otherStats = Player:FindFirstChild('otherstats')
  113. local armorStats = Player:FindFirstChild('armorstats')
  114. local costObject = PreviewArmor:FindFirstChild('Cost')
  115. if persistentModel and otherStats and armorStats and costObject then
  116. --[[
  117. local coinsObject = persistentModel:FindFirstChild('Coins')
  118. local unsavedCoinsObject = otherStats:FindFirstChild('UnsavedCoins')
  119. local allItemsModel = armorStats:FindFirstChild('AllItems')
  120. local cost = costObject.Value
  121. if coinsObject and unsavedCoinsObject and allItemsModel then
  122. -- Check for enough money
  123. local coinsInHand = unsavedCoinsObject.Value
  124. local coinsInBank = coinsObject.Value
  125. local moneyTransferred = false
  126. if coinsInHand >= cost then
  127. unsavedCoinsObject.Value = unsavedCoinsObject.Value - cost
  128. moneyTransferred = true
  129. elseif coinsInHand + coinsInBank >= cost then
  130. cost = cost - unsavedCoinsObject.Value
  131. unsavedCoinsObject.Value = 0
  132. coinsObject.Value = coinsObject.Value - cost
  133. moneyTransferred = true
  134. else -- Not enough cash!
  135. --TODO: Negative feedback
  136. end
  137.  
  138. -- If they've paid up, give em the armor!
  139. if moneyTransferred then
  140. BeforeBuyFrame.Visible = false
  141. AfterBuyFrame.Visible = true
  142. BuyButton.Selected = true
  143. local newArmor = PreviewArmor:Clone()
  144. for _, child in pairs(newArmor:GetChildren()) do
  145. if STATIC_DATA_NAMES[child.Name] then
  146. child:Destroy()
  147. end
  148. end
  149. local referenceObject = Instance.new('ObjectValue')
  150. referenceObject.Name = 'Def'
  151. referenceObject.Value = PreviewArmor
  152. referenceObject.Parent = newArmor
  153. newArmor.Parent = allItemsModel
  154. end
  155. end]]
  156.  
  157. -- New way of purchasing: Ask CoinService to buy it
  158. -- if not JustAttemptedPurchase then
  159. -- JustAttemptedPurchase = true
  160. -- local messageObject = Instance.new('ObjectValue')
  161. -- messageObject.Name = 'Buy'
  162. -- messageObject.Value = Player
  163. -- local parameterObject = Instance.new('StringValue')
  164. -- parameterObject.Name = 'Identifier'
  165. -- parameterObject.Value = PreviewArmor.Name
  166. -- parameterObject.Parent = messageObject
  167. -- DebrisService:AddItem(messageObject, MESSAGE_DEBRIS_TIME)
  168. -- messageObject.ChildAdded:connect(function(child)
  169. -- if child.Name == 'Success' and child:IsA('IntValue') then
  170. -- if child.Value == 0 then
  171. -- child.Changed:wait()
  172. -- end
  173. -- if child.Value == 1 then
  174. -- BeforeBuyFrame.Visible = false
  175. -- AfterBuyFrame.Visible = true
  176. -- BuyButton.Selected = true
  177. -- JustAttemptedPurchase = false
  178. -- DebrisService:AddItem(messageObject, 0)
  179. -- elseif child.Value == -1 then
  180. -- -- Denied
  181. -- end
  182. -- end
  183. -- end)
  184. -- messageObject.Parent = CoinServiceScript
  185. -- Spawn(function()
  186. -- wait(PURCHASE_DEBOUNCE_TIME)
  187. -- JustAttemptedPurchase = false
  188. -- end)
  189. -- end
  190. if not JustAttemptedPurchase then
  191. JustAttemptedPurchase = true
  192. if _G.BuyItem(Player, PreviewArmor.Name) then
  193. BeforeBuyFrame.Visible = false
  194. AfterBuyFrame.Visible = true
  195. BuyButton.Selected = true
  196. JustAttemptedPurchase = false
  197. end
  198. end
  199. end
  200. end
  201. end
  202.  
  203. local function OnExit()
  204. ShopFrame.Visible = false
  205. OpenedObject.Value = false
  206. end
  207.  
  208. local function OnOpenedChanged(newValue)
  209. if newValue then
  210. QueueUpdateArmorData:Invoke()
  211. PopulateGrid()
  212. OnGridItemClicked(GridItems[1])
  213. end
  214. ShopFrame.Visible = newValue
  215. end
  216.  
  217. local function OnArmorChanged()
  218. if ShopFrame.Visible then
  219. OnOpenedChanged(true)
  220. end
  221. end
  222.  
  223. --local function OnMoreCoinsClicked()
  224. -- MarketplaceService:PromptProductPurchase(Player, MORE_COINS_ID)
  225. --end
  226. --
  227. --local function OnPromptProductPurchaseFinished(userId, productId, isPurchased)
  228. -- _G.print("OnPromptProductPurchaseFinished:", userId, productId, isPurchased)
  229. -- if isPurchased and userId == Player.userId and productId == MORE_COINS_ID then
  230. -- _G.print("Success")
  231. -- _G.GivePlayerCoins(Player, 150)
  232. -- _G.GivePlayerPoints(Player, 1)
  233. -- else
  234. -- _G.print("Failure")
  235. -- end
  236. --end
  237.  
  238. ExitButton.MouseButton1Click:connect(OnExit)
  239. BuyButton.MouseButton1Click:connect(OnPurchase)
  240. OpenedObject.Changed:connect(OnOpenedChanged)
  241.  
  242. ArmorDataModel.ChildAdded:connect(OnArmorChanged)
  243. ArmorDataModel.ChildRemoved:connect(OnArmorChanged)
  244.  
  245. --MoreCoinsButton.MouseButton1Click:connect(OnMoreCoinsClicked)
  246. --MarketplaceService.PromptProductPurchaseFinished:connect(OnPromptProductPurchaseFinished)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement