Bolodefchoco_LUAXML

[Script] Map Quantity/Author Collector

Sep 23rd, 2018
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local list = [[
  2. @1929779
  3. @1930027
  4. @1975543
  5. @1995971
  6. @1995980
  7. @1017676
  8.  
  9. ]]
  10.  
  11. local maps
  12. do
  13.     maps = { }
  14.  
  15.     local counter = 0
  16.     string.gsub(list, "@(%d+)", function(code)
  17.         counter = counter + 1
  18.         maps[counter] = tonumber(code)
  19.     end)
  20.  
  21.     local timer = 0
  22.     local newGame = tfm.exec.newGame
  23.     tfm.exec.newGame = function(...)
  24.         if os.time() > timer then
  25.             timer = os.time() + 3000
  26.             return newGame(...)
  27.         end
  28.     end
  29. end
  30.  
  31. local splitByChar = function(content, int)
  32.     int = int or 5000
  33.  
  34.     local data = {}
  35.  
  36.     local current = 0
  37.     while #content > current do
  38.         current = current + (int + 1)
  39.         data[#data + 1] = string.sub(content, current - int, current)
  40.     end
  41.  
  42.     return data
  43. end
  44.  
  45. local data = { }
  46.  
  47. local currentRound = 1
  48. eventNewGame = function()
  49.     currentRound = currentRound + 1
  50.  
  51.     local author = tfm.get.room.xmlMapInfo.author
  52.     if not data[author] then
  53.         data[author] = { quantity = 0, maps = { } }
  54.     end
  55.     data[author].quantity = data[author].quantity + 1
  56.     data[author].maps[#data[author].maps + 1] = tfm.get.room.currentMap
  57.  
  58.     if currentRound > #maps then
  59.         ui.setShamanName(#maps .. " / " .. #maps)
  60.         currentRound = 0
  61.  
  62.         local copy, counter = { }, 0
  63.         for k, v in next, data do
  64.             counter = counter + 1
  65.             copy[counter] = { k, v }
  66.         end
  67.         table.sort(copy, function(value1, value2)
  68.             return value1[2].quantity > value2[2].quantity
  69.         end)
  70.  
  71.         counter = 0
  72.         local results = { }
  73.         for info = 1, #copy do
  74.             counter = counter + 1
  75.             results[counter] = copy[info][1] .. " (" .. copy[info][2].quantity .. "): " .. table.concat(copy[info][2].maps, " ")
  76.         end
  77.  
  78.         local lines = splitByChar(table.concat(results, "\n"))
  79.         for line = 1, #lines do
  80.             print(lines[line])
  81.         end
  82.     else
  83.         ui.setShamanName(currentRound .. " / " .. #maps)
  84.     end
  85. end
  86.  
  87. tfm.exec.disableAutoNewGame()
  88. tfm.exec.disableAutoShaman()
  89.  
  90. eventLoop = function()
  91.     if currentRound > 0 then
  92.         tfm.exec.newGame(maps[currentRound])
  93.     end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment