Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _DA = {}
- local _S = {
- candidates = {},
- canGetWinner = true,
- }
- local _UI = {
- showCandidates = function(name, callback)
- if not callback then
- ui.addTextArea(1, "Candidatos <b><a href='event:showCandidates'>»</a></b>", name, 200, 200)
- else
- local str = ""
- if #_S.candidates > 0 then
- 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
- ui.addTextArea(1, string.format("Candidatos : %s<b><a href='event:closeCandidatesGui'>«</a></b>", str), name, 150, 360)
- else
- ui.addPopup(0, 0, "Não há candidatos.", name, 600, 300)
- end
- end
- end,
- addApplyButton = function(name)
- ui.addTextArea(2, "<a href='event:apply'>Candidatar-se</a>", name, 400)
- end,
- }
- function eventNewPlayer(name)
- if not _DA[name] then
- _DA[name] = {
- voted = false,
- candidate = false,
- }
- end
- _UI.showCandidates(name, false)
- _UI.addApplyButton(name)
- end
- function eventLoop(cT, rT)
- time = (rT/1000)
- if time < 0 then time = 0 end
- local min, sec = math.floor((time/60)%60), math.floor(time%60)
- min, sec = (min < 10 and "0"..min or min), (sec < 10 and "0"..sec or sec)
- if time > 1 then
- ui.addTextArea(0, string.format("A votação encerra em <v>%s:%s", min, sec), nil)
- else
- if _S.canGetWinner then
- ui.removeTextArea(0, nil)
- local votes = {}
- local winner = ""
- for i = 1, #_S.candidates do
- if _S.candidates[i].votes > 0 then
- table.insert(votes, _S.candidates[i].votes)
- end
- end
- if #votes > 0 then
- table.sort(votes, function(k,v) return k>v end)
- end
- for i = 1, #_S.candidates do
- if _S.candidates[i].votes == votes[1] then
- winner = _S.candidates[i].nick
- break
- end
- end
- 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
- _S.canGetWinner = false
- end
- end
- end
- function eventTextAreaCallback(id, name, link)
- if link == 'join' then
- if not _S.candidates[name] then table.insert(_S.candidates, name) _UI.showCandidates(name, false) end
- elseif link == 'showCandidates' then
- _UI.showCandidates(name, true)
- elseif link == 'closeCandidatesGui' then
- _UI.showCandidates(name, false)
- elseif link == 'apply' then
- if not _DA[name].candidate then
- table.insert(_S.candidates, {nick=name,votes=0}) _DA[name].candidate = true
- _DA[name].candidate = true
- else
- ui.addPopup(0, 0, "Parabens vc se candidatou.", name, 300)
- end
- ui.removeTextArea(2, name)
- end
- for i = 1, #_S.candidates do
- if _S.candidates[i].nick == link and _S.candidates[i].nick ~= name and not _DA[name].voted then
- _S.candidates[i].votes = _S.candidates[i].votes + 1
- _UI.showCandidates(name, true)
- _DA[name].voted = true
- break
- end
- end
- end
- table.foreach(tfm.get.room.playerList, eventNewPlayer)
- tfm.exec.setUIMapName("Corra do VAMP")
- table.foreach({"utoNewGame","utoShaman","utoTimeLeft","fkDeath"}, function(k,v) tfm.exec['disableA'..v]() end)
- tfm.exec.newGame()
- --Creator: Bolodefchoco
- --Made in: 27/05/2016
- --Last update: 27/05/2016
- --[[ Notes:
- Does:
- Uma rotação automática sem usar função.
- ]]--
- TIME_PERMAP = 2.5 --< Altere 2.5 (2m e 30s) para o tempo que cada mapa deverá começar
- maps = {7152091,1,2,3} --< Introduza todos os mapas aqui
- tfm.exec.disableAutoNewGame()
- system.players=function()
- local alive,players = {},{}
- for k,v in next,tfm.get.room.playerList do
- if not v.isDead then
- alive[#alive+1]=k
- end
- players[#players+1]=k
- end
- return alive,players
- end
- eventLoop=function(time)
- local alive = system.players()
- if time <= 0 or #alive < 1 then
- local lastMap = currentMap or 0
- repeat currentMap = maps[math.random(#maps)] until currentMap ~= lastMap
- tfm.exec.newGame(currentMap)
- end
- end
- eventNewGame=function()
- tfm.exec.setGameTime(TIME_PERMAP*60)
- end
- eventLoop(-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement