Advertisement
alditojeje

Torneo v1.0

Sep 21st, 2020 (edited)
1,630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.15 KB | None | 0 0
  1. --[[
  2.     FALTA
  3.     restart sin recargar lua    
  4.     poder cambiar la cantidad de tiempo y mapas en la interfaz y no en el codigo [Se puede desde el chat]
  5.  
  6. ▄▄▄█████▓█     █░▒█████     ▄▄▄█████▓█████▄▄▄      ███▄ ▄███▓ ██████
  7. ▓  ██▒ ▓▓█░ █ ░█▒██▒  ██▒   ▓  ██▒ ▓▓█   ▒████▄   ▓██▒▀█▀ ██▒██    ▒
  8. ▒ ▓██░ ▒▒█░ █ ░█▒██░  ██▒   ▒ ▓██░ ▒▒███ ▒██  ▀█▄ ▓██    ▓██░ ▓██▄  
  9. ░ ▓██▓ ░░█░ █ ░█▒██   ██░   ░ ▓██▓ ░▒▓█  ░██▄▄▄▄██▒██    ▒██  ▒   ██▒
  10.   ▒██▒ ░░░██▒██▓░ ████▓▒░     ▒██▒ ░░▒████▓█   ▓██▒██▒   ░██▒██████▒▒
  11.   ▒ ░░  ░ ▓░▒ ▒ ░ ▒░▒░▒░      ▒ ░░  ░░ ▒░ ▒▒   ▓▒█░ ▒░   ░  ▒ ▒▓▒ ▒ ░
  12.     ░     ▒ ░ ░   ░ ▒ ▒░        ░    ░ ░  ░▒   ▒▒ ░  ░      ░ ░▒  ░ ░
  13.   ░       ░   ░ ░ ░ ░ ▒       ░        ░   ░   ▒  ░      ░  ░  ░  ░  
  14.             ░       ░ ░                ░  ░    ░  ░      ░        ░  
  15.                 by Blood#3565 and Misterthepro#0000
  16.              version 1.0
  17.  
  18. ]]
  19.  
  20. --[[
  21.     Comandos:
  22.     !team1 [player] -- Establece los jugadores del equipo 1
  23.     !team2 [player] -- Establece los jugadores del equipo 2
  24.     !add team1 [player] -- Añade jugadores al equipo 1
  25.     !add team2 [player] -- Añade jugadores al equipo 2
  26.     !next o !n -- Cambia al siguiente mapa en el lobby
  27.     !timemap [segundos] o !maptime [segundos] o !tm [segundos] o !mt [segundos] -- Cambia en segundos el tiempo de cada mapa
  28.     !maps [cantidad] o !mapas [cantidad] o !m [cantidad] -- Cambia la cantidad total de mapas a jugar
  29.     !addtime [segundos] -- Añade segundos al mapa actual
  30.     !admin [jugador] -- Añade un nuevo admin
  31.     !unadmin [jugador] -- Elimina a un admin
  32.    
  33.  
  34.  
  35. ]]
  36.  
  37. local _, msg = pcall(nil)
  38. local admin = string.match(msg, "^(.-)%.")
  39.  
  40. --[[
  41. players = almacena la lista de jugadores de cada equipo
  42. points = los puntos de cada equipo
  43. countPlayers = la cantidad de jugadores de cada equipo
  44. ]] -- Variables más globales
  45. local admins = {
  46.     [admin] = true, -- Este pertenece a quien cargó el lua, no es necesario que lo cambies
  47.     ["Blood#3565"] = true,
  48.     ["Alditohacker#0000"] = true,
  49.     ["S_hippo#0000"] = true}
  50. local teams = {team1 = {players = {}, points = 0, countPlayers = 1, color = "<font color='#CB546B'>", totalPlayers = 0},
  51.                team2 = {players = {}, points = 0, countPlayers = 1, color = "<font color='#2F7FCC'>", totalPlayers = 0}}
  52. local playerInfo = {}
  53. local playerIn, index = "", 0 -- variable que se modifica para saber en que equipo está el jugador
  54. local mapTime = 180 -- tiempo de cada mapa bootcamp
  55. local autoJoin = "OFF"
  56. local watchingRecords = {} -- personas que tienen abierta la lista de records (Letra L)
  57. watchingRecords["always"] = true
  58. local maps = {'#3', '#3'}
  59. --local maps = {'7053913', '7053913'}
  60. local mapsPlayed, mapsToPlay = 0, 3 -- Mapas Jugados / Mapas por jugar
  61. local actualMap = 666666 -- código del mapa
  62. local os_time = os.time
  63. local stop = false
  64. local stopTime = 0
  65.  
  66. -- Colores
  67. local verde = "<font color='#00C17C'>"
  68. local morado = "<font color='#C53DFF'>"
  69.  
  70. -- Variables que se deberían resetear al iniciar un nuevo mapa:
  71. main = function()
  72.     toRespawn = {}
  73.     primerPuesto, segundoPuesto, tercerPuesto = false, false, false
  74.     times = {}
  75.     countTimes = 1
  76.     recordsString = "\n<textformat tabstops='[29, 205]'>"
  77.     putAmount()
  78. end
  79.  
  80. -- Variables que se deberían resetear al iniciar una nueva partida
  81. restart = function()
  82.       inGame = false
  83.       mapBc = true
  84.       bestTimes, countBestTimes = {}, 1
  85.       infoText = "<p align='center'><font color='#00C17C' size='15'><b>Pasando al siguiente mapa</b>"
  86. end
  87.  
  88. putAmount = function()
  89.     for name in next, playerInfo do --
  90.         playerInfo[name].totalAmount = playerInfo[name].totalAmount + playerInfo[name].amount
  91.         playerInfo[name].amount = 0
  92.         playerInfo[name].alreadyRespawn = false
  93.     end
  94. end
  95.  
  96. main()
  97. restart()
  98.  
  99. keys = function(name) -- activa las teclas necesarias
  100.     tfm.exec.bindKeyboard(name, 76, false, true) -- L
  101.     tfm.exec.bindKeyboard(name, 46, false, true) -- Supr
  102.     tfm.exec.bindKeyboard(name, 17, false, true) -- Ctrl
  103. end
  104.  
  105. tfm.exec.disableAutoScore()
  106. tfm.exec.disableAutoShaman()
  107. tfm.exec.disableAutoTimeLeft()
  108. tfm.exec.disableAutoNewGame()
  109. tfm.exec.disableAfkDeath()
  110. tfm.exec.disablePhysicalConsumables()
  111.  
  112. removeText = function(min, max, name)
  113.     for min = min, max do
  114.         ui.removeTextArea(min, name)
  115.     end
  116. end
  117.  
  118. inTeam = function(player) -- verifica si el jugador ya está en un team, guarda en una variable global cuál es su team y su index
  119.     for i, name in next, teams.team1.players do
  120.         if name == player then
  121.             playerIn = "team1"
  122.             index = i
  123.             return true
  124.         end
  125.     end
  126.     for i, name in next, teams.team2.players do
  127.         if name == player then
  128.             playerIn = "team2"
  129.             index = i
  130.             return true
  131.         end
  132.     end
  133. end
  134.  
  135. putColor = function(name)
  136.     if inTeam(name) then
  137.         local color = teams[playerIn].color:gsub("<font color='#", "0x"):gsub("'>", "")
  138.         tfm.exec.setNameColor(name, color)
  139.     end
  140. end
  141.  
  142. addPoints = function(name, points)
  143.     inTeam(name)
  144.     teams[playerIn].points = teams[playerIn].points + points
  145.     playerInfo[name].scorePoints = playerInfo[name].scorePoints + points
  146.     tfm.exec.setPlayerScore(name, points, true)
  147. end
  148.  
  149. addPlayerTeam = function(team, player) -- Agrega un nuevo jugador a el equipo asignado.
  150.     if tfm.get.room.playerList[player] then
  151.         if inTeam(player) then
  152.             teams[playerIn].players[index] = false
  153.         end
  154.         team.players[team.countPlayers] = player
  155.         team.countPlayers = team.countPlayers + 1
  156.         tfm.exec.respawnPlayer(player)
  157.         putColor(player)
  158.     else
  159.         print(player .. " no encontrado, no se añadió al equipo.")
  160.     end
  161. end
  162.  
  163. concatTeam = function(team) -- Retorna en string a todos los jugadores de un team, exceptuando los que sean false
  164.     local totalPlayers = ""
  165.     team.totalPlayers = 0
  166.     for _, name in next, team.players do
  167.         if name then
  168.             totalPlayers = totalPlayers .. name .. "\n"
  169.             team.totalPlayers = team.totalPlayers + 1
  170.         end
  171.     end
  172.     return totalPlayers
  173. end
  174.  
  175. sortByAmount = function(typeAmount) -- Puede ser amount o totalAmount
  176.     local aux, countAux, playersAmount = {}, 1, ""
  177.     for name in next, playerInfo do
  178.         aux[countAux] = {name, playerInfo[name][typeAmount]}
  179.         countAux = countAux + 1
  180.     end
  181.     table.sort(aux, function(k, v) return k[2] > v[2] end)
  182.    
  183.     for _, playerAmount in next, aux do
  184.         if playerAmount[2] > 0 then
  185.             inTeam(playerAmount[1])
  186.             local amount = verde .. playerAmount[2] .. "</font>"
  187.             local name = teams[playerIn].color .. playerAmount[1] .. "</font>"
  188.             playersAmount = playersAmount .. "\n" .. name .. "\t" .. amount
  189.         end
  190.     end
  191.     return playersAmount
  192.   end
  193.  
  194. mapStats = function()
  195.     local firstsPlace, playersTime, playersAmount = "", "", "<textformat tabstops='[190]'>"
  196.     -- obtengo los primeros puestos
  197.     if primerPuesto then
  198.         inTeam(primerPuesto)
  199.         primerPuesto = teams[playerIn].color .. primerPuesto .. "</font>"
  200.         firstsPlace = firstsPlace .. verde .. "\n\n01</font> " .. primerPuesto
  201.     end
  202.     if segundoPuesto then
  203.         inTeam(segundoPuesto)
  204.         segundoPuesto = teams[playerIn].color .. segundoPuesto .. "</font>"
  205.         firstsPlace = firstsPlace .. verde .."\n02</font> " .. segundoPuesto
  206.     end
  207.     if tercerPuesto then
  208.         inTeam(tercerPuesto)
  209.         tercerPuesto = teams[playerIn].color .. tercerPuesto .. "</font>"
  210.         firstsPlace = firstsPlace .. verde .."\n03</font> " .. tercerPuesto
  211.     end
  212.     -- los tiempos totales del mapa
  213.     watchRecords("always")
  214.     playersTime = recordsString:gsub("01", "</textformat><textformat tabstops='[29, 175]'>01")
  215.     -- las cantidades de cada jugador, tiene su propia funcion
  216.     playersAmount = playersAmount .. sortByAmount("amount")
  217.  
  218.     ui.addTextArea(31, "<p align='center'> <font size ='16' color='#00C17C'><b>Estadísticas", nil, 20, 137, 760, 220, 0x1E1E1E, 0x121212,
  219.     1, true)
  220.     ui.addTextArea(32, "<p align='center'><font size ='15' color='#00C17C'><b>Primeros Puestos</b></font>" .. firstsPlace,  nil, 35, 170, 230, 170, 0x2B2B2B, 0x2B2B2B, 1, true)
  221.     ui.addTextArea(33, "<p align='center'><font size ='15' color='#00C17C'><b>Cantidades</b></font></p>" .. playersAmount, nil, 285, 170, 230, 170, 0x2B2B2B, 0x2B2B2B, 1, true)
  222.     ui.addTextArea(34, "<p align='center'><font size ='15' color='#00C17C'><b>Tiempos</b></font></p>" ..  playersTime, nil, 535, 170, 230, 170, 0x2B2B2B, 0x2B2B2B, 1, true)
  223. end
  224.  
  225. scoreTimes = function()
  226.     for i, time in ipairs(times) do -- recorro toda la tabla times
  227.         if i == 1 then
  228.             addPoints(time.name, 5)
  229.             bestTimes[countBestTimes] = {name = time.name, time = time.time, map = time.map}
  230.             countBestTimes = countBestTimes + 1
  231.         elseif i == 2 then
  232.             addPoints(time.name, 4)
  233.         elseif i == 3 then
  234.             addPoints(time.name, 3)
  235.         else
  236.             return
  237.         end
  238.     end
  239. end
  240.  
  241. finalStats = function()
  242.     -- equipo ganador --
  243.     local teamWinner, totalTimes, totalAmounts = "", "\n<textformat tabstops='[72, 300]'>", "\n<textformat tabstops='[29, 325]'>"
  244.     if teams.team1.points > teams.team2.points then
  245.     teamWinner = "<font color = '#CB546B'>Team Red Wins</font>"
  246.     elseif teams.team1.points < teams.team2.points then
  247.         teamWinner = "<font color = '#2F7FCC'>Team Blue Wins</font>"
  248.     else
  249.     teamWinner = "<font color='#00C17C'>Empate jajaencerio</font>"
  250.     end
  251.     -- fin equipo ganador
  252.     -- mejores tiempos
  253.     for i, time in ipairs(bestTimes) do -- recorro toda la tabla times
  254.         if i < 10 then i = 0 .. i end -- le agrego el 0 al  inicio para que se vea 01, 02, 03 etc los 9 primeros end
  255.         inTeam(time.name)
  256.         name = teams[playerIn].color .. time.name .. "</font>"
  257.         totalTimes = totalTimes .. verde .. "@" .. time.map .. " \t" .. name .. "\t " .. verde .. time.time .. "s\n</font>" -- almaceno todos los times en un string
  258.     end
  259.     totalTimes = totalTimes .. "</textformat>"
  260.     --fin mejores tiempos
  261.  
  262.     -- mejor jugador
  263.     local scoreTop = -1
  264.     local mvpPlayer = ""
  265.     for name in pairs(playerInfo) do
  266.         if playerInfo[name].scorePoints > scoreTop then
  267.             scoreTop = playerInfo[name].scorePoints
  268.             mvpPlayer = name
  269.         end
  270.     end
  271.  
  272.     inTeam(mvpPlayer)
  273.     mvpPlayer = teams[playerIn].color .. mvpPlayer .. "</font>"
  274.     -- fin mejor jugador
  275.     -- cantidades
  276.    
  277.     totalAmounts = totalAmounts .. sortByAmount("totalAmount")
  278.     -- fin cantidades
  279.     texto = "<textformat tabstops='[310, 550]'><p align='left'>" .. mvpPlayer .. " MVP\t" .. teamWinner .. "\t<font color='#CB546B'><b>Red: " .. teams.team1.points .. "<font color='#2F7FCC'>   Blue: " .. teams.team2.points
  280.  
  281.     ui.addTextArea(60, "<p align='center'><font size ='16' color='#00C17C'><b>Estadísticas Finales\n\n\n\n\n\n\n\n\n\n\n\n" .. texto, nil, 20, 127, 760, 260, 0x1E1E1E, 0x121212, 1, true)
  282.     ui.addTextArea(61, "<p align='center'><font size ='15' color='#00C17C'><b>Cantidades Totales</b></font></p>" .. totalAmounts, nil, 35, 160, 350, 170, 0x2B2B2B, 0x2B2B2B, 1, true)
  283.     ui.addTextArea(62, "<p align='center'><font size ='15' color='#00C17C'><b>Mejores Tiempos</b></font></p>" ..  totalTimes, nil, 415, 160, 350, 170, 0x2B2B2B, 0x2B2B2B, 1, true)
  284.  
  285.  
  286. end
  287.  
  288. newMap = function() -- Empieza un nuevo mapa.
  289.     if mapsPlayed == mapsToPlay then -- JUEGO TERMINADO!
  290.         putAmount()
  291.         inGame = false
  292.         print("Juego terminado!")
  293.         removeText(31, 34, nil)
  294.         finalStats()
  295.         tfm.exec.newGame(7692636)
  296.     else
  297.         if mapBc then -- Verifica si tiene que cargar un nuevo mapa de bootcamp
  298.             local map = maps[math.random(2)] -- Acordarse de cambiar el #map por el número total de mapas
  299.             tfm.exec.newGame(map)
  300.             mapBc = false
  301.             main()
  302.             removeText(31, 34, nil)
  303.             tfm.exec.setGameTime(mapTime)
  304.  
  305.         else -- Si no, es porque es el fin de un mapa de bootcamp.
  306.             tfm.exec.newGame(7692636)
  307.             scoreTimes()
  308.             mapBc = true
  309.             mapsPlayed = mapsPlayed + 1 -- Al final del mapa en lobby, se suma +1 los mapas jugados
  310.             mapStats()
  311.             --------- TextAre de Botón
  312.             for name in next, admins do      
  313.                 ui.addTextArea(8, "", name, 770, 35, 20, 20, 0x2B2B2B, 0x121212, 1, true)
  314.                 ui.addTextArea(9, "<V><a href='event:nextMap'><font size='18'><b>»",
  315.                                 name, 771, 32, 40, 20, 0, 0, 1, true)
  316.             end
  317.             -------------
  318.             tfm.exec.setGameTime(99999)
  319.         end
  320.     end
  321. end
  322.  
  323. updateMapName = function()
  324.     local space = "\t<font color='#6A7495'>|\t"
  325.     local text = ""
  326.     if mapBc then
  327.         text =  "By Blood#3565 and Misterthepro" .. space ..
  328.         "<font color='#CB546B'>Red: " .. teams.team1.points .. space ..
  329.         "<font color='#2F7FCC'> Blue: ".. teams.team2.points .. space ..
  330.         "<J>Quedan " .. mapsToPlay - mapsPlayed .. " mapas."
  331.     else
  332.         local bestTime = "None"
  333.         if countTimes > 1 then
  334.             bestTime = times[1].name .. " " .. times[1].time .. "s"
  335.         end
  336.         text = "@" .. actualMap .. space ..
  337.         "<font color='#CB546B'>Red: " .. teams.team1.points .. space ..
  338.         "<font color='#2F7FCC'> Blue: ".. teams.team2.points .. space ..
  339.         "<J>" .. bestTime
  340.     end
  341.     tfm.exec.setUIMapName(text)
  342. end
  343.  
  344. watchRecords = function(name)
  345.     if watchingRecords[name] then -- Si no está abierto la lista de records, la abro actualizando los records.
  346.       recordsString = "\n<textformat tabstops='[29, 205]'>"
  347.       for i, time in ipairs(times) do -- recorro toda la tabla times
  348.             if i > 14 then break end
  349.             if i < 10 then
  350.                 i = 0 .. i -- le agrego el 0 al  inicio para que se vea 01, 02, 03 etc los 9 primeros
  351.             end
  352.             if #recordsString < 1850 then
  353.                 inTeam(time.name)
  354.                 local playerName = teams[playerIn].color .. time.name .. "</font>"
  355.                 recordsString = recordsString .. verde .. i .. " \t" .. playerName .. "\t " .. verde .. time.time .. "s\n</font>" -- almaceno todos los times en un string
  356.             end
  357.       end
  358.       ui.addTextArea(20, "", name, 275, 80, 250, 200, 0x2B2B2B, 0x121212, 1, true) -- textArea de fondo gris
  359.       ui.addTextArea(21, recordsString, name, 275, 80, 0, 0, 0, 0, 1, true) -- tiempos totales
  360.       ui.addTextArea(22, "<p align='center'><font size ='13' color='#00C17C'><b>Tiempos", name, 352, 65, 100, 20, 0x2B2B2B, 0x121212, 1, true)
  361.     else -- Si está abierta, entonces la cierro
  362.         removeText(20, 22, name)
  363.     end
  364. end
  365.  
  366. nextMap = function()
  367.     removeText(8, 9, nil)
  368.     if mapsPlayed == mapsToPlay then -- JUEGO TERMINADO!
  369.         infoText = "Enfrentamiento terminado"
  370.     end
  371.     ui.addTextArea(10, infoText, nil, 283, 23, 0, 25, 0x2B2B2B, 0x121212, 0.7, true)
  372.     tfm.exec.setGameTime(5)
  373. end
  374.  
  375. fillTeams = function ()
  376.     teams.team1.players = {}
  377.     teams.team2.players = {}
  378.     local intTeam, countPlayers = 1, 0
  379.     local playersWithoutTeam = {}
  380.     -- añado a todos los jugadores al mismo array
  381.     for name, p in pairs(tfm.get.room.playerList) do
  382.         countPlayers = countPlayers + 1
  383.         playersWithoutTeam[countPlayers] = name
  384.     end
  385.  
  386.     for i = 1, countPlayers do
  387.         local numJugador = math.random(countPlayers)
  388.         local playerToAdd = playersWithoutTeam[numJugador]
  389.         table.remove(playersWithoutTeam, numJugador) -- D:
  390.         if intTeam == 1 then
  391.             addPlayerTeam(teams.team1, playerToAdd)
  392.             intTeam = 2
  393.         elseif intTeam == 2 then
  394.             addPlayerTeam(teams.team2, playerToAdd)
  395.             intTeam = 1
  396.         end
  397.         countPlayers = countPlayers - 1
  398.     end
  399.     updateTexts()
  400. end
  401.  
  402. local macro_time = 2000 -- time to reset
  403. local macro_warn = 22 -- sends a warning to the admins
  404. local macro_freeze = 30 -- freezes them
  405. local macro_keys = { -- keys that antimacro detects
  406.     [38] = "Up",
  407.     [87] = "W",
  408.     [90] = "Z"
  409. }
  410. local macro_info = {}
  411. local concatenation = {}
  412.  
  413. updateTexts = function()
  414.     if not inGame then
  415.         ui.updateTextArea(2, "<p align='center'><font size='15' color='#CB546B'><b>Team 1</font><font size='12'><N>\n\n" .. concatTeam(teams.team1), nil)
  416.         ui.updateTextArea(3, "<p align='center'><font size='15' color='#2F7FCC'><b>Team 2</font><font size='12'><N>\n\n" .. concatTeam(teams.team2), nil)
  417.         ui.addTextArea(4, "<p align='center'><font size ='15'><b>Configuración</b></font><font size='12'>"
  418.         .. verde .. "\n\nAdministrador: </font>" .. morado .. admin .. "</font>"
  419.         .. "\n" .. verde .. "Mapas por jugar: </font>" .. morado .. mapsToPlay
  420.         .. "\n" .. verde .. "Tiempo por mapa: </font>" .. morado .. mapTime .. "s (" .. math.floor(mapTime / 60) .. " minutos)"
  421.         .. "\n" .. verde .. "Jugadores: </font>" .. morado .. teams.team1.totalPlayers .. "vs" .. teams.team2.totalPlayers
  422.         .. "\n" .. verde .. "AutoJoin: </font>" .. morado .. "<a href='event:autojoin'>" .. autoJoin .. "</a>"
  423.         .. "\n\n" .. verde .. "<b><a href='event:fillTeams'>Llenar Equipos</font></a></b>"
  424.         .. verde .. "\n\n\n<b><font size='14'><p align='center'><a href='event:startGame'>Empezar</a>", nil, 285, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)            
  425.     end
  426. end
  427.  
  428. --removeStats = function()
  429.  
  430. --end
  431.  
  432. -- Eventos de tfm
  433.  
  434. eventKeyboard = function(player, key)
  435.     if key == 76 then
  436.         if watchingRecords[player] then
  437.             watchingRecords[player] = false
  438.             watchRecords(player)
  439.         else
  440.             watchingRecords[player] = true
  441.             watchRecords(player)
  442.         end
  443.     elseif key == 46 or key == 17 then
  444.         tfm.exec.killPlayer(player)
  445.     end -- End if key Principal
  446.     if not macro_keys[key] then return end -- solo sigue si la tecla fue UP, W o Z
  447.     -- By tocutoeltocu
  448.     local info = macro_info[player][key]
  449.     local now = os_time()
  450.  
  451.     info[1] = info[1] + 1
  452.  
  453.     if now >= info[2] then
  454.         if info[4] then
  455.             local count = 3
  456.             concatenation[1] = "<r>[AntiMacro] <bv>"
  457.             concatenation[2] = player
  458.             concatenation[3] = "<bl> fue congelado por usar trampas!"
  459.             local data
  460.             for _key, name in next, macro_keys do
  461.                 data = macro_info[player][_key]
  462.                 count = count + 4
  463.                 concatenation[count - 3] = " "
  464.                 concatenation[count - 2] = name
  465.                 concatenation[count - 1] = ": "
  466.                 if now >= data[2] and info ~= data then
  467.                     concatenation[count] = "0"
  468.                 else
  469.                     concatenation[count] = data[1]
  470.                 end
  471.             end
  472.             local msg = table.concat(concatenation, "", 1, count)
  473.             --tfm.exec.chatMessage(msg)
  474.             print(msg)
  475.             tfm.exec.freezePlayer(player)
  476.         end
  477.         info[1] = 1
  478.         info[2] = now + macro_time
  479.         info[3] = false
  480.         info[4] = false
  481.         return
  482.     elseif not info[3] and info[1] >= macro_warn then
  483.         info[3] = true
  484.         local count = 3
  485.         concatenation[1] = "<j>[AntiMacro] <bv>"
  486.         concatenation[2] = player
  487.         concatenation[3] = "<bl> puede estar usando macros."
  488.         local data
  489.         for _key, name in next, macro_keys do
  490.             data = macro_info[player][_key]
  491.             count = count + 4
  492.             concatenation[count - 3] = " "
  493.             concatenation[count - 2] = name
  494.             concatenation[count - 1] = ": "
  495.             if now >= data[2] then
  496.                 concatenation[count] = "0"
  497.             else
  498.                 concatenation[count] = data[1]
  499.             end
  500.         end
  501.         local msg = table.concat(concatenation, "", 1, count)
  502.         print(msg)
  503.     elseif not info[4] and info[1] >= macro_freeze then
  504.         info[4] = true
  505.     end
  506. end
  507.  
  508. eventNewPlayer = function(name)
  509.     tfm.exec.setPlayerScore(name, 0)
  510.     updateMapName()
  511.     if not playerInfo[name] then
  512.         playerInfo[name] = {totalAmount = 0, amount = 0, alreadyRespawn = false, scorePoints = 0}
  513.     else
  514.         tfm.exec.setPlayerScore(name, playerInfo[name].scorePoints)
  515.     end
  516.     keys(name)
  517.     if not inGame then
  518.         startGui(name)
  519.     else
  520.         if autoJoin == "ON" and (not inTeam(name)) then
  521.             concatTeam(teams.team1)
  522.             concatTeam(teams.team2)
  523.             if teams.team1.totalPlayers <= teams.team2.totalPlayers then
  524.                 addPlayerTeam(teams.team1, name)
  525.             else
  526.                 addPlayerTeam(teams.team2, name)
  527.             end
  528.         end
  529.     end
  530.     local info = {}
  531.     for key in next, macro_keys do
  532.         info[key] = {0, os_time() + macro_time, false, false}
  533.         system.bindKeyboard(name, key, true, true)
  534.     end
  535.     macro_info[name] = info
  536. end
  537.  
  538. eventChatCommand = function(name, cmd)
  539.     if admins[name] then
  540.         local args, count = {}, 1
  541.         -- Lo que hace lo siguiente, es que por cada espacio (" ") que tengas en el comando que hayas escrito, lo separa y lo guarda todo en el array args.
  542.         -- por ejemplo, por el comando:
  543.         -- !add team1 Blood#3565
  544.         -- Lo separaria en:
  545.         ---------------------------
  546.         -- [add][team1][blood#3565]
  547.         --   1       2      3
  548.         -----------------------------
  549.         for arg in cmd:gmatch("[^%s]+") do
  550.             args[count] = arg
  551.             count = count + 1
  552.         end
  553.         if args[1] == "team1" or args[1] == "team2" then -- Agrega un jugador a algún team
  554.             teams[args[1]].players = {}
  555.             teams[args[1]].countPlayers = 1
  556.             for i = 2, count - 1 do addPlayerTeam(teams[args[1]], args[i]) end
  557.             updateTexts()
  558.         elseif args[1] == "add" then
  559.             if args[2] == "team1" or args[2] == "team2" then
  560.                 for i = 3, count - 1 do
  561.                     addPlayerTeam(teams[args[2]], args[i])
  562.                 end
  563.             end
  564.             updateTexts()
  565.         elseif args[1] == "next" or args[1] == "n" then
  566.             if mapBc then
  567.                 nextMap()
  568.             end
  569.         elseif args[1] == "skip" then
  570.             if not mapBc then
  571.                 --if countTimes > 1 then
  572.                   --  removeStats()
  573.                 --end
  574.                 mapBc = true
  575.                 newMap()
  576.             end
  577.         elseif args[1] == "stop" then
  578.             if not stop then
  579.                 stopTime = restante / 1000
  580.                 stop = true
  581.                 tfm.exec.setGameTime(9999)
  582.             else
  583.                 stop = false
  584.                 eventNewGame()
  585.                 tfm.exec.setGameTime(stopTime)
  586.             end
  587.         elseif args[1] == "addtime" then
  588.             local timeForMap = tonumber(args[2])
  589.             restante = restante / 1000
  590.             if timeForMap ~= nil then
  591.                 tfm.exec.setGameTime(restante + timeForMap)
  592.             end
  593.         elseif args[1] == "admin" and args[2] ~= nil then
  594.             admins[args[2]] = true
  595.         elseif args[1] == "unadmin" and args[2] ~= nil and args[2] ~= admin then
  596.             admins[args[2]] = false
  597.         elseif args[1] == "timemap" or args[1] == "maptime" or args[1] == "tm" or args[1] == "mt" then
  598.             local timeForMap = tonumber(args[2])
  599.             if timeForMap ~= nil then
  600.                 mapTime = timeForMap
  601.                 if not inGame then
  602.                     ui.addTextArea(4, "<p align='center'><font size ='15'><b>Configuración</b></font><font size='12'>"
  603.                     .. verde .. "\n\nAdministrador: </font>" .. morado .. admin .. "</font>"
  604.                     .. "\n" .. verde .. "Mapas por jugar: </font>" .. morado .. mapsToPlay
  605.                     .. "\n" .. verde .. "Tiempo por mapa: </font>" .. morado .. mapTime .. "s (" .. math.floor(mapTime / 60) .. " minutos)"
  606.                     .. "\n" .. verde .. "Jugadores: </font>" .. morado .. teams.team1.totalPlayers .. "vs" .. teams.team2.totalPlayers
  607.                     .. "\n" .. verde .. "AutoJoin: </font>" .. morado .. "<a href='event:autojoin'>" .. autoJoin .. "</a>"
  608.                     .. "\n\n" .. verde .. "<b><a href='event:fillTeams'>Llenar Equipos</font></a></b>"
  609.                     .. verde .. "\n\n\n<b><font size='14'><p align='center'><a href='event:startGame'>Empezar</a>", nil, 285, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)
  610.                 end
  611.             else
  612.                 print("Número invalido. No se pudo cambiar el tiempo de cada mapa.")
  613.             end
  614.         elseif args[1] == "maps" or args[1] == "mapas" or args[1] == "m" then
  615.             local mapsPlay = tonumber(args[2])
  616.             if mapsPlay ~= nil then
  617.                 mapsToPlay = mapsPlay
  618.                 if not inGame then
  619.                     updateMapName()
  620.                     ui.addTextArea(4, "<p align='center'><font size ='15'><b>Configuración</b></font><font size='12'>"
  621.                     .. verde .. "\n\nAdministrador: </font>" .. morado .. admin .. "</font>"
  622.                     .. "\n" .. verde .. "Mapas por jugar: </font>" .. morado .. mapsToPlay
  623.                     .. "\n" .. verde .. "Tiempo por mapa: </font>" .. morado .. mapTime .. "s (" .. math.floor(mapTime / 60) .. " minutos)"
  624.                     .. "\n" .. verde .. "Jugadores: </font>" .. morado .. teams.team1.totalPlayers .. "vs" .. teams.team2.totalPlayers
  625.                     .. "\n" .. verde .. "AutoJoin: </font>" .. morado .. "<a href='event:autojoin'>" .. autoJoin .. "</a>"
  626.                     .. "\n\n" .. verde .. "<b><a href='event:fillTeams'>Llenar Equipos</font></a></b>"
  627.                     .. verde .. "\n\n\n<b><font size='14'><p align='center'><a href='event:startGame'>Empezar</a>", nil, 285, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)
  628.                 end
  629.             else
  630.                 print("Número invalido. No se pudo cambiar los mapas totales.")
  631.             end
  632.         end -- End IF principal sobre comandos de administrador
  633.     end -- end if admins
  634.     if cmd == "records" then
  635.         if watchingRecords[name] then
  636.             watchingRecords[name] = false
  637.             watchRecords(name)
  638.         else
  639.             watchingRecords[name] = true
  640.             watchRecords(name)
  641.         end
  642.     end
  643. end
  644.  
  645.  
  646. eventLoop = function(currentTime, remaining)
  647.     restante = remaining
  648.     for name, time in next, toRespawn do -- Respawnea a cualquier jugador que haya muerto o ganado con 1s de descanso.
  649.         if time <= os_time() - 1000 then tfm.exec.respawnPlayer(name) putColor(name) end
  650.     end
  651.     if (remaining < 500 and inGame) then newMap() end
  652. end
  653.  
  654. eventPlayerDied = function(name) -- Lo respawneo si está en un equipo
  655.     if inTeam(name) then
  656.         toRespawn[name] = os_time()
  657.         playerInfo[name].alreadyRespawn = true
  658.     end
  659.     if stop then
  660.         toRespawn[name] = 9999999999999
  661.     end
  662. end
  663.  
  664. eventNewGame = function() -- Mato a todas las personas que no estén en un equipo
  665.     if inGame then
  666.         for name in pairs(tfm.get.room.playerList) do
  667.             tfm.exec.respawnPlayer(name)
  668.             putColor(name)
  669.             if (autoJoin == "OFF") and (not inTeam(name)) then
  670.                 tfm.exec.killPlayer(name)
  671.             else
  672.                 if not inTeam(name) then
  673.                     concatTeam(teams.team1)
  674.                     concatTeam(teams.team2)
  675.                     if teams.team1.totalPlayers <= teams.team2.totalPlayers then
  676.                         addPlayerTeam(teams.team1, name)
  677.                     else
  678.                         addPlayerTeam(teams.team2, name)
  679.                     end
  680.                 end
  681.             end
  682.         end
  683.     end
  684.     if inGame then actualMap = tfm.get.room.xmlMapInfo.mapCode end
  685.     ui.removeTextArea(10, nil)
  686.     updateMapName()
  687. end
  688.  
  689. eventTextAreaCallback = function (id, name, callback)
  690.     if not admins[name] then return end -- Si cualquiera que haga click no es admin, no hace nada
  691.  
  692.     if callback == "startGame" then
  693.         inGame = true
  694.         removeText(1, 4, nil) -- Se remueven los textareas del inicio
  695.         newMap()
  696.     elseif callback == "nextMap" then
  697.         nextMap()
  698.     elseif callback == "fillTeams" then
  699.         fillTeams()
  700.     elseif callback == "autojoin" then
  701.         if autoJoin == "ON" then
  702.             autoJoin = "OFF"
  703.         else
  704.             autoJoin = "ON"
  705.         end
  706.         ui.addTextArea(4, "<p align='center'><font size ='15'><b>Configuración</b></font><font size='12'>"
  707.         .. verde .. "\n\nAdministrador: </font>" .. morado .. admin .. "</font>"
  708.         .. "\n" .. verde .. "Mapas por jugar: </font>" .. morado .. mapsToPlay
  709.         .. "\n" .. verde .. "Tiempo por mapa: </font>" .. morado .. mapTime .. "s (" .. math.floor(mapTime / 60) .. " minutos)"
  710.         .. "\n" .. verde .. "Jugadores: </font>" .. morado .. teams.team1.totalPlayers .. "vs" .. teams.team2.totalPlayers
  711.         .. "\n" .. verde .. "AutoJoin: </font>" .. morado .. "<a href='event:autojoin'>" .. autoJoin .. "</a>"
  712.         .. "\n\n" .. verde .. "<b><a href='event:fillTeams'>Llenar Equipos</font></a></b>"
  713.         .. verde .. "\n\n\n<b><font size='14'><p align='center'><a href='event:startGame'>Empezar</a>", name, 285, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)
  714.  
  715.     end
  716. end
  717.  
  718. eventPlayerWon = function(player, timeElapsed, timeRespawn)
  719.     -- consigo el team del jugador
  720.     local completedIn = timeRespawn / 100
  721.     -- dependiendo del puesto en el que llegó, le doy puntos a él y a su equipo
  722.     if not primerPuesto then
  723.         primerPuesto = player
  724.         addPoints(player, 5)
  725.     elseif not segundoPuesto then
  726.         segundoPuesto = player
  727.         addPoints(player, 4)
  728.     elseif not tercerPuesto then
  729.         tercerPuesto = player
  730.         addPoints(player, 3)
  731.     else
  732.         addPoints(player, 2)
  733.     end
  734.     -- le aumento en 1 sus cantidades
  735.     playerInfo[player].amount = playerInfo[player].amount + 1
  736.     toRespawn[player] = os_time()
  737.     if not playerInfo[player].alreadyRespawn then
  738.         completedIn = completedIn - 3
  739.         playerInfo[player].alreadyRespawn = true
  740.     end
  741.     -- Almaceno el time en la variable que tiene todos los tiempos del mapa:
  742.     times[countTimes] = {time = completedIn, name = player, map = actualMap}
  743.     countTimes = countTimes + 1
  744.     -- Ordeno los tiempos:
  745.     table.sort(times, function(i, v) return i.time < v.time end)
  746.     --
  747.     for name in next, watchingRecords do
  748.         watchRecords(name)
  749.     end
  750.     updateMapName()
  751. end
  752.  
  753. startGui = function(name) -- interfaz gráfica inicial
  754. ui.addTextArea(1, "<p align='center'> <font size ='16' color='#00C17C'><b>Información Inicial", name, 20, 137, 760, 240, 0x1E1E1E, 0x121212,
  755.  1, true)
  756.  ui.addTextArea (2, "<p align='center'><font size='15' color='#CB546B'><b>Team 1</font><font size='12'><N>\n\n" .. concatTeam(teams.team1), name, 35, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)
  757.  ui.addTextArea(3, "<p align='center'><font size='15' color='#2F7FCC'><b>Team 2</font><font size='12'><N>\n\n" .. concatTeam(teams.team2), name, 535, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)
  758.  ui.addTextArea(4, "<p align='center'><font size ='15'><b>Configuración</b></font><font size='12'>"
  759.  .. verde .. "\n\nAdministrador: </font>" .. morado .. admin .. "</font>"
  760.  .. "\n" .. verde .. "Mapas por jugar: </font>" .. morado .. mapsToPlay
  761.  .. "\n" .. verde .. "Tiempo por mapa: </font>" .. morado .. mapTime .. "s (" .. math.floor(mapTime / 60) .. " minutos)"
  762.  .. "\n" .. verde .. "Jugadores: </font>" .. morado .. teams.team1.totalPlayers .. "vs" .. teams.team2.totalPlayers
  763.  .. "\n" .. verde .. "AutoJoin: </font>" .. morado .. "<a href='event:autojoin'>" .. autoJoin .. "</a>"
  764.  .. "\n\n" .. verde .. "<b><a href='event:fillTeams'>Llenar Equipos</font></a></b>"
  765.  .. verde .. "\n\n\n<b><font size='14'><p align='center'><a href='event:startGame'>Empezar</a>", name, 285, 170, 230, 190, 0x2B2B2B, 0x2B2B2B, 1, true)
  766. end
  767.  
  768. for name in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end
  769.  
  770. tfm.exec.newGame(7692636)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement