Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Ejemplo de tienda
- keys = {0,2,32}
- _left = 0
- _right = 2
- _space = 32
- -- {nombre, precio, descripción}
- shopData = {
- {"Velocidad", 1500, "Te da un pequeño impulso de velocidad hacia los lados."};
- {"Fuerza", 2000, "???"};
- {"Super salto", 3000, "Te permite dar un gran salto usando ESPACIO."};
- {"Cañón", 5000, "Lanza un cañón a tus oponentes."};
- {"METEORIC BURST", 10000, "Desata todo el poder interior de tu rata para generar una explosión destructiva."};
- }
- shopPages = math.ceil(#shopData/3)
- _velocidad = 1
- _fuerza = 2
- _superSalto = 3
- _canon = 4
- _meteoricBurst = 5
- mice = {}
- function main()
- for n in pairs(tfm.get.room.playerList) do
- eventNewPlayer(n)
- end
- end
- function eventNewPlayer(name)
- mice[name] = {
- shop = {},
- money = 10000,
- shopOpen = false,
- shopPage = 1
- }
- for i=1,#shopData do
- mice[name].shop[i] = false
- end
- for _,k in pairs(keys) do
- system.bindKeyboard(name, k, true)
- end
- ui.addTextArea(0, "<p align='center'><a href='event:openShop'> $ </a></p>", nil, 780, 380, 16, 16, nil, nil, 0.8, true)
- end
- function eventKeyboard(name, key, down, px, py)
- local mouse = mice[name]
- local s = mouse.shop
- if key == _left and s[_velocidad] then
- tfm.exec.movePlayer(name, 0, 0, true, -30, 0, true)
- elseif key == _right and s[_velocidad] then
- tfm.exec.movePlayer(name, 0, 0, true, 30, 0, true)
- elseif key == _space and s[_superSalto] then
- tfm.exec.movePlayer(name, 0, 0, true, 0, -50, true)
- end
- end
- function eventTextAreaCallback(id, name, cb)
- local mouse = mice[name]
- if cb == "openShop" then
- if mouse.shopOpen then
- mouse.shopOpen = false
- closeShop(name)
- else
- mouse.shopPage = 1
- mouse.shopOpen = true
- openShop(name)
- end
- elseif cb == "prevPage" then
- if mouse.shopPage == 1 then return
- elseif mouse.shopPage == 2 then
- ui.removeTextArea(12, name)
- end
- if mouse.shopPage == shopPages then
- ui.addTextArea(13, "<p align='center'><font size='26' color='#EEEE00'><a href='event:nextPage'>></a></font></p>", name, 648, 184, 40, 40, 0x5f5f5f, 0x0, 1, false)
- end
- mouse.shopPage = mouse.shopPage - 1
- updateShop(name)
- elseif cb == "nextPage" then
- if mouse.shopPage == shopPages then return
- elseif mouse.shopPage == shopPages-1 then
- ui.removeTextArea(13, name)
- end
- if mouse.shopPage == 1 then
- ui.addTextArea(12, "<p align='center'><font size='26' color='#EEEE00'><a href='event:prevPage'><</a></font></p>", name, 112, 184, 40, 40, 0x5f5f5f, 0x0, 1, false)
- end
- mouse.shopPage = mouse.shopPage + 1
- updateShop(name)
- elseif cb:sub(1,3) == "buy" then
- local k = tonumber(cb:sub(4))
- mouse.shop[k] = true
- mouse.money = mouse.money - shopData[k][2]
- updateShop(name)
- end
- end
- function openShop(name)
- ui.addTextArea(10, "<p align='center'><font size='28'>Tienda</font></p>", name, 150, 54, 500, 300, 0x5f5f5f, 0x0, 1, false)
- ui.addTextArea(11, "", name, 678, 312, 98, 42, 0x5f5f5f, 0x0, 1, false)
- ui.addTextArea(13, "<p align='center'><font size='26' color='#EEEE00'><a href='event:nextPage'>></a></font></p>", name, 648, 184, 40, 40, 0x5f5f5f, 0x0, 1, false)
- updateShop(name)
- end
- function updateShop(name)
- mouse = mice[name]
- ui.updateTextArea(11, "<font color='#FFFFFF'>Dinero:</font><br><font size='18' color='#EEEE00'>$"..mouse.money.."</font>", name)
- local page = mouse.shopPage
- local money = mouse.money
- if page ~= 1 then
- for i=0,6,3 do
- for j=14,16 do
- ui.removeTextArea(j+i, name)
- end
- end
- end
- for i=1,3 do
- local k = (page-1)*3 + i
- if not shopData[k] then break end
- local data = shopData[k]
- local di = 3*(i-1)
- local x1 = 174 + 166*(i-1)
- ui.addTextArea(14 + di, "<p align='center'><font size='14' color='#010101'><b>"..data[1].."</b></font></p>", name, x1, 112, 120, 38, 0xc5c5c5, 0x0, 1, false)
- ui.addTextArea(15 + di, "<font color='#FFFFFF'>"..data[3].."</font>", name, x1, 170, 120, 100, 0x7c7c7c, 0x0, 1, false)
- local text, color
- if mouse.shop[k] then
- color = "7777EE"
- text = "Equipado"
- else
- local buyText
- if money >= data[2] then
- color = "55EE55"
- buyText = "<br><a href='event:buy"..k.."'>Comprar</a>"
- else
- color = "EE5555"
- buyText = ""
- end
- text = "$"..data[2]..buyText
- end
- ui.addTextArea(16 + di, "<p align='center'><font size='18' color='#"..color.."'>"..text.."</font></p>", name, x1, 286, 120, 51, 0x324650, 0x0, 0, false)
- end
- end
- function closeShop(name)
- for i=10,22 do
- ui.removeTextArea(i, name)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement