KananGamer

[TFM-LUA] O chão é água

Dec 23rd, 2020 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.51 KB | None | 0 0
  1. --[[
  2.     Criador: Nettoork#0000
  3.     Versão: 1.1 [23/12/2020]
  4.     Descrição: Esse script é uma paródia do "Chão é lava".
  5. ]]--
  6.  
  7. -- Variáveis modificáveis
  8. local admins = {} -- Não é necessário por seu nickname, apenas de outras pessoas
  9. local maps = {7214563, 7792590}
  10. local objects = {1, 2, 3, 4, 6, 7, 10, 39, 59, 60, 62, 68}
  11.  
  12. local translations = {
  13.     ["br"] = {
  14.         ["adminWelcome"] = "<CH>Seja bem-vindo(a) ao <font color='#2CC5D9'><B>O chão é água</B></font>! Utilize !help para ver seus comandos de administrador.</CH>",
  15.         ["welcome"] = "<CH>Seja bem-vindo(a) ao <font color='#2CC5D9'><B>O chão é água</B></font>! Cuidado para não afundar ;)</CH>",
  16.         ["startMinigame"] = "Inicie o minigame",
  17.         ["stopMinigame"] = "Pare o minigame",
  18.         ["avaliableCommands"] = "<ROSE>Você tem disponível %d comando(s):</ROSE>",
  19.         ["starting"] = "<VP>O minigame foi iniciado.</VP>",
  20.         ["stoping"] = "<VP>O minigame foi parado.</VP>",
  21.         ["playerWon"] = "%s\n\n\n<font size='50' color='#FFFF00'>%s venceu!</font>",
  22.         ["nobodyWon"] = "<font size='50' color='#FFFF00'>Ninguém venceu!</font>",
  23.         ["gameName"] = "<p align='center'><font size='50' color='#2FDDF9'>O CHÃO É ÁGUA</font></p>",
  24.         ["nextMap"] = "Avançar para o próximo mapa"
  25.     }
  26. }
  27.  
  28. -- Não mexa a partir daqui
  29. do
  30.     local _, nickname = pcall(nil)
  31.     table.insert(admins, string.match(nickname, "(.-)%."))
  32. end
  33.  
  34. local game = {
  35.     mapDelay = 0,
  36.     mapCache = {},
  37.     needNext = false,
  38.     isEnding = false,
  39.     language = translations[tfm.get.room.community] and tfm.get.room.community or "br",
  40.     timer = os.time(),
  41.     stage = 1,
  42.     isEnding = false,
  43.     canPlay = false,
  44.     spawned = false,
  45.     time = 60,
  46.     objects = {}
  47. }
  48.  
  49. local tableStringToTable = function(tableC)
  50.     local finalTable = {}
  51.     for i, v in next, tableC do
  52.         finalTable[v] = true
  53.     end
  54.     return finalTable
  55. end
  56.  
  57. local split = function(t, s)
  58.     local a={}
  59.     for i in string.gmatch(t, "[^" .. (s or "%s") .. "]+") do
  60.         a[#a + 1] = i
  61.     end
  62.     return a
  63. end
  64.  
  65. admins = tableStringToTable(admins)
  66.  
  67. function getMessage(message, ...)
  68.     return translations[game.language][message] and translations[game.language][message]:format(...) or "Message not found"
  69. end
  70.  
  71. local commands, command_list, command_length = {
  72.     ["start"] = {desc = getMessage("startMinigame")},
  73.     ["stop"] = {desc = getMessage("stopMinigame")},
  74.     ["next"] = {desc = getMessage("nextMap")}
  75. }, '', 0
  76.  
  77. for i in next, commands do
  78.     system.disableChatCommandDisplay(i)
  79.  
  80.     command_length = command_length + 1
  81.     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 and ': '..commands[i].desc or '')
  82. end
  83.  
  84. function spawnObjects()
  85.     for i = 1, math.ceil((game.time / 10 > 1 and game.time / 10 or 1))  do
  86.         local object = objects[math.random(1, #objects)]
  87.         game.objects[#game.objects + 1] = tfm.exec.addShamanObject(object, math.random(100, 1500), 360, object == 62 and object or 0, 0, 0, object == 62)
  88.     end
  89. end
  90.  
  91. function removeObjects()
  92.     for i, v in next, game.objects do
  93.         tfm.exec.removeObject(v)
  94.     end
  95.  
  96.     game.objects = {}
  97. end
  98.  
  99. function nextMap()
  100.     if game.mapDelay and os.time() < game.mapDelay then
  101.         game.needNext = true
  102.     else
  103.         game.needNext = false
  104.         game.mapDelay = os.time() + 3500
  105.  
  106.         if game.nextMap then
  107.             tfm.exec.newGame(game.nextMap)
  108.             game.nextMap = false
  109.         else
  110.             if #game.mapCache == 0 then
  111.                 for index, map in next, maps do
  112.                     game.mapCache[#game.mapCache + 1] = map
  113.                 end
  114.             end
  115.  
  116.             tfm.exec.newGame(table.remove(game.mapCache, math.random(#game.mapCache)), math.random(1, 5) == 1 and true or false)
  117.         end
  118.     end
  119. end
  120.  
  121. function showMessage(message)
  122.     ui.addTextArea(1, "<p align='center'>"..message.."</p>", nil, 5, 125, 790, 0, 0, 0, 0, true)
  123. end
  124.  
  125. function checkPlayers()
  126.     if game.canPlay then
  127.         local alive = 0
  128.  
  129.         for name, data in next, tfm.get.room.playerList do
  130.             if not data.isDead then
  131.                 alive = alive + 1
  132.             end
  133.         end
  134.  
  135.         if alive <= 1 then
  136.             if alive <= 0 then
  137.                 showMessage(getMessage("nobodyWon"))
  138.             else
  139.                 for name, data in next, tfm.get.room.playerList do
  140.                     if not data.isDead then
  141.                         tfm.exec.giveCheese(name, true)
  142.                         tfm.exec.playerVictory(name)
  143.                         showMessage(getMessage("playerWon", getMessage("gameName"), name))
  144.                         break
  145.                     end
  146.                 end
  147.             end
  148.  
  149.             game.stage = 100
  150.             game.timer = os.time()
  151.         end
  152.     end
  153. end
  154.  
  155. function setGround(name)
  156.     if name == "dirt" then
  157.         tfm.exec.addPhysicObject(1, 800, 387, {type = 6, width = 1600, height = 37, foreground = false, friction = 0.3, restitution = 0.2, angle = 0, miceCollision = true, groundCollision = true})
  158.     elseif name == "water" then
  159.         tfm.exec.addPhysicObject(1, 800, 387, {fixedRotation = true, dynamic = true, angularDamping = 99999, linearDamping = 99999, mass = 99999, type = 9, width = 1600, height = 37, foreground = false, friction = 0.3, restitution = 0.2, angle = 0, miceCollision = false, groundCollision = true})
  160.     end
  161. end
  162.  
  163. function eventLoop(t1, t2)
  164.     local timer = os.time() - game.timer
  165.     game.time = math.floor(t2/1000)
  166.  
  167.     if game.canPlay then
  168.         if t1 >= 35000 and t2 <= 36000 then
  169.             table.foreach(tfm.get.room.playerList, tfm.exec.giveMeep)
  170.         end
  171.  
  172.         if game.stage == 1 then
  173.             if timer > 2000 then
  174.                 game.stage = 2
  175.                 game.timer = os.time()
  176.             end
  177.         elseif game.stage == 2 then
  178.             local number = math.floor(timer/1000)
  179.             local maxTime = 10
  180.  
  181.             if maxTime - number <= 0 then
  182.                 game.stage = 3
  183.                 game.timer = os.time()
  184.                 ui.removeTextArea(1)
  185.                 setGround("water")
  186.                 showMessage(getMessage("gameName"))
  187.             else
  188.                 if maxTime - number == 4 and not game.spawned then
  189.                     game.spawned = true
  190.                     spawnObjects()
  191.                 end
  192.  
  193.                 ui.addTextArea(1, "<font size='90'><p align='center'>"..(maxTime - number).."</p></font>", nil, 5, 125, 790, 290, 1, 1, 0, true)
  194.             end
  195.         elseif game.stage == 3 then
  196.             if timer >= 4000 then
  197.                 setGround("dirt")
  198.                 ui.removeTextArea(1)
  199.                 game.spawned = false
  200.                 game.stage = 1
  201.                 game.timer = os.time()
  202.                 removeObjects()
  203.             end
  204.         elseif game.stage == 100 then
  205.             if timer >= 6000 then
  206.                 nextMap()
  207.             end
  208.         end
  209.     end
  210.  
  211.     if game.needNext then
  212.         nextMap()
  213.     end
  214. end
  215.  
  216. function eventChatCommand(name, command)
  217.     local arg = split(command, " ")
  218.  
  219.     if admins[name] then
  220.         if arg[1] == "start" and not game.canPlay then
  221.             tfm.exec.chatMessage(getMessage("starting"), name)
  222.             game.canPlay = true
  223.             nextMap()
  224.         elseif arg[1] == "stop" and game.canPlay then
  225.             tfm.exec.chatMessage(getMessage("stoping"), name)
  226.             game.canPlay = false
  227.             ui.removeTextArea(1)
  228.             nextMap()
  229.         elseif arg[1] == "help" then
  230.             tfm.exec.chatMessage(getMessage("avaliableCommands", command_length) .. command_list, name)
  231.         elseif arg[1] == "check" then
  232.             checkPlayers()
  233.         elseif arg[1] == "next" then
  234.             nextMap()
  235.         end
  236.     end
  237. end
  238.  
  239. function eventNewGame()
  240.     setGround("dirt")
  241.     ui.removeTextArea(1)
  242.  
  243.     tfm.exec.setGameTime(60)
  244.     game.stage = 1
  245.     game.timer = os.time()
  246.     game.time = 60
  247.     game.spawned = false
  248. end
  249.  
  250. function eventNewPlayer(name)
  251.     if admins[name] then
  252.         tfm.exec.chatMessage(getMessage("adminWelcome"), name)
  253.     else
  254.         tfm.exec.chatMessage(getMessage("welcome"), name)
  255.     end
  256. end
  257.  
  258. eventPlayerDied = checkPlayers
  259. eventPlayerLeft = checkPlayers
  260.  
  261. system.disableChatCommandDisplay();
  262.  
  263. for index, value in next, {'AutoShaman', 'AutoNewGame', 'AutoTimeLeft', 'AutoScore', 'PhysicalConsumables', 'DebugCommand', 'MinimalistMode'} do
  264.     tfm.exec['disable' .. value]()
  265. end
  266.  
  267. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  268. nextMap()
Add Comment
Please, Sign In to add comment