Advertisement
Guest User

Shaman construtor

a guest
Feb 14th, 2015
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. groundsTable = {}
  2. selectedGround = false
  3. tfm.exec.disableAutoShaman(true)
  4.  
  5. function split(str)
  6.     tok = {}
  7.     for token in string.gmatch(str, "[^%s]+") do
  8.         table.insert(tok,token)
  9.     end
  10.     str = tok[1]
  11.     tok = {}
  12.     for a in string.gmatch(str,'[^,]+') do
  13.         table.insert(tok,a)
  14.     end
  15.     return tok
  16. end
  17.  
  18. function parseXml(shaman)
  19. vanillaGrounds = ''
  20. groundsTable = {}
  21.     if tfm.get.room.xmlMapInfo.xml then
  22.         c = 0
  23.         xml = tfm.get.room.xmlMapInfo.xml
  24.         grounds = xml:match('<S>[^´]+/>'):gsub("<S>","")
  25.         for id in grounds:gmatch('<S[^/]+/>') do
  26.             c = c+1
  27.             groundsTable[c] = {id = c,
  28.             L = id:match('L="[0-9-]+"'):gsub("L=",""):gsub('"',""),
  29.             H = id:match('H="[0-9-]+"'):gsub("H=",""):gsub('"',""),
  30.             X = id:match('X="[0-9-]+"'):gsub("X=",""):gsub('"',""),
  31.             Y = id:match('Y="[0-9-]+"'):gsub("Y=",""):gsub('"',""),
  32.             T = id:match('T="[0-9-]+"'):gsub("T=",""):gsub('"',""),
  33.             O = '0'
  34.             }
  35.             if groundsTable[c].T == "12" or groundsTable[c].T == "13" then
  36.                 groundsTable[c].O = id:match('o="[A-Za-z0-9]+"'):gsub("o=",""):gsub('"',"")
  37.             end
  38.             groundsTable[c].OTHERS = split(id:match('P="[^¨]+"'):gsub("P=",""):gsub('"',""))
  39.             id = id:gsub('X=',string.format('lua="%s" X=',c))
  40.             vanillaGrounds = vanillaGrounds..id
  41.         end
  42.         xmlStart = xml:match('<C>[^´]+<S>')
  43.         xmlEnd = xml:match('</S>[^´]+</C>')
  44.         xml = string.format("%s%s%s",xmlStart,vanillaGrounds,xmlEnd)
  45.         tfm.exec.newGame(xml)
  46.         tfm.exec.setShaman(shaman)
  47.         system.bindMouse(shaman)
  48.         print('<ROSE>[Game]<N> Agora é o seu turno! Utilize o mouse para mover os pisos.')
  49.     end
  50. end
  51.  
  52. function eventSummoningEnd(playerName, objectType, xPosition, yPosition, angle, xSpeed, ySpeed, other)
  53. tfm.exec.removeObject(other.id)
  54. end
  55.  
  56. function getShamanRoom()
  57. sc = {score = 0, name = 'Souris'}
  58.     for k,v in pairs(tfm.get.room.playerList) do
  59.         system.bindMouse(k,false)
  60.         if v.score >= sc.score then
  61.             sc = {score = v.score, name = k}
  62.         end
  63.     end
  64.     tfm.exec.setPlayerScore(sc.name,0)
  65.     return sc.name
  66. end
  67.  
  68. function eventNewGame()
  69. if tfm.get.room.xmlMapInfo.xml then
  70.     mapAuthor = tfm.get.room.xmlMapInfo.author
  71.         if mapAuthor ~= '#Module' then
  72.             parseXml(getShamanRoom())
  73.         end
  74.     end
  75. end
  76.  
  77. function eventMouse(player,x,y)
  78.     if not selectedGround then
  79.         for id,tabl in pairs(groundsTable) do
  80.             if x > tabl.X-tabl.L/2 and x < tabl.X+tabl.L/2 and y > tabl.Y-tabl.H/2 and y < tabl.Y+tabl.H/2 then
  81.                 ui.addTextArea(1,'',nil,tabl.X-tabl.L/2,tabl.Y-tabl.H/2,tabl.L,tabl.H,0xFEFF00,0xFEFF00,0.2,false)
  82.                 selectedGround = id
  83.             end
  84.         end
  85.     else
  86.         tfm.exec.addPhysicObject(selectedGround,x,y,{color = '0x'..groundsTable[selectedGround].O, type = groundsTable[selectedGround].T, width = groundsTable[selectedGround].L, height = groundsTable[selectedGround].H, mass = groundsTable[selectedGround].OTHERS[1], friction = groundsTable[selectedGround].OTHERS[3], restitution = groundsTable[selectedGround].OTHERS[4], angle = groundsTable[selectedGround].OTHERS[5]})
  87.         groundsTable[selectedGround].X = x
  88.         groundsTable[selectedGround].Y = y
  89.         selectedGround = false
  90.         ui.removeTextArea(1)
  91.     end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement