Advertisement
KevinK_O

Lua 1 vs 1 [P17]

May 24th, 2020
1,498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.73 KB | None | 0 0
  1. tfm.exec.disableAutoShaman()
  2. tfm.exec.disableAutoNewGame()
  3. tfm.exec.disableAutoTimeLeft()
  4. tfm.exec.newGame("@7727559")
  5. tfm.exec.setUIMapName("<n>Creado por</n> <j>+Lknx#0000</j>")
  6.  
  7. local ADMINISTRADOR = "+Lknx#0000" --
  8. local WINS = 15 --
  9.  
  10. system.disableChatCommandDisplay("np", true)
  11. system.disableChatCommandDisplay("ani", true)
  12. system.disableChatCommandDisplay("equipo1", true)
  13. system.disableChatCommandDisplay("equipo2", true)
  14. system.disableChatCommandDisplay("puntaje", true)
  15. system.disableChatCommandDisplay("resultado", true)
  16. system.disableChatCommandDisplay("saltar", true)
  17. system.disableChatCommandDisplay("pausa", true)
  18.  
  19. tfm.exec.disablePhysicalConsumables()
  20. tfm.exec.disableAutoShaman()
  21. tfm.exec.disableAutoNewGame()
  22. tfm.exec.disableAutoTimeLeft()
  23.  
  24.  
  25. --[[
  26. ]]
  27.  
  28. local teams = {
  29.     [1] = {},
  30.     [2] = {},
  31. }
  32. local points = {
  33.     [1] = 0,
  34.     [2] = 0,
  35. }
  36.  
  37. local admin_buttons = {
  38.     ['Saltar'] = function(admin)
  39.         eventChatCommand(admin, 'np')
  40.     end,
  41.     ['Mapa (Leve)'] = function(admin)
  42.         eventChatCommand(admin, 'npp ant')
  43.     end,
  44.     ['Mapa (Pulo)'] = function(admin)
  45.         eventChatCommand(admin, 'npp ant pulo'"ff6347",
  46.     [2] = "19b5fe"
  47. }
  48. local queue = {}
  49.  
  50. function newMap()
  51.     local mapcode = maps[math.random(#maps)]
  52.     if #queue > 0 then
  53.         mapcode = queue[1]
  54.         table.remove(queue, 1)
  55.     end
  56.    
  57.     if not PAUSED == true then
  58.         tfm.exec.newGame(mapcode)
  59.     end
  60.  
  61. tfm.exec.setUIMapName("<n>Creado por</n> <j>+Lknx#0000</j>")
  62.  
  63. tfm.exec.newGame(mapcode)
  64.     for player, data in pairs(tfm.get.room.playerList) do
  65.         if not playersInGame[player] then
  66.             tfm.exec.killPlayer(player)
  67.         end
  68.     end
  69.     tfm.exec.setGameTime(120)
  70. end
  71.  
  72. function eventPlayerWon(player)
  73.     if not isfirst then
  74.         isfirst = true
  75.         tfm.exec.setGameTime(1)
  76.         if table.contains(teams[1], player) then
  77.             tfm.exec.setGameTime(1)
  78.             for i = 0, 3 do
  79.                 defaultEffect(9, {13}, math.random(800), math.random(400), 20)
  80.             end
  81.             points[1] = points[1]+1
  82.         elseif table.contains(teams[2], player) then
  83.             tfm.exec.setGameTime(1)
  84.             for i = 0, 3 do
  85.                 defaultEffect(9, {9}, math.random(800), math.random(400), 20)
  86.             end
  87.             points[2] = points[2]+1
  88.         else
  89.             isfirst = false
  90.         end
  91.         winner = false
  92.         if points[1] >= WINS then
  93.             winner = 1
  94.         elseif points[2] >= WINS then
  95.             winner = 2
  96.         end
  97.         if winner then
  98.             gameRunning = false
  99.             winTime = os.time()
  100.             ui.addTextArea(22, string.format("<p align='center'><font size='37' color='#%s'><font face='Century Gothic'>¡EL EQUIPO %s ES EL GANADOR!", colors[winner], winner), nil, 1, 170, 800, 500, 0, 0, 0, true)
  101.         end
  102.         displayScore()
  103.     end
  104. end
  105.  
  106. function eventLoop(elapsed, remain)
  107.     if gameRunning then
  108.         remain = remain/1000
  109.         if remain < 0 then
  110.             remain = 100
  111.             newMap()
  112.         end
  113.     else
  114.         if winTime then
  115.             if winTime > os.time()-30000 then
  116.                 for i = 0, 2 do
  117.                     defaultEffect(9, {11, 9, 0, 13}, math.random(800), math.random(400), 80)
  118.                 end
  119.             else
  120.                 winTime = false
  121.                 ui.removeTextArea(20)
  122.                 ui.removeTextArea(21)
  123.                 ui.removeTextArea(22)
  124.                 displayTeams()
  125.                 teams = {
  126.                     [1] = {},
  127.                     [2] = {},
  128.                 }
  129.                 points = {
  130.                     [1] = 0,
  131.                     [2] = 0,
  132.                 }
  133.                 playersInGame = {}
  134.             end
  135.         end
  136.     end
  137. end
  138.  
  139.  
  140. function eventChatCommand(player, command)
  141.     if player:lower() == ADMINISTRADOR:lower() then
  142.         args = string.split(command, " ")
  143.         if args[1] == "equipo1" then
  144.             table.remove(args, 1)
  145.             teams[1] = {}
  146.             points[1] = 0
  147.             for index, player in pairs(args) do
  148.                 table.insert(teams[1], player)
  149.                 playersInGame[player] = true
  150.             end
  151.             displayTeams()
  152.  
  153.         elseif args[1] == "equipo2" then
  154.             table.remove(args, 1)
  155.             teams[2] = {}
  156.             points[2] = 0
  157.             for index, player in pairs(args) do
  158.                 table.insert(teams[2], player)
  159.                 playersInGame[player] = true
  160.             end
  161.             displayTeams()
  162.  
  163.         elseif args[1] == "puntaje" then
  164.             if args[2] and args[3] then
  165.                 local team = tonumber(args[2]:match("team(%d+)") or 0)
  166.                 if team > 0 and team < 3 then
  167.                     local newScore = tonumber(args[3]) or points[team]
  168.                     points[team] = newScore
  169.                     displayScore()
  170.                 end
  171.             end
  172.  
  173.  
  174.  
  175.  
  176. elseif args[1] == "ani" then
  177.             if args[2] == "si" then
  178.                 PAUSED = true
  179.                 print("a")
  180.                 ui.addTextArea(128, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<p align='center'><font size='20'>Ani la más <font color='#F5FA51'>linda</font>", nil, -492, -186, 1783, 943, 0x1b1c1c, 0x000000, 1, true)
  181.             end
  182. if args[2] == "no" then
  183.                 PAUSED = false 
  184.                 print("b")
  185.                 ui.removeTextArea(128,nil) 
  186.              end
  187.  
  188. elseif args[1] == "pausa" then
  189.             if args[2] == "activar" then
  190.                 PAUSED = true
  191.                 print("a")
  192.  
  193. ui.addTextArea(127, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<p align='center'><font size='20'><font color='#F5FA51'>[ES]</font> El juego ha sido pausado</font>\n\n<p align='center'><font size='20'><font color='#F5FA51'>[EN]</font> The game has been paused</font>\n\n<p align='center'><font size='20'><font color='#F5FA51'>[BR]</font> O jogo foi pausado</font>\n\n<p align='center'><font size='20'><font color='#F5FA51'>[TR]</font> Oyun duraklatıldı</font>\n\n<p align='center'><font size='20'><font color='#F5FA51'>[FR]</font> Le jeu a été interrompu</font>\n\n<p align='center'><font size='20'><font color='#F5FA51'>[PL]</font> Gra została wstrzymana</font>", nil, -489, -167, 1782, 942, 0x1b1c1c, 0x000000, 1, true)
  194.  
  195.             end
  196.             if args[2] == "desactivar" then
  197.                 PAUSED = false 
  198.                 print("b")
  199.                 ui.removeTextArea(127,nil) 
  200.              end
  201.  
  202.         elseif args[1] == "saltar" then
  203.             newMap()
  204.         elseif args[1] == "np" then
  205.             if args[2] then
  206.                 table.insert(queue, args[2])
  207.             end
  208.         elseif args[1] == "resultado" then
  209.             if args[2] then
  210.                 WINS = tonumber(args[2])
  211.                 displayScore()
  212.             end
  213.         elseif args[1] == "np" then
  214.             if args[2] then
  215.                 table.insert(queue, args[2])
  216.             end
  217.         end
  218.     end
  219. end
  220.  
  221. function eventNewGame()
  222.     if gameRunning then
  223.         isfirst = false
  224.         for i, p in pairs(teams[1]) do
  225.             tfm.exec.setNameColor(p, "0x"..colors[1])
  226.         end
  227.         for i, p in pairs(teams[2]) do
  228.             tfm.exec.setNameColor(p, "0x"..colors[2])
  229.         end
  230.         displayScore()
  231.     end
  232. end
  233.  
  234. function displayScore()
  235.  
  236. ui.addTextArea(190, "", nil, 345, -30, 121, 30, 0x1b1c1c, 0xffffff, 1, true)
  237.  
  238. ui.addTextArea(19, string.format("<p align='center'><font size='23'><font color='#%s'>%s<N> - <font color='#%s'>%s", colors[1], points[1], colors[2], points[2]), nil, 345, -30, 121, 30, 0, 0, 0, true)
  239.  
  240. end
  241.  
  242. function displayTeams()
  243.  
  244. ui.addTextArea(300, "", nil, -492, -186, 1783, 943, 0x0a0a0a, 0x000000, 1, true)
  245.  
  246.     ui.addTextArea(1, "", nil, 199, 69, 400, 260, 0x5A7A8B, 0x5A7A8B, 1, true)
  247.     ui.addTextArea(2, "", nil, 201, 71, 400, 260, 0x0E1417, 0x0E1417, 1, true)
  248.     ui.addTextArea(4, "", nil, 209, 79, 142, 22, 0x324650, 0x5A7A8B, 1, true)
  249.     ui.addTextArea(5, "<p align='center'><font color='#ffffff'>Equipo 1", nil, 210, 80, 140, 20, 0x202324, 0x000000, 1, true)
  250.     ui.addTextArea(6, "", nil, 449, 79, 142, 22, 0x324650, 0x5A7A8B, 1, true)
  251.     ui.addTextArea(7, "<p align='center'><font color='#ffffff'>Equipo 2", nil, 450, 80, 140, 20, 0x202324, 0x000000, 1, true)
  252.     ui.addTextArea(10, "", nil, 209, 120, 140, 200, 0x5A7A8B, 0x5A7A8B, 1, true)
  253.     ui.addTextArea(11, "<p align='center'><font color='#"..colors[1].."'>"..table.concat(teams[1], "\n"), nil, 210, 121, 138, 198, 0x202324, 0x000000, 1, true)
  254.     ui.addTextArea(12, "", nil, 451, 120, 140, 200, 0x5A7A8B, 0x5A7A8B, 1, true)
  255.     ui.addTextArea(13, "<p align='center'><font color='#"..colors[2].."'>"..table.concat(teams[2], "\n"), nil, 452, 121, 138, 198, 0x202324, 0x000000, 1, true)
  256.     ui.addTextArea(15, "", nil, 380, 202, 40, 20, 0x5A7A8B, 0x5A7A8B, 1, true)
  257.     ui.addTextArea(16, "<p align='center'><font color='#ffffff'>VS", nil, 381, 203, 38, 18, 0x202324, 0x000000, 1, true)
  258.     ui.addTextArea(16, "<p align='center'><font color='#ffffff'><a href='event:iniciarJogo'>GO", ADMINISTRADOR, 381, 203, 38, 18, 0x202324, 0x202324, 1, true)
  259.     ui.addTextArea(19, "<p align='center'><b>LUA VERSUS RACING</b>", nil, 322, 32, 162, 19, 0x202324, 0x000000, 1, true)
  260.     ui.addTextArea(20, "<p align='center'><b>Modalidad:</b> Racing", nil, 670, 28, 126, 19, 0x202324, 0x000000, 1, true)
  261.  
  262.  
  263. end
  264.  
  265.    
  266.  
  267. function eventTextAreaCallback(id, player, callback)
  268.     if callback == 'iniciarJogo' then
  269.         if #teams[2] > 0 and #teams[1] > 0 then
  270.             gameRunning = true
  271.             for i = 1, 16 do
  272.                 ui.removeTextArea(i)
  273.             end
  274.             defaultEffect(9, {9}, 400, 212, 80)
  275.             newMap()
  276.    ui.removeTextArea(20)
  277.    ui.removeTextArea(300)
  278.  
  279.         end
  280.     end
  281. end
  282.  
  283. function string.split(s, pattern, n)
  284.     local st = {}
  285.     for sb in string.gmatch(s, "[^"..pattern.."]+") do
  286.     if not n or n > -1 then
  287.         table.insert(st,sb)
  288.     else
  289.         st[#st] = st[#st]..pattern..sb
  290.     end
  291.     n = n and n-1 or false
  292.     end
  293.     return st
  294. end
  295.  
  296. function table.contains(tableT, element)
  297.     for _, value in pairs(tableT) do
  298.         if value == element then
  299.             return true
  300.         end
  301.     end
  302.     return false
  303. end
  304.  
  305. defaultEffect=function(id,p,x,y,rand) -- thanks for the function santah
  306.     local minDist = 1
  307.     local outerBorder = 20
  308.     local maxDist = 30
  309.     local totalParticles = rand and 40 or (id == -1 and 35 or 75)
  310.     for i = 1, totalParticles do
  311.         if rand then
  312.             id = p[math.random(#p)]
  313.         end
  314.         local dist = math.min(math.random(minDist, maxDist), outerBorder)
  315.         local angle = math.random(0, 360)
  316.         local r = math.rad(angle)
  317.         local dx = math.cos(r)
  318.         local dy = math.sin(r)
  319.         local vx = dist * dx / 10
  320.         local vy = dist * dy / 10
  321.         local ax = -vx / dist / 15
  322.         local ay = (-vy / dist / 15) + 0.05
  323.         if id == -1 then
  324.             tfm.exec.displayParticle(9, x + dx, y + dy, vx, vy, ax, ay, nil)
  325.             tfm.exec.displayParticle(1, x + dx, y + dy, vx, vy, ax, ay, nil)
  326.         else
  327.             tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
  328.         end
  329.     end
  330. end
  331.  
  332. displayTeams()
  333.  
  334. function eventPlayerDied()
  335.     local alive = 0
  336.     for k,v in pairs(tfm.get.room.playerList) do
  337.         if not v.isDead then
  338.             alive = alive+1
  339.         end
  340.     end
  341.     if alive < 1 then
  342.         tfm.exec.setGameTime(1)
  343.     end
  344.  
  345. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement