Advertisement
Flyingwr

[Script] Dança das cadeiras

Oct 21st, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.61 KB | None | 0 0
  1. local data = {
  2.     system = {
  3.         n = {},
  4.         chairs = {},
  5.         currentChair = nil
  6.     },
  7.     players = {},
  8.     playersinroom = 0,
  9.     time = 45,
  10.     maps = {
  11.         rotation = {7280261},
  12.         xml = {
  13.             mapcode = '',
  14.             author = '',
  15.             xmlinfo = ''
  16.         }
  17.     },
  18.     maydecrease = false,
  19.     round = 0,
  20.     noplayersxml = '<C><P /><Z><S><S L="800" H="10" X="400" Y="300" T="14" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" X="805" H="400" Y="200" T="14" P="0,0,,,0,0,0,0" /><S L="10" H="400" X="-5" Y="200" T="14" P="0,0,,,0,0,0,0" /></S><D /><O /></Z></C>',
  21.     loadstr = ''
  22. }
  23.  
  24. table.foreach({"MinimalistMode", "MortCommand", "PhysicalConsumables", "AutoTimeLeft", "AutoNewGame", "AfkDeath", "AutoShaman", "AutoScore"}, function(k, v) tfm.exec['disable'..v]() end)
  25.  
  26. function playersCount()
  27.     local n = 0
  28.  
  29.     for k in next, tfm.get.room.playerList do
  30.         n = n + 1
  31.     end
  32.  
  33.     data.playersinroom = n
  34.  
  35.     for i = 1, (n - 1) do
  36.         table.insert(data.system.n, i)
  37.     end
  38.  
  39.     if (#data.system.n > 0) then
  40.         tfm.exec.newGame(data.maps.rotation[math.random(#data.maps.rotation)])
  41.     end
  42. end
  43.  
  44. playersCount()
  45.  
  46. function setChairs()
  47.     local chairscode = ''
  48.     local x = {60, 135, 210, 285, 360, 435, 510, 585, 660, 735}
  49.  
  50.     for k, v in next, data.system.n do
  51.         data.system.chairs[v] = {}
  52.  
  53.         data.system.chairs[v].color = string.format('%x', math.random(0x000000, 0xffffff))
  54.         data.system.chairs[v].code = string.format('<P P="0,0" C="%s" Y="320" T="19" X="%s" />', data.system.chairs[v].color, x[v])
  55.         data.system.chairs[v].x = x[v]
  56.         data.system.chairs[v].y = 320
  57.         data.system.chairs[v].busy = false
  58.  
  59.         chairscode = chairscode .. data.system.chairs[v].code
  60.     end
  61.  
  62.     local xml = data.maps.xml.xmlinfo
  63.     xml = xml:gsub('<P', '<P Ca=""')
  64.     xml = (xml:find('<D />') and xml:gsub('<D />', string.format('<D>%s</D>', chairscode)) or xml:find('<D>') and xml:gsub('<D>', string.format('<D>%s', chairscode)))
  65.  
  66.     data.round = data.round + 1
  67.  
  68.     tfm.exec.newGame(xml)
  69.     ui.removeTextArea(666, nil)
  70. end
  71.  
  72. function playerWin(name)
  73.     tfm.exec.giveCheese(name)
  74.     tfm.exec.playerVictory(name)
  75. end
  76.  
  77. function table.delete(t, v)
  78.     for key, value in ipairs(t) do
  79.         if (v == t[key]) then
  80.             table.remove(t, key)
  81.         end
  82.     end
  83. end
  84.  
  85. function eventNewGame()
  86.     data.maydecrease = true
  87.     data.loadstr = ''
  88.     data.time = 45
  89.     data.start = true
  90.  
  91.     if (data.round == 0) then
  92.         ui.addTextArea(666, "", nil, -2500, -2500, 5000, 5000, 0x6A7495, 0x6A7495, 1, true)
  93.  
  94.         local xml = tfm.get.room.xmlMapInfo.xml
  95.         if xml then
  96.             data.maps.xml.mapcode = tfm.get.room.currentMap
  97.             data.maps.xml.author = tfm.get.room.xmlMapInfo.author
  98.             data.maps.xml.xmlinfo = xml
  99.         end
  100.  
  101.         ui.setMapName("Loading")
  102.     elseif (data.round > 0) then
  103.         ui.setMapName(string.format("<j>%s <bl>- %s    <font color='#60608F'>|    <n>Cadeiras : <v>%s/%s", data.maps.xml.author, data.maps.xml.mapcode, #data.system.n, data.playersinroom))
  104.  
  105.         tfm.exec.setGameTime(data.time)
  106.  
  107.         tfm.exec.addPhysicObject(0, 400, 327, {type = 14, width = 800, height = 10})
  108.         tfm.exec.addPhysicObject(1, 400, 140, {type = 14, width = 800, height = 10})
  109.  
  110.         for k, v in next, data.players do
  111.             if (v.chair ~= 0) then
  112.                 ui.removeTextArea(v.chair, nil)
  113.                 v.chair = 0
  114.             end
  115.         end
  116.     elseif (data.round == 10) then
  117.         data.round = 0
  118.     end
  119. end
  120.  
  121. function eventNewPlayer(name)
  122.     data.players[name] = {
  123.         chair = 0
  124.     }
  125.  
  126.     system.bindKeyboard(name, 32, true)
  127.     tfm.exec.setPlayerScore(name, 0)
  128. end
  129. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  130.  
  131. function eventPlayerLeft(name)
  132.     data.players[name] = nil
  133.  
  134.     if (data.players[name].chair ~= 0) then
  135.         data.players[name].chair = 0
  136.         if data.system.chairs[data.players[name].chair] then
  137.             data.system.chairs[data.players[name].chair].busy = false
  138.         end
  139.         ui.removeTextArea(data.players[name].chair, nil)
  140.     end
  141. end
  142.  
  143. function eventLoop(elapsed, remaining)
  144.     local elapsed, remaining = (elapsed/1000), (remaining/1000)
  145.  
  146.     data.time = (data.time - 0.5)
  147.  
  148.     if (data.round > 0) then
  149.         if (math.floor(remaining) <= 5) then
  150.             table.foreach(data.players, function(k, v) if (v.chair == 0) then tfm.exec.killPlayer(k) end end)
  151.         end
  152.  
  153.         if data.maydecrease then
  154.             if (data.time > 20) then
  155.                 if not tostring(data.time):find('.5') then
  156.                     local arrow = {x = 0, y = 0}
  157.  
  158.                     data.system.currentChair = data.system.n[math.random(#data.system.n)]
  159.                     arrow.x, arrow.y = data.system.chairs[data.system.currentChair].x, (data.system.chairs[data.system.currentChair].y - 50)
  160.  
  161.                     tfm.exec.addShamanObject(0, arrow.x, arrow.y)
  162.                 end
  163.             elseif (data.time == 20) then
  164.                 tfm.exec.removePhysicObject(1)
  165.             elseif (data.time == 0) then
  166.                 if (#data.system.n > 1) then
  167.                     table.delete(data.system.n, data.system.currentChair)
  168.                     setChairs()
  169.                 end
  170.             end
  171.         end
  172.     elseif (data.round == 0) then
  173.         data.loadstr = (data.loadstr ~= '...' and data.loadstr .. '.' or '.')
  174.         ui.setMapName("Loading" .. data.loadstr)
  175.         if (data.time < 42) then
  176.             setChairs()
  177.         end
  178.     end
  179. end
  180.  
  181. function eventKeyboard(name, key, down, x, y)
  182.     for k, v in next, data.system.n do
  183.         if (#data.system.chairs > 0) then
  184.             if (math.abs(data.system.chairs[v].x - x) <= 18) and not data.system.chairs[v].busy and (data.players[name].chair == 0) then
  185.                 data.players[name].chair = v
  186.                 data.system.chairs[v].busy = true
  187.                 ui.addTextArea(v, "<p align='center'><font size='10' color='#" .. data.system.chairs[v].color .. "'>" .. name, nil, (data.system.chairs[v].x - 50), (data.system.chairs[v].y + 10), 100, nil, nil, nil, 50, true)
  188.                 tfm.exec.setNameColor(name, '0x' .. data.system.chairs[v].color)
  189.             end
  190.         end
  191.     end
  192. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement