tfm.exec.disableAutoNewGame() tfm.exec.disableAllShamanSkills() local alives = 0 -- vivos local shaman = "" -- nome do shaman function updateAlives(count) -- para não ficar repetindo toda hora alives = alives +- count alives = alives + count -- se o count for negativo ele subtrai em vez de adicionar end function eventNewGame() -- dispara toda vez que um novo mapa começa -- reseta a quantidade de vivos e o nome do shaman alives = 0 shaman = "" for name,player in pairs(tfm.get.room.playerList) do if (not player.isDead) then -- ratos que acabaram de sair da sala, ou que acabaram de entrar podem aparecer mortos portanto verifica se é vivo ou morto updateAlives(1) end if (player.isShaman) then -- naturalmente o isShaman é verdadeiro quando o jogador é um shaman, não precisa de == true shaman = name end end end function eventNewPlayer(name) -- dispara quando um novo jogador entra na sala e recebe o nome dele com #tag for key=0,3 do -- faz um loop entre 0 e 3 diminuindo o uso de funções repetidas -- quem está apertando já é verificado em eventKeyboard, não há necessidade de por ele em eventNewGame system.bindKeyboard(name, key, true) end end function eventPlayerDied(name) -- dispara quando alguém morre updateAlives(-1) end function eventPlayerWon(name) -- dispara quando alguém entra na toca updateAlives(-1) end function eventLoop(timeElapsed, timeRemaining) if alives == 0 or timeRemaining < 1000 then tfm.exec.newGame(math.random(200)) updateAlives(-1) -- se a função demorar para mudar de mapa não repete o chamado pois alives se torna -1, a não ser que o tempo seja < 1000 end end function eventKeyboard(name, key, down, x, y) -- nome, chave, chaveEstáPressionada, x, y (as coords são do rato) if (name == shaman) then local shaman = tfm.get.room.playerList[name] local ax, ay = 0, 0 if (key == 0) then ax = -100 elseif (key == 1) then ay = -100 elseif (key == 2) then ax = 100 elseif (key == 3) then ay = 100 end for pName in pairs(tfm.get.room.playerList) do -- se você quiser pode usar for pName in next, tfm.get.room.playerList do em vez de pairs tfm.exec.movePlayer(pName, shaman.x + ax, shaman.y + ay) end end end table.foreach(tfm.get.room.playerList, eventNewPlayer) -- para quem já estava na sala ser considerado como novo jogador, ele anda pelo playerList e envia o name para o eventNewPlayer tfm.exec.newGame(math.random(200))