Soristl

Basketball Street beta

Mar 30th, 2022 (edited)
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 60.62 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 (15)
  170. tfm.exec.disableAutoScore (true)
  171. system.disableChatCommandDisplay (nil, true)
  172.  
  173. local admins = {
  174.     ["Refletz#6472"] = true,
  175.     ["Soristl1#0000"] = true
  176. }
  177.  
  178. local mode = ""
  179. local initTimer = os.time() + 15000
  180. local winnerTimer = ""
  181.  
  182. local quantity = {red = 0, blue = 0}
  183. local idImage = ""
  184.  
  185. local redPoints = 0
  186. local bluePoints = 0
  187. local winscore = 10
  188.  
  189. local ballObject = {owner = "", id = nil, Spawn = false, ID_image = "", playerIsRight = "", lastKeyPressed = 0, verifyCoords = false}
  190.  
  191. local ballForce = {
  192.     [1] = {vx = -40, vy = -20},
  193.     [2] = {vx = -40, vy = -25},
  194.     [3] = {vx = -40, vy = -70},
  195.     [4] = {vx = -50, vy = -80},
  196.     [5] = {vx = -70, vy = -100},
  197.     [6] = {vx = -80, vy = -110},
  198.     [7] = {vx = -90, vy = -120},
  199. }
  200.  
  201. local storePointsOfPlayers = {}
  202.  
  203. local lang = {}
  204. lang.br = {
  205.     messageWelcome = "Bem vindo ao <j>Basketball Street<n> digite !help para entender melhor o jogo",
  206.     menuOpenText = "<br><br><a href='event:howtoplay'>Como jogar</a><br><a href='event:commands'>Comandos</a><br><a href='event:powers'>Poderes</a><br><a href='event:credits'>Creditos</a><br>",
  207.     howToPlayText = "<p align='center'><font size='15px'>Como jogar<br><br><p align='left'><font size='13px'>Você pega/rouba a bola com o <j>Espaço<n> e carrega a força da bola segurando o <j>Espaço<n><br><br>Para passar a bola basta usar o clique do mouse sobre o rato do seu time<br><br>as letras <j>W<n> e <j>seta pra cima<n> pressionadas duas vezes rapidamente ativa o pulo alto <br><br>Existe poderes que aparecem no mapa que seu rato pode passar para pega-los, você pode ativa-los apertando a tecla <j>M<n><br><br>Vence a equipe que fizer 10 pontos primeiro",
  208.     commandsText = "<p align='center'><font size='15px'>Comandos<br><br><p align='left'><font size='12px'><j>!Join<n> - Para entrar na partida<br><j>!Leave<n> - Para sair da partida",
  209.     creditsText = "<p align='center'><font size='15px'>Créditos<br><br><p align='left'><font size='12px'>O jogo foi desenvolvido por <ch>Refletz#6472<n> com agradecimentos especiais ao <ch>Laaagaado<n>, <ch>Esh<n>, <ch>Despyzi#7871<n> (Criador da imagem).",
  210.     closeUIText = "<p align='center'><font size='12px'><a href='event:closeWindow'>Fechar",
  211.     messageFullTeam = "Os times estão cheios",
  212.     messageRedPoint = "Ponto do vermelho",
  213.     messageBluePoint = "Ponto do azul",
  214.     messageWhoMakePoint = "feito por",
  215.     messageIfHaveAssist = "e a assistência foi do",
  216.     messageRedWinner = "<r>A equipe vermelha venceu<n>",
  217.     messageBlueWinner = "<bv>A equipe azul venceu<n>",
  218.     messageMvp = {
  219.         [1] = "O MVP da partida foi",
  220.         [2] = "com",
  221.         [3] = "pontos",
  222.     },
  223.     powersTitle = "<p align='center'><font size='15px'>Poderes",
  224.     powersList = {
  225.         [1] = {name = "<p align='center'><font size='12px'><b>Velocidade", description = "Descrição: quando ativado, será acrescentado uma velocidade a mais para a direção que seu rato estiver correndo"},
  226.         [2] = {name = "<p align='center'><font size='12px'><b>Bomba", description = "Descrição: quando ativado, será adicionado uma explosão ao redor do rato que afeta tanto os ratos quanto os objetos"},
  227.     },
  228.     buttonNext = "<p align='center'><font size='12px'>Próximo",
  229.     buttonPrev = "<p align='center'><font size='12px'>Voltar",
  230. }
  231.  
  232. lang.en = {
  233.     messageWelcome = "Welcome to <j>Basketball Street<n> type !help to understand the game",
  234.     menuOpenText = "<br><br><a href='event:howtoplay'>How to play</a><br><a href='event:commands'>Commands</a><br><a href='event:powers'>Powers</a><br><a href='event:credits'>Credits</a><br>",
  235.     howToPlayText = "<p align='center'><font size='15px'>How to play<br><br><p align='left'><font size='13px'>You can catch/steal the ball with <j>Space<n> and carry the power of the ball pressing <j>Space<n><br><br>For pass the ball just use click of mouse on rat of your team<br><br>the letters <j>W<n> and <j>Up arrow<n> pressed two times quickly, activates the high jump <br><br>Exist powers that on the map your rat can pass to catch them, you can activate pressing the key <j>M<n><br><br>The team that scored 10 points first wins.",
  236.     commandsText = "<p align='center'><font size='15px'>Commands<br><br><p align='left'><font size='12px'><j>!Join<n> - For join in the match <br><j>!Leave<n> - For leave of the match",
  237.     creditsText = "<p align='center'><font size='15px'>Credits<br><br><p align='left'><font size='12px'>The game was developed by <ch>Refletz#6472<n> with special thanks to <ch>Laaagaado<n>, <ch>Esh<n>, <ch>Despyzi#7871<n> (Image creator).",
  238.     closeUIText = "<p align='center'><font size='12px'><a href='event:closeWindow'>Close",
  239.     messageFullTeam = "The teams are full",
  240.     messageRedPoint = "Red scored",
  241.     messageBluePoint = "Blue scored",
  242.     messageWhoMakePoint = "scored by",
  243.     messageIfHaveAssist = "and the assist is",
  244.     messageRedWinner = "<r>The red team won<n>",
  245.     messageBlueWinner = "<bv>The blue team won<n>",
  246.     messageMvp = {
  247.         [1] = "The MVP of the match is",
  248.         [2] = "with",
  249.         [3] = "points",
  250.     },
  251.     powersTitle = "<p align='center'><font size='15px'>Powers",
  252.     powersList = {
  253.         [1] = {name = "<p align='center'><font size='12px'><b>Speed", description = "Description: when activated, an extra speed will be added to the direction your mouse is running"},
  254.         [2] = {name = "<p align='center'><font size='12px'><b>Bomb", description = "Description: when activated, an explosion around the mouse will be added that affects both mice and objects"},
  255.     },
  256.     buttonNext = "<p align='center'><font size='12px'>Next",
  257.     buttonPrev = "<p align='center'><font size='12px'>Previous",
  258. }
  259.  
  260. if tfm.get.room.language == "br" then
  261.     trad = lang.br 
  262. elseif tfm.get.room.language == "en" then
  263.     trad = lang.en
  264. else
  265.     trad = lang.en
  266. end
  267.  
  268. local playerLanguage = {}
  269. local playerImage = {}
  270. local wallJumpEvent = {}
  271.  
  272. local forceIndex = 0
  273.  
  274. local shootEvent = {x = 0, y = 0}
  275.  
  276. local teamRed = {
  277.     [1] = {player = ""},
  278.     [2] = {player = ""},
  279.     [3] = {player = ""},
  280. }
  281.  
  282. local teamBlue = {
  283.     [1] = {player = ""},
  284.     [2] = {player = ""},
  285.     [3] = {player = ""},
  286. }
  287.  
  288. local playersJoined = {}
  289. local playerTeam = {}
  290. local playersActions = {}
  291. local pagePowersCount = {}
  292. local pagePowersImages = {}
  293.  
  294. gameStats = {canPass = true, canCatchBall = true, canPowerTheBall = true, LastShoot = {name = "", x = 0}, LastPass = "", powerDelayOcurrency = false, powerShootEvent = false, loopCordinatesOfBall = true, ocurrencyLoop8th = 0, forceIndex = 0, spacePressed = false}
  295. local powers = {
  296.     [1] = {powerName = "Speed", image = "17c433ac5d5.png"},
  297.     [2] = {powerName = "Explosion", image = "17c3eb819c9.png"}
  298. }
  299.  
  300. local imagesPowersStorage = {}
  301. local imagePower = { [1] = {image = "", powerIndex = 0} }
  302. local invetoryPlayer = {}
  303.  
  304. local teamsX_textarea = {70, 240, 410}
  305. local distanceToCatch = {x = 35, y = 40}
  306. local playerDirection = {x1 = 0, x2 = 0}
  307.  
  308. for name, data in pairs(tfm.get.room.playerList) do
  309.     playersJoined[name] = false
  310.     playerTeam[name] = {}
  311.     invetoryPlayer[name] = {powerIndex = 0, image = "", lastKeyPressed = 0, powerBall = false}
  312.     playerLanguage[name] = {tr = trad, name}
  313.     playerImage[name] = {}
  314.     wallJumpEvent[name] = {firstJump = false, delayWallJump = false}
  315.     storePointsOfPlayers[name] = {points = 0}
  316.     pagePowersCount[name] = 1
  317.     pagePowersImages[name] = {}
  318. end
  319.  
  320. function separateThePowersListInPages()
  321.     local count = trad.powersList
  322.     local pages = {}
  323.     for i = 1, #count do
  324.         if i % 2 == 0 then
  325.             pages[#pages + 1] = {i - 1, i}
  326.         elseif i % 2 == 1 and i == #count then
  327.             pages[#pages + 1] = {i}
  328.         end
  329.     end
  330.     return pages
  331. end
  332.  
  333. local pagesList = separateThePowersListInPages()
  334.  
  335. function ui.addWindow(id, text, player, x, y, width, height, alpha, corners, closeButton, buttonText)
  336.     id = tostring(id)
  337.     ui.addTextArea(id.."000000000", "", player, x, y, width, height, 0x573926, 0x573926, alpha, true)
  338.     ui.addTextArea(id.."0", "", player, x+1, y+1, width-2, height-2, 0x8a583c, 0x8a583c, alpha, true)
  339.     ui.addTextArea(id.."00", "", player, x+3, y+3, width-6, height-6, 0x2b1f19, 0x2b1f19, alpha, true)
  340.     ui.addTextArea(id.."000", "", player, x+4, y+4, width-8, height-8, 0xc191c, 0xc191c, alpha, true)
  341.     ui.addTextArea(id.."0000", "", player, x+5, y+5, width-10, height-10, 0x2d5a61, 0x2d5a61, alpha, true)
  342.     ui.addTextArea(id.."00000", text, player, x+5, y+6, width-10, height-12, 0x142b2e, 0x142b2e, alpha, true)
  343.     local imageId = {}
  344.     if corners then
  345.         table.insert(imageId, tfm.exec.addImage("155cbe97a3f.png", "&1", x-7, (y+height)-22, player))
  346.         table.insert(imageId, tfm.exec.addImage("155cbe99c72.png", "&1", x-7, y-7, player))
  347.         table.insert(imageId, tfm.exec.addImage("155cbe9bc9b.png", "&1", (x+width)-20, (y+height)-22, player))
  348.         table.insert(imageId, tfm.exec.addImage("155cbea943a.png", "&1", (x+width)-20, y-7, player))
  349.     end
  350.     if closeButton then
  351.         ui.addTextArea(id.."000000", "", player, x+8, y+height-22, width-16, 13, 0x7a8d93, 0x7a8d93, alpha, true)
  352.         ui.addTextArea(id.."0000000", "", player, x+9, y+height-21, width-16, 13, 0xe1619, 0xe1619, alpha, true)
  353.         ui.addTextArea(id.."00000000", "", player, x+9, y+height-21, width-17, 12, 0x314e57, 0x314e57, alpha, true)
  354.         ui.addTextArea(id.."", buttonText, player, x+9, y+height-24, width-17, nil, 0x314e57, 0x314e57, 0, true)
  355.     end
  356.     return imageId
  357. end
  358.  
  359. function buttonNextOrPrev(id, name, x, y, width, height, alpha, text)
  360.     id = tostring(id)
  361.     ui.addTextArea(id.."0000000000", "", name, x+8, y+height-22, width-16, 13, 0x7a8d93, 0x7a8d93, alpha, true)
  362.     ui.addTextArea(id.."00000000000", "", name, x+9, y+height-21, width-16, 13, 0xe1619, 0xe1619, alpha, true)
  363.     ui.addTextArea(id.."000000000000", "", name, x+9, y+height-21, width-17, 12, 0x314e57, 0x314e57, alpha, true)
  364.     ui.addTextArea(id.."0000000000000", text, name, x+9, y+height-24, width-17, nil, 0x314e57, 0x314e57, 0, true)
  365. end
  366.  
  367. function init()
  368.     if imagePower[1].image ~= "" then tfm.exec.removeImage(imagePower[1].image) end
  369.     for name, data in pairs(tfm.get.room.playerList) do
  370.         tfm.exec.setPlayerScore(name, 0, false)
  371.         storePointsOfPlayers[name].points = 0
  372.     end
  373.     initTimer = os.time() + 15000
  374.     redPoints = 0
  375.     bluePoints = 0
  376.     winscore = 10
  377.     updateTables()
  378.     tfm.exec.newGame('<C><P F="0" L="1200" /><Z><S><S L="1200" H="10" X="600" Y="400" T="7" P="0,0,0.1,0.2,0,0,0,0" /><S L="10" H="405" X="1195" Y="203" T="0" m="" P="0,0,0.3,0.2,0,0,0,0" /><S L="10" H="408" X="3" Y="203" T="0" m="" P="0,0,0.3,0.2,0,0,0,0" /><S L="1200" H="10" X="600" Y="3" T="0" m="" P="0,0,0.3,0.2,0,0,0,0" /><S L="30" H="294" X="24" Y="250" T="9" m="" P="0,0,,,,0,0,0" /><S m="" L="522" H="10" X="329" Y="102" T="0" P="0,0,0.3,0.2,0,0,0,0" /><S m="" L="100" X="512" H="23" Y="379" T="0" P="0,0,0.3,0.2,0,0,0,0" /></S><D><DS Y="380" X="251" /><P X="738" Y="394" T="157" P="0,0" /><P X="514" Y="391" T="238" P="0,0" /><P X="515" Y="394" T="193" P="1,0" /><P X="627" Y="395" T="253" P="0,0" /><P X="880" Y="395" T="253" P="0,0" /><P X="819" Y="395" T="254" P="0,0" /><P X="328" Y="396" T="254" P="0,0" /><P X="154" Y="395" T="254" P="0,0" /><P X="1006" Y="394" T="274" P="0,0" /><P X="1119" Y="395" T="275" P="0,0" /><P X="758" Y="94" T="156" P="0,0" /><P X="954" Y="149" T="155" P="0,0" /><P X="984" Y="90" T="154" P="0,0" /><P X="948" Y="396" T="8" P="0,0" /><P X="844" Y="393" T="10" P="0,0" /></D><O /></Z></C>')
  379.     ui.setMapName("<CH> Basketball Street<n>")
  380.     local x = 70
  381.     ui.addTextArea(0, "", nil, 50, 100, 540, 200, 0x324650, 0x3A495C, 1, false)
  382.     ui.addTextArea(-1, "<p align='center'>The game will start in", nil, 50, 100, 540, 15, 0x324650, 0x3A495C, 0, false)
  383.     for i = 1, 3 do
  384.         ui.addTextArea(i, "<br><p align='center'><font size='15px'><a href='event:joinRed"..i.."'>Join", nil, x, 150, 150, 50, 0xEB4848, 0xEE1313, 1, false)
  385.         x = x + 170
  386.     end
  387.     local x = 70
  388.     for i = 1, 3 do
  389.         ui.addTextArea(i + 3, "<br><p align='center'><font size='15px'><a href='event:joinBlue"..i.."'>Join", nil, x, 220, 150, 50, 0x2167ED, 0xfff, 1, false)
  390.         x = x + 170
  391.     end
  392.     ui.addWindow(7, "<p align='center'><font size='13px'><a href='event:menuOpen'>Menu", nil, 5, 15, 100, 30, 1, false, false, _)
  393.     mode = "start"
  394. end
  395.  
  396. function updateTables()
  397.     teamRed = {
  398.         [1] = {player = ""},
  399.         [2] = {player = ""},
  400.         [3] = {player = ""},
  401.     }
  402.     teamBlue = {
  403.         [1] = {player = ""},
  404.         [2] = {player = ""},
  405.         [3] = {player = ""},
  406.     }
  407.     playersJoined = {}
  408.     playerTeam = {}
  409.     playersActions = {}
  410.     invetoryPlayer = {}
  411.     playerDirection = {x1 = 0, x2 = 0}
  412.     gameStats = {canPass = true, canCatchBall = true, canPowerTheBall = true, LastShoot = {name = "", x = 0}, LastPass = "", powerDelayOcurrency = false, powerShootEvent = false, loopCordinatesOfBall = true, ocurrencyLoop8th = 0, forceIndex = 0, spacePressed = false, CatchTheBallBeforeStarting = true}
  413.     for name, data in pairs(tfm.get.room.playerList) do
  414.         playersJoined[name] = false
  415.         playerTeam[name] = {}
  416.         invetoryPlayer[name] = {powerIndex = 0, image = "", lastKeyPressed = 0, powerBall = false}
  417.     end
  418. end
  419.  
  420. function eventNewPlayer(name)
  421.     playersJoined[name] = false
  422.     playerTeam[name] = {}
  423.     storePointsOfPlayers[name] = {points = 0}
  424.     wallJumpEvent[name] = {firstJump = false, delayWallJump = false}
  425.     invetoryPlayer[name] = {powerIndex = 0, image = "", lastKeyPressed = 0, powerBall = false}
  426.     playerLanguage[name] = {tr = trad, name}
  427.     playerImage[name] = {}
  428.     tfm.exec.respawnPlayer(name)
  429.     pagePowersCount[name] = 1
  430.     pagePowersImages[name] = {}
  431.     tfm.exec.chatMessage(trad.messageWelcome, name)
  432.     if mode == "start" then
  433.         local x = 70
  434.         ui.addTextArea(0, "", name, 50, 100, 540, 200, 0x324650, 0x3A495C, 1, false)
  435.         for i = 1, 3 do
  436.             if teamRed[i].player == "" then
  437.                 ui.addTextArea(i, "<br><p align='center'><font size='15px'><a href='event:joinRed"..i.."'>Join", name, x, 150, 150, 50, 0xEB4848, 0xEE1313, 1, false)
  438.             else
  439.                 ui.addTextArea(i, "<br><p align='center'><font size='15px'><a href='event:leaveRed"..i.."'>"..slicedName(teamRed[i].player), name, x, 150, 150, 50, 0x9E0707, 0x535251, 1, false)
  440.             end
  441.             if teamBlue[i].player == "" then
  442.                 ui.addTextArea(i + 3, "<br><p align='center'><font size='15px'><a href='event:joinBlue"..i.."'>Join", name, x, 220, 150, 50, 0x2167ED, 0xfff, 1, false)
  443.             else
  444.                 ui.addTextArea(i + 3, "<br><p align='center'><font size='15px'><a href='event:leaveBlue"..i.."'>"..slicedName(teamBlue[i].player), name, x, 220, 150, 50, 0x0C409A, 0x535251, 1, false)
  445.             end
  446.             x = x + 170
  447.         end
  448.     elseif mode ~= "start" then
  449.         ui.setMapName("<N><ch>#Basketball Street<n>   <G>|                                                    <r>Red<n> "..redPoints.."<G> | <bv>Blue<n> "..bluePoints.."<")
  450.     end
  451. end
  452.  
  453. function eventPlayerLeft(name)
  454.     local x = 70
  455.     storePointsOfPlayers[name].points = 0
  456.     if mode == "start" then
  457.         for i = 1, 3 do
  458.             if teamRed[i].player == name then
  459.                 teamRed[i].player = ""
  460.                 ui.addTextArea(i, "<br><p align='center'><font size='15px'><a href='event:joinRed"..i.."'>Join", nil, x, 150, 150, 50, 0xEB4848, 0xEE1313, 1, false)
  461.             end
  462.             if teamBlue[i].player == name then
  463.                 teamBlue[i].player = ""
  464.                 ui.addTextArea(i + 3, "<br><p align='center'><font size='15px'><a href='event:joinBlue"..i.."'>Join", nil, x, 220, 150, 50, 0x2167ED, 0xfff, 1, false)
  465.             end
  466.             x = x + 170
  467.         end
  468.     elseif mode ~= "start" then
  469.         if ballObject.owner == name then
  470.             system.bindMouse(ballObject.owner, false)
  471.             eventKeyBoardControl(ballObject.owner, false)
  472.             removeTimer("powerShoot")
  473.             gameStats.powerShootEvent = false
  474.             tfm.exec.removeImage(idImage)
  475.             tfm.exec.removeImage(ballObject.ID_image)
  476.             ui.removeTextArea(999)
  477.             ui.removeTextArea(1000)
  478.             ui.removeTextArea(1001)
  479.             ballObject.id = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, true)
  480.             tfm.exec.moveObject(ballObject.id, tfm.get.room.playerList[ballObject.owner].x, tfm.get.room.playerList[ballObject.owner].y, false, 0, 0, false, 0, false)
  481.             ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
  482.             ballObject.Spawn = true
  483.             ballObject.owner = ""
  484.         end
  485.         for i = 1, 3 do
  486.             if teamRed[i].player == name then
  487.                 playersActions[teamRed[i].player] = {canCatch = true}
  488.                 setKeysEvent(teamRed[i].player, false, false)
  489.                 playerTeam[teamRed[i].player].team = ""
  490.                 teamRed[i].player = ""
  491.             end
  492.             if teamBlue[i].player == name then
  493.                 playersActions[teamBlue[i].player] = {canCatch = true}
  494.                 setKeysEvent(teamBlue[i].player, false, false)
  495.                 playerTeam[teamBlue[i].player].team = ""
  496.                 teamBlue[i].player = ""
  497.             end
  498.         end
  499.     end
  500. end
  501.  
  502. function eventTextAreaCallback(id, name, c)
  503.     if string.sub(c, 1, 7) == "joinRed" and type(tonumber(string.sub(c, 8))) == "number" and not playersJoined[name] then
  504.         playersJoined[name] = true
  505.         teamRed[tonumber(string.sub(c, 8))].player = name
  506.         ui.addTextArea(tonumber(string.sub(c, 8)), "<br><p align='center'><font size='15px'><a href='event:leaveRed"..tonumber(string.sub(c, 8)).."'>"..slicedName(teamRed[tonumber(string.sub(c, 8))].player), nil, teamsX_textarea[tonumber(string.sub(c, 8))], 150, 150, 50, 0x9E0707, 0x535251, 1, false)
  507.     elseif string.sub(c, 1, 8) == "joinBlue" and type(tonumber(string.sub(c, 9))) == "number" and not playersJoined[name] then
  508.         playersJoined[name] = true
  509.         teamBlue[tonumber(string.sub(c, 9))].player = name
  510.         ui.addTextArea(tonumber(string.sub(c, 9)) + 3, "<br><p align='center'><font size='15px'><a href='event:leaveBlue"..tonumber(string.sub(c, 9)).."'>"..slicedName(teamBlue[tonumber(string.sub(c, 9))].player), nil, teamsX_textarea[tonumber(string.sub(c, 9))], 220, 150, 50, 0x0C409A, 0x535251, 1, false)
  511.     elseif string.sub(c, 1, 8) == "leaveRed" and type(tonumber(string.sub(c, 9))) == "number" and teamRed[tonumber(string.sub(c, 9))].player == name then
  512.         playersJoined[name] = false
  513.         teamRed[tonumber(string.sub(c, 9))].player = ""
  514.         ui.addTextArea(tonumber(string.sub(c, 9)), "<br><p align='center'><font size='15px'><a href='event:joinRed"..tonumber(string.sub(c, 9)).."'>Join", nil, teamsX_textarea[tonumber(string.sub(c, 9))], 150, 150, 50, 0xEB4848, 0xEE1313, 1, false)
  515.     elseif string.sub(c, 1, 9) == "leaveBlue" and type(tonumber(string.sub(c, 10))) == "number" and teamBlue[tonumber(string.sub(c, 10))].player == name then
  516.         playersJoined[name] = false
  517.         teamBlue[tonumber(string.sub(c, 10))].player = ""
  518.         ui.addTextArea(tonumber(string.sub(c, 10)) + 3, "<br><p align='center'><font size='15px'><a href='event:joinBlue"..tonumber(string.sub(c, 10)).."'>Join", nil, teamsX_textarea[tonumber(string.sub(c, 10))], 220, 150, 50, 0x2167ED, 0xfff, 1, false)
  519.     elseif c == "menuOpen" then
  520.         ui.addWindow(7, "<p align='center'><font size='13px'><a href='event:menuClose'>Menu</a>"..playerLanguage[name].tr.menuOpenText, name, 5, 15, 100, 120, 1, false, false, _)
  521.     elseif c == "menuClose" then
  522.         ui.addWindow(7, "<p align='center'><font size='13px'><a href='event:menuOpen'>Menu", name, 5, 15, 100, 30, 1, false, false, _)
  523.     elseif c == "howtoplay" then
  524.         removeImageOfTheWindow(name)
  525.         removeImageOfThePowersWindow(name)
  526.         playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.howToPlayText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
  527.     elseif c == "commands" then
  528.         removeImageOfTheWindow(name)
  529.         removeImageOfThePowersWindow(name)
  530.         playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.commandsText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
  531.     elseif c == "powers" then
  532.         removeImageOfTheWindow(name)
  533.         removeImageOfThePowersWindow(name)
  534.         playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.powersTitle, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
  535.         createWindowPowers(name)
  536.     elseif c == "credits" then
  537.         removeImageOfThePowersWindow(name)
  538.         removeImageOfTheWindow(name)
  539.         playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.creditsText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
  540.     elseif c == "closeWindow" then
  541.         closeWindow(8, name)
  542.         for i = -1, -6, -1 do
  543.             closeWindow(i, name)
  544.         end
  545.         for i = -7, -8, -1 do
  546.             closeButtonNextOrPrev(i, name)
  547.         end
  548.         removeImageOfThePowersWindow(name)
  549.         removeImageOfTheWindow(name)
  550.     end
  551. end
  552.  
  553. function createWindowPowers(name)
  554.     ui.addWindow(-1, "", name, 150, 95, 280, 180, 1, false, false)
  555.     ui.addWindow(-2, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][1]].name, name, 160, 105, 260, 30, 1, false, false)
  556.     ui.addWindow(-3, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][1]].description, name, 160, 155, 260, 110, 1, false, false)
  557.     pagePowersImages[name][1] = tfm.exec.addImage("17c433ac5d5.png", "&2", 380, 105, name)
  558.     if #pagesList[pagePowersCount[name]] == 2 then
  559.         ui.addWindow(-4, "", name, 470, 95, 280, 180, 1, false, false)
  560.         ui.addWindow(-5, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][2]].name, name, 480, 105, 260, 30, 1, false, false)
  561.         ui.addWindow(-6, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][2]].description, name, 480, 155, 260, 110, 1, false, false)
  562.         pagePowersImages[name][2] = tfm.exec.addImage("17c3eb819c9.png", "&3", 700, 105, name)
  563.     end
  564.     pagePowers(name)
  565. end
  566.  
  567. function pagePowers(name)
  568.     if pagePowersCount[name] > 1 and pagePowersCount[name] < #pageList then
  569.         buttonNextOrPrev(-8, name, 540, 300, 200, 30, 1, "<a href='event:next'>"..playerLanguage[name].tr.buttonNext.."</a>")
  570.     else
  571.         buttonNextOrPrev(-8, name, 540, 300, 200, 30, 1, "<n2>"..playerLanguage[name].tr.buttonNext.."<n>")
  572.     end
  573.     if pagePowersCount[name] > 1 then
  574.         buttonNextOrPrev(-7, name, 160, 300, 200, 30, 1, "<a href='event:prev'>"..playerLanguage[name].tr.buttonPrev.."</a>")
  575.     else
  576.         buttonNextOrPrev(-7, name, 160, 300, 200, 30, 1, "<n2>"..playerLanguage[name].tr.buttonPrev.."<n>")
  577.     end
  578. end
  579.  
  580. function removeImageOfTheWindow(name)
  581.     if #playerImage[name] > 0 then
  582.         for i = 1, #playerImage[name] do
  583.             tfm.exec.removeImage(playerImage[name][i])
  584.         end
  585.     end
  586. end
  587.  
  588. function removeImageOfThePowersWindow(name)
  589.     for i = 1, #pagePowersImages[name] do
  590.         tfm.exec.removeImage(pagePowersImages[name][i])
  591.     end
  592. end
  593.  
  594. function closeWindow(id, name)
  595.     local id = tostring(id)
  596.     local str = "0"
  597.     ui.removeTextArea(id, name)
  598.     for i = 1, 9 do
  599.         ui.removeTextArea(id..""..str.."", name)
  600.         str = ""..str.."0"
  601.     end
  602. end
  603.  
  604. function closeButtonNextOrPrev(id, name)
  605.     local id = tostring(id)
  606.     local str = "0000000000"
  607.     ui.removeTextArea(id, name)
  608.     for i = 1, 4 do
  609.         ui.removeTextArea(id..""..str.."", name)
  610.         str = ""..str.."0"
  611.     end
  612. end
  613.  
  614. function closeWindow(id, name)
  615.     local id = tostring(id)
  616.     local str = "0"
  617.     ui.removeTextArea(id, name)
  618.     for i = 1, 9 do
  619.         ui.removeTextArea(id..""..str.."", name)
  620.         str = ""..str.."0"
  621.     end
  622. end
  623.  
  624. function slicedName(name)
  625.     local name = ""..string.sub(name, 1, (string.len(name)- 5))..""
  626.     return name
  627. end
  628.  
  629. function eventLoop(elapsedTime, remainingTime)
  630.     timersLoop()
  631.     if mode == "start" then
  632.         local x = math.ceil((initTimer - os.time())/1000)
  633.         local c = string.format("%d", x)
  634.         ui.addTextArea(-1, "<p align='center'>The game will start in "..c.."s", nil, 50, 100, 540, 20, 0x324650, 0x3A495C, 0, false)
  635.         if x == 0 then
  636.             quantityPlayersJoined()
  637.             if quantity.red >= 1 and quantity.blue >= 1 then
  638.                 startGame()
  639.             else
  640.                 initTimer = os.time() + 15000
  641.             end
  642.         end
  643.     elseif mode == "gameStarted" then
  644.         if not gameStats.powerDelayOcurrency then
  645.             gameStats.powerDelayOcurrency = true
  646.             createPower()
  647.         end
  648.         if ballObject.verifyCoords then
  649.             if tfm.get.room.objectList[ballObject.id].x == 105 and tfm.get.room.objectList[ballObject.id].y == 187 then
  650.                 eventPoint()
  651.             end
  652.         end
  653.     elseif mode == "winner" then
  654.         local x = math.ceil((winnerTimer - os.time())/1000)
  655.         local c = string.format("%d", x)
  656.         if x == 0 then
  657.             clearTimers()
  658.             init()
  659.         end
  660.     end
  661. end
  662.  
  663. function quantityPlayersJoined()
  664.     quantity.red = 0
  665.     quantity.blue = 0
  666.     for i = 1, 3 do
  667.         if teamRed[i].player ~= "" then
  668.             quantity.red = quantity.red + 1
  669.         end
  670.         if teamBlue[i].player ~= "" then
  671.             quantity.blue = quantity.blue + 1
  672.         end
  673.     end
  674.     return quantity
  675. end
  676.  
  677. function startGame()    
  678.     tfm.exec.newGame('<C><P /><Z><S><S i="0,-390,17bd7bf6780.jpg" L="799" H="10" c="3" Y="387" T="0" X="401" P="0,0,0.2,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="800" X="401" c="3" Y="117" T="0" m="" H="10" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" H="103" c="3" Y="71" T="0" m="" X="3" /><S P="0,0,0.3,0.2,0,0,0,0" L="804" H="10" c="3" Y="24" T="0" m="" X="400" /><S X="57" L="10" H="360" c="1" Y="212" T="0" m="" P="0,0,0,0.2,0,0,0,0" /><S P="0,0,0,0.2,0,0,0,0" L="10" H="500" c="3" Y="141" T="0" m="" X="796" /><S P="0,0,0.3,0.3,-40,0,0,0" L="150" X="113" Y="-11" T="0" m="" H="10" /><S P="0,0,0.3,0.2,0,0,0,0" L="641" H="10" Y="-55" T="0" m="" X="484" /><S P="0,0,0.3,0.6,0,0,0,0" L="20" X="70" Y="152" T="0" m="" H="10" /><S P="0,0,0.3,0.6,-15,0,0,0" L="10" X="82" Y="178" T="0" m="" H="61" /><S P="0,0,0.3,0.6,0,0,0,0" L="40" X="105" Y="208" T="0" m="" H="10" /><S P="0,0,0.3,0.6,15,0,0,0" L="10" X="128" c="1" Y="178" T="0" m="" H="61" /><S P="0,0,0.2,0.8,0,0,0,0" L="799" H="10" c="2" Y="392" T="0" m="" X="403" /><S P="0,0,,,,0,0,0" L="40" X="105" Y="176" T="9" m="" H="36" /><S P="0,0,0.3,0.2,-10,0,0,0" L="200" X="225" c="2" Y="-40" T="0" m="" H="10" /><S P="0,0,0,0.2,0,0,0,0" L="10" X="146" c="3" Y="138" T="0" m="" H="42" /><S H="30" L="10" X="62" c="2" Y="92" T="1" m="" P="0,0,0,0.6,-17,0,0,0" /><S P="0,0,0.3,1.5,30,0,0,0" L="10" H="61" c="3" Y="184" T="0" m="" X="131" /><S H="500" L="10" X="796" c="2" Y="141" T="0" m="" P="0,0,0.3,0.7,0,0,0,0" /><S P="0,0,0.3,0.7,0,0,0,0" L="10" X="57" c="2" Y="141" T="0" m="" H="500" /><S m="" L="10" H="10" X="61" Y="140" T="0" P="0,0,0,0.2,0,0,0,0" /></S><D><DS Y="98" X="407" /></D><O /></Z></C>')
  679.     for i = 1, 3 do
  680.         if teamRed[i].player ~= "" then
  681.             playersActions[teamRed[i].player] = {canCatch = true}
  682.             setKeysEvent(teamRed[i].player, true, false)
  683.             playerTeam[teamRed[i].player].team = "Red"
  684.             tfm.exec.movePlayer(teamRed[i].player, math.random(240, 700), 368)
  685.             tfm.exec.setNameColor(teamRed[i].player, 0xEB4848)
  686.             windowUIPowersShow(teamRed[i].player)
  687.         end
  688.         if teamBlue[i].player ~= "" then
  689.             playersActions[teamBlue[i].player] = {canCatch = true}
  690.             setKeysEvent(teamBlue[i].player, true, false)
  691.             playerTeam[teamBlue[i].player].team = "Blue"
  692.             tfm.exec.movePlayer(teamBlue[i].player, math.random(240, 700), 368)
  693.             tfm.exec.setNameColor(teamBlue[i].player, 0x2167ED)
  694.             windowUIPowersShow(teamBlue[i].player)
  695.         end
  696.     end
  697.     CatchTheBallBeforeStarting = addTimer(function(i)
  698.         gameStats.CatchTheBallBeforeStarting = false
  699.         if i == 1 then
  700.             gameStats.CatchTheBallBeforeStarting = true
  701.         end
  702.     end, 500, 1, "CatchTheBallBeforeStarting")
  703.     ui.setMapName("<N><ch>#Basketball Street<n>   <G>|                                                    <r>Red<n> "..redPoints.."<G> | <bv>Blue<n> "..bluePoints.."<")
  704.     spawnBall()
  705.     clearTextArea()
  706.     identifyPlayers()
  707.     timerToVerifyIfPlayerIsMovingWithBall()
  708.     mode = "gameStarted"
  709. end
  710.  
  711. function setKeysEvent(name, active, isFinish)
  712.     local keys = {1, 32, 77}
  713.     for j = 1, #keys do
  714.         system.bindKeyboard(name, keys[j], true, active)
  715.     end
  716.     system.bindKeyboard(name, 32, false, active)
  717.     if isFinish then
  718.         eventKeyBoardControl(name, active)
  719.     end
  720. end
  721.  
  722. function windowUIPowersShow(name)
  723.     ui.addTextArea(2400, "", name, 740, 130, 40, 40, 0x161616, 0x161616, 0.5, false)
  724. end
  725.  
  726. function spawnBall()
  727.     tfm.exec.addPhysicObject(1, 146, 37, {type = 14, width = 250, height = 10, miceCollision = false, groundCollision = true, angle = 90})
  728.     local velocityY = {-100, -75, -50}
  729.     ballObject.id = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, true)
  730.     tfm.exec.moveObject(ballObject.id, math.random(166, 740), math.random(153, 180), false, 0, velocityY[math.random(#velocityY)], false, 0, false)
  731.     ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
  732.     ballObject.Spawn = true
  733.     if gameStats.loopCordinatesOfBall then
  734.         gameStats.loopCordinatesOfBall = false
  735.         timerLoopToCoordinatesOfBall()
  736.     end
  737. end
  738.  
  739. function eventKeyboard(name, key, down, x, y)
  740.     if key == 32 then
  741.         if mode == "gameStarted" and ballObject.owner ~= name and playersActions[name].canCatch and gameStats.canCatchBall and down and gameStats.CatchTheBallBeforeStarting then
  742.             if x - 20 >= 180 then
  743.                 playersActions[name].canCatch = false
  744.                 getBall(name, x, y)
  745.             elseif x - 20 <= 180 and y >= 276 then
  746.                 playersActions[name].canCatch = false
  747.                 getBall(name, x, y)
  748.             end
  749.         elseif ballObject.owner ~= name and gameStats.canCatchBall and not playersActions[name].canCatch then
  750.             delayCatchEVT(name)
  751.         elseif ballObject.owner == name then
  752.             gameStats.spacePressed = down
  753.             if gameStats.spacePressed and gameStats.canPowerTheBall and not gameStats.powerShootEvent and playersActions[name].canCatch then
  754.                 local powerBars = ""
  755.                 removeTimer("powerShoot")
  756.                 ui.removeTextArea(999)
  757.                 ui.removeTextArea(1000)
  758.                 ui.removeTextArea(1001)
  759.                 if gameStats.canPowerTheBall and gameStats.spacePressed then
  760.                     powerShoot = addTimer(function(i)
  761.                         if i == 1 then
  762.                             gameStats.ocurrencyLoop8th = 0    
  763.                             gameStats.powerShootEvent = true
  764.                         end
  765.                         gameStats.forceIndex = i
  766.                         if i >= 0 and i <= (gameStats.ocurrencyLoop8th + 4) and gameStats.spacePressed then
  767.                             powerBars = powerBars.."<vp>_<n>"
  768.                             ui.addTextArea(999, "<font size='15px'>[", name, x - 35, y, 65, 20, 0x161616, 0x161616, 0.5, true)
  769.                             ui.addTextArea(1000, powerBars, name, x - 28, y, 72, 20, 0x161616, 0x161616, 0, true)
  770.                             ui.addTextArea(1001, "<font size='15px'>]", name, x + 22, y, 75, 20, 0x161616, 0x161616, 0, true)
  771.                         elseif i >= (gameStats.ocurrencyLoop8th + 5) and i <= (gameStats.ocurrencyLoop8th + 6) and gameStats.spacePressed then
  772.                             powerBars = powerBars.."<j>_<n>"
  773.                             ui.addTextArea(999, "<font size='15px'>[", name, x - 35, y, 65, 20, 0x161616, 0x161616, 0.5, true)
  774.                             ui.addTextArea(1000, powerBars, name, x - 28, y, 72, 20, 0x161616, 0x161616, 0, true)
  775.                             ui.addTextArea(1001, "<font size='15px'>]", name, x + 22, y, 75, 20, 0x161616, 0x161616, 0, true)
  776.                         elseif i == (gameStats.ocurrencyLoop8th + 7) and gameStats.spacePressed then
  777.                             powerBars = powerBars.."<r>_<n>"
  778.                             ui.addTextArea(999, "<font size='15px'>[", name, x - 35, y, 65, 20, 0x161616, 0x161616, 0.5, true)
  779.                             ui.addTextArea(1000, powerBars, name, x - 28, y, 72, 20, 0x161616, 0x161616, 0, true)
  780.                             ui.addTextArea(1001, "<font size='15px'>]", name, x + 22, y, 75, 20, 0x161616, 0x161616, 0, true)
  781.                             powerBars = ""
  782.                             delayLoopOnPowerShootTimer(ballObject.owner, i)
  783.                         else
  784.                             if (gameStats.forceIndex - gameStats.ocurrencyLoop8th) >= 0 and (gameStats.forceIndex - gameStats.ocurrencyLoop8th) <= 7 and gameStats.powerShootEvent and gameStats.canPowerTheBall and not gameStats.spacePressed and ballObject.owner == name then
  785.                                 ui.removeTextArea(999)
  786.                                 ui.removeTextArea(1000)
  787.                                 ui.removeTextArea(1001)
  788.                                 removeTimer("powerShoot")
  789.                                 playersActions[name].canCatch = false
  790.                                 gameStats.canPowerTheBall = false
  791.                                 shootTheBall(shootEvent.x, shootEvent.y, gameStats.forceIndex - gameStats.ocurrencyLoop8th, name)
  792.                             end
  793.                         end
  794.                     end, 500, 0, "powerShoot")
  795.                 end
  796.             end
  797.         end
  798.     elseif key == 0 or key == 1 or key == 2 or key == 3 then
  799.         if key == 0 or key == 2 then
  800.             invetoryPlayer[name].lastKeyPressed = key
  801.             if ballObject.owner == name then
  802.                 ballObject.lastKeyPressed = key
  803.                 if key == 2 then
  804.                     if not ballObject.playerIsRight then
  805.                         tfm.exec.removeImage(ballObject.ID_image)
  806.                         ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, 5, -15, nil, 1, 1, _, 1)
  807.                         ballObject.playerIsRight = true
  808.                     end
  809.                 elseif key == 0 then
  810.                     if ballObject.playerIsRight then
  811.                         tfm.exec.removeImage(ballObject.ID_image)
  812.                         ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, -35, -15, nil, 1, 1, _, 1)
  813.                         ballObject.playerIsRight = false
  814.                     end
  815.                 end
  816.             end
  817.         end
  818.         gameStats.playerMove = true
  819.         tfm.get.room.playerList[name].x = x
  820.         tfm.get.room.playerList[name].y = y
  821.     elseif key == 77 then
  822.         if invetoryPlayer[name].powerIndex ~= 0 then
  823.             if invetoryPlayer[name].powerIndex.powerName == "Speed" then
  824.                 if invetoryPlayer[name].lastKeyPressed == 0 then
  825.                     tfm.exec.movePlayer(name, 0, 0, true, -100, 0, false)
  826.                 elseif invetoryPlayer[name].lastKeyPressed == 2 then
  827.                     tfm.exec.movePlayer(name, 0, 0, true, 100, 0, false)
  828.                 end
  829.                 if ballObject.owner ~= name then
  830.                     eventKeyBoardControl(name, false)
  831.                 end
  832.             elseif invetoryPlayer[name].powerIndex.powerName == "Explosion" then
  833.                 tfm.exec.explosion(x, y - 10, 30, 100, false)
  834.             end
  835.             invetoryPlayer[name].powerIndex = 0
  836.             tfm.exec.removeImage(invetoryPlayer[name].image)
  837.             invetoryPlayer[name].image = ""
  838.         end
  839.     end
  840.     if key == 1 and not wallJumpEvent[name].delayWallJump then
  841.         if wallJumpEvent[name].firstJump and not wallJumpEvent[name].delayWallJump then
  842.             wallJumpEvent[name].delayWallJump = true
  843.             tfm.exec.movePlayer(name, 0, 0, true, 0, -120, true)
  844.             delayWallJump = addTimer(function(i)
  845.                 if i == 1 then
  846.                     wallJumpEvent[name].delayWallJump = false
  847.                 end
  848.             end, 2000, 1, "delayWallJump")
  849.         end
  850.         if not wallJumpEvent[name].firstJump and not wallJumpEvent[name].delayWallJump then
  851.             wallJumpEvent[name].firstJump = true
  852.             timerToExecuteFirstJump(name)
  853.         end
  854.     end
  855.     if ballObject.owner == name then
  856.         shootEvent.x = x
  857.         shootEvent.y = y
  858.     end
  859. end
  860.  
  861. function timerToExecuteFirstJump(name)
  862.     firstJump = addTimer(function(i)
  863.         if i == 1 then
  864.             wallJumpEvent[name].firstJump = false
  865.         end
  866.     end, 1000, 1, "firstJump")
  867. end
  868.  
  869. function delayLoopOnPowerShootTimer(name, indexOnPowerShoot)
  870.     pauseTimer("powerShoot")
  871.     delayLoop = addTimer(function(i)
  872.         if (gameStats.forceIndex - gameStats.ocurrencyLoop8th) >= 0 and (gameStats.forceIndex - gameStats.ocurrencyLoop8th) <= 7 and gameStats.powerShootEvent and gameStats.canPowerTheBall and not gameStats.spacePressed then
  873.             removeTimer("delayLoop")
  874.             ui.removeTextArea(999)
  875.             ui.removeTextArea(1000)
  876.             ui.removeTextArea(1001)
  877.             removeTimer("powerShoot")
  878.             playersActions[name].canCatch = false
  879.             gameStats.canPowerTheBall = false
  880.             shootTheBall(shootEvent.x, shootEvent.y, gameStats.forceIndex - gameStats.ocurrencyLoop8th, name)
  881.         end
  882.         if i == 1 then
  883.             resumeTimer("powerShoot")
  884.             if indexOnPowerShoot == 7 then
  885.                 gameStats.ocurrencyLoop8th = 7
  886.             else
  887.                 gameStats.ocurrencyLoop8th = gameStats.ocurrencyLoop8th + 7
  888.             end                
  889.             gameStats.forceIndex = indexOnPowerShoot
  890.         end
  891.     end, 1000, 1, "delayLoop")
  892. end
  893.  
  894. function delayCatchEVT(name)
  895.     delayCatch = addTimer(function(i)
  896.         if i == 1 then
  897.             playersActions[name].canCatch = true
  898.         end
  899.     end, 1500, 1, "delayCatch")
  900. end
  901.  
  902. function delayCatchEVTPowerTheBall(name)
  903.     delayCatchPower = addTimer(function(i)
  904.         if i == 1 then
  905.             playersActions[name].canCatch = true
  906.         end
  907.     end, 4500, 1, "delayCatchPower")
  908. end
  909.  
  910. function timerToVerifyIfPlayerIsMovingWithBall()
  911.     timerLoopVerify = addTimer(function(i)
  912.         if ballObject.owner ~= "" then
  913.             if gameStats.movePlayer then
  914.                 gameStats.movePlayer = false
  915.                 distanceToCatch.x = 25
  916.                 distanceToCatch.y = 25
  917.                 playerDirection.x1 = 0
  918.                 playerDirection.x2 = 0
  919.             else
  920.                 distanceToCatch.x = 35
  921.                 distanceToCatch.y = 45
  922.                 if invetoryPlayer[ballObject.owner].lastKeyPressed == 0 then
  923.                     playerDirection.x1 = -10
  924.                     playerDirection.x2 = 0
  925.                 elseif invetoryPlayer[ballObject.owner].lastKeyPressed == 2 then
  926.                     playerDirection.x1 = 0
  927.                     playerDirection.x2 = 10
  928.                 end
  929.             end
  930.         end
  931.     end, 1500, 0, "timerLoopVerify")
  932. end
  933.  
  934. function timerDelayPowerTheBall()
  935.     gameStats.canPowerTheBall = false
  936.     powerTheBall = addTimer(function(i)
  937.         if i == 1 then
  938.             gameStats.canPowerTheBall = true
  939.             gameStats.powerShootEvent = false
  940.         end
  941.     end, 500, 1, "powerTheBall")
  942. end
  943.  
  944. function eventMouse(name, x, y)
  945.     print(x)
  946.     print(y)
  947.     if name == ballObject.owner and gameStats.canPass then
  948.         passToTeamPlayer(name, x, y, playerTeam[name].team)
  949.     end
  950. end
  951.  
  952. function getBall(name, x, y)
  953.     if ballObject.Spawn then
  954.         if ballObject.owner == "" then
  955.             local ballX1 = (tfm.get.room.objectList[ballObject.id].x - tfm.get.room.objectList[ballObject.id].vx) - 60
  956.             local ballX2 = (tfm.get.room.objectList[ballObject.id].x + tfm.get.room.objectList[ballObject.id].vx) + 60
  957.             local ballY1 = (tfm.get.room.objectList[ballObject.id].y - tfm.get.room.objectList[ballObject.id].vy) - 60
  958.             local ballY2 = (tfm.get.room.objectList[ballObject.id].y + tfm.get.room.objectList[ballObject.id].vy) + 60
  959.             if x + 25 >= ballX1 and x - 25 <= ballX2 and y + 25 >= ballY1 and y - 25 <= ballY2 then
  960.                 ballWithPlayer(name)
  961.             end
  962.         end
  963.     else
  964.         if ballObject.owner ~= "" and ballObject.owner ~= name and playerTeam[ballObject.owner].team ~= playerTeam[name].team then
  965.             local ballX1 = (tfm.get.room.playerList[ballObject.owner].x - tfm.get.room.playerList[ballObject.owner].vx - distanceToCatch.x - playerDirection.x1)
  966.             local ballX2 = (tfm.get.room.playerList[ballObject.owner].x + tfm.get.room.playerList[ballObject.owner].vx + distanceToCatch.x + playerDirection.x2)
  967.             local ballY1 = (tfm.get.room.playerList[ballObject.owner].y - tfm.get.room.playerList[ballObject.owner].vy - distanceToCatch.y)
  968.             local ballY2 = (tfm.get.room.playerList[ballObject.owner].y + tfm.get.room.playerList[ballObject.owner].vy + distanceToCatch.y)
  969.             if x + 10 >= ballX1 and x - 10 <= ballX2 and y + 10 >= ballY1 and y - 10 <= ballY2 then
  970.                 ballCatch(name)
  971.             end
  972.         end
  973.     end
  974. end
  975.  
  976. function ballWithPlayer(name)
  977.     tfm.exec.removePhysicObject(1)
  978.     ballObject.verifyCoords = false
  979.     ballObject.Spawn = false
  980.     canCatchBall()
  981.     tfm.exec.removeObject(ballObject.id)
  982.     idImage = tfm.exec.addImage("175aa78bb80.png", "$"..name, -45, -125, nil)
  983.     ballObject.owner = name
  984.     system.bindMouse(name, true)
  985.     playersActions[name].canCatch = true
  986.     showImageBallWithPlayer(name)
  987.     eventKeyBoardControl(name, true)
  988. end
  989.  
  990. function ballCatch(name)
  991.     system.bindMouse(ballObject.owner, false)
  992.     eventKeyBoardControl(ballObject.owner, false)
  993.     removeTimer("powerShoot")
  994.     gameStats.powerShootEvent = false
  995.     ui.removeTextArea(999)
  996.     ui.removeTextArea(1000)
  997.     ui.removeTextArea(1001)
  998.     ballObject.verifyCoords = false
  999.     ballObject.Spawn = false
  1000.     forceIndex = 0
  1001.     canCatchBall()
  1002.     tfm.exec.removeImage(idImage)
  1003.     tfm.exec.removeImage(ballObject.ID_image)
  1004.     delayCatchEVT(ballObject.owner)
  1005.     idImage = tfm.exec.addImage("175aa78bb80.png", "$"..name, -45, -125, nil)
  1006.     ballObject.owner = name
  1007.     playersActions[name].canCatch = true
  1008.     showImageBallWithPlayer(name)
  1009.     system.bindMouse(ballObject.owner, true)
  1010.     eventKeyBoardControl(ballObject.owner, true)
  1011. end
  1012.  
  1013. function timerLoopToCoordinatesOfBall()
  1014.     delayToStart = addTimer(function(i)
  1015.         coordinatesOfBall = addTimer(function(i)
  1016.             if ballObject.Spawn then
  1017.                 if tfm.get.room.objectList[ballObject.id].vx > 0 then
  1018.                     tfm.get.room.objectList[ballObject.id].x = tfm.get.room.objectList[ballObject.id].x + (tfm.get.room.objectList[ballObject.id].vx * 60)
  1019.                 elseif tfm.get.room.objectList[ballObject.id].vx < 0 then
  1020.                     tfm.get.room.objectList[ballObject.id].x = tfm.get.room.objectList[ballObject.id].x - (tfm.get.room.objectList[ballObject.id].vx * 60)
  1021.                 end
  1022.                 if tfm.get.room.objectList[ballObject.id].vy > 0 then
  1023.                     tfm.get.room.objectList[ballObject.id].y = tfm.get.room.objectList[ballObject.id].y + (tfm.get.room.objectList[ballObject.id].vy * 60)
  1024.                 elseif tfm.get.room.objectList[ballObject.id].vy < 0 then
  1025.                     tfm.get.room.objectList[ballObject.id].y = tfm.get.room.objectList[ballObject.id].y - (tfm.get.room.objectList[ballObject.id].vy * 60)
  1026.                 end
  1027.                 verifyCollisionOfBallWithWall()
  1028.             end
  1029.         end, 1000, 0, "coordinatesOfBall")
  1030.     end, 2500, 1, "delayToStart")
  1031. end
  1032.  
  1033. function verifyCollisionOfBallWithWall()
  1034.     --this function is responsible for verifying if the function of calculating the coordinates of the ball goes beyond the limits of the map
  1035.     if tfm.get.room.objectList[ballObject.id].x >= 751 then
  1036.         tfm.get.room.objectList[ballObject.id].x = 751
  1037.     elseif tfm.get.room.objectList[ballObject.id].x <= 102 and tfm.get.room.objectList[ballObject.id].y > 220 then
  1038.         tfm.get.room.objectList[ballObject.id].x = 102
  1039.     end
  1040.     if tfm.get.room.objectList[ballObject.id].y >= 268 then
  1041.         tfm.get.room.objectList[ballObject.id].y = 268
  1042.     end
  1043. end
  1044.  
  1045. function shootTheBall(x, y, forceIndex, name)
  1046.     ui.removeTextArea(999)
  1047.     ui.removeTextArea(1000)
  1048.     ui.removeTextArea(1001)
  1049.     removeTimer("powerShoot")
  1050.     tfm.exec.removeImage(idImage)
  1051.     tfm.exec.removeImage(ballObject.ID_image)
  1052.     system.bindMouse(ballObject.owner, false)
  1053.     eventKeyBoardControl(ballObject.owner, false)
  1054.     gameStats.LastShoot.name = name
  1055.     gameStats.LastShoot.x = x
  1056.     ballObject.Spawn = true
  1057.     ballObject.verifyCoords = true
  1058.     ballObject.id = tfm.exec.addShamanObject(17, x, y, 0, 0, 0, true)
  1059.     local distanceX = 0
  1060.     local distanceY = 0
  1061.     if ballForce[forceIndex] == nil or type(forceIndex) ~= "number" then
  1062.         forceIndex = 1
  1063.     end
  1064.     if ballObject.lastKeyPressed == 0 then
  1065.         if x <= 288 and y >= 372 and forceIndex >= 5 then
  1066.             distanceX = x - 285
  1067.             distanceY = -50
  1068.         elseif x <= 345 then
  1069.             distanceX = -5
  1070.             distanceY = -50
  1071.         end
  1072.         tfm.exec.moveObject(ballObject.id, x, y, false, ballForce[forceIndex].vx - distanceX, ballForce[forceIndex].vy + distanceY, false, 0, true)
  1073.     else
  1074.         tfm.exec.moveObject(ballObject.id, x, y, false, math.abs(ballForce[forceIndex].vx) - distanceX, ballForce[forceIndex].vy + distanceY, false, 0, true)
  1075.     end
  1076.     ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
  1077.     timerDelayPowerTheBall()
  1078.     if forceIndex > 4 then
  1079.         canCatchBallOnShoot(2000)
  1080.     else
  1081.         canCatchBallOnShoot(1000)
  1082.     end
  1083.     ballObject.owner = ""
  1084.     gameStats.forceIndex = 0
  1085.     gameStats.ocurrencyLoop8th = 0
  1086.     delayCatchEVT(name)
  1087. end
  1088.  
  1089. function eventKeyBoardControl(name, active)
  1090.     local keys = {0, 2, 3}
  1091.     for i = 1, 3 do
  1092.         system.bindKeyboard(name, keys[i], true, active)
  1093.     end
  1094. end
  1095.  
  1096. function showImageBallWithPlayer(name)
  1097.     if tfm.get.room.playerList[name].isFacingRight then
  1098.         ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, 5, -15, nil, 1, 1, _, 1)
  1099.         ballObject.playerIsRight = true
  1100.     else
  1101.         ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, -35, -15, nil, 1, 1, _, 1)
  1102.         ballObject.playerIsRight = false
  1103.     end
  1104. end
  1105.  
  1106. function identifyPlayers()
  1107.     for i = 1, 3 do
  1108.         if teamRed[i].player ~= "" then
  1109.             playerTeam[teamRed[i].player].team = "Red"
  1110.         end
  1111.         if teamBlue[i].player ~= "" then
  1112.             playerTeam[teamBlue[i].player].team = "Blue"
  1113.         end
  1114.     end
  1115. end
  1116.  
  1117. function passToTeamPlayer(name, x, y, playerTeamName)
  1118.     if playerTeamName == "Red" then
  1119.         teamName = teamRed
  1120.     else
  1121.         teamName = teamBlue
  1122.     end
  1123.     local minDistance = ""
  1124.     local playerIndex = ""
  1125.     for i = 1, 3 do
  1126.         if teamName[i].player ~= ballObject.owner and teamName[i].player ~= "" then
  1127.             local player = teamName[i].player
  1128.             if math.abs(x - tfm.get.room.playerList[player].x) <= 30 and math.abs(y - tfm.get.room.playerList[player].y) <= 30 then
  1129.                 if minDistance == "" then
  1130.                     minDistance = tfm.get.room.playerList[player].x
  1131.                     playerIndex = i
  1132.                 else
  1133.                     if tfm.get.room.playerList[player] < minDistance then
  1134.                         minDistance = tfm.get.room.playerList[player].x
  1135.                         playerIndex = i
  1136.                     end
  1137.                 end
  1138.             end
  1139.         end
  1140.     end
  1141.     if minDistance ~= "" and mode == "gameStarted" then
  1142.         removeTimer("powerShoot")
  1143.         ui.removeTextArea(999)
  1144.         ui.removeTextArea(1000)
  1145.         ui.removeTextArea(1001)
  1146.         eventKeyBoardControl(ballObject.owner, false)
  1147.         tfm.exec.removeImage(idImage)
  1148.         tfm.exec.removeImage(ballObject.ID_image)
  1149.         system.bindMouse(ballObject.owner, false)
  1150.         ballObject.owner = teamName[playerIndex].player
  1151.         idImage = tfm.exec.addImage("175aa78bb80.png", "$"..ballObject.owner, -45, -125, nil)
  1152.         eventKeyBoardControl(ballObject.owner, true)
  1153.         showImageBallWithPlayer(ballObject.owner)
  1154.         system.bindMouse(ballObject.owner, true)
  1155.         gameStats.canPass = false
  1156.         gameStats.LastPass = ballObject.owner
  1157.         gameStats.powerShootEvent = false
  1158.         gameStats.canCatchBall = false
  1159.         canCatchBall()
  1160.         delayPass = addTimer(function(i)
  1161.             if i == 1 then
  1162.                 gameStats.canPass = true
  1163.             end
  1164.         end, 500, 1, "delayPass")
  1165.     end
  1166. end
  1167.  
  1168. function canCatchBall()
  1169.     gameStats.canCatchBall = false
  1170.     delayCatchBall = addTimer(function(i)
  1171.         if i == 1 then
  1172.             gameStats.canCatchBall = true
  1173.         end
  1174.     end, 2500, 1, "delayCatchBall")
  1175. end
  1176.  
  1177. function canCatchBallOnShoot(setTimer)
  1178.     gameStats.canCatchBall = false
  1179.     delayCatchBall = addTimer(function(i)
  1180.         if i == 1 then
  1181.             gameStats.canCatchBall = true
  1182.         end
  1183.     end, setTimer, 1, "delayCatchBall")
  1184. end
  1185.  
  1186. function eventPoint()
  1187.     ballObject.verifyCoords = false
  1188.     ballObject.Spawn = false
  1189.     tfm.exec.removeObject(ballObject.id)
  1190.     local point = 0
  1191.     local assist = false
  1192.     if gameStats.LastShoot.x <= 288 then
  1193.         point = 2
  1194.     else
  1195.         point = 3
  1196.     end
  1197.     if gameStats.LastPass ~= "" then
  1198.         if playerTeam[gameStats.LastShoot.name].team == playerTeam[gameStats.LastPass].team then
  1199.             assist = true
  1200.         end
  1201.     end
  1202.     if playerTeam[gameStats.LastShoot.name].team == "Red" then
  1203.         redPoints = redPoints + point
  1204.         messageWhenMakePoint(trad.messageRedPoint, point, assist, "<r>")
  1205.         tfm.exec.chatMessage("<r>Red "..redPoints.."<n> - <bv>"..bluePoints.." Blue<n>" , nil)
  1206.         setScoreForPlayer(gameStats.LastShoot.name, assist, point)
  1207.     elseif playerTeam[gameStats.LastShoot.name].team == "Blue" then
  1208.         bluePoints = bluePoints + point
  1209.         messageWhenMakePoint(trad.messageBluePoint, point, assist, "<bv>")
  1210.         tfm.exec.chatMessage("<r>Red "..redPoints.."<n> - <bv>"..bluePoints.." Blue<n>" , nil)
  1211.         setScoreForPlayer(gameStats.LastShoot.name, assist, point)
  1212.     end
  1213.     if redPoints >= winscore then
  1214.         gameFinish()
  1215.         tfm.exec.chatMessage(trad.messageRedWinner , nil)
  1216.         winnerTimer = os.time() + 8000
  1217.         local mvp = findMvp()
  1218.         table.sort(mvp, function(a, b) return a.points > b.points end)
  1219.         tfm.exec.chatMessage(""..trad.messageMvp[1].." "..mvp[1].name.." "..trad.messageMvp[2].." "..mvp[1].points.." "..trad.messageMvp[3].."", nil)
  1220.         mode = "winner"
  1221.     elseif bluePoints >= winscore then
  1222.         gameFinish()
  1223.         tfm.exec.chatMessage(trad.messageBlueWinner , nil)
  1224.         winnerTimer = os.time() + 8000
  1225.         local mvp = findMvp()
  1226.         tfm.exec.chatMessage(""..trad.messageMvp[1].." "..mvp[1].name.." "..trad.messageMvp[2].." "..mvp[1].points.." "..trad.messageMvp[3].."", nil)
  1227.         mode = "winner"
  1228.     else
  1229.         spawnBall()
  1230.     end
  1231.     ui.setMapName("<N><ch>#Basketball Street<n>   <G>|                                                    <r>Red<n> "..redPoints.."<G> | <bv>Blue<n> "..bluePoints.."<")
  1232. end
  1233.  
  1234. function setScoreForPlayer(playerMakePoint, playerMakeAssist, point)
  1235.     local value_assistence = 1
  1236.     tfm.exec.setPlayerScore(playerMakePoint, point, true)
  1237.     storePointsOfPlayers[playerMakePoint].points = storePointsOfPlayers[playerMakePoint].points + point
  1238.     if playerMakeAssist then
  1239.         tfm.exec.setPlayerScore(gameStats.LastPass, value_assistence, true)
  1240.         storePointsOfPlayers[gameStats.LastPass].points = storePointsOfPlayers[gameStats.LastPass].points + value_assistence
  1241.     end
  1242. end
  1243.  
  1244. function findMvp()
  1245.     local mvp = {}
  1246.     for name, data in pairs(tfm.get.room.playerList) do
  1247.         mvp[#mvp + 1] = {name = name, points = storePointsOfPlayers[name].points}
  1248.     end
  1249.     return mvp
  1250. end
  1251.  
  1252. function messageWhenMakePoint(teamPoint, point, assist, tag)
  1253.     if assist then
  1254.         tfm.exec.chatMessage(""..tag.."+"..point.." "..teamPoint.."<n> "..trad.messageWhoMakePoint.." "..gameStats.LastShoot.name.." "..trad.messageIfHaveAssist.." "..gameStats.LastPass.."", nil)
  1255.     else
  1256.         tfm.exec.chatMessage(""..tag.."+"..point.." "..teamPoint.."<n> "..trad.messageWhoMakePoint.." "..gameStats.LastShoot.name.."" , nil)
  1257.     end
  1258. end
  1259.  
  1260. function gameFinish()
  1261.     tfm.exec.removeBonus(id, nil)
  1262.     if imagePower[1].image ~= "" then tfm.exec.removeImage(imagePower[1].image) end
  1263.     ballObject.Spawn = false
  1264.     ui.removeTextArea(2400)
  1265.     removeTimer("SpawnPowerLoop")
  1266.     removeTimer("loopTimer")
  1267.     removeTimer("timerLoopVerify")
  1268.     removeTimer("coordinatesOfBall")
  1269.     for i = 1, 3 do
  1270.         if teamRed[i].player ~= "" then
  1271.             disableActionsOnGame(teamRed[i].player)
  1272.         end
  1273.         if teamBlue[i].player ~= "" then
  1274.             disableActionsOnGame(teamBlue[i].player)
  1275.         end
  1276.     end
  1277. end
  1278.  
  1279. function disableActionsOnGame(name)
  1280.     tfm.exec.removeImage(invetoryPlayer[name].image)
  1281.     setKeysEvent(name, false, true)
  1282.     setKeysEvent(name, false, true)
  1283. end
  1284.  
  1285. function clearTextArea()
  1286.     ui.removeTextArea(-1)
  1287.     for i = 0, 6 do
  1288.         ui.removeTextArea(i)
  1289.     end
  1290. end
  1291.  
  1292. function createPower()
  1293.     loopTimer = addTimer(function(i)
  1294.         SpawnPowerLoop = addTimer(function(i)
  1295.             if i == 1 then
  1296.                 if imagePower[1].image ~= "" then
  1297.                     tfm.exec.removeBonus(1, nil)
  1298.                     tfm.exec.removeImage(imagePower[1].image)
  1299.                 end
  1300.                 local x = math.random(240, 720)
  1301.                 local y = math.random(130, 366)
  1302.                 local powerSelect = powers[math.random(1, #powers)]
  1303.                 imagePower[1].powerIndex = powerSelect
  1304.                 tfm.exec.addBonus(0, x, y, 1, 0, false, nil)
  1305.                 imagePower[1].image = tfm.exec.addImage(powerSelect.image, "&1", x, y, nil)
  1306.             end
  1307.         end, 15000, 1, "SpawnPowerLoop")
  1308.     end, 16000, 0, "loopTimer")
  1309. end
  1310.  
  1311. function eventPlayerBonusGrabbed(name, id)
  1312.     tfm.exec.removeBonus(id, nil)
  1313.     tfm.exec.removeImage(imagePower[1].image)
  1314.     if invetoryPlayer[name].image ~= "" then
  1315.         tfm.exec.removeImage(invetoryPlayer[name].image)
  1316.     end
  1317.     invetoryPlayer[name].powerIndex = imagePower[1].powerIndex
  1318.     if invetoryPlayer[name].powerIndex.powerName == "Speed" then
  1319.         eventKeyBoardControl(name, true)
  1320.     end
  1321.     invetoryPlayer[name].image = tfm.exec.addImage(imagePower[1].powerIndex.image, ":1", 745, 138, name)
  1322. end
  1323.  
  1324. function eventChatCommand(name, cmd)
  1325.     if admins[name] then
  1326.         if string.lower(string.sub(cmd, 1, 8)) == "winscore" and type(tonumber(string.sub(cmd, 10))) == "number" and mode == "gameStarted"  then
  1327.             winscore = tonumber(string.sub(cmd, 10))
  1328.         elseif (cmd:sub(0,10) == "resettimer") and mode == "start" then
  1329.             initTimer = os.time() + 15000
  1330.         end
  1331.     end
  1332.     if (cmd:sub(1,4) == "lang") then
  1333.         local v = string.lower(cmd:sub(6,7))
  1334.         if v == "br" then
  1335.             playerLanguage[name].tr = lang.br
  1336.         elseif v == "en" then
  1337.             playerLanguage[name].tr = lang.en
  1338.         end
  1339.     elseif (cmd:sub(1,4) == "help") then
  1340.         removeImageOfTheWindow(name)
  1341.         removeImageOfThePowersWindow(name)
  1342.         playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.howToPlayText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
  1343.     elseif string.lower(cmd) == "join" and not playersJoined[name] and mode == "gameStarted"then
  1344.         chooseTeam(name)
  1345.     elseif string.lower(cmd) == "leave" and playersJoined[name] and mode == "gameStarted" then
  1346.         leaveTeam(name)
  1347.     end
  1348. end
  1349.  
  1350. function chooseTeam(name)
  1351.     quantityPlayersJoined()
  1352.     if quantity.red < quantity.blue then
  1353.         joinOnTeam(name, teamRed, 0xEB4848)
  1354.     elseif quantity.blue < quantity.red then
  1355.         joinOnTeam(name, teamBlue, 0x2167ED)
  1356.     elseif quantity.red == quantity.blue and quantity.red ~= 3 then
  1357.         joinOnTeam(name, teamRed, 0xEB4848)
  1358.     else
  1359.         tfm.exec.chatMessage(trad.messageFullTeam, name)
  1360.     end
  1361. end
  1362.  
  1363. function joinOnTeam(name, teamName, color)
  1364.     for i = 1, #teamName do
  1365.         if teamName[i].player == "" then
  1366.             teamName[i].player = name
  1367.             playersJoined[name] = true
  1368.             playersActions[teamName[i].player] = {canCatch = false}
  1369.             setKeysEvent(teamName[i].player, true, false)
  1370.             tfm.exec.movePlayer(teamName[i].player, math.random(240, 700), 368)
  1371.             tfm.exec.setNameColor(teamName[i].player, color)
  1372.             windowUIPowersShow(teamName[i].player)
  1373.             delayCatchEVT(name)
  1374.             if color == 0xEB4848 then
  1375.                 playerTeam[name].team = "Red"
  1376.             else
  1377.                 playerTeam[name].team = "Blue"
  1378.             end
  1379.             break
  1380.         end
  1381.     end
  1382. end
  1383.  
  1384. function leaveTeam(name)
  1385.     if playerTeam[name].team == "Red" then
  1386.         for i = 1, 3 do
  1387.             if teamRed[i].player == name then
  1388.                 disableSettingsPlayerOnTeam(i, name, teamRed)
  1389.                 break
  1390.             end
  1391.         end
  1392.     elseif playerTeam[name].team == "Blue" then
  1393.         for i = 1, 3 do
  1394.             if teamBlue[i].player == name then
  1395.                 disableSettingsPlayerOnTeam(i, name, teamBlue)
  1396.                 break
  1397.             end
  1398.         end
  1399.     end
  1400. end
  1401.  
  1402. function disableSettingsPlayerOnTeam(index, name, teamName)
  1403.     if ballObject.owner == name then
  1404.         system.bindMouse(ballObject.owner, false)
  1405.         eventKeyBoardControl(ballObject.owner, false)
  1406.         removeTimer("powerShoot")
  1407.         gameStats.powerShootEvent = false
  1408.         tfm.exec.removeImage(idImage)
  1409.         tfm.exec.removeImage(ballObject.ID_image)
  1410.         ui.removeTextArea(999)
  1411.         ui.removeTextArea(1000)
  1412.         ui.removeTextArea(1001)
  1413.         ballObject.id = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, true)
  1414.         tfm.exec.moveObject(ballObject.id, tfm.get.room.playerList[ballObject.owner].x, tfm.get.room.playerList[ballObject.owner].y, false, 0, 0, false, 0, false)
  1415.         ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
  1416.         ballObject.Spawn = true
  1417.         ballObject.owner = ""
  1418.     end
  1419.     playersJoined[name] = false
  1420.     playersActions[teamName[index].player] = {canCatch = true}
  1421.     setKeysEvent(teamName[index].player, false, false)
  1422.     tfm.exec.movePlayer(teamName[index].player, 422, 90)
  1423.     tfm.exec.setNameColor(teamName[index].player, 0xA7A4A2)
  1424.     ui.removeTextArea(2400, name)
  1425.     teamName[index].player = ""
  1426. end
  1427.  
  1428. init()
Add Comment
Please, Sign In to add comment