Advertisement
Guest User

Ground mover

a guest
Jul 18th, 2015
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. groundsTable = {}
  2. selectedGround = false
  3. tfm.exec.disableAutoNewGame(true)
  4. tfm.exec.disableAutoShaman(true)
  5.  
  6. function split(str)
  7.     tok = {}
  8.     for token in string.gmatch(str, "[^%s]+") do
  9.         table.insert(tok,token)
  10.     end
  11.     str = tok[1]
  12.     tok = {}
  13.     for a in string.gmatch(str,'[^,]+') do
  14.         table.insert(tok,a)
  15.     end
  16.     return tok
  17. end
  18.  
  19. function parseXml(shaman)
  20. vanillaGrounds = ''
  21. groundsTable = {}
  22.     if tfm.get.room.xmlMapInfo.xml then
  23.         c = 0
  24.         xml = tfm.get.room.xmlMapInfo.xml
  25.         grounds = xml:match('<S>[^´]+/>'):gsub("<S>","")
  26.         for id in grounds:gmatch('<S[^/]+/>') do
  27.             c = c+1
  28.             groundsTable[c] = {id = c,
  29.             L = id:match('L="[0-9-.]+"'):gsub("L=",""):gsub('"',""),
  30.             H = id:match('H="[0-9-.]+"'):gsub("H=",""):gsub('"',""),
  31.             X = id:match('X="[0-9-.]+"'):gsub("X=",""):gsub('"',""),
  32.             Y = id:match('Y="[0-9-.]+"'):gsub("Y=",""):gsub('"',""),
  33.             T = id:match('T="[0-9-.]+"'):gsub("T=",""):gsub('"',""),
  34.             O = '0'
  35.             }
  36.             if groundsTable[c].T == "12" or groundsTable[c].T == "13" then
  37.                 if id:find('o=') then
  38.                     groundsTable[c].O = id:match('[oO]="([^"]+)')
  39.                 end
  40.             end
  41.             groundsTable[c].OTHERS = split(id:match('P="[^¨]+"'):gsub("P=",""):gsub('"',""))
  42.             id = id:gsub('X=',string.format('lua="%s" X=',c))
  43.             vanillaGrounds = vanillaGrounds..id
  44.         end
  45.         xmlStart = xml:match('<C>[^´]+<S>')
  46.         xmlEnd = xml:match('</S>[^´]+</C>')
  47.         xml = string.format("%s%s%s",xmlStart,vanillaGrounds,xmlEnd)
  48.         tfm.exec.newGame(xml)
  49.         tfm.exec.addPhysicObject(666, 200, -260, {type = 16})
  50.         for id,tabl in pairs(groundsTable) do
  51.             x = tabl.X
  52.             y = tabl.Y
  53.             tfm.exec.addJoint('-'..id, 666, 666, {point1 = string.format('%s,%s', x, y), point2 = string.format('%s,%s', x+1, y+2), line = 15, color= 0xD2504D, alpha = 0.6, foreground = true})
  54.         end
  55.         tfm.exec.setShaman(shaman)
  56.         system.bindMouse(shaman)
  57.     end
  58. end
  59.  
  60. function eventSummoningEnd(playerName, objectType, xPosition, yPosition, angle, xSpeed, ySpeed, other)
  61. tfm.exec.removeObject(other.id)
  62. end
  63.  
  64. function getShamanRoom()
  65. sc = {score = 0, name = 'Souris'}
  66.     for k,v in pairs(tfm.get.room.playerList) do
  67.         system.bindMouse(k,false)
  68.         if v.score >= sc.score then
  69.             sc = {score = v.score, name = k}
  70.         end
  71.     end
  72.     tfm.exec.setPlayerScore(sc.name,0)
  73.     return sc.name
  74. end
  75.  
  76. function eventNewGame()
  77. if tfm.get.room.xmlMapInfo.xml then
  78.     mapAuthor = tfm.get.room.xmlMapInfo.author
  79.         if mapAuthor ~= '#Module' then
  80.             parseXml(getShamanRoom())
  81.         end
  82.     end
  83. end
  84.  
  85. function eventMouse(player,x,y)
  86.     if not selectedGround then
  87.         for id,tabl in pairs(groundsTable) do
  88.             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
  89.                 selectedGround = id
  90.                 tfm.exec.addJoint('-'..id, 666, 666, {point1 = string.format('%s,%s', tabl.X, tabl.Y), point2 = string.format('%s,%s', tabl.X+1, tabl.Y), line = 15, color= 0x5CB85C, alpha = 0.6, foreground = true})
  91.             end
  92.         end
  93.     else
  94.         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]})
  95.         groundsTable[selectedGround].X = x
  96.         groundsTable[selectedGround].Y = y
  97.         x = groundsTable[selectedGround].X
  98.         y = groundsTable[selectedGround].Y
  99.         tfm.exec.addJoint('-'..selectedGround, 666, 666, {point1 = string.format('%s,%s', x, y), point2 = string.format('%s,%s', x+1, y), line = 15, color= 0xD2504D, alpha = 0.6, foreground = true})
  100.         selectedGround = false
  101.     end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement