Bolodefchoco_LUAXML

[Script] Load grounds

Aug 11th, 2018
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. local owner
  2. do
  3.     local _, err = pcall(nil)
  4.     owner = string.match(err, "(.-)%.")
  5. end
  6.  
  7. assert(owner, "Impossible to find owner name.")
  8.  
  9. string.split = function(str, pat)
  10.     local out = { }
  11.  
  12.     local len = 0
  13.     string.gsub(str, pat, function(value)
  14.         len = len + 1
  15.         out[len] = tonumber(value) or value
  16.     end)
  17.  
  18.     return out
  19. end
  20.  
  21. eventChatCommand = function(playerName, command)
  22.     if playerName == owner then
  23.         local cmd = string.split(command, "%S+")
  24.  
  25.         if cmd[1] == "edit" and cmd[2] then
  26.             tfm.exec.newGame(cmd[2])
  27.         end
  28.     end
  29. end
  30.  
  31. local parseProperties = function(data)
  32.     local out = { }
  33.  
  34.     string.gsub(data, "(%-?%w+)=\"(.-)\"", function(attribute, value)
  35.         if string.find(value, ',') then
  36.             local values, counter = { }, 0
  37.  
  38.             value = string.gsub(value, "^,", "0,")
  39.             value = string.gsub(value, ",,", ",0,")
  40.             value = string.gsub(value, ",$", ",0")
  41.  
  42.             string.gsub(value, "[^,]+", function(sub_value)
  43.                 counter = counter + 1
  44.                 values[counter] = tonumber(sub_value) or sub_value
  45.                 value = values
  46.             end)
  47.         else
  48.             value = tonumber(value) or value
  49.         end
  50.  
  51.         out[attribute] = value
  52.     end)
  53.  
  54.     return out
  55. end
  56.  
  57. local grounds = { }
  58.  
  59. local runAgain = false
  60. eventNewGame = function()
  61.     local xml = (tfm.get.room.xmlMapInfo or {}).xml
  62.     if xml then
  63.         if runAgain then
  64.             runAgain = false
  65.  
  66.             for ground = 1, #grounds do
  67.                 tfm.exec.addPhysicObject(ground, grounds[ground].X, grounds[ground].Y, {
  68.                     angle = grounds[ground].P[5],
  69.                     angularDamping = grounds[ground].P[8],
  70.                     color = grounds[ground].o and tonumber(grounds[ground].o, 16),
  71.                     dynamic = grounds[ground].P[1] == 1,
  72.                     fixedRotation = grounds[ground].P[6] == 1,
  73.                     foreground = not not grounds[ground].N,
  74.                     friction = grounds[ground].P[3],
  75.                     groundCollision = (not grounds[ground].c or grounds[ground].c == 1 or grounds[ground].c == 2),
  76.                     height = grounds[ground].H,
  77.                     linearDamping = grounds[ground].P[7],
  78.                     mass = grounds[ground].P[2],
  79.                     miceCollision = (not grounds[ground].c or grounds[ground].c == 1 or grounds[ground].c == 3),
  80.                     restitution = grounds[ground].P[4],
  81.                     type = grounds[ground].T,
  82.                     width = grounds[ground].L
  83.                 })
  84.             end
  85.         else
  86.             grounds = { }
  87.  
  88.             local counter = 0
  89.             string.gsub(xml, "<S (.-)>", function(data)
  90.                 counter = counter + 1
  91.                 grounds[counter] = parseProperties(data)
  92.             end)
  93.            
  94.             runAgain = true
  95.         end
  96.     end
  97. end
  98.  
  99. eventLoop = function()
  100.     if runAgain then
  101.         tfm.exec.newGame("<C><P /><Z><S /><D /><O /></Z></C>")
  102.     end
  103. end
  104.  
  105. tfm.exec.disableAutoNewGame()
  106. tfm.exec.disableAutoShaman()
Advertisement
Add Comment
Please, Sign In to add comment