Advertisement
alditojeje

torneo prueba

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