Advertisement
KananGamer

[TFM-LUA] Quiz

Apr 22nd, 2020
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.99 KB | None | 0 0
  1. local default_questions = {
  2.     {
  3.         title = 'O Transformice foi criado em que ano?',
  4.         answer = '2010',
  5.         options = {'2009', '2011', '2012'}
  6.     },
  7.     {
  8.         title = 'O transformice foi criado em 2010?',
  9.         answer = true
  10.     },
  11.     {
  12.         title = 'Biscoito ou Bolacha?',
  13.         answer = 'Biscoito',
  14.         options = {'Bolacha'}
  15.     },
  16.     {
  17.         title = 'Funcorps fazem parte da staff?',
  18.         answer = false
  19.     },
  20.     {
  21.         title = 'Feijão por cima do arroz, ou arroz por cima do feijão?',
  22.         answer = 'Feijão por cima do arroz',
  23.         options = {'Arroz por cima do feijão'}
  24.     },
  25. }
  26.  
  27. local commands = {
  28.     ['skip'] = {desc = 'Pule uma pergunta'},
  29.     ['say'] = {options = '[Mensagem]', desc = 'Envie uma mensagem customizada'}
  30. }
  31.  
  32. local map = '<C><P /><Z><S><S P="0,0,0.3,0.2,0,0,0,0" L="3000" o="0" X="422" c="4" Y="191" T="12" H="3000" /><S L="799" X="400" H="29" Y="387" T="6" P="0,0,0.3,0.2,0,0,0,0" /><S L="40" X="21" H="196" Y="275" T="6" P="0,0,0,0,0,0,0,0" /><S L="40" H="196" X="780" Y="275" T="6" P="0,0,0,0,0,0,0,0" /><S P="0,0,0,0,0,0,0,0" L="94" o="ffffff" H="20" Y="79" T="12" X="400" /><S L="94" o="ffffff" H="20" X="400" Y="29" T="12" P="0,0,0,0,0,0,0,0" /><S P="0,0,0,0,90,0,0,0" L="70" o="ffffff" X="363" H="20" Y="54" T="12" lua="1" /><S P="0,0,0,0,90,0,0,0" L="70" o="ffffff" H="20" lua="0" Y="54" T="12" X="437" /><S P="0,0,0,0,0,0,0,0" L="10" o="0" H="175" Y="89" T="12" X="36" /><S L="10" o="0" H="175" X="765" Y="89" T="12" P="0,0,0,0,0,0,0,0" /></S><D><DS Y="58" X="402" /></D><O /></Z></C>'
  33.  
  34. local command_list = ''
  35. local command_length = 0
  36. local questions = {}
  37. local skip = false
  38.  
  39. for i in next, commands do
  40.     system.disableChatCommandDisplay(i)
  41.  
  42.     command_length = command_length + 1
  43.     command_list = ('%s\n<J>!%s</J><BL>%s : %s</BL>'):format(command_list, i, commands[i].options and ' <V>'..commands[i].options..'</V>' or '', commands[i].desc)
  44. end
  45.  
  46. do
  47.     local _, nickname = pcall(nil)
  48.     owner = string.match(nickname, "(.-)%.")
  49. end
  50.  
  51. function split (t, s)
  52.     local a={}
  53.     for i in string.gmatch(t, "[^" .. (s or "%s") .. "]+") do
  54.         a[#a + 1] = i
  55.     end
  56.     return a
  57. end
  58.  
  59. -- table copy
  60. function copy(a,b)if type(a)~='table'then return a end;if b and b[a]then return b[a]end;local c=b or{}local d=setmetatable({},getmetatable(a))c[a]=d;for e,f in pairs(a)do d[copy(e,c)]=copy(f,c)end;return d end
  61.  
  62. -- Sleep
  63. do local a={}avl=function()local b={}for c,d in next,a do if not d[2]or d[2]<os.time()then if coroutine.status(d[1])=='dead'then b[#b+1]=c else local e,f=coroutine.resume(d[1])d[2]=f end end end;if b[1]then for c,d in next,b do a[d]=nil end end end;timer=function(g)local h=nil;a[#a+1]={coroutine.create(function()local i=function(j)coroutine.yield(os.time()+math.floor(j/500)*500)end;g(i)end),timeValue=nil}end end
  64.  
  65. eventLoop = avl
  66.  
  67. function resetQuestions()
  68.     questions = copy(default_questions)
  69. end
  70.  
  71. function generateGrounds(grounds, correct, options)
  72.     local new_options = {}
  73.     local correct_coords = {}
  74.  
  75.     for i = 1, grounds - 1 do
  76.         new_options[#new_options + 1] = table.remove(options, math.random(#options))
  77.     end
  78.    
  79.     new_options[#new_options + 1] = correct
  80.  
  81.     for i = 1, grounds do
  82.         local dif = 800/grounds
  83.         local x = i * dif
  84.         local answer = tostring(table.remove(new_options, math.random(#new_options)))
  85.         local textAreaX = x - (i == 1 and dif - 40 or dif) + 10
  86.         local textAreaY = 200
  87.         local textAreaWidth = (i == 1 and dif - 40 or i == grounds and dif - 30 or dif) - 20
  88.         local textAreaHeight = 170
  89.        
  90.         if answer == correct then
  91.             correct_coords = {x = textAreaX, y = textAreaY, width = textAreaWidth, height = textAreaHeight}
  92.         end
  93.  
  94.         ui.addTextArea(i, '<p align="center"><font size="30">' .. answer .. '</font></p>', nil, textAreaX, textAreaY, textAreaWidth, textAreaHeight, 0xFFFFFF, 0xFFFFFF, 0, false)
  95.        
  96.         if i ~= grounds then
  97.             tfm.exec.addPhysicObject(i + 2, x, 280, {type = 8, miceCollision = true, width = 10, height = 180})
  98.         end
  99.     end
  100.    
  101.     return correct_coords
  102. end
  103.  
  104. function checkPlayers(killed)
  105.     local alive = 0
  106.     local last
  107.    
  108.     for name, data in next, tfm.get.room.playerList do
  109.         if not data.isDead and not killed[name] then
  110.             alive = alive + 1
  111.             last = name
  112.         end
  113.     end
  114.    
  115.     return alive, last
  116. end
  117.  
  118. function showMessage(message)
  119.     ui.addTextArea(0, "<p align='center'><font size='30'>"..message.."</font></p>", nil, 50, 110, 700, 0, 1, 1, 0, true)
  120. end
  121.  
  122. function eventNewGame()
  123.     timer(function(sleep)
  124.         sleep(10000)
  125.  
  126.         -- Questions loop
  127.         while true do
  128.             skip = false
  129.             for name, data in next, tfm.get.room.playerList do
  130.                 tfm.exec.movePlayer(name, 400, 58)
  131.             end
  132.            
  133.             ui.removeTextArea(0)
  134.    
  135.             for i = 0, 7 do
  136.                 tfm.exec.removePhysicObject(i)
  137.             end
  138.  
  139.             if #questions == 0 then
  140.                 resetQuestions()
  141.             end
  142.  
  143.             local question = table.remove(questions, math.random(#questions))
  144.             local correct_coords = {}
  145.            
  146.             if type(question.answer) == 'boolean' then
  147.                 correct_coords = generateGrounds(2, question.answer and 'Sim' or 'Não', {not question.answer and 'Sim' or 'Não'})
  148.             else
  149.                 local houses = math.random(#question.options > 3 and 3 or #question.options) + 1
  150.                 correct_coords = generateGrounds(houses, question.answer, question.options)
  151.             end
  152.  
  153.             showMessage(question.title)
  154.  
  155.             for i = 1, 20 do
  156.                 if skip then break end
  157.                 sleep(500)
  158.             end
  159.            
  160.             local killed = {}
  161.            
  162.             if not skip then
  163.                 for name, data in next, tfm.get.room.playerList do
  164.                     if not data.isDead then
  165.                         if not (data.x >= correct_coords.x and data.x <= correct_coords.x + correct_coords.width and data.y >= correct_coords.y and data.y <= correct_coords.y + correct_coords.height) then
  166.                             tfm.exec.killPlayer(name)
  167.                             killed[name] = true
  168.                         end
  169.                     end
  170.                 end
  171.             end
  172.                
  173.             for i = 0, 4 do
  174.                 ui.removeTextArea(i)
  175.             end
  176.  
  177.             if not skip then
  178.                 local players, last = checkPlayers(killed)
  179.                 if players == 1 then
  180.                     tfm.exec.giveCheese(last)
  181.                     tfm.exec.playerVictory(last)
  182.                     showMessage("Parabéns, "..last.."!")
  183.                     break
  184.                 elseif players == 0 then
  185.                     showMessage("Não há vencedor(a)!")
  186.                     break
  187.                 end
  188.                
  189.                 sleep(5000)
  190.             end
  191.         end
  192.        
  193.         sleep(5000)
  194.         ui.removeTextArea(0)
  195.         tfm.exec.newGame(map)
  196.     end)
  197. end
  198.  
  199. function eventChatCommand(name, cmd)
  200.     local args = split(cmd, ' ')
  201.  
  202.     if name == owner then
  203.         if args[1] == 'say' and args[1] then
  204.             table.remove(args, 1)
  205.             local message = table.concat(args, ' ')
  206.  
  207.             tfm.exec.chatMessage(('<font color="#fe8446">[%s]</font> <J>%s</J>'):format(string.match(name, "(.-)#."), message))
  208.         elseif args[1] == 'skip' then
  209.             skip = true
  210.         end
  211.     end
  212. end
  213.  
  214. function eventNewPlayer(name)
  215.     if name == owner then
  216.         tfm.exec.chatMessage('<ROSE>Olá, <font color="#fe8446">'..string.match(name, "(.-)#.")..'</font>! Você tem disponível '..command_length..' comandos:</ROSE>'..command_list, name)
  217.     end
  218. end
  219.  
  220. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  221.  
  222. for index, value in next, {'AutoShaman', 'AutoNewGame', 'AutoTimeLeft', 'PhysicalConsumables', 'AfkDeath', 'DebugCommand', 'AutoScore'} do
  223.     tfm.exec['disable' .. value]()
  224. end
  225.  
  226. tfm.exec.newGame(map)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement