Advertisement
Guest User

Testador de mapas - #circuit - Transformice Lua

a guest
Apr 16th, 2015
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 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>Erro: Não há objetos de shaman.")
  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.                 if string.find(v, 'D=""') then
  65.                     primeiroPlano = true
  66.                 end
  67.             end
  68.             local xx = tonumber(string.match(v, 'X=".-"'):sub(4,-2))
  69.             local yy = tonumber(string.match(v, 'Y=".-"'):sub(4,-2))
  70.             table.insert(respawn, {x=xx, y=yy})
  71.         end
  72.     else
  73.         print("<r>Erro: Não há decorações.")
  74.         return false
  75.     end
  76.     l = string.match(xml, 'Laps="%d-"')
  77.     if l then
  78.         l = l:sub(7,-2)
  79.         laps = tonumber(l)
  80.     else
  81.         laps = 3
  82.     end
  83.     if blue and not orange then
  84.         print("<j>Aviso: Não há portal laranja.")
  85.     end
  86.     if orange and not blue then
  87.         print("<j>Aviso: Não há portal laranja.")
  88.     end
  89.     if #respawn ~= #checkPoint then
  90.         print("<r>Erro: Quantidade de respawns é diferente de checkpoints.")
  91.         return false
  92.     elseif #powerUp == 0 then
  93.         print("<r>Erro: Não há powerups.")
  94.         return false
  95.     elseif #checkPoint < 3 then
  96.         print("<r>Erro: Menos de 3 checkpoints.")
  97.         return false
  98.     end
  99.     for i, v in pairs(checkPoint) do
  100.         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
  101.             tfm.exec.chatMessage(string.format("<j>Aviso: Respawn %d não está dentro do checkpoint %d.", i, i))
  102.         end
  103.     end
  104.     xml = xml:gsub("<S>.-</S>", "<S>"..novosPisos.."</S>")
  105.     xml = xml:gsub("<O>.-</O>", "<O>"..novosObjetos.."</O>")
  106.     xml = xml:gsub("<T.-/>", function(a)
  107.         if toca then
  108.             toca = false
  109.             return a
  110.         else
  111.             return ""
  112.         end
  113.     end)
  114.     return xml, checkPoint, powerUp, respawn, blue, orange
  115. end
  116.  
  117. function eventNewGame()
  118.     xml = false
  119.     if loaded then
  120.         loaded = false
  121.         if tfm.get.room.currentMap:sub(1,1) == "@" then
  122.             tfm.exec.setUIMapName(author.."<bl> - "..code)
  123.             for i, v in pairs(checkPoint) do
  124.                 local txt = i
  125.                 for j=1, 200 do
  126.                     txt = txt .. " " .. i
  127.                 end
  128.                 ui.addTextArea(i, "<font size='40px' 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)
  129.             end
  130.             for i, v in pairs(powerUp) do
  131.                 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)
  132.             end
  133.             for i, v in pairs(respawn) do
  134.                 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)
  135.             end
  136.             if blue then
  137.                 tfm.exec.addShamanObject(26, blue.x, blue.y, 0, 0, 0, false)
  138.             end
  139.             if orange then
  140.                 tfm.exec.addShamanObject(27, orange.x, orange.y, 0, 0, 0, false)
  141.             end
  142.         end
  143.     else
  144.         xml, checkPoint, powerUp, respawn, blue, orange = geraXml(tfm.get.room.xmlMapInfo.xml)
  145.         loaded = true
  146.         code = tfm.get.room.currentMap
  147.         author = tfm.get.room.xmlMapInfo.author
  148.         if xml then
  149.             tfm.exec.newGame(xml)
  150.         else
  151.             tfm.exec.newGame(0)
  152.         end
  153.        
  154.     end
  155. end
  156.  
  157. tfm.exec.disableAutoShaman(true)
  158. tfm.exec.disableAutoNewGame(true)
  159. tfm.exec.newGame(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement