Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ASSET_URL = 'http://www.roblox.com/asset?id='
- --[[local STATIC_DATA_NAMES = {
- Armor = true,
- Name = true,
- Desc = true,
- Slot = true,
- Thumbnail = true
- }]]
- local MESSAGE_DEBRIS_TIME = 3
- local PURCHASE_DEBOUNCE_TIME = 1
- --local MORE_COINS_ID = (Game.PlaceId == 96623001) and 19518348 or 19518905
- local LightingService = Game:GetService('Lighting')
- local DebrisService = Game:GetService('Debris')
- local MarketplaceService = Game:GetService('MarketplaceService')
- local ArmorDataModel = LightingService:WaitForChild('ArmorData')
- local CoinServiceScript = Workspace:WaitForChild('CoinService')
- local QueueUpdateArmorData = Workspace:WaitForChild('ArmorService'):WaitForChild('QueueUpdateArmorData')
- local ShopGui = script.Parent
- local PlayerGui = ShopGui.Parent
- local Player = PlayerGui.Parent
- local OpenedObject = ShopGui:WaitForChild('Opened')
- local ShopFrame = ShopGui:WaitForChild('ShopFrame')
- local ExitButton = ShopFrame:WaitForChild('Exit')
- local PreviewFrame = ShopFrame:WaitForChild('PreviewPanel')
- local PreviewImage = PreviewFrame:WaitForChild('Image')
- local PreviewName = PreviewFrame:WaitForChild('Name')
- local PreviewDescription = PreviewFrame:WaitForChild('Description')
- local GridFrame = ShopFrame:WaitForChild('Grid')
- local HeadFrame = GridFrame:WaitForChild('Left')
- local BodyFrame = GridFrame:WaitForChild('Middle')
- local LegsFrame = GridFrame:WaitForChild('Right')
- local BaseGridItem = GridFrame:WaitForChild('BaseGridItem')
- --local MoreCoinsButton = GridFrame:WaitForChild('MORECOINS')
- local BuyButton = PreviewFrame:WaitForChild('Buy')
- local BeforeBuyFrame = BuyButton:WaitForChild('Before')
- local BeforeBuyText = BeforeBuyFrame:WaitForChild('Text')
- local AfterBuyFrame = BuyButton:WaitForChild('After')
- local GridItems = {}
- local PreviewArmor = nil
- local JustAttemptedPurchase = false
- local function OnGridItemClicked(gridItemTable)
- if gridItemTable then
- local gridItem, armor = gridItemTable[1], gridItemTable[2]
- if gridItem and armor then
- local nameObject = armor:FindFirstChild('Name')
- local descriptionObject = armor:FindFirstChild('Desc')
- local costObject = armor:FindFirstChild('Cost')
- if nameObject and descriptionObject and costObject then
- PreviewImage.Image = gridItem.Image
- PreviewName.Text = nameObject.Value
- PreviewDescription.Text = descriptionObject.Value
- PreviewArmor = armor
- BeforeBuyText.Text = costObject.Value
- BeforeBuyFrame.Visible = true
- end
- end
- end
- BuyButton.Selected = false
- AfterBuyFrame.Visible = false
- JustAttemptedPurchase = false
- end
- local function PopulateGrid()
- -- Clear any existing grid items
- for _, gridItemTable in pairs(GridItems) do
- local gridItem = gridItemTable[1]
- if gridItem then
- gridItem:Destroy()
- end
- end
- GridItems = {}
- -- Make new grid items
- for _, child in pairs(ArmorDataModel:GetChildren()) do
- local thumbnailObject = child:FindFirstChild('Thumbnail')
- local slotObject = child:FindFirstChild('Slot')
- local costObject = child:FindFirstChild('Cost')
- if thumbnailObject and slotObject and costObject and costObject.Value > 0 then
- local gridItem = BaseGridItem:Clone()
- gridItem.Name = "GridItem"
- gridItem.Image = ASSET_URL .. thumbnailObject.Value
- local slotName = slotObject.Value
- local slot = slotName == 'Head' and HeadFrame or slotName == 'Body' and BodyFrame or slotName == 'Legs' and LegsFrame or nil
- gridItem.Parent = slot
- local slotChildCount = #slot:GetChildren()
- if slotChildCount-3 > 4 then
- gridItem.Position = UDim2.new(0, 65, 0, BaseGridItem.Position.Y.Offset + (65 * (slotChildCount - 3 - 5)))
- else
- gridItem.Position = UDim2.new(0, 0, 0, BaseGridItem.Position.Y.Offset + (65 * (slotChildCount - 3)))
- end
- gridItem.Size = UDim2.new(0, 65, 0, 65)
- local gridItemTable = {gridItem, child}
- gridItem.MouseButton1Click:connect(function()
- OnGridItemClicked(gridItemTable)
- end)
- table.insert(GridItems, gridItemTable)
- gridItem.Visible = true
- end
- end
- end
- local function OnPurchase()
- if BeforeBuyFrame.Visible and PreviewArmor then
- local persistentModel = Player:FindFirstChild('PersistentModel')
- local otherStats = Player:FindFirstChild('otherstats')
- local armorStats = Player:FindFirstChild('armorstats')
- local costObject = PreviewArmor:FindFirstChild('Cost')
- if persistentModel and otherStats and armorStats and costObject then
- --[[
- local coinsObject = persistentModel:FindFirstChild('Coins')
- local unsavedCoinsObject = otherStats:FindFirstChild('UnsavedCoins')
- local allItemsModel = armorStats:FindFirstChild('AllItems')
- local cost = costObject.Value
- if coinsObject and unsavedCoinsObject and allItemsModel then
- -- Check for enough money
- local coinsInHand = unsavedCoinsObject.Value
- local coinsInBank = coinsObject.Value
- local moneyTransferred = false
- if coinsInHand >= cost then
- unsavedCoinsObject.Value = unsavedCoinsObject.Value - cost
- moneyTransferred = true
- elseif coinsInHand + coinsInBank >= cost then
- cost = cost - unsavedCoinsObject.Value
- unsavedCoinsObject.Value = 0
- coinsObject.Value = coinsObject.Value - cost
- moneyTransferred = true
- else -- Not enough cash!
- --TODO: Negative feedback
- end
- -- If they've paid up, give em the armor!
- if moneyTransferred then
- BeforeBuyFrame.Visible = false
- AfterBuyFrame.Visible = true
- BuyButton.Selected = true
- local newArmor = PreviewArmor:Clone()
- for _, child in pairs(newArmor:GetChildren()) do
- if STATIC_DATA_NAMES[child.Name] then
- child:Destroy()
- end
- end
- local referenceObject = Instance.new('ObjectValue')
- referenceObject.Name = 'Def'
- referenceObject.Value = PreviewArmor
- referenceObject.Parent = newArmor
- newArmor.Parent = allItemsModel
- end
- end]]
- -- New way of purchasing: Ask CoinService to buy it
- -- if not JustAttemptedPurchase then
- -- JustAttemptedPurchase = true
- -- local messageObject = Instance.new('ObjectValue')
- -- messageObject.Name = 'Buy'
- -- messageObject.Value = Player
- -- local parameterObject = Instance.new('StringValue')
- -- parameterObject.Name = 'Identifier'
- -- parameterObject.Value = PreviewArmor.Name
- -- parameterObject.Parent = messageObject
- -- DebrisService:AddItem(messageObject, MESSAGE_DEBRIS_TIME)
- -- messageObject.ChildAdded:connect(function(child)
- -- if child.Name == 'Success' and child:IsA('IntValue') then
- -- if child.Value == 0 then
- -- child.Changed:wait()
- -- end
- -- if child.Value == 1 then
- -- BeforeBuyFrame.Visible = false
- -- AfterBuyFrame.Visible = true
- -- BuyButton.Selected = true
- -- JustAttemptedPurchase = false
- -- DebrisService:AddItem(messageObject, 0)
- -- elseif child.Value == -1 then
- -- -- Denied
- -- end
- -- end
- -- end)
- -- messageObject.Parent = CoinServiceScript
- -- Spawn(function()
- -- wait(PURCHASE_DEBOUNCE_TIME)
- -- JustAttemptedPurchase = false
- -- end)
- -- end
- if not JustAttemptedPurchase then
- JustAttemptedPurchase = true
- if _G.BuyItem(Player, PreviewArmor.Name) then
- BeforeBuyFrame.Visible = false
- AfterBuyFrame.Visible = true
- BuyButton.Selected = true
- JustAttemptedPurchase = false
- end
- end
- end
- end
- end
- local function OnExit()
- ShopFrame.Visible = false
- OpenedObject.Value = false
- end
- local function OnOpenedChanged(newValue)
- if newValue then
- QueueUpdateArmorData:Invoke()
- PopulateGrid()
- OnGridItemClicked(GridItems[1])
- end
- ShopFrame.Visible = newValue
- end
- local function OnArmorChanged()
- if ShopFrame.Visible then
- OnOpenedChanged(true)
- end
- end
- --local function OnMoreCoinsClicked()
- -- MarketplaceService:PromptProductPurchase(Player, MORE_COINS_ID)
- --end
- --
- --local function OnPromptProductPurchaseFinished(userId, productId, isPurchased)
- -- _G.print("OnPromptProductPurchaseFinished:", userId, productId, isPurchased)
- -- if isPurchased and userId == Player.userId and productId == MORE_COINS_ID then
- -- _G.print("Success")
- -- _G.GivePlayerCoins(Player, 150)
- -- _G.GivePlayerPoints(Player, 1)
- -- else
- -- _G.print("Failure")
- -- end
- --end
- ExitButton.MouseButton1Click:connect(OnExit)
- BuyButton.MouseButton1Click:connect(OnPurchase)
- OpenedObject.Changed:connect(OnOpenedChanged)
- ArmorDataModel.ChildAdded:connect(OnArmorChanged)
- ArmorDataModel.ChildRemoved:connect(OnArmorChanged)
- --MoreCoinsButton.MouseButton1Click:connect(OnMoreCoinsClicked)
- --MarketplaceService.PromptProductPurchaseFinished:connect(OnPromptProductPurchaseFinished)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement