-- STOP -- Escrito por Ninguem - 31/08/2015 ADM = {"Rodybrazil"} CAT = {"Nome","Vegetal","Animal","Marca","Profissão","Objeto","TV/Filme","Lugar","Parte do corpo","O Tig é...","Transformice"} ID = {cat=1,camada=2,add=3,msg=4,tempo=5,stop=6} PLAYER = {} ESCOLHA = {} MODO = "inicio" ROUND = 1 PALAVRA = 1 MAXROUND = 5 TEMPO = false LETRA = "" function atualizaCat(first) local txt = "

Selecione as categorias.

\n\n" for i, v in pairs(CAT) do txt = txt .. string.format("- %s [remover]\n", v, v) end txt = txt .. "\n- Adicionar\n\n

Começar

" for i, v in pairs(ADM) do ui.addTextArea(ID.cat, txt, v, 300, 50, 200, 300, 1, 1, 0.8, true) end end function atualizaPlayer() local txt = ROUND <= MAXROUND and string.format("

Round %d/%d\n

", ROUND, MAXROUND) or "

Placar final\n\n

" local cont = 0 local total = 0 local player = {} for i, v in pairs(PLAYER) do table.insert(player, {nome = i, pontos = v.pontos, vitoria = v.vitoria, num = v.num}) end table.sort(player, function(a, b) if a.pontos and b.pontos then return a.pontos > b.pontos end end) for i, v in ipairs(player) do txt = txt .. string.format("<%s>- %s - %d pontos %s\n", v.num and v.num > 0 and "vp" or "r", v.nome, v.pontos or 0, v.vitoria and v.vitoria > 0 and string.format("- Vitórias: %d", v.vitoria) or "") if v.num > 0 then cont = cont + 1 end total = total + 1 if total > 20 then break end end if cont == total then TEMPO = os.time()+5000 end ui.addTextArea(ID.cat, txt, nil, 300, 50, 200, 250, 1, 1, 0.8, true) end function split(txt) local arg = {} for i, v in string.gmatch(txt, "[%S]+") do table.insert(arg, i) end return arg end function isAdm(p) for i, v in pairs(ADM) do if v == p then return true end end end function buscaItem(t, item) for i, v in pairs(t) do if v == item then return i end end return false end function buscaPalavra(item) for i, v in pairs(ESCOLHA) do if v.p == item then return i end end return false end function zeraTudo(zeraVitoria, zeraPontos) for i, v in pairs(tfm.get.room.playerList) do PLAYER[i] = PLAYER[i] or {} PLAYER[i].num = 0 PLAYER[i].palavra = {} for _, v in pairs(CAT) do PLAYER[i].palavra[v] = "" end if zeraVitoria then PLAYER[i].vitoria = 0 end if zeraPontos then PLAYER[i].pontos = 0 tfm.exec.setPlayerScore(i, 0, false) end end end function atualizaPalavras(p) local cont = 0 for i, v in pairs(CAT) do ui.addTextArea(i+1000, string.format("

%s\n%s", i, v, PLAYER[p].palavra[v]), p, ((i-1)%5)*160+5, math.floor((i-1)/5)*55+150, 150, 45, 1, 1, 0.8, true) if PLAYER[p].palavra[v] ~= "" then cont = cont + 1 end end if cont == #CAT then ui.addTextArea(ID.stop, "

Você foi muito rápido! Tempo para pedir stop: " .. math.floor((TEMPO - os.time())/1000), p, 5, 375, 790, 20, 1, 1, 0.8, true) end end function atualizaSeleciona(p) for i, v in ipairs(ESCOLHA) do ui.addTextArea(i+1000, string.format("

<%s>%s", i, PLAYER[p].escolha[i] and "vp" or "r", v.p), p, ((i-1)%5)*160+5, math.floor((i-1)/5)*50+150, 150, 40, 1, 1, 0.8, true) end end function selecionaPalavra() for i=1, #ESCOLHA do table.remove(ESCOLHA) ui.removeTextArea(i+1000, nil) end for i, v in pairs(PLAYER) do if v.palavra[CAT[PALAVRA]] ~= "" then if buscaPalavra(v.palavra[CAT[PALAVRA]]) then ESCOLHA[buscaPalavra(v.palavra[CAT[PALAVRA]])].pontos = 5 else table.insert(ESCOLHA, {p = v.palavra[CAT[PALAVRA]], pontos = 10}) end end end table.sort(ESCOLHA, function(a, b) return a.p < b.p end) for i, v in pairs(PLAYER) do v.escolha = {} for j, x in pairs(ESCOLHA) do table.insert(v.escolha, true) end end ui.addTextArea(ID.cat, "

" .. CAT[PALAVRA] .. " com " .. LETRA, nil, 5, 80, 790, 40, 1, 1, 0.8, true) TEMPO = os.time() + 5000+(2000*#ESCOLHA) ui.addTextArea(ID.tempo, "

20

", nil, 380, 350, 40, 40, 1, 1, 0.8, true) end function eventChatCommand(p, cmd) if cmd == "stop" and MODO == "round" and os.time() > TEMPO then local cont = 0 for i, v in pairs(PLAYER[p].palavra) do cont = v ~= "" and cont + 1 or cont end if cont == #CAT then ui.removeTextArea(ID.stop, nil) ui.removeTextArea(ID.cat, nil) for i=1, #CAT do ui.removeTextArea(i+1000, nil) end MODO = "fim" PALAVRA = 1 ui.addTextArea(ID.msg, "

Clique nas palavras ERRADAS e marque de vermelho para anular seus pontos.", nil, 5, 50, 790, 20, 1, 1, 0.8, true) ESCOLHA = {} selecionaPalavra() for i, v in pairs(PLAYER) do atualizaSeleciona(i) end end end end function eventTextAreaCallback(id, p, cmd) local arg = split(cmd) if #arg > 0 then if arg[1] == "add" then ui.addPopup(ID.add, 2, "Adicionar categoria", p, 300, 200, 200, true) elseif arg[1] == "del" then table.remove(CAT, buscaItem(CAT, table.concat(arg, " ", 2))) atualizaCat(false) elseif arg[1] == "start" then MODO = "espera" TEMPO = os.time()+40000 zeraTudo(true, true) atualizaPlayer(true) ui.addTextArea(ID.tempo, "

40

", nil, 520, 50, 40, 40, 1, 1, 0.8, true) ui.addTextArea(ID.msg, "

Escolha um número

", nil, 150, 320, 490, 20, 1, 1, 0.8, true) for i=1, 10 do ui.addTextArea(i+30, string.format("

%d", i, i), nil, 150+((i-1)*50), 350, 40, 40, 1, 1, 0.8, true) end elseif arg[1] == "num" then PLAYER[p].num = tonumber(arg[2],10) atualizaPlayer(true) for i=1, 10 do ui.removeTextArea(i+30, p) end ui.removeTextArea(ID.msg, p) elseif arg[1] == "palavra" then ui.addPopup(tonumber(arg[2],10), 2, CAT[tonumber(arg[2],10)], p, 300, 200, 200, true) elseif arg[1] == "escolha" then PLAYER[p].escolha[tonumber(arg[2],10)] = PLAYER[p].escolha and not PLAYER[p].escolha[tonumber(arg[2],10)] or false if PLAYER[p].escolha then ui.addTextArea(tonumber(arg[2],10)+1000, string.format("

<%s>%s", tonumber(arg[2],10), PLAYER[p].escolha and PLAYER[p].escolha[tonumber(arg[2],10)] and "vp" or "r", ESCOLHA[tonumber(arg[2],10)] and ESCOLHA[tonumber(arg[2],10)].p or ""), p, ((tonumber(arg[2],10)-1)%5)*160+5, math.floor((tonumber(arg[2],10)-1)/5)*50+150, 150, 40, 1, 1, 0.8, true) end if not PLAYER[p].escolha[tonumber(arg[2],10)] then --tfm.exec.chatMessage(""..p.." votou para negar "..ESCOLHA[tonumber(arg[2],10)].p) end end end end function eventPopupAnswer(id, p, resp) if id == ID.add and resp ~= "" and MODO == "inicio" then if not buscaItem(CAT, resp) then table.insert(CAT, resp) atualizaCat(false) end elseif MODO == "round" and (string.upper(resp)):sub(1,1) == LETRA then PLAYER[p].palavra[CAT[id]] = string.upper(resp) atualizaPalavras(p) end end function eventNewPlayer(p) PLAYER[p] = {num = 0, pontos = 0, vitoria = 0, palavra = {}} for i, v in pairs(CAT) do PLAYER[p].palavra[v] = "" end if MODO == "espera" then atualizaPlayer(true) end tfm.exec.respawnPlayer(p) end function eventPlayerLeft(p) PLAYER[p] = nil if MODO == "espera" then atualizaPlayer(false) end end function eventPlayerGetCheese(p) tfm.exec.killPlayer(p) tfm.exec.respawnPlayer(p) end function eventPlayerDied(p) tfm.exec.respawnPlayer(p) end function eventLoop(current, remaining) if MODO == "espera" then local t = math.ceil((TEMPO - os.time())/1000) ui.updateTextArea(ID.tempo, string.format("

%d

", t), nil) if os.time() > TEMPO then MODO = "letra" local txt = string.format("

Round %d/%d\n

", ROUND, MAXROUND) local cont = 0 local player = {} for i, v in pairs(PLAYER) do table.insert(player, {nome = i, pontos = v.pontos, vitoria = v.vitoria, num = v.num}) end table.sort(player, function(a, b) if a.pontos and b.pontos then return a.pontos > b.pontos end end) for i, v in ipairs(player) do txt = txt .. string.format("- %s escolheu %s\n", v.nome, v.num) cont = cont + v.num end txt = txt .. "\n

Soma: " .. cont LETRA = string.char(cont%26 == 0 and 90 or cont%26+64) ui.addTextArea(ID.cat, txt, nil, 300, 50, 200, 250, 1, 1, 0.8, true) ui.removeTextArea(ID.tempo) TEMPO = os.time()+10000 for i=1, 10 do ui.removeTextArea(i+30, p) end ui.removeTextArea(ID.msg, p) end elseif MODO == "letra" then if os.time() > TEMPO then MODO = "round" TEMPO = os.time()+30000+(5000*#CAT) ui.removeTextArea(ID.cat, nil) ui.addTextArea(ID.cat, string.format("

A letra é:\n%s

", LETRA), nil, 300, 50, 200, 80, 1, 1, 0.8, true) for i, v in pairs(PLAYER) do atualizaPalavras(i) end end elseif MODO == "round" then if os.time() > TEMPO then ui.updateTextArea(ID.stop, "

Digite !stop no chat.", nil) else ui.updateTextArea(ID.stop, "

Você foi muito rápido! Tempo para pedir stop: " .. math.floor((TEMPO - os.time())/1000), nil) end elseif MODO == "fim" then local t = math.ceil((TEMPO - os.time())/1000) ui.updateTextArea(ID.tempo, string.format("

%d

", t), nil) if os.time() > TEMPO then for i, v in pairs(ESCOLHA) do local cont = 0 for j, x in pairs(PLAYER) do if isAdm(j) and x.escolha then cont = x.escolha[i] and cont + 1 or cont end end ESCOLHA[i].pontos = cont>0 and v.pontos or 0 end for i, v in pairs(PLAYER) do if v.palavra[CAT[PALAVRA]] ~= "" then v.pontos = v.pontos + ESCOLHA[buscaPalavra(v.palavra[CAT[PALAVRA]])].pontos end tfm.exec.setPlayerScore(i, v.pontos, false) end if PALAVRA < #CAT then PALAVRA = PALAVRA + 1 selecionaPalavra() for i, v in pairs(PLAYER) do atualizaSeleciona(i) end elseif ROUND < MAXROUND then ROUND = ROUND + 1 MODO = "espera" TEMPO = os.time()+40000 zeraTudo(false, false) atualizaPlayer(true) ui.addTextArea(ID.tempo, "

40

", nil, 520, 50, 40, 40, 1, 1, 0.8, true) ui.addTextArea(ID.msg, "

Escolha um número

", nil, 150, 320, 490, 20, 1, 1, 0.8, true) for i=1, 10 do ui.addTextArea(i+30, string.format("

%d", i, i), nil, 150+((i-1)*50), 350, 40, 40, 1, 1, 0.8, true) end for i, v in pairs(ESCOLHA) do ui.removeTextArea(i+1000, nil) end else ROUND = ROUND + 1 MODO = "vitoria" TEMPO = os.time()+30000 atualizaPlayer() local maior = 0 local n = "" for i, v in pairs(PLAYER) do if v.pontos and v.pontos > maior then maior = v.pontos n = i end end PLAYER[n].vitoria = PLAYER[n].vitoria + 1 for i, v in pairs(ESCOLHA) do ui.removeTextArea(i+1000, nil) end ui.removeTextArea(ID.msg, nil) end end elseif MODO == "vitoria" then for i=1, 50 do tfm.exec.displayParticle(math.random(21,24), math.random(1,800), 20, math.random(-20,20)/100, math.random(10,1000)/100, 0, 0, nil) end if os.time() > TEMPO then MODO = "espera" TEMPO = os.time()+40000 ROUND = 1 zeraTudo(false, true) atualizaPlayer(true) ui.addTextArea(ID.tempo, "

40

", nil, 520, 50, 40, 40, 1, 1, 0.8, true) ui.addTextArea(ID.msg, "

Escolha um número

", nil, 150, 320, 490, 20, 1, 1, 0.8, true) for i=1, 10 do ui.addTextArea(i+30, string.format("

%d", i, i), nil, 150+((i-1)*50), 350, 40, 40, 1, 1, 0.8, true) end end end end tfm.exec.disableAfkDeath(true) tfm.exec.disableAutoShaman(true) tfm.exec.disableAutoScore(true) tfm.exec.disableAutoNewGame(true) tfm.exec.newGame("@630022") atualizaCat(true)