Advertisement
Soristl

Mini Game RBG

Oct 23rd, 2022 (edited)
1,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.56 KB | None | 0 0
  1. -- from https://www.lua.org/pil/11.4.html
  2. local List = {}
  3. function List.new ()
  4.     return {first = 0, last = -1}
  5. end
  6.  
  7. function List.pushleft (list, value)
  8.     local first = list.first - 1
  9.     list.first = first
  10.     list[first] = value
  11. end
  12.  
  13. function List.pushright (list, value)
  14.     local last = list.last + 1
  15.     list.last = last
  16.     list[last] = value
  17. end
  18.  
  19. function List.popleft (list)
  20.     local first = list.first
  21.     if first > list.last then
  22.         return nil
  23.     end
  24.     local value = list[first]
  25.     list[first] = nil        -- to allow garbage collection
  26.     list.first = first + 1
  27.     return value
  28. end
  29.  
  30. function List.popright (list)
  31.     local last = list.last
  32.     if list.first > last then
  33.         return nil
  34.     end
  35.     local value = list[last]
  36.     list[last] = nil         -- to allow garbage collection
  37.     list.last = last - 1
  38.     return value
  39. end
  40.  
  41. -- the lib
  42. local timerList = {}
  43. local timersPool = List.new()
  44.  
  45. function addTimer(callback, ms, loops, label, ...)
  46.     local id = List.popleft(timersPool)
  47.     if id then
  48.         local timer = timerList[id]
  49.         timer.callback = callback
  50.         timer.label = label
  51.         timer.arguments = {...}
  52.         timer.time = ms
  53.         timer.currentTime = 0
  54.         timer.currentLoop = 0
  55.         timer.loops = loops or 1
  56.         timer.isComplete = false
  57.         timer.isPaused = false
  58.         timer.isEnabled = true
  59.     else   
  60.         id = #timerList+1
  61.         timerList[id] = {
  62.         callback = callback,
  63.         label = label,
  64.         arguments = {...},
  65.         time = ms,
  66.         currentTime = 0,
  67.         currentLoop = 0,
  68.         loops = loops or 1,
  69.         isComplete = false,
  70.         isPaused = false,
  71.         isEnabled = true,
  72.     }
  73.     end
  74.     return id
  75. end
  76.  
  77. function getTimerId(label)
  78.     local found
  79.     for id = 1, #timerList do
  80.         local timer = timerList[id]
  81.         if timer.label == label then
  82.             found = id
  83.             break
  84.         end
  85.     end
  86.     return found
  87. end
  88.  
  89. function pauseTimer(id)
  90.     if type(id) == 'string' then
  91.         id = getTimerId(id)
  92.     end
  93.  
  94.     if timerList[id] and timerList[id].isEnabled then
  95.         timerList[id].isPaused = true
  96.         return true
  97.     end
  98.     return false
  99. end
  100.  
  101. function resumeTimer(id)
  102.     if type(id) == 'string' then
  103.         id = getTimerId(id)
  104.     end
  105.  
  106.     if timerList[id] and timerList[id].isPaused then
  107.         timerList[id].isPaused = false
  108.         return true
  109.     end
  110.     return false
  111. end
  112.  
  113. function removeTimer(id)
  114.     if type(id) == 'string' then
  115.         id = getTimerId(id)
  116.     end
  117.  
  118.     if timerList[id] and timerList[id].isEnabled then
  119.         timerList[id].isEnabled = false
  120.         List.pushright(timersPool, id)
  121.         return true
  122.     end
  123.     return false
  124. end
  125.  
  126. function clearTimers()
  127.     local timer
  128.     repeat
  129.         timer = List.popleft(timersPool)
  130.         if timer then
  131.             table.remove(timerList, timer)
  132.         end
  133.     until timer == nil
  134. end
  135.  
  136. function timersLoop()
  137.     for id = 1, #timerList do
  138.         local timer = timerList[id]
  139.         if timer.isEnabled and timer.isPaused == false then
  140.             if not timer.isComplete then
  141.                 timer.currentTime = timer.currentTime + 500
  142.                 if timer.currentTime >= timer.time then
  143.                     timer.currentTime = 0
  144.                     timer.currentLoop = timer.currentLoop + 1
  145.                     if timer.loops > 0 then
  146.                         if timer.currentLoop >= timer.loops then
  147.                             timer.isComplete = true
  148.                             if eventTimerComplete ~= nil then
  149.                                 eventTimerComplete(id, timer.label)
  150.                             end
  151.                             removeTimer(id)
  152.                         end
  153.                     end
  154.                     if timer.callback ~= nil then
  155.                         timer.callback(timer.currentLoop, table.unpack(timer.arguments))
  156.                     end
  157.                 end
  158.             end
  159.         end
  160.     end
  161. end
  162.  
  163. tfm.exec.disableAutoShaman(true)
  164. tfm.exec.disableAutoNewGame(true)
  165. tfm.exec.disableAutoScore (true)
  166. tfm.exec.disableAutoTimeLeft (true)
  167. tfm.exec.disablePhysicalConsumables (true)
  168. tfm.exec.disableAfkDeath (true)
  169. tfm.exec.setRoomMaxPlayers (16)
  170. system.disableChatCommandDisplay (nil, true)
  171. tfm.exec.disableMortCommand(true)
  172. tfm.exec.disableAllShamanSkills(true)
  173.  
  174. local admins = {
  175.     ["Refletz#6472"] = true,
  176.     ["Soristl1#0000"] = true,
  177.     ["Ipionle#0000"] = true,
  178.     ["Ccfoudre#0000"] = true,
  179.     ["Potinho1234#0000"] = true
  180. }
  181.  
  182. local shamanSpawner = {
  183.     [1] = {name = ''}
  184. }
  185.  
  186. local teamSurvive = {
  187.     [1] = {name = '', isLive = true},
  188.     [2] = {name = '', isLive = true},
  189.     [3] = {name = '', isLive = true},
  190.     [4] = {name = '', isLive = true},
  191.     [5] = {name = '', isLive = true}
  192. }
  193.  
  194. local initGame = os.time() + 15000
  195. local gameTime = os.time() + 30000
  196. local gameTimeEnd = os.time() + 5000
  197.  
  198. local maps = {
  199.     [1] = '<C><P /><Z><S><S H="10" L="10" X="463" c="3" Y="60" T="1" P="0,0,0,0.2,0,0,0,0" /><S H="10" L="10" X="564" c="3" Y="60" T="1" P="0,0,0,0.2,0,0,0,0" /><S H="10" L="10" X="513" c="3" Y="102" T="1" P="0,0,0,0.2,0,0,0,0" /><S H="10" L="10" X="460" c="3" Y="124" T="1" P="0,0,0,0.2,0,0,0,0" /><S H="10" L="10" X="564" c="3" Y="124" T="1" P="0,0,0,0.2,0,0,0,0" /><S H="84" L="10" o="324650" X="193" c="3" v="10000" Y="86" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="324650" X="268" c="3" v="10000" Y="86" T="12" H="84" /><S H="84" L="10" o="324650" X="230" c="3" v="10000" Y="49" T="12" P="0,0,0.3,0.2,90,0,0,0" /><S P="0,0,0.3,0.2,90,0,0,0" L="10" o="324650" X="230" c="3" v="10000" Y="123" T="12" H="84" /><S P="0,0,0.3,0,0,0,0,0" L="10" X="419" c="3" Y="169" T="19" H="53" /><S P="0,0,0,0.2,60,0,0,0" L="10" X="390" c="3" Y="206" T="1" H="60" /><S P="0,0,0,0.2,0,0,0,0" L="76" X="334" c="3" Y="224" T="1" H="10" /><S P="0,0,0,0.2,0,0,0,0" L="10" H="10" c="3" Y="170" T="1" X="511" /><S X="460" L="10" H="10" c="3" Y="200" T="1" P="0,0,0,0.2,0,0,0,0" /><S X="564" L="10" H="10" c="3" Y="201" T="1" P="0,0,0,0.2,0,0,0,0" /><S L="10" X="774" H="63" Y="376" T="3" P="0,0,0,20,50,0,0,0" /><S L="10" H="63" X="27" Y="380" T="3" P="0,0,0,20,-50,0,0,0" /><S P="0,0,0,0.2,0,0,0,0" L="10" X="309" c="3" Y="274" T="1" H="10" /><S P="0,0,0,0.2,0,0,0,0" L="10" X="385" c="3" Y="278" T="1" H="10" /><S P="0,0,0,0.2,0,0,0,0" L="10" X="461" c="3" Y="266" T="1" H="10" /><S P="0,0,0,0.2,0,0,0,0" L="10" X="515" c="3" Y="239" T="1" H="10" /><S H="10" L="10" X="253" c="3" Y="256" T="1" P="0,0,0,0.2,0,0,0,0" /></S><D><DS Y="105" X="461" /></D><O /></Z></C>'
  200. }
  201.  
  202. local playersJoined = {}
  203.  
  204. local mode = ""
  205.  
  206. local gameStats = {
  207.     msgWinner = '',
  208.     modePlayersSurviveSkills = true,
  209.     modePortals = false,
  210.     modeSurvive = false,
  211.     modeDefense = false,
  212.     modeThreeLifes = true
  213. }
  214.  
  215. local playerDirection = {}
  216. local playerActions = {}
  217. local playerLife = {}
  218. local playersOnPageCommands = {}
  219.  
  220. local x = {280, 460, 640, 280, 460}
  221. local y = {100, 100, 100, 160, 160}
  222.  
  223. for name, data in pairs(tfm.get.room.playerList) do
  224.     tfm.exec.setPlayerScore(name, 0, false)
  225.     playersJoined[name] = false
  226.     playerDirection[name] = 0
  227.     playerActions[name] = {canShoot = true, canAttachBallon = true}
  228.     playerLife[name] = 0
  229.     playersOnPageCommands[name] = false
  230. end
  231.  
  232. function ui.addWindow(id, text, player, x, y, width, height, alpha, corners, closeButton, buttonText)
  233.     id = tostring(id)
  234.     ui.addTextArea(id.."0", "", player, x+1, y+1, width-2, height-2, 0x8a583c, 0x8a583c, alpha, true)
  235.     ui.addTextArea(id.."00", "", player, x+3, y+3, width-6, height-6, 0x2b1f19, 0x2b1f19, alpha, true)
  236.     ui.addTextArea(id.."000", "", player, x+4, y+4, width-8, height-8, 0xc191c, 0xc191c, alpha, true)
  237.     ui.addTextArea(id.."0000", "", player, x+5, y+5, width-10, height-10, 0x2d5a61, 0x2d5a61, alpha, true)
  238.     ui.addTextArea(id.."00000", text, player, x+5, y+6, width-10, height-12, 0x142b2e, 0x142b2e, alpha, true)
  239.     local imageId = {}
  240.     if corners then
  241.         table.insert(imageId, tfm.exec.addImage("155cbe97a3f.png", "&1", x-7, (y+height)-22, player))
  242.         table.insert(imageId, tfm.exec.addImage("155cbe99c72.png", "&1", x-7, y-7, player))
  243.         table.insert(imageId, tfm.exec.addImage("155cbe9bc9b.png", "&1", (x+width)-20, (y+height)-22, player))
  244.         table.insert(imageId, tfm.exec.addImage("155cbea943a.png", "&1", (x+width)-20, y-7, player))
  245.     end
  246.     if closeButton then
  247.         ui.addTextArea(id.."000000", "", player, x+8, y+height-22, width-16, 13, 0x7a8d93, 0x7a8d93, alpha, true)
  248.         ui.addTextArea(id.."0000000", "", player, x+9, y+height-21, width-16, 13, 0xe1619, 0xe1619, alpha, true)
  249.         ui.addTextArea(id.."00000000", "", player, x+9, y+height-21, width-17, 12, 0x314e57, 0x314e57, alpha, true)
  250.         ui.addTextArea(id.."", buttonText, player, x+9, y+height-24, width-17, nil, 0x314e57, 0x314e57, 0, true)
  251.     end
  252.     return imageId
  253. end
  254.  
  255. function closeWindow(id, name)
  256.     local id = tostring(id)
  257.     local str = "0"
  258.     ui.removeTextArea(id, name)
  259.     for i = 1, 9 do
  260.         ui.removeTextArea(id..""..str.."", name)
  261.         str = ""..str.."0"
  262.     end
  263. end
  264.  
  265. function init()
  266.     mode = "startGame"
  267.     tfm.exec.disableAllShamanSkills(true)
  268.     for name, data in pairs(tfm.get.room.playerList) do
  269.         playersJoined[name] = false
  270.         playerDirection[name] = 0
  271.         playerActions[name] = {canShoot = true, canAttachBallon = true}
  272.         playerLife[name] = 0
  273.         for j = 0, 3 do
  274.             system.bindKeyboard(name, j, true, false)
  275.             system.bindKeyboard(name, j, false, false)
  276.         end
  277.         system.bindKeyboard(name, 32, false, false)
  278.     end
  279.  
  280.     tfm.exec.newGame('<C><P /><Z><S><S L="800" H="50" X="400" Y="385" T="6" P="0,0,0.3,0.2,0,0,0,0" /><S m="" L="10" H="404" X="2" Y="202" T="1" P="0,0,0,0.2,0,0,0,0" /><S m="" L="10" X="795" H="404" Y="203" T="1" P="0,0,0,0.2,0,0,0,0" /><S m="" L="10" H="800" X="396" Y="7" T="1" P="0,0,0,0.2,90,0,0,0" /></S><D><DS Y="349" X="400" /><P P="0,0" Y="359" T="6" X="217" /><P P="0,0" Y="363" T="4" X="580" /><P P="0,0" Y="360" T="5" X="319" /><P P="0,0" Y="0" T="257" X="0" /></D><O /></Z></C>')
  281.  
  282.     shamanSpawner = {
  283.         [1] = {name = ''}
  284.     }
  285.  
  286.     gameStats = {
  287.         msgWinner = '',
  288.         modePlayersSurviveSkills = true,
  289.         modePortals = false,
  290.         modeSurvive = false,
  291.         modeDefense = false,
  292.         modeThreeLifes = true
  293.     }
  294.  
  295.     teamSurvive = {
  296.         [1] = {name = '', isLive = true},
  297.         [2] = {name = '', isLive = true},
  298.         [3] = {name = '', isLive = true},
  299.         [4] = {name = '', isLive = true},
  300.         [5] = {name = '', isLive = true}
  301.     }
  302.     ui.addTextArea(6, "<p align='center'>", nil, 375, 50, 30, 20, 0x161616, 0x161616, 1, false)
  303.     ui.addTextArea(0, "<p align='center'><font size='14px'><a href='event:shamanSpawner'>Join", nil, 100, 100, 150, 40, 0xE14747, 0xE14747, 1, false)
  304.     for i = 1, 5 do
  305.         ui.addTextArea(i, "<p align='center'><font size='14px'><a href='event:joinTeam"..i.."'>Join", nil, x[i], y[i], 150, 40, 0x184F81, 0x184F81, 1, false)
  306.     end
  307.     initGame = os.time() + 15000
  308. end
  309.  
  310. function eventTextAreaCallback(id, name, c)
  311.     if c == "shamanSpawner" and not playersJoined[name] and shamanSpawner[1].name == '' then
  312.         shamanSpawner[1].name = name
  313.         playersJoined[name] = true
  314.         ui.addTextArea(0, "<p align='center'><font size='14px'><a href='event:shamanSpawnerLeave'>"..shamanSpawner[1].name.."", nil, 100, 100, 150, 40, 0x871F1F, 0x871F1F, 1, false)
  315.     elseif c == "shamanSpawnerLeave" and shamanSpawner[1].name == name then
  316.         shamanSpawner[1].name = ''
  317.         playersJoined[name] = false
  318.         ui.addTextArea(0, "<p align='center'><font size='14px'><a href='event:shamanSpawner'>Join", nil, 100, 100, 150, 40, 0xE14747, 0xE14747, 1, false)
  319.     elseif string.sub(c, 1, 8) == "joinTeam" and not playersJoined[name] and teamSurvive[tonumber(string.sub(c, 9))].name == ''  then
  320.         local index = tonumber(string.sub(c, 9))
  321.         teamSurvive[index].name = name
  322.         playersJoined[name] = true
  323.         ui.addTextArea(index, "<p align='center'><font size='14px'><a href='event:leaveTeam"..index.."'>"..name.."", nil, x[index], y[index], 150, 40, 0x0B3356, 0x0B3356, 1, false)
  324.     elseif string.sub(c, 1, 9) == "leaveTeam" and teamSurvive[tonumber(string.sub(c, 10))].name == name then
  325.         local index = tonumber(string.sub(c, 10))
  326.         playersJoined[name] = false
  327.         teamSurvive[index].name = ''
  328.         ui.addTextArea(index, "<p align='center'><font size='14px'><a href='event:joinTeam"..index.."'>Join", nil, x[index], y[index], 150, 40, 0x184F81, 0x184F81, 1, false)
  329.     elseif c == "closeInterfaceListCommands" then
  330.         closeWindow(22, name)
  331.         for i = 19994, 19997 do
  332.             ui.removeTextArea(i, name)
  333.         end
  334.         playersOnPageCommands[name] = false
  335.     end
  336.     if admins[name] then
  337.         if c == "mode1" then
  338.             if gameStats.modePlayersSurviveSkills then
  339.                 gameStats.modePlayersSurviveSkills = false
  340.                 reloadInterfaceListCommands()
  341.                 return
  342.             end
  343.             gameStats.modePlayersSurviveSkills = true
  344.             reloadInterfaceListCommands()
  345.         elseif c == "mode2" then
  346.             if gameStats.modePortals then
  347.                 gameStats.modePortals = false
  348.                 reloadInterfaceListCommands()
  349.                 return
  350.             end
  351.             gameStats.modePortals = true
  352.             reloadInterfaceListCommands()
  353.         elseif c == "mode3" then
  354.             if gameStats.modeSurvive then
  355.                 gameStats.modeSurvive = false
  356.                 reloadInterfaceListCommands()
  357.                 return
  358.             end
  359.             gameStats.modeSurvive = true
  360.             reloadInterfaceListCommands()
  361.         elseif c == "mode4" then
  362.             if gameStats.modeDefense then
  363.                 gameStats.modeDefense = false
  364.                 reloadInterfaceListCommands()
  365.                 return
  366.             end
  367.             gameStats.modeDefense = true
  368.             reloadInterfaceListCommands()
  369.         elseif c == "mode5" then
  370.             if gameStats.modeThreeLifes then
  371.                 gameStats.modeThreeLifes = false
  372.                 reloadInterfaceListCommands()
  373.                 return
  374.             end
  375.             gameStats.modeThreeLifes = true
  376.             reloadInterfaceListCommands()
  377.         end
  378.     end
  379. end
  380.  
  381. function reloadInterfaceListCommands()
  382.     for name, data in pairs(tfm.get.room.playerList) do
  383.         if playersOnPageCommands[name] then
  384.             interfaceListCommands(name)
  385.         end
  386.     end
  387. end
  388.  
  389. function interfaceListCommands(name)
  390.     ui.addWindow(22, "<p align='center'>Lista de comandos", name, 125, 60, 650, 300, 1, false, true, "<p align='center'><a href='event:closeInterfaceListCommands'>Fechar</a>")
  391.     ui.addTextArea(19994, "Habilidades para o rato<br>Modo de portais<br>Modo sobrevivência<br>", name, 140, 90, 200, 220, 0xc191c, 0xc191c, 1, true)
  392.     ui.addTextArea(19995, ""..verifyIsModeEnable(gameStats.modePlayersSurviveSkills, 'mode1').."<br>"..verifyIsModeEnable(gameStats.modePortals, 'mode2').."<br>"..verifyIsModeEnable(gameStats.modeSurvive, 'mode3').."", name, 360, 90, 50, 220, 0xc191c, 0xc191c, 1, true)
  393.     ui.addTextArea(19996, "Modo de defesa<br>Modo de três vidas", name, 480, 90, 200, 220, 0xc191c, 0xc191c, 1, true)
  394.     ui.addTextArea(19997, ""..verifyIsModeEnable(gameStats.modeDefense , 'mode4').."<br>"..verifyIsModeEnable(gameStats.modeThreeLifes, 'mode5').."", name, 700, 90, 50, 220, 0xc191c, 0xc191c, 1, true)
  395.     playersOnPageCommands[name] = true
  396. end
  397.  
  398. function verifyIsModeEnable(mode, callback)
  399.     if mode then
  400.         return "<vp><a href='event:"..callback.."'>[ Sim ]</a><n>"
  401.     end
  402.     return "<r><a href='event:"..callback.."'>[ Não ]</a><n>"
  403. end
  404.  
  405. function eventLoop(elapsedTime, remainingTime)
  406.     if mode == "startGame" then
  407.         local x = math.ceil((initGame - os.time())/1000)
  408.         local c = string.format("%d", x)
  409.         ui.addTextArea(6, "<p align='center'>"..c.."", nil, 375, 50, 30, 20, 0x161616, 0x161616, 1, false)
  410.         if x == 0 then
  411.             local playersOnGame = quantityPlayers()
  412.  
  413.             if playersOnGame.shaman == 1 and playersOnGame.players >= 1 then
  414.                 mode = "gameStart"
  415.                 startGame()
  416.             else
  417.                 initGame = os.time() + 15000
  418.             end
  419.         end
  420.         elseif mode == "gameStart" then
  421.             local x = math.ceil((gameTime - os.time())/1000)
  422.             local c = string.format("%d", x)
  423.             ui.addTextArea(6, "<p align='center'>"..c.."", nil, 375, 380, 30, 20, 0x161616, 0x161616, 1, false)
  424.             if x == 0 then
  425.                 local playersOnGame = quantityPlayers()
  426.                 if playersOnGame.players == 0 then
  427.                     gameStats.msgWinner = "O totem do shaman venceu!"
  428.                     tfm.exec.setPlayerScore(shamanSpawner[1].name, 10, true)
  429.                 else
  430.                     gameStats.msgWinner = "Os sobreviventes venceram!"
  431.                     for i = 1, 5 do
  432.                         if teamSurvive[i].name ~= '' then
  433.                             tfm.exec.setPlayerScore(teamSurvive[i].name, 10, true)
  434.                         end
  435.                     end
  436.                 end
  437.                 gameTimeEnd = os.time() + 5000
  438.                 mode = "gameEnd"
  439.             end
  440.         elseif mode == "gameEnd" then
  441.             local x = math.ceil((gameTimeEnd - os.time())/1000)
  442.             local c = string.format("%d", x)
  443.             ui.addTextArea(6, "<p align='center'><font size='30px'><textformat leading='150'><br>"..gameStats.msgWinner.."", nil, 0, 0, 800, 400, 0x161616, 0x161616, 0.8, true)
  444.             if x == 0 then
  445.                 removeTimer('mode_portals')
  446.                 removeTimer('mode_survive')
  447.                 init()
  448.             end
  449.     end
  450.     timersLoop()
  451. end
  452.  
  453. function eventChatCommand(name, c)
  454.     if admins[name] then
  455.         if c == "rr" and mode == "gameStart" then
  456.             gameTime = os.time() + 5000
  457.         elseif c == "resettimer" then
  458.             initGame = os.time() + 15000
  459.         elseif c == "test" then
  460.             shamanSpawner[1].name = 'asdasd'
  461.         elseif c == "cmds" then
  462.             interfaceListCommands(name)
  463.         end
  464.     end
  465. end
  466.  
  467. function startGame()
  468.     tfm.exec.newGame(maps[1])
  469.     for name, data in pairs(tfm.get.room.playerList) do
  470.         if not playersJoined[name] then
  471.             tfm.exec.killPlayer(name)
  472.         end
  473.     end
  474.     removeTextAreasOfLobby()
  475.     teleportPlayers()
  476.     killShaman()
  477.     addBonus()
  478.     PlayersSurviveSkills()
  479.     modePortals()
  480.     modeSurvive()
  481.     modeDefense()
  482.     gameTime = os.time() + 30000
  483.     modeThreeLifes()
  484. end
  485.  
  486. function modeThreeLifes()
  487.     if gameStats.modeThreeLifes then
  488.         gameTime = os.time() + 5 * 60000 -- 5 minutes
  489.         for i = 1, 5 do
  490.             if teamSurvive[i].name ~= '' then
  491.                 playerLife[teamSurvive[i].name] = 2
  492.             end
  493.         end
  494.     end
  495. end
  496.  
  497. function modePortals()
  498.     if gameStats.modePortals then
  499.         mode_portals = addTimer(function(i)
  500.             local portals_spawn_x = {461, 461, 513, 563, 563, 514, 588, 384, 355}
  501.             local portals_spawn_y = {105, 40, 81, 105, 40, 216, 269, 256, 204}
  502.             local portal_orange = math.random(1, #portals_spawn_x)
  503.             local portal_blue = math.random(1, #portals_spawn_x)
  504.             local portal_orange_id = tfm.exec.addShamanObject(27, portals_spawn_x[portal_orange], portals_spawn_y[portal_orange], 0, 0, 0, true)
  505.             local portal_blue_id = tfm.exec.addShamanObject(26, portals_spawn_x[portal_blue], portals_spawn_y[portal_blue], 0, 0, 0, true)
  506.             if i == 5 then
  507.                 tfm.exec.removeObject(portal_orange_id)
  508.                 tfm.exec.removeObject(portal_blue_id)
  509.             end
  510.         end, 5000, 5, "mode_portals")
  511.     end
  512. end
  513.  
  514. function modeSurvive()
  515.     if gameStats.modeSurvive then
  516.         mode_survive = addTimer(function(i)
  517.             local spawn_x = {461, 461, 513, 563, 563, 514, 588, 384, 355}
  518.             local spawn_y = {105, 40, 81, 105, 40, 216, 269, 256, 204}
  519.             local randomIndex = math.random(1, #spawn_x)
  520.             tfm.exec.addBonus(2, spawn_x[randomIndex], spawn_y[randomIndex], math.random(), 0, true, nil)
  521.         end, 5000, 5, "mode_survive")
  522.     end
  523. end
  524.  
  525. function modeDefense()
  526.     if gameStats.modeDefense then
  527.         tfm.exec.addPhysicObject(1, 431, 161, {
  528.             type = 8,
  529.             width = 10,
  530.             height = 620,
  531.             miceCollision = false,
  532.             groundCollision = true
  533.         })
  534.         mode_defense = addTimer(function(i)
  535.             tfm.exec.removePhysicObject(1)
  536.         end, 7000, 1, "mode_defense")
  537.     end
  538. end
  539.  
  540. function PlayersSurviveSkills()
  541.     if gameStats.modePlayersSurviveSkills then
  542.         for i = 1, 5 do
  543.             if teamSurvive[i].name ~= '' then
  544.                 for j = 0, 3 do
  545.                     system.bindKeyboard(teamSurvive[i].name, j, true, true)
  546.                     system.bindKeyboard(teamSurvive[i].name, j, false, true)
  547.                 end
  548.                 system.bindKeyboard(teamSurvive[i].name, 32, true, true)
  549.                 system.bindKeyboard(teamSurvive[i].name, 32, false, true)
  550.             end
  551.         end
  552.     end
  553. end
  554.  
  555. function eventKeyboard(name, key, down, x, y, xPlayerVelocity, yPlayerVelocity)
  556.     if key >= 0 and key <= 3 then
  557.         tfm.get.room.playerList[name].x = x
  558.         tfm.get.room.playerList[name].y = y
  559.         if key == 0 or key == 2 then
  560.             playerDirection[name] = key
  561.         elseif key == 3 and playersJoined[name] and playerActions[name].canShoot then
  562.             playerActions[name].canShoot = false
  563.             local xVelocity = 0
  564.             local xPlayer = 0
  565.             if playerDirection[name] == 0 then
  566.                 xVelocity = -170
  567.                 xPlayer = -2
  568.             elseif playerDirection[name] == 2 then
  569.                 xVelocity = 170
  570.                 xPlayer = 2
  571.             end
  572.             local cannonId = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, false)
  573.             tfm.exec.moveObject(cannonId, x - xPlayer, y+8, false, xVelocity, -10, false, 0, false)
  574.             cannonShoot = addTimer(function(i)
  575.                 if i == 1 then
  576.                     tfm.exec.removeObject(cannonId)
  577.                 end
  578.             end, 3000, 1, "cannonShoot")
  579.         end
  580.     elseif key == 32 and playersJoined[name] and playerActions[name].canAttachBallon then
  581.         playerActions[name].canAttachBallon = false
  582.         local ballonId = tfm.exec.attachBalloon(name, true, 1, true, 1)
  583.         AttachBallon = addTimer(function(i)
  584.             if i == 1 then
  585.                 tfm.exec.removeObject(ballonId)
  586.             end
  587.         end, 10000, 1, "AttachBallon")
  588.     end
  589. end
  590.  
  591. function teleportPlayers()
  592.     local coordinateSpawnSurvives = {
  593.         x = {461, 461, 513, 563, 563},
  594.         y = {105, 40, 81, 105, 40}
  595.     }
  596.  
  597.     local coordinateSpawnShaman = {x = 230, y = 90}
  598.  
  599.     tfm.exec.movePlayer(shamanSpawner[1].name, coordinateSpawnShaman.x, coordinateSpawnShaman.y)
  600.     tfm.exec.setShaman(shamanSpawner[1].name, true)
  601.  
  602.     for i = 1, 5 do
  603.         local randomIndex = math.random(1, 5)
  604.         tfm.exec.movePlayer(teamSurvive[i].name, coordinateSpawnSurvives.x[randomIndex], coordinateSpawnSurvives.y[randomIndex])
  605.     end
  606.  
  607. end
  608.  
  609. function quantityPlayers()
  610.     local quantity = {shaman = 0, players = 0}
  611.     if shamanSpawner[1].name ~= '' then
  612.         quantity.shaman = 1
  613.     end
  614.     for i = 1, 5 do
  615.         if teamSurvive[i].name ~= '' then
  616.             quantity.players = quantity.players + 1
  617.         end
  618.     end
  619.  
  620.     return quantity
  621. end
  622.  
  623. function removeTextAreasOfLobby()
  624.     for i = 0, 6 do
  625.         ui.removeTextArea(i)
  626.     end
  627. end
  628.  
  629. function killShaman()
  630.     tfm.exec.disableAllShamanSkills(false)
  631.     kill_Shaman = addTimer(function(i)
  632.         if i == 1 then
  633.             tfm.exec.killPlayer(shamanSpawner[1].name)
  634.             tfm.exec.disableAllShamanSkills(true)
  635.         end
  636.     end, 10000, 1, "kill_Shaman")
  637. end
  638.  
  639. function addBonus()
  640.     local x = {254, 422, 539}
  641.     for i = 1, 3 do
  642.         tfm.exec.addBonus(3, x[i], 331, i, 0, true, nil)
  643.     end
  644. end
  645.  
  646. function eventNewPlayer(name)
  647.     tfm.exec.setPlayerScore(name, 0, false)
  648.     tfm.exec.respawnPlayer(name)
  649.     playersJoined[name] = false
  650.     playersOnPageCommands[name] = false
  651.     playerDirection[name] = 0
  652.     playerLife[name] = 0
  653.     playerActions[name] = {canShoot = true, canAttachBallon = true}
  654.     if mode == "startGame" then
  655.         if shamanSpawner[1].name == '' then
  656.             ui.addTextArea(0, "<p align='center'><font size='14px'><a href='event:shamanSpawner'>Join", nil, 100, 100, 150, 40, 0xE14747, 0xE14747, 1, false)
  657.         else
  658.             ui.addTextArea(0, "<p align='center'><font size='14px'><a href='event:shamanSpawnerLeave'>"..shamanSpawner[1].name.."", nil, 100, 100, 150, 40, 0x871F1F, 0x871F1F, 1, false)
  659.         end
  660.         for i = 1, 5 do
  661.             if teamSurvive[i].name == '' then
  662.                 ui.addTextArea(i, "<p align='center'><font size='14px'><a href='event:joinTeam"..i.."'>Join", nil, x[i], y[i], 150, 40, 0x184F81, 0x184F81, 1, false)
  663.             else
  664.                 ui.addTextArea(i, "<p align='center'><font size='14px'><a href='event:leaveTeam"..i.."'>"..teamSurvive[i].name.."", nil, x[i], y[i], 150, 40, 0x0B3356, 0x0B3356, 1, false)
  665.             end
  666.         end
  667.     end
  668. end
  669.  
  670. function eventPlayerLeft(name)
  671.     if mode == "startGame" then
  672.         for i = 1, 5 do
  673.             if teamSurvive[i].name == name then
  674.                 teamSurvive[i].name = ''
  675.                 ui.addTextArea(i, "<p align='center'><font size='14px'><a href='event:joinTeam"..i.."'>Join", nil, x[i], y[i], 150, 40, 0x184F81, 0x184F81, 1, false)
  676.             end
  677.             if shamanSpawner[1].name == name then
  678.                 ui.addTextArea(0, "<p align='center'><font size='14px'><a href='event:shamanSpawner'>Join", nil, 100, 100, 150, 40, 0xE14747, 0xE14747, 1, false)
  679.             end
  680.         end
  681.     end
  682.     if mode ~= "startGame" then
  683.         for i = 1, 5 do
  684.             if teamSurvive[i].name == name then
  685.                 teamSurvive[i].name = ''
  686.             end
  687.         end
  688.         verifyQuantityPlayers()
  689.     end
  690. end
  691.  
  692. function eventPlayerDied(name)
  693.     if mode == "gameStart" then
  694.         if gameStats.modeThreeLifes then
  695.             if playerLife[name] == 0 then
  696.                 for i = 1, 5 do
  697.                     if teamSurvive[i].name == name then
  698.                         teamSurvive[i].name = ''
  699.                     end
  700.                 end
  701.             else
  702.                 playerLife[name] = playerLife[name] - 1
  703.                 respawnPlayer = addTimer(function(i)
  704.                     if i == 1 then
  705.                         tfm.exec.respawnPlayer(name)
  706.                         local coordinateSpawnSurvives = {
  707.                             x = {461, 461, 513, 563, 563},
  708.                             y = {105, 40, 81, 105, 40}
  709.                         }
  710.                         local randomIndex = math.random(1, 5)
  711.                         tfm.exec.movePlayer(name, coordinateSpawnSurvives.x[randomIndex], coordinateSpawnSurvives.y[randomIndex])
  712.                         if gameStats.modePlayersSurviveSkills then
  713.                             playerActions[name] = {canShoot = true, canAttachBallon = true}
  714.                         end
  715.                     end
  716.                 end, 3000, 1, "respawnPlayer")
  717.             end
  718.         else
  719.             for i = 1, 5 do
  720.                 if teamSurvive[i].name == name then
  721.                     teamSurvive[i].name = ''
  722.                 end
  723.             end
  724.         end
  725.        
  726.         verifyQuantityPlayers()
  727.     end
  728. end
  729.  
  730. function verifyQuantityPlayers()
  731.     local playersOnGame = quantityPlayers()
  732.  
  733.     if playersOnGame.players == 0 then
  734.         gameStats.msgWinner = "O totem do shaman venceu!"
  735.         gameTimeEnd = os.time() + 5000
  736.         tfm.exec.setPlayerScore(shamanSpawner[1].name, 10, true)
  737.         mode = "gameEnd"
  738.     end
  739. end
  740.  
  741. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement