Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  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()
  99. --Creator: Bolodefchoco
  100. --Made in: 27/05/2016
  101. --Last update: 27/05/2016
  102. --[[ Notes:
  103. Does:
  104. Uma rotação automática sem usar função.
  105. ]]--
  106.  
  107. TIME_PERMAP = 2.5 --< Altere 2.5 (2m e 30s) para o tempo que cada mapa deverá começar
  108.  
  109. maps = {7152091,1,2,3} --< Introduza todos os mapas aqui
  110.  
  111. tfm.exec.disableAutoNewGame()
  112.  
  113. system.players=function()
  114. local alive,players = {},{}
  115. for k,v in next,tfm.get.room.playerList do
  116. if not v.isDead then
  117. alive[#alive+1]=k
  118. end
  119. players[#players+1]=k
  120. end
  121. return alive,players
  122. end
  123.  
  124. eventLoop=function(time)
  125. local alive = system.players()
  126. if time <= 0 or #alive < 1 then
  127. local lastMap = currentMap or 0
  128. repeat currentMap = maps[math.random(#maps)] until currentMap ~= lastMap
  129. tfm.exec.newGame(currentMap)
  130. end
  131. end
  132.  
  133. eventNewGame=function()
  134. tfm.exec.setGameTime(TIME_PERMAP*60)
  135. end
  136.  
  137. eventLoop(-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement