Advertisement
Bolodefchoco_LUAXML

#bolodefchoco0perguntas

Dec 26th, 2019
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.72 KB | None | 0 0
  1.     local initModuleTimer = 1000
  2.      
  3.     local playerData = { }
  4.      
  5.     local stageNames = { "I", "II", "III", "IV", "V" }
  6.     local totalStages = #stageNames
  7.      
  8.     local displayStageNames = function(playerName)
  9.         for i = 1, totalStages do
  10.             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)
  11.         end
  12.        
  13.         ui.setMapName("Perguntas")
  14.     end
  15.      
  16.     local setPlayerData = function(playerName)
  17.         playerData[playerName] = {
  18.             currentStage = 0,
  19.             hasSkipped = false
  20.         }
  21.        
  22.         tfm.exec.setPlayerScore(playerName, 0)
  23.     end
  24.      
  25.     local chooseShaman = true
  26.     local newShaman, nextShaman
  27.     local currentQuestion, currentAnswer
  28.     local skip = 0
  29.      
  30.     local getNewShaman = function()
  31.         if nextShaman and playerData[nextShaman] then
  32.             return nextShaman
  33.         end
  34.      
  35.         local scores, counter = { }, 0
  36.         local hasMoreThanZeroPoints = false
  37.        
  38.         local score
  39.         for playerName, data in next, playerData do
  40.             score = tfm.get.room.playerList[playerName].score
  41.        
  42.             counter = counter + 1
  43.             scores[counter] = {
  44.                 playerName = playerName,
  45.                 score = score
  46.             }
  47.            
  48.             if score > 0 then
  49.                 hasMoreThanZeroPoints = true
  50.             end
  51.         end
  52.        
  53.         if hasMoreThanZeroPoints then
  54.             table.sort(scores, function(p1, p2)
  55.                 return p1.score > p2.score
  56.             end)
  57.      
  58.             return scores[1].playerName
  59.         else
  60.             return scores[math.random(counter)].playerName
  61.         end
  62.     end
  63.      
  64.     local resetAllScores = function()
  65.         for playerName in next, tfm.get.room.playerList do
  66.             tfm.exec.setPlayerScore(playerName, 0)
  67.         end
  68.     end
  69.      
  70.     local moveAllToSpawnPoint = function()
  71.         for playerName in next, tfm.get.room.playerList do
  72.             tfm.exec.movePlayer(playerName, 125, 365)
  73.         end
  74.     end
  75.  
  76.     local displayAnswer = function()
  77.         if not currentAnswer then return end
  78.         tfm.exec.chatMessage("A resposta da pergunta era <B>" .. currentAnswer .. "</B>.")
  79.     end
  80.    
  81.     local startChooseFlow = function(ignoreAnswer)
  82.         if newShaman then
  83.             tfm.exec.respawnPlayer(newShaman)
  84.             newShaman = nil
  85.         end
  86.         if not ignoreAnswer then
  87.             displayAnswer()
  88.         end
  89.      
  90.         currentQuestion = nil
  91.         currentAnswer = nil
  92.         skip = 0
  93.         chooseShaman = true
  94.      
  95.         moveAllToSpawnPoint()
  96.      
  97.         ui.removeTextArea(0)
  98.         tfm.exec.setGameTime(5)
  99.         tfm.exec.chatMessage("Escolhendo Shaman...")
  100.     end
  101.      
  102.     local displayQuestion = function(playerName)
  103.         if not currentQuestion then return end
  104.         ui.addTextArea(0, "<p align='center'><font size='20'>" .. currentQuestion, playerName, 5, 50, 400, nil, nil, nil, .75, true)
  105.     end
  106.      
  107.     local resetAllPlayerData = function()
  108.         for playerName, data in next, playerData do
  109.             data.hasSkipped = false
  110.             data.currentStage = 0
  111.         end
  112.     end
  113.      
  114.     eventNewPlayer = function(playerName)
  115.         setPlayerData(playerName)
  116.         displayStageNames(playerName)
  117.        
  118.         displayQuestion(playerName)
  119.         tfm.exec.respawnPlayer(playerName)
  120.  
  121.         tfm.exec.chatMessage("<J>Bem vindo ao module Corrida de Perguntas! Digite !help para mais informações.", playerName)
  122.     end
  123.      
  124.     eventNewGame = function()
  125.         for playerName in next, tfm.get.room.playerList do
  126.             setPlayerData(playerName)
  127.         end
  128.         displayStageNames()
  129.      
  130.         startChooseFlow()
  131.     end
  132.      
  133.     eventLoop = function(currentTime, remainingTime)
  134.         if initModuleTimer > 0 then
  135.             initModuleTimer = initModuleTimer - 500
  136.             return
  137.         end
  138.      
  139.         if chooseShaman then
  140.             if remainingTime > 0 then return end
  141.             chooseShaman = false
  142.      
  143.             newShaman = getNewShaman()
  144.             nextShaman = nil
  145.            
  146.             tfm.exec.killPlayer(newShaman)
  147.             tfm.exec.chatMessage("<J>Você é o shaman! Digite <B>!q</B> para fazer a pergunta", newShaman)
  148.            
  149.             resetAllScores()
  150.             resetAllPlayerData()
  151.      
  152.             ui.setShamanName(newShaman)
  153.             tfm.exec.chatMessage("<CEP>".. newShaman .. " estará fazendo as perguntas agora")
  154.            
  155.             tfm.exec.setGameTime(60)
  156.         else
  157.             if remainingTime <= 0 then
  158.                 startChooseFlow()
  159.             end
  160.         end
  161.     end
  162.      
  163.     eventChatCommand = function(playerName, command)
  164.         if chooseShaman then return end
  165.      
  166.         if playerName == newShaman then
  167.             if command == 'q' then
  168.                 ui.addPopup(0, 2, "Digite sua pergunta", newShaman, 200, 170, 400, true)
  169.             elseif command == "skip" then
  170.                 tfm.exec.chatMessage("<R>".. playerName .. " pulou a vez")
  171.                 startChooseFlow()
  172.                 return
  173.             end
  174.         end
  175.         if command == "help" then
  176.             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)
  177.         elseif command == "skip" then
  178.             if playerData[playerName].hasSkipped then return end
  179.             playerData[playerName].hasSkipped = true
  180.      
  181.             local half = math.ceil(tfm.get.room.uniquePlayers / 2)
  182.            
  183.             skip = skip + 1
  184.             if skip >= half then
  185.                 tfm.exec.chatMessage("<R>".. newShaman .. " perdeu a vez")
  186.                 startChooseFlow()
  187.             else
  188.                 tfm.exec.chatMessage("Skip", playerName)
  189.             end
  190.         end
  191.     end
  192.      
  193.     eventPopupAnswer = function(id, playerName, answer)
  194.         if chooseShaman then return end
  195.         if playerName ~= newShaman then return end
  196.         if id == 0 then -- Pergunta
  197.             currentAnswer = nil
  198.             currentQuestion = answer
  199.      
  200.             tfm.exec.chatMessage("Sua pergunta: " .. answer, playerName)
  201.             ui.addPopup(1, 2, "Digite a resposta da sua pergunta", playerName, 200, 170, 400, true)
  202.         elseif id == 1 then -- Resposta
  203.             currentAnswer = string.lower(answer)
  204.            
  205.             displayQuestion()
  206.             tfm.exec.setGameTime(60)
  207.  
  208.             tfm.exec.chatMessage("A resposta para sua pergunta: " .. currentAnswer, playerName)
  209.         end
  210.     end
  211.      
  212.     eventChatMessage = function(playerName, message)
  213.         if chooseShaman then return end
  214.         if message ~= currentAnswer then return end
  215.         if playerName == newShaman then
  216.             return startChooseFlow()
  217.         end
  218.         tfm.exec.chatMessage("<VP>".. playerName .. " acertou!")
  219.         displayAnswer()
  220.  
  221.         currentAnswer = nil
  222.      
  223.         tfm.exec.movePlayer(playerName, 500 + playerData[playerName].currentStage * 200, 365)
  224.         playerData[playerName].currentStage = playerData[playerName].currentStage + 1
  225.        
  226.         tfm.exec.setPlayerScore(playerName, 1, true)
  227.        
  228.         if playerData[playerName].currentStage == totalStages then
  229.             nextShaman = playerName
  230.             startChooseFlow(true)
  231.         else
  232.             tfm.exec.setGameTime(60)
  233.             ui.removeTextArea(0)
  234.         end
  235.     end
  236.      
  237.     eventPlayerLeft = function(playerName)
  238.         playerData[playerName] = nil
  239.  
  240.         if chooseShaman then return end
  241.         if playerName ~= newShaman and playerName ~= nextShaman then return end
  242.  
  243.         startChooseFlow()
  244.     end
  245.  
  246.     tfm.exec.disableAutoNewGame()
  247.     tfm.exec.disableAutoShaman()
  248.     tfm.exec.disableAfkDeath()
  249.     tfm.exec.disableMortCommand()
  250.     tfm.exec.disableAutoScore()
  251.      
  252.     system.disableChatCommandDisplay()
  253.      
  254.     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