Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local initModuleTimer = 1000
- local playerData = { }
- local stageNames = { "I", "II", "III", "IV", "V" }
- local totalStages = #stageNames
- local displayStageNames = function(playerName)
- for i = 1, totalStages do
- ui.addTextArea(i, "<p align='center'><font size='30' color='#000000'><B>" .. stageNames[i], playerName, 390 + (i - 1) * 200, 180, 200, nil, 1, 1, 0, false)
- end
- ui.setMapName("Perguntas")
- end
- local setPlayerData = function(playerName)
- playerData[playerName] = {
- currentStage = 0,
- hasSkipped = false
- }
- tfm.exec.setPlayerScore(playerName, 0)
- end
- local chooseShaman = true
- local newShaman, nextShaman
- local currentQuestion, currentAnswer
- local skip = 0
- local getNewShaman = function()
- if nextShaman and playerData[nextShaman] then
- return nextShaman
- end
- local scores, counter = { }, 0
- local hasMoreThanZeroPoints = false
- local score
- for playerName, data in next, playerData do
- score = tfm.get.room.playerList[playerName].score
- counter = counter + 1
- scores[counter] = {
- playerName = playerName,
- score = score
- }
- if score > 0 then
- hasMoreThanZeroPoints = true
- end
- end
- if hasMoreThanZeroPoints then
- table.sort(scores, function(p1, p2)
- return p1.score > p2.score
- end)
- return scores[1].playerName
- else
- return scores[math.random(counter)].playerName
- end
- end
- local resetAllScores = function()
- for playerName in next, tfm.get.room.playerList do
- tfm.exec.setPlayerScore(playerName, 0)
- end
- end
- local moveAllToSpawnPoint = function()
- for playerName in next, tfm.get.room.playerList do
- tfm.exec.movePlayer(playerName, 125, 365)
- end
- end
- local displayAnswer = function()
- if not currentAnswer then return end
- tfm.exec.chatMessage("A resposta da pergunta era <B>" .. currentAnswer .. "</B>.")
- end
- local startChooseFlow = function(ignoreAnswer)
- if newShaman then
- tfm.exec.respawnPlayer(newShaman)
- newShaman = nil
- end
- if not ignoreAnswer then
- displayAnswer()
- end
- currentQuestion = nil
- currentAnswer = nil
- skip = 0
- chooseShaman = true
- moveAllToSpawnPoint()
- ui.removeTextArea(0)
- tfm.exec.setGameTime(5)
- tfm.exec.chatMessage("Escolhendo Shaman...")
- end
- local displayQuestion = function(playerName)
- if not currentQuestion then return end
- ui.addTextArea(0, "<p align='center'><font size='20'>" .. currentQuestion, playerName, 5, 50, 400, nil, nil, nil, .75, true)
- end
- local resetAllPlayerData = function()
- for playerName, data in next, playerData do
- data.hasSkipped = false
- data.currentStage = 0
- end
- end
- eventNewPlayer = function(playerName)
- setPlayerData(playerName)
- displayStageNames(playerName)
- displayQuestion(playerName)
- tfm.exec.respawnPlayer(playerName)
- tfm.exec.chatMessage("<J>Bem vindo ao module Corrida de Perguntas! Digite !help para mais informações.", playerName)
- end
- eventNewGame = function()
- for playerName in next, tfm.get.room.playerList do
- setPlayerData(playerName)
- end
- displayStageNames()
- startChooseFlow()
- end
- eventLoop = function(currentTime, remainingTime)
- if initModuleTimer > 0 then
- initModuleTimer = initModuleTimer - 500
- return
- end
- if chooseShaman then
- if remainingTime > 0 then return end
- chooseShaman = false
- newShaman = getNewShaman()
- nextShaman = nil
- tfm.exec.killPlayer(newShaman)
- tfm.exec.chatMessage("<J>Você é o shaman! Digite <B>!q</B> para fazer a pergunta", newShaman)
- resetAllScores()
- resetAllPlayerData()
- ui.setShamanName(newShaman)
- tfm.exec.chatMessage("<CEP>".. newShaman .. " estará fazendo as perguntas agora")
- tfm.exec.setGameTime(60)
- else
- if remainingTime <= 0 then
- startChooseFlow()
- end
- end
- end
- eventChatCommand = function(playerName, command)
- if chooseShaman then return end
- if playerName == newShaman then
- if command == 'q' then
- ui.addPopup(0, 2, "Digite sua pergunta", newShaman, 200, 170, 400, true)
- elseif command == "skip" then
- tfm.exec.chatMessage("<R>".. playerName .. " pulou a vez")
- startChooseFlow()
- return
- end
- end
- if command == "help" then
- tfm.exec.chatMessage("<CEP>O minigame consiste em um Shaman que irá realizar perguntas para os demais jogadores responder. O primeiro jogador a acertar 5 perguntas ganha o jogo e se torna o próximo Shaman. Digite !q para fazer uma pergunta quando for sua vez de ser o Shaman.", playerName)
- elseif command == "skip" then
- if playerData[playerName].hasSkipped then return end
- playerData[playerName].hasSkipped = true
- local half = math.ceil(tfm.get.room.uniquePlayers / 2)
- skip = skip + 1
- if skip >= half then
- tfm.exec.chatMessage("<R>".. newShaman .. " perdeu a vez")
- startChooseFlow()
- else
- tfm.exec.chatMessage("Skip", playerName)
- end
- end
- end
- eventPopupAnswer = function(id, playerName, answer)
- if chooseShaman then return end
- if playerName ~= newShaman then return end
- if id == 0 then -- Pergunta
- currentAnswer = nil
- currentQuestion = answer
- tfm.exec.chatMessage("Sua pergunta: " .. answer, playerName)
- ui.addPopup(1, 2, "Digite a resposta da sua pergunta", playerName, 200, 170, 400, true)
- elseif id == 1 then -- Resposta
- currentAnswer = string.lower(answer)
- displayQuestion()
- tfm.exec.setGameTime(60)
- tfm.exec.chatMessage("A resposta para sua pergunta: " .. currentAnswer, playerName)
- end
- end
- eventChatMessage = function(playerName, message)
- if chooseShaman then return end
- if message ~= currentAnswer then return end
- if playerName == newShaman then
- return startChooseFlow()
- end
- tfm.exec.chatMessage("<VP>".. playerName .. " acertou!")
- displayAnswer()
- currentAnswer = nil
- tfm.exec.movePlayer(playerName, 500 + playerData[playerName].currentStage * 200, 365)
- playerData[playerName].currentStage = playerData[playerName].currentStage + 1
- tfm.exec.setPlayerScore(playerName, 1, true)
- if playerData[playerName].currentStage == totalStages then
- nextShaman = playerName
- startChooseFlow(true)
- else
- tfm.exec.setGameTime(60)
- ui.removeTextArea(0)
- end
- end
- eventPlayerLeft = function(playerName)
- playerData[playerName] = nil
- if chooseShaman then return end
- if playerName ~= newShaman and playerName ~= nextShaman then return end
- startChooseFlow()
- end
- tfm.exec.disableAutoNewGame()
- tfm.exec.disableAutoShaman()
- tfm.exec.disableAfkDeath()
- tfm.exec.disableMortCommand()
- tfm.exec.disableAutoScore()
- system.disableChatCommandDisplay()
- tfm.exec.newGame('<C><P DS="m;45,365,65,365,85,365,105,365,125,365,145,365,165,365,185,365,205,365,225,365,245,365,265,365,285,365,305,365,325,365,345,365" L="1400" /><Z><S><S L="400" H="20" X="1390" Y="200" T="10" P=",,.3,,270,,," /><S L="400" X="10" H="20" Y="200" T="10" P=",,.3,,90,,," /><S L="400" X="390" H="20" Y="200" T="10" P=",,.3,,270,,," /><S L="400" H="20" X="400" Y="200" T="10" P=",,.3,,90,,," /><S L="400" H="20" X="590" Y="200" T="10" P=",,.3,,270,,," /><S L="400" X="790" H="20" Y="200" T="10" P=",,.3,,270,,," /><S L="400" H="20" X="990" Y="200" T="10" P=",,.3,,270,,," /><S L="400" X="1190" H="20" Y="200" T="10" P=",,.3,,270,,," /><S L="400" X="600" H="20" Y="200" T="10" P=",,.3,,90,,," /><S L="400" H="20" X="800" Y="200" T="10" P=",,.3,,90,,," /><S L="400" X="1000" H="20" Y="200" T="10" P=",,.3,,90,,," /><S L="400" H="20" X="1200" Y="200" T="10" P=",,.3,,90,,," /><S L="1400" X="700" H="20" Y="10" T="10" P=",,.3,,180,,," /><S L="1400" H="20" X="700" Y="390" T="10" P=",,.3,,,,," /></S><D /><O /></Z></C>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement