Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile('ui/uistoreacceptbox')
- local storeWindow = nil
- local indexDescription = nil
- local indexList = nil
- local imageDesc = nil
- local titleDesc = nil
- local description = nil
- local acceptWindow = nil
- local transferPointsWindow = nil
- local function short(value)
- local text = value
- if string.len(text) >= 13 then
- shorten = string.sub(text, 1, 10)
- return shorten .. "..."
- else
- return text
- end
- end
- local function formatNumbers(number)
- local ret = number
- while true do
- ret, k = string.gsub(ret, "^(-?%d+)(%d%d%d)", '%1,%2')
- if k == 0 then
- break
- end
- end
- return ret
- end
- function init()
- g_ui.importStyle('ui/acceptwindow')
- storeWindow = g_ui.displayUI('store_module')
- storeWindow:hide()
- storeButton = modules.client_topmenu.addRightGameToggleButton('storeButton', tr('Diamond Store') .. ' (Ctrl+X)', '/images/topbuttons/market', toggle)
- storeButton:setOn(true)
- g_keyboard.bindKeyPress('Ctrl+X', toggle)
- ProtocolGame.registerExtendedOpcode(COINS_OPCODE, coinsBalance)
- transferPointsWindow = g_ui.displayUI('transferpoints')
- indexList = storeWindow:getChildById('indexList')
- indexDescription = storeWindow:getChildById('indexDescription')
- imageDesc = storeWindow:getChildById('indexDescription'):getChildById('imageDesc')
- titleDesc = storeWindow:getChildById('indexDescription'):getChildById('titleDesc')
- description = storeWindow:getChildById('indexDescription'):getChildById('description')
- productList = storeWindow:getChildById('productList')
- ProtocolGame.registerExtendedOpcode(185, listar)
- for i = 1, #storeIndex do
- local label = g_ui.createWidget('StoreButton', indexList)
- label:setId(i)
- label:setIcon(storeIndex[i].imageList)
- label:setText(tr(storeIndex[i].name))
- label.index = i
- local labelId = storeWindow:getChildById('indexList'):getChildById(i)
- labelId.onClick = function(self)
- local descriptionImage = storeWindow:getChildById('indexDescription'):getChildById('imageDesc')
- descriptionImage:setImageSource(storeIndex[i].image)
- local descriptionTitle = storeWindow:getChildById('indexDescription'):getChildById('titleDesc')
- descriptionTitle:setText(storeIndex[i].name)
- local description = storeWindow:getChildById('indexDescription'):getChildById('description')
- description:setText(storeIndex[i].description)
- local productsPanel = storeWindow:getChildById('productList')
- local children = productsPanel:getChildren()
- for k = 1, #children do
- children[k]:destroy()
- end
- for j=1, #storeProducts do
- if storeIndex[i].id == storeProducts[j].category_id then
- local productLabel = g_ui.createWidget('ProductButton', productList)
- productLabel:setId(j)
- productLabel:setTooltip(storeProducts[j].tooltip)
- local productLabelTitle = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTitle')
- productLabelTitle:setText(short(storeProducts[j].name))
- local productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImage')
- if storeProducts[j].category_type == "item" then
- productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageItem')
- productLabelImage:setItemId(storeProducts[j].image)
- elseif storeProducts[j].category_type == "outfit" then
- productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageOutfit')
- outfit = {type = 958, head = 0, body = 0, legs = 0, feet = 0, addons = 0}
- outfit.type = storeProducts[j].image
- outfit.head = 0
- outfit.body = 0
- outfit.legs = 0
- outfit.feet = 0
- outfit.addons = 0
- productLabelImage:recursiveGetChildById('creature'):setOutfit(outfit)
- productLabelImage:recursiveGetChildById('creature'):getCreature():setOutfit(outfit)
- else
- productLabelImage:setImageSource(storeIndex[i].image)
- end
- local productLabelTokenPrice = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTokenPrice')
- productLabelTokenPrice:setText(formatNumbers(storeProducts[j].price))
- local buyWindow = storeWindow:getChildById('productList'):getChildById(j)
- buyWindow.onClick = function(self)
- if acceptWindow then
- return true
- end
- local acceptFunc = function()
- local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
- local unformatted = balance:gsub(',', '')
- local balanceInfo = tonumber(unformatted)
- if storeProducts[j].price then
- g_game.talk(COMMAND_BUYITEM .. ' ' .. storeIndex[i].id .. ', ' .. storeProducts[j].id)
- acceptWindow:destroy()
- acceptWindow = nil
- local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
- local unformatted = balance:gsub(',', '')
- local balanceInfo = tonumber(unformatted)
- local balanceAfterPurchase = balanceInfo - storeProducts[j].price
- local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
- balanceLabel:setText((formatNumbers(balanceAfterPurchase)))
- else
- io.popen('start ' .. WEBSITE_GETCOINS)
- acceptWindow:destroy()
- acceptWindow = nil
- end
- end
- local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end
- transferPointsWindow:setVisible(false)
- acceptWindow = displayAcceptBox(tr('Buy ' .. storeProducts[j].name), tr(storeProducts[j].description),
- { { text=tr('Buy'), callback=acceptFunc },
- { text=tr('Cancel'), callback=cancelFunc },
- anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
- return true
- end
- end
- end
- end
- end
- connect(g_game, {
- onGameStart = refresh,
- onGameEnd = offline
- })
- refresh()
- end
- function terminate()
- storeWindow:hide()
- g_keyboard.unbindKeyPress('Ctrl+U')
- ProtocolGame.unregisterExtendedOpcode(COINS_OPCODE)
- ProtocolGame.unregisterExtendedOpcode(185)
- disconnect(g_game, {
- onGameStart = refresh,
- onGameEnd = offline
- })
- end
- function coinsBalance(protocol, opcode, buffer)
- local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
- balanceLabel:setText(formatNumbers(buffer))
- end
- function refresh()
- local player = g_game.getLocalPlayer()
- if not player then
- return
- end
- end
- function offline()
- storeWindow:hide()
- end
- function toggle()
- if storeWindow:isVisible() then
- onCloseStore()
- else
- onOpenStore()
- end
- end
- function listar(protocol, opcode, buffer)
- local _items = string.explode(buffer, "@")
- print(_items[1])
- --for l = 1,
- for i = 1, #_items do
- local list = string.explode(_items[i], "&")
- storeProducts[i] = {
- name = list[1],
- id = list[2],
- category_id = list[3],
- description = list[4],
- tooltip = list[5],
- price = list[6],
- image = list[7],
- category_type = list[8],
- }
- end
- end
- function onOpenStore()
- storeWindow:show()
- storeWindow:raise()
- storeWindow:focus()
- --listar('30x Vitamin H& 2357&10&Do you really want to buy "Shiny Arch Heatran"?\n\nNote: The Pokemon will only be received by the character\nwho purchased it in the Store.&Shiny Arch Heatran\n Held X Epic, Held Y Epic, Held Z Epic, Held W Hallow Tier 2 \n Boost 400 \n Vitamin 30 \n Card Random \n Maestria 10 \n Shiny Level 10 \n With random bonus catalyst ground force from 50.&100&/images/shop/offer/pokemons/shinyarch_heatran@')
- local descriptionImage = storeWindow:getChildById('indexDescription'):getChildById('imageDesc')
- descriptionImage:setImageSource(storeIndex[1].image)
- local descriptionTitle = storeWindow:getChildById('indexDescription'):getChildById('titleDesc')
- descriptionTitle:setText(storeIndex[1].name)
- local description = storeWindow:getChildById('indexDescription'):getChildById('description')
- description:setText(storeIndex[1].description)
- local productsPanel = storeWindow:getChildById('productList')
- local children = productsPanel:getChildren()
- for k = 1, #children do
- children[k]:destroy()
- end
- for j=1, #storeProducts do
- if storeIndex[1].id == storeProducts[j].category_id then
- local productLabel = g_ui.createWidget('ProductButton', productList)
- productLabel:setId(j)
- productLabel:setTooltip(storeProducts[j].tooltip)
- local productLabelTitle = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTitle')
- productLabelTitle:setText(short(storeProducts[j].name))
- local productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImage')
- if storeProducts[j].category_type == "item" then
- productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageItem')
- productLabelImage:setItemId(storeProducts[j].image)
- --productLabelImage:setImageSource(storeIndex[i].image)
- --productLabelImage.onClick = function(self)
- elseif storeProducts[j].category_type == "outfit" then
- productLabelImage:setImageSource(storeIndex[i].image)
- --productLabelImage.onClick = function(self)
- else
- productLabelImage:setImageSource(storeIndex[i].image)
- --productLabelImage.onClick = function(self)
- --productLabelImage = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelImageItem')
- --productLabelImage:setItemId(2160)
- end
- local productLabelTokenPrice = storeWindow:getChildById('productList'):getChildById(j):getChildById('productLabelTokenPrice')
- productLabelTokenPrice:setText(formatNumbers(storeProducts[j].price))
- local buyWindow = storeWindow:getChildById('productList'):getChildById(j)
- buyWindow.onClick = function(self)
- if acceptWindow then
- return true
- end
- local acceptFunc = function()
- local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
- local unformatted = balance:gsub(',', '')
- local balanceInfo = tonumber(unformatted)
- if storeProducts[j].price then
- g_game.talk(COMMAND_BUYITEM .. ' ' .. storeIndex[1].id .. ', ' .. storeProducts[j].id)
- acceptWindow:destroy()
- acceptWindow = nil
- local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
- local unformatted = balance:gsub(',', '')
- local balanceInfo = tonumber(unformatted)
- local balanceAfterPurchase = balanceInfo - storeProducts[j].price
- local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
- balanceLabel:setText((formatNumbers(balanceAfterPurchase)))
- else
- io.popen('start ' .. WEBSITE_GETCOINS)
- acceptWindow:destroy()
- acceptWindow = nil
- end
- end
- local cancelFunc = function() acceptWindow:destroy() acceptWindow = nil end
- transferPointsWindow:setVisible(false)
- acceptWindow = displayAcceptBox(tr('Buy ' .. storeProducts[j].name), tr(storeProducts[j].description),
- { { text=tr('Buy'), callback=acceptFunc },
- { text=tr('Cancel'), callback=cancelFunc },
- anchor=AnchorHorizontalCenter }, acceptFunc, cancelFunc)
- return true
- end
- end
- end
- end
- function onCloseStore()
- storeWindow:hide()
- transferPointsWindow:setVisible(false)
- if acceptWindow then
- acceptWindow:destroy()
- acceptWindow = nil
- end
- end
- function transferPoints()
- local value = transferPointsWindow:getChildById('transferPointsValue')
- value:setText(tr('0'))
- local balanceInfo = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
- local balance = transferPointsWindow:getChildById('coinBalance2')
- balance:setText(formatNumbers(balanceInfo))
- transferPointsWindow:setVisible(true)
- transferPointsWindow:focus()
- transferPointsWindow:raise()
- acceptWindow:destroy()
- acceptWindow = nil
- end
- function transferAccept()
- local nickname = transferPointsWindow:getChildById('transferPointsText'):getText()
- local value = transferPointsWindow:getChildById('transferPointsValue'):getText()
- g_game.talk(COMMAND_TRANSFER .. ' ' .. nickname .. ', '.. value)
- local balance = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance'):getText()
- local unformatted = balance:gsub(',', '')
- local balanceInfo = tonumber(unformatted)
- local getValue = tonumber(value)
- local balanceAfterSend = balanceInfo - getValue
- local balanceLabel = storeWindow:getChildById('balanceInfo'):getChildById('coinBalance')
- balanceLabel:setText((formatNumbers(balanceAfterSend)))
- transferPointsWindow:setVisible(false)
- end
- function transferCancel()
- transferPointsWindow:setVisible(false)
- end
- function getCoins()
- io.popen('start ' .. WEBSITE_GETCOINS)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement