Advertisement
Eliaseeg

Mayhem

Mar 30th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.07 KB | None | 0 0
  1. --[[
  2. #mayhem
  3. G:
  4.     • Kill the shaman
  5.     • Avalanche
  6.     • Don't touch the cheese
  7.     • Mad Mice
  8.     • Simon say
  9.     • Survival   
  10. ]]
  11. local maps = {"@5896722", "@5896725", "@5635429", "@5896728", "@5896731", "@5896733"}
  12. local lobby = {"@5468613"}
  13. local game = {"@999999"}
  14. local winner = {10, 20}
  15.  
  16. local _modos = {
  17.     {"Kill the shaman", 100},
  18.     {"Avalanche", 60},
  19.     {"Don't touch the cheese", 120},
  20.     {"Mad mice", 30},
  21.     {"Simon say", 40},
  22.     {"Survival", 50},
  23.     {"Lobby", 30}
  24. }
  25. local game_index = {"Kill the shaman", "Avalanche", "Don't touch the cheese", "Mad mice", "Simon say", "Survival"}
  26. local KILL,AVALANCHE,CHEESE,MAD,SIMON,SURVIVAL = 1,2,3,4,5,6
  27. local modos = {}
  28. for i=1,5 do modos[i] = {name = _modos[i][1], time = _modos[i][2]} end
  29.  
  30. local playersInRoom = 0
  31. local round = 0
  32. local xmldom
  33. local lastMap
  34. local lastRound = "a"
  35. local gameStarted
  36. local gameLoaded
  37. local gameFinished
  38. local first
  39. local second
  40. local third
  41.  
  42. -- Makinit's flattenFunctionTree
  43. do
  44.     function flattenFunctionTree(tree, path)
  45.         for name, value in pairs(tree) do
  46.             if type(value) == "table" then
  47.                 flattenFunctionTree(value, path .. name .. "_")
  48.             elseif type(value) == "function" then
  49.                 _G[path .. name] = value
  50.             end
  51.         end
  52.     end
  53.    
  54.     local temp = {}
  55.     for name, value in pairs(_G) do
  56.         if value ~= _G then
  57.             temp[name] = value
  58.         end
  59.     end
  60.     flattenFunctionTree(temp, "")
  61. end
  62.  
  63. function main()
  64.     tfm_exec_disableAutoNewGame(true)  
  65.     tfm_exec_disableAutoTimeLeft(true)
  66.     tfm_exec_disableAllShamanSkills(true)
  67.     tfm_exec_disableAutoShaman(true)
  68.     tfm_exec_disableAutoTimeLeft(true)
  69.     math_randomseed(os.time())
  70.     startGame()
  71. end
  72.  
  73. function startGame()
  74.     if lastRound == "Game" then
  75.         local newMap;
  76.         repeat
  77.             newMap = table.random(maps)
  78.         until newMap ~= lastMap
  79.         lastMap = newMap
  80.         tfm_exec_newGame(newMap)
  81.         lastRound = "afasfa"
  82.     else
  83.         tfm_exec_newGame(table.random(game))
  84.         tfm_exec_setGameTime(10)
  85.         lastRound = "Game"
  86.     end
  87. end
  88.  
  89. function eventNewGame()
  90.     round = round + 1
  91.     gameLoaded = true
  92.     print(lastRound)
  93.     if round == 0 then
  94.         winners(first, second, third)
  95.     elseif round == 5 then
  96.         round = 0
  97.     end
  98.    
  99.     if lastRound == "afasfa" and gameStarted then
  100.         local xml = tfm.get.room.xmlMapInfo.xml
  101.         xmldom = parseXml(xml)
  102.         gameMode = path(xmldom, "P")[1].attribute.g or 0
  103.         gameMode = tonumber(gameMode) or gameMode + 0
  104.         tfm_exec_setGameTime(modos[gameMode].time + 8)
  105.        
  106.         toDelete = game_index[gameMode]
  107.         table.delete(game_index, toDelete)
  108.     end
  109.    
  110. end
  111.  
  112. function eventLoop(time, left)
  113.     if not gameLoaded then return end
  114.     if time > 800 and not gameStarted and lastRound ~= "Game" then
  115.         modeStart()
  116.         gameStarted = true
  117.     end
  118.     if not gameFinished and left <= 0 then
  119.         modeEnd()
  120.     elseif gameFinished and left <= 0 then
  121.         startGame()
  122.     end
  123. end
  124.  
  125. function modeEnd()
  126.     tfm_exec_setGameTime(5)
  127.     gameFinished = true
  128. end
  129.  
  130. function modeStart()
  131.     print("<bv>Go!")
  132. end
  133.  
  134. function winners(first, second, third)
  135.     first = first or 'No one'
  136.     second = second or 'No one'
  137.     third = third or 'No one'
  138.     gameFinished = true
  139.     gameStarted = false
  140.     tfm_exec_newGame(table.random(winner))
  141. end
  142.  
  143. function table.random(t, associative)
  144.     associative = associative or false
  145.     if associative then
  146.         local t2 = {}
  147.         for k in pairs(t) do
  148.             t2[#t2 + 1] = k
  149.         end
  150.         return t[table.random(t2)]
  151.     else
  152.         return t[math_random(1,#t)]
  153.     end
  154. end
  155.  
  156. function table.find(tbl, element)
  157.     if element == nil then
  158.         return false
  159.     end
  160.     for key, value in pairs(tbl) do
  161.         if value == element then
  162.             return true
  163.         end
  164.     end
  165.     return false
  166. end
  167.  
  168. function table.delete(tbl, element)
  169.     if type(tbl)=="table" then
  170.         for a,b in pairs(tbl)do
  171.             if tbl[a] == element then
  172.                 table_remove(tbl, a)
  173.                 break
  174.             end
  175.         end
  176.     end
  177. end
  178. --  Makinit's xml library
  179. do
  180.     local namePattern = "[%a_:][%w%.%-_:]*"
  181.     function parseXml(xml)
  182.         local root = {}
  183.         local parents = {}
  184.         local element = root
  185.         for closing, name, attributes, empty, text in string_gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  186.              if closing == "/" then
  187.                 local parent = parents[element]
  188.                 if parent and name == element.name then
  189.                     element = parent
  190.                 end
  191.                    
  192.             else
  193.                 if name ~= "L" then
  194.                     local child = {name = name, attribute = {}}
  195.                     table_insert(element, child)
  196.                     parents[child] = element
  197.                     if empty ~= "/" then
  198.                         element = child
  199.                     end
  200.                     for name, value in string_gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  201.                         child.attribute[name] = value
  202.                     end
  203.                 end
  204.             end
  205.             if text ~= "" then
  206.                 local child = {text = text}
  207.                 table_insert(element, child)
  208.                 parents[child] = element
  209.             end
  210.         end
  211.         return root[1]
  212.     end
  213.  
  214.     function path(nodes, ...)
  215.         nodes = {nodes}
  216.         for i, name in ipairs(arg) do
  217.             local match = {}
  218.             for i, node in ipairs(nodes) do
  219.                 for i, child in ipairs(node) do
  220.                     if child.name == name then
  221.                         table_insert(match, child)
  222.                     end
  223.                 end
  224.             end
  225.             nodes = match
  226.         end
  227.         return nodes
  228.     end
  229. end
  230.  
  231. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement