Advertisement
Guest User

[Español] Circuit Map Test - Transformice Lua

a guest
May 9th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.69 KB | None | 0 0
  1. blue = false
  2. orange = false
  3. checkPoint = {}
  4. powerUp = {}
  5. respawn = {}
  6. xml = false
  7. loaded = true
  8.  
  9. function geraXml(xml)
  10.     local blue = false
  11.     local orange = false
  12.     local checkPoint = {}
  13.     local powerUp = {}
  14.     local respawn = {}
  15.     local pisos = string.match(xml, "<S>.-</S>")
  16.     local novosPisos = ""
  17.     if pisos then
  18.         pisos = pisos:sub(4,-5)
  19.         for v in string.gmatch(pisos, "<S.-/>") do
  20.             local xx = tonumber(string.match(v, 'X=".-"'):sub(4,-2))
  21.             local yy = tonumber(string.match(v, 'Y=".-"'):sub(4,-2))
  22.             local ll = tonumber(string.match(v, 'L=".-"'):sub(4,-2))
  23.             local hh = tonumber(string.match(v, 'H=".-"'):sub(4,-2))
  24.             if string.find(v, 'T="8"') then
  25.                 table.insert(checkPoint, {x=xx, y=yy, l=ll, h=hh})
  26.             else
  27.                 novosPisos = novosPisos .. v
  28.             end
  29.         end
  30.     else
  31.         print("<r>Erro: Não há pisos.")
  32.         return false
  33.     end
  34.     local objetos = string.match(xml, "<O>.-</O>")
  35.     local novosObjetos = ""
  36.     if objetos then
  37.         objetos = objetos:sub(4,-5)
  38.         for v in string.gmatch(objetos, "<O.-/>") do
  39.             local xx = tonumber(string.match(v, 'X=".-"'):sub(4,-2))
  40.             local yy = tonumber(string.match(v, 'Y=".-"'):sub(4,-2))
  41.             if string.find(v, 'C="15"') then
  42.                 table.insert(powerUp, {x=xx, y=yy})
  43.             elseif string.find(v, 'C="16"') then
  44.                 blue = {x=xx, y=yy}
  45.             elseif string.find(v, 'C="13"') then
  46.                 orange = {x=xx, y=yy}
  47.             else
  48.                 novosObjetos = novosObjetos .. v
  49.             end
  50.         end
  51.     else
  52.         print("<r>Error: No hay objetos de chamán.")
  53.         return false
  54.     end
  55.     local decoracao = string.match(xml, "<D>.-</D>")
  56.     local primeira = true
  57.     local toca = true
  58.     primeiroPlano = false
  59.     if decoracao then
  60.         decoracao = decoracao:sub(4,-5)
  61.         for v in string.gmatch(decoracao, "<T.-/>") do
  62.             if primeira then
  63.                 primeira = false
  64.             end
  65.             local xx = tonumber(string.match(v, 'X=".-"'):sub(4,-2))
  66.             local yy = tonumber(string.match(v, 'Y=".-"'):sub(4,-2))
  67.             table.insert(respawn, {x=xx, y=yy})
  68.         end
  69.     else
  70.         print("<r>Error: No hay decoraciones.")
  71.         return false
  72.     end
  73.     l = string.match(xml, 'Laps="%d-"')
  74.     if l then
  75.         l = l:sub(7,-2)
  76.         laps = tonumber(l)
  77.     else
  78.         laps = 3
  79.     end
  80.     if blue and not orange then
  81.         print("<j>Aviso: No hay portal naranja.")
  82.     end
  83.     if orange and not blue then
  84.         print("<j>Aviso: No hay portal azul.")
  85.     end
  86.     if #respawn ~= #checkPoint then
  87.         print("<r>Error: La cantidad de respawns es diferente a la de checkpoints.")
  88.         return false
  89.     elseif #powerUp == 0 then
  90.         print("<r>Error: No hay powerups.")
  91.         return false
  92.     elseif #checkPoint < 3 then
  93.         print("<r>Error: Menos de 3 checkpoints.")
  94.         return false
  95.     end
  96.     for i, v in pairs(checkPoint) do
  97.         if respawn[i].x < v.x-v.l or respawn[i].x > v.x+v.l or respawn[i].y < v.y-v.h or respawn[i].y > v.y+v.h then
  98.             print(string.format("<j>Aviso: Respawn %d no esta adentro del checkpoint %d.", i, i))
  99.         end
  100.     end
  101.     xml = xml:gsub("<S>.-</S>", "<S>"..novosPisos.."</S>")
  102.     xml = xml:gsub("<O>.-</O>", "<O>"..novosObjetos.."</O>")
  103.     xml = xml:gsub('m=""', "")
  104.     xml = xml:gsub('T="14"', 'T="0"')
  105.     xml = xml:gsub('o=".-"', function(a)
  106.         if #a > 10 then
  107.             return 'o="ffffff"'
  108.         else
  109.             return a
  110.         end
  111.     end)
  112.     xml = xml:gsub("<T.-/>", function(a)
  113.         if toca then
  114.             toca = false
  115.             return a
  116.         else
  117.             return ""
  118.         end
  119.     end)
  120.     return xml, checkPoint, powerUp, respawn, blue, orange
  121. end
  122.  
  123. function eventNewGame()
  124.     xml = false
  125.     if loaded then
  126.         loaded = false
  127.         if tfm.get.room.currentMap:sub(1,1) == "@" then
  128.             tfm.exec.setUIMapName(author.."<bl> - "..code)
  129.             for i, v in pairs(checkPoint) do
  130.                 local txt = i
  131.                 for j=1, 400 do
  132.                     txt = txt .. " " .. i
  133.                 end
  134.                 ui.addTextArea(i, "<font size='60px' color='#ffffff'>"..txt, nil, v.x+5-v.l/2, v.y+5-v.h/2, v.l-10, v.h-10, 0xffffff, 0xffffff, 0.2, false)
  135.             end
  136.             for i, v in pairs(powerUp) do
  137.                 ui.addTextArea(i+100, "<font size='15px' color='#ffff00'><p align='center'><b>?", nil, v.x+5-16, v.y+5-16, 22, 22, 0xffff00, 0xffff00, 0.5, false)
  138.             end
  139.             for i, v in pairs(respawn) do
  140.                 ui.addTextArea(i+200, "<font size='15px' color='#00ff00'><p align='center'><b>"..i, nil, v.x+5-16, v.y+5-31, 22, 22, 0x00ff00, 0x00ff00, 0.5, false)
  141.             end
  142.             if blue then
  143.                 tfm.exec.addShamanObject(26, blue.x, blue.y, 0, 0, 0, false)
  144.             end
  145.             if orange then
  146.                 tfm.exec.addShamanObject(27, orange.x, orange.y, 0, 0, 0, false)
  147.             end
  148.         end
  149.     else
  150.         for i=1, 300 do
  151.             ui.removeTextArea(i, nil)
  152.         end
  153.         xml, checkPoint, powerUp, respawn, blue, orange = geraXml(tfm.get.room.xmlMapInfo.xml)
  154.         loaded = true
  155.         code = tfm.get.room.currentMap
  156.         author = tfm.get.room.xmlMapInfo.author
  157.         if xml then
  158.             tfm.exec.newGame(xml)
  159.         else
  160.             tfm.exec.newGame(0)
  161.         end
  162.        
  163.     end
  164. end
  165.  
  166. tfm.exec.disableAutoShaman(true)
  167. tfm.exec.disableAutoNewGame(true)
  168. tfm.exec.newGame(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement