Brenower

xml 3

Feb 20th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. data={}; -- Dados de cada jogador
  2. x={}; -- Posições x do +1
  3. y={}; -- Posições y do +1
  4.  
  5. tfm.exec.newGame('<C><P defilante="0,0,0,1" /><Z><S><S P="0,0,0.3,0,0,0,0,0" L="800" H="80" X="400" Y="400" T="10" /></S><D /><O><O X="401" C="6" Y="344" P="0" /></O></Z></C>')
  6.  
  7. function giveData(p) -- Dar data aos jogadores
  8.     data[p]={
  9.             x={};
  10.             y={};
  11. }
  12. end
  13.  
  14. function yPostion(p) -- Verifica se  jogador está na posição y certa
  15.     for i = #data[p].y,1,-1 do
  16.         if tfm.get.room.playerList[p].y > data[p].y[i] - 30 and tfm.get.room.playerList[p].y < data[p].y[i] + 30 then
  17.             table.remove(data[p].x,i) -- O jogador não pode ganhar mais pontos depois de pegar aquele +1
  18.             table.remove(data[p].y,i)
  19.             tfm.exec.setPlayerScore(p,1,true)
  20.         end
  21.     end
  22. end
  23.  
  24. function xPosition(p) -- Verifica se o jogador está na posição x certa
  25.     for i = #data[p].x,1,-1 do
  26.         if tfm.get.room.playerList[p].x > data[p].x[i] - 30 and tfm.get.room.playerList[p].x < data[p].x[i] + 30 then
  27.             return true -- Retorna true
  28.         end
  29.     end
  30. end
  31.  
  32. function remove(p) -- Remove dados da data do jogador
  33.     for i = #data[p].x,1,-1 do
  34.         table.remove(data[p].x,i)
  35.         table.remove(data[p].y,i)
  36.     end
  37. end
  38.  
  39. function add(p) -- Adiciona dados na data do jogador
  40.     for i = #x,1,-1 do
  41.         table.insert(data[p].x,x[i])
  42.         table.insert(data[p].y,y[i])
  43.     end
  44. end
  45.  
  46. function eventNewGame() -- Quando uma nova partida inicia-se...
  47.     for i = #x,1,-1 do
  48.         table.remove(x,i) -- Remove tudo da tabela x
  49.         table.remove(y,i) -- Remove tudo da tabela y
  50.     end
  51.     for xml in tfm.get.room.xmlMapInfo.xml:gmatch("<O[^/]+/>") do -- Pega as partes dentro <O /> no xml
  52.         if xml:match('C="(%d+)"') == "6" then -- Verifica se o objeto é uma bola
  53.             table.insert(x,tonumber(xml:match('X="(%d+)"'))) -- Inseri na tabela o x
  54.             table.insert(y,tonumber(xml:match('Y="(%d+)"'))) -- Inseri na tabela o y
  55.         end
  56.     end
  57.     for i in pairs(tfm.get.room.playerList) do
  58.         giveData(i)
  59.         remove(i)
  60.         add(i)
  61.     end
  62. end
  63.  
  64. function eventLoop()
  65.     for i in pairs(tfm.get.room.playerList) do
  66.         if data[i] and xPosition(i) == true then
  67.             yPostion(i)
  68.         end
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment