SHARE
TWEET

Untitled

a guest Aug 12th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local _DA = {}
  2. local _S = {
  3.         candidates = {},
  4.         canGetWinner = true,
  5.     }
  6. local _UI = {
  7.         showCandidates = function(name, callback)
  8.             if not callback then
  9.                 ui.addTextArea(1, "Candidatos <b><a href='event:showCandidates'>»</a></b>", name, 200, 200)
  10.             else
  11.                 local str = ""
  12.                 if #_S.candidates > 0 then
  13.                     for i = 1, #_S.candidates do str = str .. string.format("<v><a href='event:%s'>%s</a></v> <j>%s votos</j> <n>|</n> ", _S.candidates[i].nick, _S.candidates[i].nick, _S.candidates[i].votes) end
  14.                     ui.addTextArea(1, string.format("Candidatos : %s<b><a href='event:closeCandidatesGui'>«</a></b>", str), name, 150, 360)
  15.                 else
  16.                     ui.addPopup(0, 0, "Não há candidatos.", name, 600, 300)
  17.                 end
  18.             end
  19.         end,
  20.         addApplyButton = function(name)
  21.             ui.addTextArea(2, "<a href='event:apply'>Candidatar-se</a>", name, 400)
  22.         end,
  23.     }
  24.  
  25. function eventNewPlayer(name)
  26.     if not _DA[name] then
  27.         _DA[name] = {
  28.                 voted = false,
  29.                 candidate = false,
  30.             }
  31.     end
  32.     _UI.showCandidates(name, false)
  33.     _UI.addApplyButton(name)
  34. end
  35.  
  36. function eventLoop(cT, rT)
  37.     time = (rT/1000)
  38.     if time < 0 then time = 0 end
  39.     local min, sec = math.floor((time/60)%60), math.floor(time%60)
  40.     min, sec = (min < 10 and "0"..min or min), (sec < 10 and "0"..sec or sec)
  41.     if time > 1 then
  42.         ui.addTextArea(0, string.format("A votação encerra em <v>%s:%s", min, sec), nil)
  43.     else
  44.         if _S.canGetWinner then
  45.             ui.removeTextArea(0, nil)
  46.             local votes = {}
  47.             local winner = ""
  48.             for i = 1, #_S.candidates do
  49.                 if _S.candidates[i].votes > 0 then
  50.                     table.insert(votes, _S.candidates[i].votes)
  51.                 end
  52.             end
  53.             if #votes > 0 then
  54.                 table.sort(votes, function(k,v) return k>v end)
  55.             end
  56.             for i = 1, #_S.candidates do
  57.                 if _S.candidates[i].votes == votes[1] then
  58.                     winner = _S.candidates[i].nick
  59.                     break
  60.                 end
  61.             end
  62.             if winner ~= "" then ui.addTextArea(0, string.format("A votação foi encerrada. <v>%s</v> teve o maior número de votos. Parabéns!", winner), nil) tfm.exec.setVampirePlayer(winner) end
  63.             _S.canGetWinner = false
  64.         end
  65.     end
  66. end
  67.  
  68. function eventTextAreaCallback(id, name, link)
  69.     if link == 'join' then
  70.         if not _S.candidates[name] then table.insert(_S.candidates, name) _UI.showCandidates(name, false) end
  71.     elseif link == 'showCandidates' then
  72.         _UI.showCandidates(name, true)
  73.     elseif link == 'closeCandidatesGui' then
  74.         _UI.showCandidates(name, false)
  75.     elseif link == 'apply' then
  76.         if not _DA[name].candidate then
  77.             table.insert(_S.candidates, {nick=name,votes=0}) _DA[name].candidate = true
  78.             _DA[name].candidate = true
  79.         else
  80.             ui.addPopup(0, 0, "Parabens vc se candidatou.", name, 300)
  81.         end
  82.         ui.removeTextArea(2, name)
  83.     end
  84.     for i = 1, #_S.candidates do
  85.         if _S.candidates[i].nick == link and _S.candidates[i].nick ~= name and not _DA[name].voted then
  86.             _S.candidates[i].votes = _S.candidates[i].votes + 1
  87.             _UI.showCandidates(name, true)
  88.             _DA[name].voted = true
  89.             break
  90.         end
  91.     end
  92. end
  93.  
  94. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  95. tfm.exec.setUIMapName("Corra do VAMP")
  96. table.foreach({"utoNewGame","utoShaman","utoTimeLeft","fkDeath"}, function(k,v) tfm.exec['disableA'..v]() end)
  97.  
  98. tfm.exec.newGame()
RAW Paste Data
Top