Advertisement
Eliaseeg

vote system like #circuit

Jul 21st, 2017 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 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, 263, "Racing"},
  5.     {233, 360, 281, 263, "Bootcamp"},
  6.     {425, 550, 471, 263, "Deathmatch"},
  7.     {614, 735, 661, 263, "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.  
  17. function main()
  18.     tfm.exec.disableAutoShaman(true)
  19.     tfm.exec.disableAutoNewGame(true)
  20.     tfm.exec.disableAfkDeath(true)
  21.     tfm.exec.newGame(xml)
  22.    
  23.     ui.addTextArea(5, "\n\n<font size='30'><p align='center'>Racing</p></font>", nil, 32, 146, 140, 100, 0x324650, 0x000000, 1, true)
  24.     ui.addTextArea(6, "\n\n<font size='27'><p align='center'>Bootcamp</p></font>", nil, 224, 146, 140, 100, 0x324650, 0x000000, 1, true)
  25.     ui.addTextArea(7, "\n<font size='30'><p align='center'>Deathmatch</p></font>", nil, 416, 146, 140, 100, 0x324650, 0x000000, 1, true)
  26.     ui.addTextArea(8, "\n\n<font size='30'><p align='center'>Random</p></font>", nil, 608, 145, 140, 100, 0x324650, 0x000000, 1, true)
  27.     ui.addTextArea(0, "<font size='60' face='Freestyle Script'>¡Escoge un modo de juego!</font>", nil, 197, 34, 594, 78, 0x324650, 0x000000, 0, true)
  28.     ui.addTextArea(12, "<font size='30' color='#000000'>" .. countdown .. "</font>", nil, 363, 82, 42, 42, 0x324650, 0x000000, 0, true)
  29.  
  30.     table.foreach(tfm.get.room.playerList, eventNewPlayer)
  31. end
  32.  
  33. function eventNewPlayer(name)
  34.     if not mice[name] then
  35.         mice[name] = {
  36.             vote = 0
  37.         }
  38.     end
  39. end
  40.  
  41. function eventLoop()
  42.     countdown = countdown - 0.5
  43.     if countdown >= 1 then
  44.         for name, player in pairs(tfm.get.room.playerList) do
  45.             for i = 1, #positions do
  46.                 if player.x >= positions[i][1] and player.x <= positions[i][2] then
  47.                     if i <= 4 then
  48.                         mice[name].vote = i
  49.                         ui.addTextArea(10, "<font size='30'>↑</font>", name, positions[i][3], positions[i][4], 23, 53, 0x324650, 0x000000, 0, true)
  50.                     else
  51.                         mice[name].vote = 0
  52.                         ui.removeTextArea(10, name)
  53.                     end            
  54.                 end
  55.             end
  56.         end
  57.     elseif countdown <= 0 then
  58.         ui.removeTextArea(12, nil)
  59.         score = {0, 0, 0, 0}
  60.         for name, mice in pairs(mice) do
  61.             if mice.vote ~= 0 then
  62.                 score[mice.vote] = score[mice.vote] + 1
  63.             end
  64.         end
  65.         getModeWinner()
  66.         countdown = 5000
  67.     end
  68.    
  69.     ui.updateTextArea(12, "<font size='30' color='#000000'>".. countdown.. "</font>", nil)
  70. end
  71.  
  72. function max(t, fn)
  73.     local i = 0
  74.     for a = 1, #t do
  75.         if t[a] > 0 then
  76.             i = i + 1
  77.         end
  78.     end
  79.     if i > 0 then
  80.         if #t == 0 then return nil, nil end
  81.         local key, value = 1, t[1]
  82.         for i = 2, #t do
  83.             if fn(value, t[i]) then
  84.                 key, value = i, t[i]
  85.             end
  86.         end
  87.         return key, value
  88.     end
  89.     return 4
  90. end
  91.  
  92. function getModeWinner()
  93.     local mode = max(score, function(a,b) return a < b end)
  94.     print(positions[mode][5])
  95. end
  96.  
  97. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement