Advertisement
Eliaseeg

test

Jul 21st, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. local xml = '<C><P /><Z><S><S L="800" o="6a7495" H="28" X="401" Y="390" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="366" X="405" /></D><O /></Z></C>'
  2. local positions = {
  3.     -- X1, X2(detect) X, Y (arrow)
  4.     {34, 172, 86, 280, "Racing"},
  5.     {233, 360, 281, 280, "Bootcamp"},
  6.     {425, 550, 471, 280, "Deathmatch"},
  7.     {614, 735, 661, 280, "Random"},
  8.    
  9.     {173, 220},
  10.     {361, 420},
  11.     {551, 610},
  12. }
  13. local mice = {}
  14. local score = {0, 0, 0, 0}
  15. local countdown = 7
  16. local choosed = false
  17.  
  18. function main()
  19.     tfm.exec.disableAutoShaman(true)
  20.     tfm.exec.disableAutoNewGame(true)
  21.     tfm.exec.disableAfkDeath(true)
  22.     tfm.exec.newGame(xml)
  23.    
  24.     ui.addTextArea(1, "\n\n<font size='30'><p align='center'>Racing</p></font>", nil, 32, 170, 140, 100, 0x324650, 0x000000, 1, true)
  25.     ui.addTextArea(2, "\n\n<font size='27'><p align='center'>Bootcamp</p></font>", nil, 224, 170, 140, 100, 0x324650, 0x000000, 1, true)
  26.     ui.addTextArea(3, "\n<font size='30'><p align='center'>Deathmatch</p></font>", nil, 416, 170, 140, 100, 0x324650, 0x000000, 1, true)
  27.     ui.addTextArea(4, "\n\n<font size='30'><p align='center'>Random</p></font>", nil, 608, 170, 140, 100, 0x324650, 0x000000, 1, true)
  28.     ui.addTextArea(5, "<font size='30' face='Segoe Script'>¡Escoge un modo de juego!</font>", nil, 197, 34, 594, 78, 0x324650, 0x000000, 0, true)
  29.     ui.addTextArea(6, "<font size='30' face='Segoe Script' color='#000000'>" .. countdown .. "</font>", nil, 363, 82, 42, 42, 0x324650, 0x000000, 0, true)
  30.     ui.addTextArea(11, "<font size='30'>0</font>", nil, 75, 119, 57, 43, 0x324650, 0x000000, 0, true)
  31.     ui.addTextArea(12, "<font size='30'>0</font>", nil, 275, 119, 57, 43, 0x324650, 0x000000, 0, true)
  32.     ui.addTextArea(13, "<font size='30'>0</font>", nil, 475, 119, 57, 43, 0x324650, 0x000000, 0, true)
  33.     ui.addTextArea(14, "<font size='30'>0</font>", nil, 675, 119, 57, 43, 0x324650, 0x000000, 0, true)
  34.     table.foreach(tfm.get.room.playerList, eventNewPlayer)
  35. end
  36.  
  37. function eventNewPlayer(name)
  38.     if not mice[name] then
  39.         mice[name] = {
  40.             vote = 0
  41.         }
  42.     end
  43. end
  44.  
  45. function eventLoop()
  46.     countdown = countdown - 0.5
  47.     if not choosed then
  48.         for name, player in pairs(tfm.get.room.playerList) do
  49.             for i = 1, #positions do
  50.                 if player.x >= positions[i][1] and player.x <= positions[i][2] then
  51.                     if i <= 4 then
  52.                         mice[name].vote = i
  53.                         ui.addTextArea(10, "<font size='30'>↑</font>", name, positions[i][3], positions[i][4], 23, 53, 0x324650, 0x000000, 0, true)
  54.                         ui.updateTextArea(1 .. i, "<font size='30'>".. getVotes(i) .. "</font>", name)
  55.                     else
  56.                         mice[name].vote = 0
  57.                         ui.removeTextArea(10, name)
  58.                         for a = 1, 4 do
  59.                             ui.updateTextArea(1 .. a, "<font size='30'>".. getVotes(a) .. "</font>", name)
  60.                         end
  61.                     end
  62.                 end
  63.             end
  64.         end
  65.     end
  66.     if countdown <= 0 then
  67.         ui.removeTextArea(6, nil)
  68.         score = {0, 0, 0, 0}
  69.         for name, mice in pairs(mice) do
  70.             if mice.vote ~= 0 then
  71.                 score[mice.vote] = score[mice.vote] + 1
  72.             end
  73.         end
  74.         getModeWinner()
  75.         choosed = true
  76.         countdown = 5000
  77.     end
  78.     ui.updateTextArea(6, "<font size='30' color='#000000'>".. countdown.. "</font>", nil)
  79. end
  80.  
  81. function getVotes(mode)
  82.     local i = 0
  83.     for name,_ in pairs(tfm.get.room.playerList) do
  84.         if mice[name].vote == mode then
  85.             i = i + 1
  86.         end
  87.     end
  88.     return i;
  89. end
  90.  
  91. function max(t, fn)
  92.     local i = 0
  93.     for a = 1, #t do
  94.         if t[a] > 0 then
  95.             i = i + 1
  96.         end
  97.     end
  98.     if i > 0 then
  99.         if #t == 0 then return nil, nil end
  100.         local key, value = 1, t[1]
  101.         for i = 2, #t do
  102.             if fn(value, t[i]) then
  103.                 key, value = i, t[i]
  104.             end
  105.         end
  106.         return key, value
  107.     end
  108.     return 4
  109. end
  110.  
  111. function getModeWinner()
  112.     local mode = max(score, function(a,b) return a < b end)
  113.     print(positions[mode][5])
  114. end
  115.  
  116. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement