Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- from https://www.lua.org/pil/11.4.html
- local List = {}
- function List.new ()
- return {first = 0, last = -1}
- end
- function List.pushleft (list, value)
- local first = list.first - 1
- list.first = first
- list[first] = value
- end
- function List.pushright (list, value)
- local last = list.last + 1
- list.last = last
- list[last] = value
- end
- function List.popleft (list)
- local first = list.first
- if first > list.last then
- return nil
- end
- local value = list[first]
- list[first] = nil -- to allow garbage collection
- list.first = first + 1
- return value
- end
- function List.popright (list)
- local last = list.last
- if list.first > last then
- return nil
- end
- local value = list[last]
- list[last] = nil -- to allow garbage collection
- list.last = last - 1
- return value
- end
- -- the lib
- local timerList = {}
- local timersPool = List.new()
- function addTimer(callback, ms, loops, label, ...)
- local id = List.popleft(timersPool)
- if id then
- local timer = timerList[id]
- timer.callback = callback
- timer.label = label
- timer.arguments = {...}
- timer.time = ms
- timer.currentTime = 0
- timer.currentLoop = 0
- timer.loops = loops or 1
- timer.isComplete = false
- timer.isPaused = false
- timer.isEnabled = true
- else
- id = #timerList+1
- timerList[id] = {
- callback = callback,
- label = label,
- arguments = {...},
- time = ms,
- currentTime = 0,
- currentLoop = 0,
- loops = loops or 1,
- isComplete = false,
- isPaused = false,
- isEnabled = true,
- }
- end
- return id
- end
- function getTimerId(label)
- local found
- for id = 1, #timerList do
- local timer = timerList[id]
- if timer.label == label then
- found = id
- break
- end
- end
- return found
- end
- function pauseTimer(id)
- if type(id) == 'string' then
- id = getTimerId(id)
- end
- if timerList[id] and timerList[id].isEnabled then
- timerList[id].isPaused = true
- return true
- end
- return false
- end
- function resumeTimer(id)
- if type(id) == 'string' then
- id = getTimerId(id)
- end
- if timerList[id] and timerList[id].isPaused then
- timerList[id].isPaused = false
- return true
- end
- return false
- end
- function removeTimer(id)
- if type(id) == 'string' then
- id = getTimerId(id)
- end
- if timerList[id] and timerList[id].isEnabled then
- timerList[id].isEnabled = false
- List.pushright(timersPool, id)
- return true
- end
- return false
- end
- function clearTimers()
- local timer
- repeat
- timer = List.popleft(timersPool)
- if timer then
- table.remove(timerList, timer)
- end
- until timer == nil
- end
- function timersLoop()
- for id = 1, #timerList do
- local timer = timerList[id]
- if timer.isEnabled and timer.isPaused == false then
- if not timer.isComplete then
- timer.currentTime = timer.currentTime + 500
- if timer.currentTime >= timer.time then
- timer.currentTime = 0
- timer.currentLoop = timer.currentLoop + 1
- if timer.loops > 0 then
- if timer.currentLoop >= timer.loops then
- timer.isComplete = true
- if eventTimerComplete ~= nil then
- eventTimerComplete(id, timer.label)
- end
- removeTimer(id)
- end
- end
- if timer.callback ~= nil then
- timer.callback(timer.currentLoop, table.unpack(timer.arguments))
- end
- end
- end
- end
- end
- end
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoScore (true)
- tfm.exec.disableAutoTimeLeft (true)
- tfm.exec.disablePhysicalConsumables (true)
- tfm.exec.disableAfkDeath (true)
- tfm.exec.setRoomMaxPlayers (15)
- tfm.exec.disableAutoScore (true)
- system.disableChatCommandDisplay (nil, true)
- local admins = {
- ["Refletz#6472"] = true,
- ["Soristl1#0000"] = true
- }
- local mode = ""
- local initTimer = os.time() + 15000
- local winnerTimer = ""
- local quantity = {red = 0, blue = 0}
- local idImage = ""
- local redPoints = 0
- local bluePoints = 0
- local winscore = 10
- local ballObject = {owner = "", id = nil, Spawn = false, ID_image = "", playerIsRight = "", lastKeyPressed = 0, verifyCoords = false}
- local ballForce = {
- [1] = {vx = -40, vy = -20},
- [2] = {vx = -40, vy = -25},
- [3] = {vx = -40, vy = -70},
- [4] = {vx = -50, vy = -80},
- [5] = {vx = -70, vy = -100},
- [6] = {vx = -80, vy = -110},
- [7] = {vx = -90, vy = -120},
- }
- local storePointsOfPlayers = {}
- local lang = {}
- lang.br = {
- messageWelcome = "Bem vindo ao <j>Basketball Street<n> digite !help para entender melhor o jogo",
- 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>",
- 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",
- 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",
- 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).",
- closeUIText = "<p align='center'><font size='12px'><a href='event:closeWindow'>Fechar",
- messageFullTeam = "Os times estão cheios",
- messageRedPoint = "Ponto do vermelho",
- messageBluePoint = "Ponto do azul",
- messageWhoMakePoint = "feito por",
- messageIfHaveAssist = "e a assistência foi do",
- messageRedWinner = "<r>A equipe vermelha venceu<n>",
- messageBlueWinner = "<bv>A equipe azul venceu<n>",
- messageMvp = {
- [1] = "O MVP da partida foi",
- [2] = "com",
- [3] = "pontos",
- },
- powersTitle = "<p align='center'><font size='15px'>Poderes",
- powersList = {
- [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"},
- [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"},
- },
- buttonNext = "<p align='center'><font size='12px'>Próximo",
- buttonPrev = "<p align='center'><font size='12px'>Voltar",
- }
- lang.en = {
- messageWelcome = "Welcome to <j>Basketball Street<n> type !help to understand the game",
- 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>",
- 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.",
- 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",
- 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).",
- closeUIText = "<p align='center'><font size='12px'><a href='event:closeWindow'>Close",
- messageFullTeam = "The teams are full",
- messageRedPoint = "Red scored",
- messageBluePoint = "Blue scored",
- messageWhoMakePoint = "scored by",
- messageIfHaveAssist = "and the assist is",
- messageRedWinner = "<r>The red team won<n>",
- messageBlueWinner = "<bv>The blue team won<n>",
- messageMvp = {
- [1] = "The MVP of the match is",
- [2] = "with",
- [3] = "points",
- },
- powersTitle = "<p align='center'><font size='15px'>Powers",
- powersList = {
- [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"},
- [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"},
- },
- buttonNext = "<p align='center'><font size='12px'>Next",
- buttonPrev = "<p align='center'><font size='12px'>Previous",
- }
- if tfm.get.room.language == "br" then
- trad = lang.br
- elseif tfm.get.room.language == "en" then
- trad = lang.en
- else
- trad = lang.en
- end
- local playerLanguage = {}
- local playerImage = {}
- local wallJumpEvent = {}
- local forceIndex = 0
- local shootEvent = {x = 0, y = 0}
- local teamRed = {
- [1] = {player = ""},
- [2] = {player = ""},
- [3] = {player = ""},
- }
- local teamBlue = {
- [1] = {player = ""},
- [2] = {player = ""},
- [3] = {player = ""},
- }
- local playersJoined = {}
- local playerTeam = {}
- local playersActions = {}
- local pagePowersCount = {}
- local pagePowersImages = {}
- gameStats = {canPass = true, canCatchBall = true, canPowerTheBall = true, LastShoot = {name = "", x = 0}, LastPass = "", powerDelayOcurrency = false, powerShootEvent = false, loopCordinatesOfBall = true, ocurrencyLoop8th = 0, forceIndex = 0, spacePressed = false}
- local powers = {
- [1] = {powerName = "Speed", image = "17c433ac5d5.png"},
- [2] = {powerName = "Explosion", image = "17c3eb819c9.png"}
- }
- local imagesPowersStorage = {}
- local imagePower = { [1] = {image = "", powerIndex = 0} }
- local invetoryPlayer = {}
- local teamsX_textarea = {70, 240, 410}
- local distanceToCatch = {x = 35, y = 40}
- local playerDirection = {x1 = 0, x2 = 0}
- for name, data in pairs(tfm.get.room.playerList) do
- playersJoined[name] = false
- playerTeam[name] = {}
- invetoryPlayer[name] = {powerIndex = 0, image = "", lastKeyPressed = 0, powerBall = false}
- playerLanguage[name] = {tr = trad, name}
- playerImage[name] = {}
- wallJumpEvent[name] = {firstJump = false, delayWallJump = false}
- storePointsOfPlayers[name] = {points = 0}
- pagePowersCount[name] = 1
- pagePowersImages[name] = {}
- end
- function separateThePowersListInPages()
- local count = trad.powersList
- local pages = {}
- for i = 1, #count do
- if i % 2 == 0 then
- pages[#pages + 1] = {i - 1, i}
- elseif i % 2 == 1 and i == #count then
- pages[#pages + 1] = {i}
- end
- end
- return pages
- end
- local pagesList = separateThePowersListInPages()
- function ui.addWindow(id, text, player, x, y, width, height, alpha, corners, closeButton, buttonText)
- id = tostring(id)
- ui.addTextArea(id.."000000000", "", player, x, y, width, height, 0x573926, 0x573926, alpha, true)
- ui.addTextArea(id.."0", "", player, x+1, y+1, width-2, height-2, 0x8a583c, 0x8a583c, alpha, true)
- ui.addTextArea(id.."00", "", player, x+3, y+3, width-6, height-6, 0x2b1f19, 0x2b1f19, alpha, true)
- ui.addTextArea(id.."000", "", player, x+4, y+4, width-8, height-8, 0xc191c, 0xc191c, alpha, true)
- ui.addTextArea(id.."0000", "", player, x+5, y+5, width-10, height-10, 0x2d5a61, 0x2d5a61, alpha, true)
- ui.addTextArea(id.."00000", text, player, x+5, y+6, width-10, height-12, 0x142b2e, 0x142b2e, alpha, true)
- local imageId = {}
- if corners then
- table.insert(imageId, tfm.exec.addImage("155cbe97a3f.png", "&1", x-7, (y+height)-22, player))
- table.insert(imageId, tfm.exec.addImage("155cbe99c72.png", "&1", x-7, y-7, player))
- table.insert(imageId, tfm.exec.addImage("155cbe9bc9b.png", "&1", (x+width)-20, (y+height)-22, player))
- table.insert(imageId, tfm.exec.addImage("155cbea943a.png", "&1", (x+width)-20, y-7, player))
- end
- if closeButton then
- ui.addTextArea(id.."000000", "", player, x+8, y+height-22, width-16, 13, 0x7a8d93, 0x7a8d93, alpha, true)
- ui.addTextArea(id.."0000000", "", player, x+9, y+height-21, width-16, 13, 0xe1619, 0xe1619, alpha, true)
- ui.addTextArea(id.."00000000", "", player, x+9, y+height-21, width-17, 12, 0x314e57, 0x314e57, alpha, true)
- ui.addTextArea(id.."", buttonText, player, x+9, y+height-24, width-17, nil, 0x314e57, 0x314e57, 0, true)
- end
- return imageId
- end
- function buttonNextOrPrev(id, name, x, y, width, height, alpha, text)
- id = tostring(id)
- ui.addTextArea(id.."0000000000", "", name, x+8, y+height-22, width-16, 13, 0x7a8d93, 0x7a8d93, alpha, true)
- ui.addTextArea(id.."00000000000", "", name, x+9, y+height-21, width-16, 13, 0xe1619, 0xe1619, alpha, true)
- ui.addTextArea(id.."000000000000", "", name, x+9, y+height-21, width-17, 12, 0x314e57, 0x314e57, alpha, true)
- ui.addTextArea(id.."0000000000000", text, name, x+9, y+height-24, width-17, nil, 0x314e57, 0x314e57, 0, true)
- end
- function init()
- if imagePower[1].image ~= "" then tfm.exec.removeImage(imagePower[1].image) end
- for name, data in pairs(tfm.get.room.playerList) do
- tfm.exec.setPlayerScore(name, 0, false)
- storePointsOfPlayers[name].points = 0
- end
- initTimer = os.time() + 15000
- redPoints = 0
- bluePoints = 0
- winscore = 10
- updateTables()
- 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>')
- ui.setMapName("<CH> Basketball Street<n>")
- local x = 70
- ui.addTextArea(0, "", nil, 50, 100, 540, 200, 0x324650, 0x3A495C, 1, false)
- ui.addTextArea(-1, "<p align='center'>The game will start in", nil, 50, 100, 540, 15, 0x324650, 0x3A495C, 0, false)
- for i = 1, 3 do
- 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)
- x = x + 170
- end
- local x = 70
- for i = 1, 3 do
- 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)
- x = x + 170
- end
- ui.addWindow(7, "<p align='center'><font size='13px'><a href='event:menuOpen'>Menu", nil, 5, 15, 100, 30, 1, false, false, _)
- mode = "start"
- end
- function updateTables()
- teamRed = {
- [1] = {player = ""},
- [2] = {player = ""},
- [3] = {player = ""},
- }
- teamBlue = {
- [1] = {player = ""},
- [2] = {player = ""},
- [3] = {player = ""},
- }
- playersJoined = {}
- playerTeam = {}
- playersActions = {}
- invetoryPlayer = {}
- playerDirection = {x1 = 0, x2 = 0}
- 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}
- for name, data in pairs(tfm.get.room.playerList) do
- playersJoined[name] = false
- playerTeam[name] = {}
- invetoryPlayer[name] = {powerIndex = 0, image = "", lastKeyPressed = 0, powerBall = false}
- end
- end
- function eventNewPlayer(name)
- playersJoined[name] = false
- playerTeam[name] = {}
- storePointsOfPlayers[name] = {points = 0}
- wallJumpEvent[name] = {firstJump = false, delayWallJump = false}
- invetoryPlayer[name] = {powerIndex = 0, image = "", lastKeyPressed = 0, powerBall = false}
- playerLanguage[name] = {tr = trad, name}
- playerImage[name] = {}
- tfm.exec.respawnPlayer(name)
- pagePowersCount[name] = 1
- pagePowersImages[name] = {}
- tfm.exec.chatMessage(trad.messageWelcome, name)
- if mode == "start" then
- local x = 70
- ui.addTextArea(0, "", name, 50, 100, 540, 200, 0x324650, 0x3A495C, 1, false)
- for i = 1, 3 do
- if teamRed[i].player == "" then
- 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)
- else
- 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)
- end
- if teamBlue[i].player == "" then
- 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)
- else
- 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)
- end
- x = x + 170
- end
- elseif mode ~= "start" then
- ui.setMapName("<N><ch>#Basketball Street<n> <G>| <r>Red<n> "..redPoints.."<G> | <bv>Blue<n> "..bluePoints.."<")
- end
- end
- function eventPlayerLeft(name)
- local x = 70
- storePointsOfPlayers[name].points = 0
- if mode == "start" then
- for i = 1, 3 do
- if teamRed[i].player == name then
- teamRed[i].player = ""
- 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)
- end
- if teamBlue[i].player == name then
- teamBlue[i].player = ""
- 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)
- end
- x = x + 170
- end
- elseif mode ~= "start" then
- if ballObject.owner == name then
- system.bindMouse(ballObject.owner, false)
- eventKeyBoardControl(ballObject.owner, false)
- removeTimer("powerShoot")
- gameStats.powerShootEvent = false
- tfm.exec.removeImage(idImage)
- tfm.exec.removeImage(ballObject.ID_image)
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- ballObject.id = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, true)
- 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)
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
- ballObject.Spawn = true
- ballObject.owner = ""
- end
- for i = 1, 3 do
- if teamRed[i].player == name then
- playersActions[teamRed[i].player] = {canCatch = true}
- setKeysEvent(teamRed[i].player, false, false)
- playerTeam[teamRed[i].player].team = ""
- teamRed[i].player = ""
- end
- if teamBlue[i].player == name then
- playersActions[teamBlue[i].player] = {canCatch = true}
- setKeysEvent(teamBlue[i].player, false, false)
- playerTeam[teamBlue[i].player].team = ""
- teamBlue[i].player = ""
- end
- end
- end
- end
- function eventTextAreaCallback(id, name, c)
- if string.sub(c, 1, 7) == "joinRed" and type(tonumber(string.sub(c, 8))) == "number" and not playersJoined[name] then
- playersJoined[name] = true
- teamRed[tonumber(string.sub(c, 8))].player = name
- 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)
- elseif string.sub(c, 1, 8) == "joinBlue" and type(tonumber(string.sub(c, 9))) == "number" and not playersJoined[name] then
- playersJoined[name] = true
- teamBlue[tonumber(string.sub(c, 9))].player = name
- 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)
- 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
- playersJoined[name] = false
- teamRed[tonumber(string.sub(c, 9))].player = ""
- 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)
- 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
- playersJoined[name] = false
- teamBlue[tonumber(string.sub(c, 10))].player = ""
- 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)
- elseif c == "menuOpen" then
- 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, _)
- elseif c == "menuClose" then
- ui.addWindow(7, "<p align='center'><font size='13px'><a href='event:menuOpen'>Menu", name, 5, 15, 100, 30, 1, false, false, _)
- elseif c == "howtoplay" then
- removeImageOfTheWindow(name)
- removeImageOfThePowersWindow(name)
- playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.howToPlayText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
- elseif c == "commands" then
- removeImageOfTheWindow(name)
- removeImageOfThePowersWindow(name)
- playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.commandsText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
- elseif c == "powers" then
- removeImageOfTheWindow(name)
- removeImageOfThePowersWindow(name)
- playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.powersTitle, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
- createWindowPowers(name)
- elseif c == "credits" then
- removeImageOfThePowersWindow(name)
- removeImageOfTheWindow(name)
- playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.creditsText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
- elseif c == "closeWindow" then
- closeWindow(8, name)
- for i = -1, -6, -1 do
- closeWindow(i, name)
- end
- for i = -7, -8, -1 do
- closeButtonNextOrPrev(i, name)
- end
- removeImageOfThePowersWindow(name)
- removeImageOfTheWindow(name)
- end
- end
- function createWindowPowers(name)
- ui.addWindow(-1, "", name, 150, 95, 280, 180, 1, false, false)
- ui.addWindow(-2, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][1]].name, name, 160, 105, 260, 30, 1, false, false)
- ui.addWindow(-3, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][1]].description, name, 160, 155, 260, 110, 1, false, false)
- pagePowersImages[name][1] = tfm.exec.addImage("17c433ac5d5.png", "&2", 380, 105, name)
- if #pagesList[pagePowersCount[name]] == 2 then
- ui.addWindow(-4, "", name, 470, 95, 280, 180, 1, false, false)
- ui.addWindow(-5, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][2]].name, name, 480, 105, 260, 30, 1, false, false)
- ui.addWindow(-6, playerLanguage[name].tr.powersList[pagesList[pagePowersCount[name]][2]].description, name, 480, 155, 260, 110, 1, false, false)
- pagePowersImages[name][2] = tfm.exec.addImage("17c3eb819c9.png", "&3", 700, 105, name)
- end
- pagePowers(name)
- end
- function pagePowers(name)
- if pagePowersCount[name] > 1 and pagePowersCount[name] < #pageList then
- buttonNextOrPrev(-8, name, 540, 300, 200, 30, 1, "<a href='event:next'>"..playerLanguage[name].tr.buttonNext.."</a>")
- else
- buttonNextOrPrev(-8, name, 540, 300, 200, 30, 1, "<n2>"..playerLanguage[name].tr.buttonNext.."<n>")
- end
- if pagePowersCount[name] > 1 then
- buttonNextOrPrev(-7, name, 160, 300, 200, 30, 1, "<a href='event:prev'>"..playerLanguage[name].tr.buttonPrev.."</a>")
- else
- buttonNextOrPrev(-7, name, 160, 300, 200, 30, 1, "<n2>"..playerLanguage[name].tr.buttonPrev.."<n>")
- end
- end
- function removeImageOfTheWindow(name)
- if #playerImage[name] > 0 then
- for i = 1, #playerImage[name] do
- tfm.exec.removeImage(playerImage[name][i])
- end
- end
- end
- function removeImageOfThePowersWindow(name)
- for i = 1, #pagePowersImages[name] do
- tfm.exec.removeImage(pagePowersImages[name][i])
- end
- end
- function closeWindow(id, name)
- local id = tostring(id)
- local str = "0"
- ui.removeTextArea(id, name)
- for i = 1, 9 do
- ui.removeTextArea(id..""..str.."", name)
- str = ""..str.."0"
- end
- end
- function closeButtonNextOrPrev(id, name)
- local id = tostring(id)
- local str = "0000000000"
- ui.removeTextArea(id, name)
- for i = 1, 4 do
- ui.removeTextArea(id..""..str.."", name)
- str = ""..str.."0"
- end
- end
- function closeWindow(id, name)
- local id = tostring(id)
- local str = "0"
- ui.removeTextArea(id, name)
- for i = 1, 9 do
- ui.removeTextArea(id..""..str.."", name)
- str = ""..str.."0"
- end
- end
- function slicedName(name)
- local name = ""..string.sub(name, 1, (string.len(name)- 5))..""
- return name
- end
- function eventLoop(elapsedTime, remainingTime)
- timersLoop()
- if mode == "start" then
- local x = math.ceil((initTimer - os.time())/1000)
- local c = string.format("%d", x)
- ui.addTextArea(-1, "<p align='center'>The game will start in "..c.."s", nil, 50, 100, 540, 20, 0x324650, 0x3A495C, 0, false)
- if x == 0 then
- quantityPlayersJoined()
- if quantity.red >= 1 and quantity.blue >= 1 then
- startGame()
- else
- initTimer = os.time() + 15000
- end
- end
- elseif mode == "gameStarted" then
- if not gameStats.powerDelayOcurrency then
- gameStats.powerDelayOcurrency = true
- createPower()
- end
- if ballObject.verifyCoords then
- if tfm.get.room.objectList[ballObject.id].x == 105 and tfm.get.room.objectList[ballObject.id].y == 187 then
- eventPoint()
- end
- end
- elseif mode == "winner" then
- local x = math.ceil((winnerTimer - os.time())/1000)
- local c = string.format("%d", x)
- if x == 0 then
- clearTimers()
- init()
- end
- end
- end
- function quantityPlayersJoined()
- quantity.red = 0
- quantity.blue = 0
- for i = 1, 3 do
- if teamRed[i].player ~= "" then
- quantity.red = quantity.red + 1
- end
- if teamBlue[i].player ~= "" then
- quantity.blue = quantity.blue + 1
- end
- end
- return quantity
- end
- function startGame()
- 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>')
- for i = 1, 3 do
- if teamRed[i].player ~= "" then
- playersActions[teamRed[i].player] = {canCatch = true}
- setKeysEvent(teamRed[i].player, true, false)
- playerTeam[teamRed[i].player].team = "Red"
- tfm.exec.movePlayer(teamRed[i].player, math.random(240, 700), 368)
- tfm.exec.setNameColor(teamRed[i].player, 0xEB4848)
- windowUIPowersShow(teamRed[i].player)
- end
- if teamBlue[i].player ~= "" then
- playersActions[teamBlue[i].player] = {canCatch = true}
- setKeysEvent(teamBlue[i].player, true, false)
- playerTeam[teamBlue[i].player].team = "Blue"
- tfm.exec.movePlayer(teamBlue[i].player, math.random(240, 700), 368)
- tfm.exec.setNameColor(teamBlue[i].player, 0x2167ED)
- windowUIPowersShow(teamBlue[i].player)
- end
- end
- CatchTheBallBeforeStarting = addTimer(function(i)
- gameStats.CatchTheBallBeforeStarting = false
- if i == 1 then
- gameStats.CatchTheBallBeforeStarting = true
- end
- end, 500, 1, "CatchTheBallBeforeStarting")
- ui.setMapName("<N><ch>#Basketball Street<n> <G>| <r>Red<n> "..redPoints.."<G> | <bv>Blue<n> "..bluePoints.."<")
- spawnBall()
- clearTextArea()
- identifyPlayers()
- timerToVerifyIfPlayerIsMovingWithBall()
- mode = "gameStarted"
- end
- function setKeysEvent(name, active, isFinish)
- local keys = {1, 32, 77}
- for j = 1, #keys do
- system.bindKeyboard(name, keys[j], true, active)
- end
- system.bindKeyboard(name, 32, false, active)
- if isFinish then
- eventKeyBoardControl(name, active)
- end
- end
- function windowUIPowersShow(name)
- ui.addTextArea(2400, "", name, 740, 130, 40, 40, 0x161616, 0x161616, 0.5, false)
- end
- function spawnBall()
- tfm.exec.addPhysicObject(1, 146, 37, {type = 14, width = 250, height = 10, miceCollision = false, groundCollision = true, angle = 90})
- local velocityY = {-100, -75, -50}
- ballObject.id = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, true)
- tfm.exec.moveObject(ballObject.id, math.random(166, 740), math.random(153, 180), false, 0, velocityY[math.random(#velocityY)], false, 0, false)
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
- ballObject.Spawn = true
- if gameStats.loopCordinatesOfBall then
- gameStats.loopCordinatesOfBall = false
- timerLoopToCoordinatesOfBall()
- end
- end
- function eventKeyboard(name, key, down, x, y)
- if key == 32 then
- if mode == "gameStarted" and ballObject.owner ~= name and playersActions[name].canCatch and gameStats.canCatchBall and down and gameStats.CatchTheBallBeforeStarting then
- if x - 20 >= 180 then
- playersActions[name].canCatch = false
- getBall(name, x, y)
- elseif x - 20 <= 180 and y >= 276 then
- playersActions[name].canCatch = false
- getBall(name, x, y)
- end
- elseif ballObject.owner ~= name and gameStats.canCatchBall and not playersActions[name].canCatch then
- delayCatchEVT(name)
- elseif ballObject.owner == name then
- gameStats.spacePressed = down
- if gameStats.spacePressed and gameStats.canPowerTheBall and not gameStats.powerShootEvent and playersActions[name].canCatch then
- local powerBars = ""
- removeTimer("powerShoot")
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- if gameStats.canPowerTheBall and gameStats.spacePressed then
- powerShoot = addTimer(function(i)
- if i == 1 then
- gameStats.ocurrencyLoop8th = 0
- gameStats.powerShootEvent = true
- end
- gameStats.forceIndex = i
- if i >= 0 and i <= (gameStats.ocurrencyLoop8th + 4) and gameStats.spacePressed then
- powerBars = powerBars.."<vp>_<n>"
- ui.addTextArea(999, "<font size='15px'>[", name, x - 35, y, 65, 20, 0x161616, 0x161616, 0.5, true)
- ui.addTextArea(1000, powerBars, name, x - 28, y, 72, 20, 0x161616, 0x161616, 0, true)
- ui.addTextArea(1001, "<font size='15px'>]", name, x + 22, y, 75, 20, 0x161616, 0x161616, 0, true)
- elseif i >= (gameStats.ocurrencyLoop8th + 5) and i <= (gameStats.ocurrencyLoop8th + 6) and gameStats.spacePressed then
- powerBars = powerBars.."<j>_<n>"
- ui.addTextArea(999, "<font size='15px'>[", name, x - 35, y, 65, 20, 0x161616, 0x161616, 0.5, true)
- ui.addTextArea(1000, powerBars, name, x - 28, y, 72, 20, 0x161616, 0x161616, 0, true)
- ui.addTextArea(1001, "<font size='15px'>]", name, x + 22, y, 75, 20, 0x161616, 0x161616, 0, true)
- elseif i == (gameStats.ocurrencyLoop8th + 7) and gameStats.spacePressed then
- powerBars = powerBars.."<r>_<n>"
- ui.addTextArea(999, "<font size='15px'>[", name, x - 35, y, 65, 20, 0x161616, 0x161616, 0.5, true)
- ui.addTextArea(1000, powerBars, name, x - 28, y, 72, 20, 0x161616, 0x161616, 0, true)
- ui.addTextArea(1001, "<font size='15px'>]", name, x + 22, y, 75, 20, 0x161616, 0x161616, 0, true)
- powerBars = ""
- delayLoopOnPowerShootTimer(ballObject.owner, i)
- else
- 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
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- removeTimer("powerShoot")
- playersActions[name].canCatch = false
- gameStats.canPowerTheBall = false
- shootTheBall(shootEvent.x, shootEvent.y, gameStats.forceIndex - gameStats.ocurrencyLoop8th, name)
- end
- end
- end, 500, 0, "powerShoot")
- end
- end
- end
- elseif key == 0 or key == 1 or key == 2 or key == 3 then
- if key == 0 or key == 2 then
- invetoryPlayer[name].lastKeyPressed = key
- if ballObject.owner == name then
- ballObject.lastKeyPressed = key
- if key == 2 then
- if not ballObject.playerIsRight then
- tfm.exec.removeImage(ballObject.ID_image)
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, 5, -15, nil, 1, 1, _, 1)
- ballObject.playerIsRight = true
- end
- elseif key == 0 then
- if ballObject.playerIsRight then
- tfm.exec.removeImage(ballObject.ID_image)
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, -35, -15, nil, 1, 1, _, 1)
- ballObject.playerIsRight = false
- end
- end
- end
- end
- gameStats.playerMove = true
- tfm.get.room.playerList[name].x = x
- tfm.get.room.playerList[name].y = y
- elseif key == 77 then
- if invetoryPlayer[name].powerIndex ~= 0 then
- if invetoryPlayer[name].powerIndex.powerName == "Speed" then
- if invetoryPlayer[name].lastKeyPressed == 0 then
- tfm.exec.movePlayer(name, 0, 0, true, -100, 0, false)
- elseif invetoryPlayer[name].lastKeyPressed == 2 then
- tfm.exec.movePlayer(name, 0, 0, true, 100, 0, false)
- end
- if ballObject.owner ~= name then
- eventKeyBoardControl(name, false)
- end
- elseif invetoryPlayer[name].powerIndex.powerName == "Explosion" then
- tfm.exec.explosion(x, y - 10, 30, 100, false)
- end
- invetoryPlayer[name].powerIndex = 0
- tfm.exec.removeImage(invetoryPlayer[name].image)
- invetoryPlayer[name].image = ""
- end
- end
- if key == 1 and not wallJumpEvent[name].delayWallJump then
- if wallJumpEvent[name].firstJump and not wallJumpEvent[name].delayWallJump then
- wallJumpEvent[name].delayWallJump = true
- tfm.exec.movePlayer(name, 0, 0, true, 0, -120, true)
- delayWallJump = addTimer(function(i)
- if i == 1 then
- wallJumpEvent[name].delayWallJump = false
- end
- end, 2000, 1, "delayWallJump")
- end
- if not wallJumpEvent[name].firstJump and not wallJumpEvent[name].delayWallJump then
- wallJumpEvent[name].firstJump = true
- timerToExecuteFirstJump(name)
- end
- end
- if ballObject.owner == name then
- shootEvent.x = x
- shootEvent.y = y
- end
- end
- function timerToExecuteFirstJump(name)
- firstJump = addTimer(function(i)
- if i == 1 then
- wallJumpEvent[name].firstJump = false
- end
- end, 1000, 1, "firstJump")
- end
- function delayLoopOnPowerShootTimer(name, indexOnPowerShoot)
- pauseTimer("powerShoot")
- delayLoop = addTimer(function(i)
- if (gameStats.forceIndex - gameStats.ocurrencyLoop8th) >= 0 and (gameStats.forceIndex - gameStats.ocurrencyLoop8th) <= 7 and gameStats.powerShootEvent and gameStats.canPowerTheBall and not gameStats.spacePressed then
- removeTimer("delayLoop")
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- removeTimer("powerShoot")
- playersActions[name].canCatch = false
- gameStats.canPowerTheBall = false
- shootTheBall(shootEvent.x, shootEvent.y, gameStats.forceIndex - gameStats.ocurrencyLoop8th, name)
- end
- if i == 1 then
- resumeTimer("powerShoot")
- if indexOnPowerShoot == 7 then
- gameStats.ocurrencyLoop8th = 7
- else
- gameStats.ocurrencyLoop8th = gameStats.ocurrencyLoop8th + 7
- end
- gameStats.forceIndex = indexOnPowerShoot
- end
- end, 1000, 1, "delayLoop")
- end
- function delayCatchEVT(name)
- delayCatch = addTimer(function(i)
- if i == 1 then
- playersActions[name].canCatch = true
- end
- end, 1500, 1, "delayCatch")
- end
- function delayCatchEVTPowerTheBall(name)
- delayCatchPower = addTimer(function(i)
- if i == 1 then
- playersActions[name].canCatch = true
- end
- end, 4500, 1, "delayCatchPower")
- end
- function timerToVerifyIfPlayerIsMovingWithBall()
- timerLoopVerify = addTimer(function(i)
- if ballObject.owner ~= "" then
- if gameStats.movePlayer then
- gameStats.movePlayer = false
- distanceToCatch.x = 25
- distanceToCatch.y = 25
- playerDirection.x1 = 0
- playerDirection.x2 = 0
- else
- distanceToCatch.x = 35
- distanceToCatch.y = 45
- if invetoryPlayer[ballObject.owner].lastKeyPressed == 0 then
- playerDirection.x1 = -10
- playerDirection.x2 = 0
- elseif invetoryPlayer[ballObject.owner].lastKeyPressed == 2 then
- playerDirection.x1 = 0
- playerDirection.x2 = 10
- end
- end
- end
- end, 1500, 0, "timerLoopVerify")
- end
- function timerDelayPowerTheBall()
- gameStats.canPowerTheBall = false
- powerTheBall = addTimer(function(i)
- if i == 1 then
- gameStats.canPowerTheBall = true
- gameStats.powerShootEvent = false
- end
- end, 500, 1, "powerTheBall")
- end
- function eventMouse(name, x, y)
- print(x)
- print(y)
- if name == ballObject.owner and gameStats.canPass then
- passToTeamPlayer(name, x, y, playerTeam[name].team)
- end
- end
- function getBall(name, x, y)
- if ballObject.Spawn then
- if ballObject.owner == "" then
- local ballX1 = (tfm.get.room.objectList[ballObject.id].x - tfm.get.room.objectList[ballObject.id].vx) - 60
- local ballX2 = (tfm.get.room.objectList[ballObject.id].x + tfm.get.room.objectList[ballObject.id].vx) + 60
- local ballY1 = (tfm.get.room.objectList[ballObject.id].y - tfm.get.room.objectList[ballObject.id].vy) - 60
- local ballY2 = (tfm.get.room.objectList[ballObject.id].y + tfm.get.room.objectList[ballObject.id].vy) + 60
- if x + 25 >= ballX1 and x - 25 <= ballX2 and y + 25 >= ballY1 and y - 25 <= ballY2 then
- ballWithPlayer(name)
- end
- end
- else
- if ballObject.owner ~= "" and ballObject.owner ~= name and playerTeam[ballObject.owner].team ~= playerTeam[name].team then
- local ballX1 = (tfm.get.room.playerList[ballObject.owner].x - tfm.get.room.playerList[ballObject.owner].vx - distanceToCatch.x - playerDirection.x1)
- local ballX2 = (tfm.get.room.playerList[ballObject.owner].x + tfm.get.room.playerList[ballObject.owner].vx + distanceToCatch.x + playerDirection.x2)
- local ballY1 = (tfm.get.room.playerList[ballObject.owner].y - tfm.get.room.playerList[ballObject.owner].vy - distanceToCatch.y)
- local ballY2 = (tfm.get.room.playerList[ballObject.owner].y + tfm.get.room.playerList[ballObject.owner].vy + distanceToCatch.y)
- if x + 10 >= ballX1 and x - 10 <= ballX2 and y + 10 >= ballY1 and y - 10 <= ballY2 then
- ballCatch(name)
- end
- end
- end
- end
- function ballWithPlayer(name)
- tfm.exec.removePhysicObject(1)
- ballObject.verifyCoords = false
- ballObject.Spawn = false
- canCatchBall()
- tfm.exec.removeObject(ballObject.id)
- idImage = tfm.exec.addImage("175aa78bb80.png", "$"..name, -45, -125, nil)
- ballObject.owner = name
- system.bindMouse(name, true)
- playersActions[name].canCatch = true
- showImageBallWithPlayer(name)
- eventKeyBoardControl(name, true)
- end
- function ballCatch(name)
- system.bindMouse(ballObject.owner, false)
- eventKeyBoardControl(ballObject.owner, false)
- removeTimer("powerShoot")
- gameStats.powerShootEvent = false
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- ballObject.verifyCoords = false
- ballObject.Spawn = false
- forceIndex = 0
- canCatchBall()
- tfm.exec.removeImage(idImage)
- tfm.exec.removeImage(ballObject.ID_image)
- delayCatchEVT(ballObject.owner)
- idImage = tfm.exec.addImage("175aa78bb80.png", "$"..name, -45, -125, nil)
- ballObject.owner = name
- playersActions[name].canCatch = true
- showImageBallWithPlayer(name)
- system.bindMouse(ballObject.owner, true)
- eventKeyBoardControl(ballObject.owner, true)
- end
- function timerLoopToCoordinatesOfBall()
- delayToStart = addTimer(function(i)
- coordinatesOfBall = addTimer(function(i)
- if ballObject.Spawn then
- if tfm.get.room.objectList[ballObject.id].vx > 0 then
- tfm.get.room.objectList[ballObject.id].x = tfm.get.room.objectList[ballObject.id].x + (tfm.get.room.objectList[ballObject.id].vx * 60)
- elseif tfm.get.room.objectList[ballObject.id].vx < 0 then
- tfm.get.room.objectList[ballObject.id].x = tfm.get.room.objectList[ballObject.id].x - (tfm.get.room.objectList[ballObject.id].vx * 60)
- end
- if tfm.get.room.objectList[ballObject.id].vy > 0 then
- tfm.get.room.objectList[ballObject.id].y = tfm.get.room.objectList[ballObject.id].y + (tfm.get.room.objectList[ballObject.id].vy * 60)
- elseif tfm.get.room.objectList[ballObject.id].vy < 0 then
- tfm.get.room.objectList[ballObject.id].y = tfm.get.room.objectList[ballObject.id].y - (tfm.get.room.objectList[ballObject.id].vy * 60)
- end
- verifyCollisionOfBallWithWall()
- end
- end, 1000, 0, "coordinatesOfBall")
- end, 2500, 1, "delayToStart")
- end
- function verifyCollisionOfBallWithWall()
- --this function is responsible for verifying if the function of calculating the coordinates of the ball goes beyond the limits of the map
- if tfm.get.room.objectList[ballObject.id].x >= 751 then
- tfm.get.room.objectList[ballObject.id].x = 751
- elseif tfm.get.room.objectList[ballObject.id].x <= 102 and tfm.get.room.objectList[ballObject.id].y > 220 then
- tfm.get.room.objectList[ballObject.id].x = 102
- end
- if tfm.get.room.objectList[ballObject.id].y >= 268 then
- tfm.get.room.objectList[ballObject.id].y = 268
- end
- end
- function shootTheBall(x, y, forceIndex, name)
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- removeTimer("powerShoot")
- tfm.exec.removeImage(idImage)
- tfm.exec.removeImage(ballObject.ID_image)
- system.bindMouse(ballObject.owner, false)
- eventKeyBoardControl(ballObject.owner, false)
- gameStats.LastShoot.name = name
- gameStats.LastShoot.x = x
- ballObject.Spawn = true
- ballObject.verifyCoords = true
- ballObject.id = tfm.exec.addShamanObject(17, x, y, 0, 0, 0, true)
- local distanceX = 0
- local distanceY = 0
- if ballForce[forceIndex] == nil or type(forceIndex) ~= "number" then
- forceIndex = 1
- end
- if ballObject.lastKeyPressed == 0 then
- if x <= 288 and y >= 372 and forceIndex >= 5 then
- distanceX = x - 285
- distanceY = -50
- elseif x <= 345 then
- distanceX = -5
- distanceY = -50
- end
- tfm.exec.moveObject(ballObject.id, x, y, false, ballForce[forceIndex].vx - distanceX, ballForce[forceIndex].vy + distanceY, false, 0, true)
- else
- tfm.exec.moveObject(ballObject.id, x, y, false, math.abs(ballForce[forceIndex].vx) - distanceX, ballForce[forceIndex].vy + distanceY, false, 0, true)
- end
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
- timerDelayPowerTheBall()
- if forceIndex > 4 then
- canCatchBallOnShoot(2000)
- else
- canCatchBallOnShoot(1000)
- end
- ballObject.owner = ""
- gameStats.forceIndex = 0
- gameStats.ocurrencyLoop8th = 0
- delayCatchEVT(name)
- end
- function eventKeyBoardControl(name, active)
- local keys = {0, 2, 3}
- for i = 1, 3 do
- system.bindKeyboard(name, keys[i], true, active)
- end
- end
- function showImageBallWithPlayer(name)
- if tfm.get.room.playerList[name].isFacingRight then
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, 5, -15, nil, 1, 1, _, 1)
- ballObject.playerIsRight = true
- else
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "$"..name, -35, -15, nil, 1, 1, _, 1)
- ballObject.playerIsRight = false
- end
- end
- function identifyPlayers()
- for i = 1, 3 do
- if teamRed[i].player ~= "" then
- playerTeam[teamRed[i].player].team = "Red"
- end
- if teamBlue[i].player ~= "" then
- playerTeam[teamBlue[i].player].team = "Blue"
- end
- end
- end
- function passToTeamPlayer(name, x, y, playerTeamName)
- if playerTeamName == "Red" then
- teamName = teamRed
- else
- teamName = teamBlue
- end
- local minDistance = ""
- local playerIndex = ""
- for i = 1, 3 do
- if teamName[i].player ~= ballObject.owner and teamName[i].player ~= "" then
- local player = teamName[i].player
- if math.abs(x - tfm.get.room.playerList[player].x) <= 30 and math.abs(y - tfm.get.room.playerList[player].y) <= 30 then
- if minDistance == "" then
- minDistance = tfm.get.room.playerList[player].x
- playerIndex = i
- else
- if tfm.get.room.playerList[player] < minDistance then
- minDistance = tfm.get.room.playerList[player].x
- playerIndex = i
- end
- end
- end
- end
- end
- if minDistance ~= "" and mode == "gameStarted" then
- removeTimer("powerShoot")
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- eventKeyBoardControl(ballObject.owner, false)
- tfm.exec.removeImage(idImage)
- tfm.exec.removeImage(ballObject.ID_image)
- system.bindMouse(ballObject.owner, false)
- ballObject.owner = teamName[playerIndex].player
- idImage = tfm.exec.addImage("175aa78bb80.png", "$"..ballObject.owner, -45, -125, nil)
- eventKeyBoardControl(ballObject.owner, true)
- showImageBallWithPlayer(ballObject.owner)
- system.bindMouse(ballObject.owner, true)
- gameStats.canPass = false
- gameStats.LastPass = ballObject.owner
- gameStats.powerShootEvent = false
- gameStats.canCatchBall = false
- canCatchBall()
- delayPass = addTimer(function(i)
- if i == 1 then
- gameStats.canPass = true
- end
- end, 500, 1, "delayPass")
- end
- end
- function canCatchBall()
- gameStats.canCatchBall = false
- delayCatchBall = addTimer(function(i)
- if i == 1 then
- gameStats.canCatchBall = true
- end
- end, 2500, 1, "delayCatchBall")
- end
- function canCatchBallOnShoot(setTimer)
- gameStats.canCatchBall = false
- delayCatchBall = addTimer(function(i)
- if i == 1 then
- gameStats.canCatchBall = true
- end
- end, setTimer, 1, "delayCatchBall")
- end
- function eventPoint()
- ballObject.verifyCoords = false
- ballObject.Spawn = false
- tfm.exec.removeObject(ballObject.id)
- local point = 0
- local assist = false
- if gameStats.LastShoot.x <= 288 then
- point = 2
- else
- point = 3
- end
- if gameStats.LastPass ~= "" then
- if playerTeam[gameStats.LastShoot.name].team == playerTeam[gameStats.LastPass].team then
- assist = true
- end
- end
- if playerTeam[gameStats.LastShoot.name].team == "Red" then
- redPoints = redPoints + point
- messageWhenMakePoint(trad.messageRedPoint, point, assist, "<r>")
- tfm.exec.chatMessage("<r>Red "..redPoints.."<n> - <bv>"..bluePoints.." Blue<n>" , nil)
- setScoreForPlayer(gameStats.LastShoot.name, assist, point)
- elseif playerTeam[gameStats.LastShoot.name].team == "Blue" then
- bluePoints = bluePoints + point
- messageWhenMakePoint(trad.messageBluePoint, point, assist, "<bv>")
- tfm.exec.chatMessage("<r>Red "..redPoints.."<n> - <bv>"..bluePoints.." Blue<n>" , nil)
- setScoreForPlayer(gameStats.LastShoot.name, assist, point)
- end
- if redPoints >= winscore then
- gameFinish()
- tfm.exec.chatMessage(trad.messageRedWinner , nil)
- winnerTimer = os.time() + 8000
- local mvp = findMvp()
- table.sort(mvp, function(a, b) return a.points > b.points end)
- tfm.exec.chatMessage(""..trad.messageMvp[1].." "..mvp[1].name.." "..trad.messageMvp[2].." "..mvp[1].points.." "..trad.messageMvp[3].."", nil)
- mode = "winner"
- elseif bluePoints >= winscore then
- gameFinish()
- tfm.exec.chatMessage(trad.messageBlueWinner , nil)
- winnerTimer = os.time() + 8000
- local mvp = findMvp()
- tfm.exec.chatMessage(""..trad.messageMvp[1].." "..mvp[1].name.." "..trad.messageMvp[2].." "..mvp[1].points.." "..trad.messageMvp[3].."", nil)
- mode = "winner"
- else
- spawnBall()
- end
- ui.setMapName("<N><ch>#Basketball Street<n> <G>| <r>Red<n> "..redPoints.."<G> | <bv>Blue<n> "..bluePoints.."<")
- end
- function setScoreForPlayer(playerMakePoint, playerMakeAssist, point)
- local value_assistence = 1
- tfm.exec.setPlayerScore(playerMakePoint, point, true)
- storePointsOfPlayers[playerMakePoint].points = storePointsOfPlayers[playerMakePoint].points + point
- if playerMakeAssist then
- tfm.exec.setPlayerScore(gameStats.LastPass, value_assistence, true)
- storePointsOfPlayers[gameStats.LastPass].points = storePointsOfPlayers[gameStats.LastPass].points + value_assistence
- end
- end
- function findMvp()
- local mvp = {}
- for name, data in pairs(tfm.get.room.playerList) do
- mvp[#mvp + 1] = {name = name, points = storePointsOfPlayers[name].points}
- end
- return mvp
- end
- function messageWhenMakePoint(teamPoint, point, assist, tag)
- if assist then
- tfm.exec.chatMessage(""..tag.."+"..point.." "..teamPoint.."<n> "..trad.messageWhoMakePoint.." "..gameStats.LastShoot.name.." "..trad.messageIfHaveAssist.." "..gameStats.LastPass.."", nil)
- else
- tfm.exec.chatMessage(""..tag.."+"..point.." "..teamPoint.."<n> "..trad.messageWhoMakePoint.." "..gameStats.LastShoot.name.."" , nil)
- end
- end
- function gameFinish()
- tfm.exec.removeBonus(id, nil)
- if imagePower[1].image ~= "" then tfm.exec.removeImage(imagePower[1].image) end
- ballObject.Spawn = false
- ui.removeTextArea(2400)
- removeTimer("SpawnPowerLoop")
- removeTimer("loopTimer")
- removeTimer("timerLoopVerify")
- removeTimer("coordinatesOfBall")
- for i = 1, 3 do
- if teamRed[i].player ~= "" then
- disableActionsOnGame(teamRed[i].player)
- end
- if teamBlue[i].player ~= "" then
- disableActionsOnGame(teamBlue[i].player)
- end
- end
- end
- function disableActionsOnGame(name)
- tfm.exec.removeImage(invetoryPlayer[name].image)
- setKeysEvent(name, false, true)
- setKeysEvent(name, false, true)
- end
- function clearTextArea()
- ui.removeTextArea(-1)
- for i = 0, 6 do
- ui.removeTextArea(i)
- end
- end
- function createPower()
- loopTimer = addTimer(function(i)
- SpawnPowerLoop = addTimer(function(i)
- if i == 1 then
- if imagePower[1].image ~= "" then
- tfm.exec.removeBonus(1, nil)
- tfm.exec.removeImage(imagePower[1].image)
- end
- local x = math.random(240, 720)
- local y = math.random(130, 366)
- local powerSelect = powers[math.random(1, #powers)]
- imagePower[1].powerIndex = powerSelect
- tfm.exec.addBonus(0, x, y, 1, 0, false, nil)
- imagePower[1].image = tfm.exec.addImage(powerSelect.image, "&1", x, y, nil)
- end
- end, 15000, 1, "SpawnPowerLoop")
- end, 16000, 0, "loopTimer")
- end
- function eventPlayerBonusGrabbed(name, id)
- tfm.exec.removeBonus(id, nil)
- tfm.exec.removeImage(imagePower[1].image)
- if invetoryPlayer[name].image ~= "" then
- tfm.exec.removeImage(invetoryPlayer[name].image)
- end
- invetoryPlayer[name].powerIndex = imagePower[1].powerIndex
- if invetoryPlayer[name].powerIndex.powerName == "Speed" then
- eventKeyBoardControl(name, true)
- end
- invetoryPlayer[name].image = tfm.exec.addImage(imagePower[1].powerIndex.image, ":1", 745, 138, name)
- end
- function eventChatCommand(name, cmd)
- if admins[name] then
- if string.lower(string.sub(cmd, 1, 8)) == "winscore" and type(tonumber(string.sub(cmd, 10))) == "number" and mode == "gameStarted" then
- winscore = tonumber(string.sub(cmd, 10))
- elseif (cmd:sub(0,10) == "resettimer") and mode == "start" then
- initTimer = os.time() + 15000
- end
- end
- if (cmd:sub(1,4) == "lang") then
- local v = string.lower(cmd:sub(6,7))
- if v == "br" then
- playerLanguage[name].tr = lang.br
- elseif v == "en" then
- playerLanguage[name].tr = lang.en
- end
- elseif (cmd:sub(1,4) == "help") then
- removeImageOfTheWindow(name)
- removeImageOfThePowersWindow(name)
- playerImage[name] = ui.addWindow(8, playerLanguage[name].tr.howToPlayText, name, 125, 60, 650, 300, 1, true, true, playerLanguage[name].tr.closeUIText)
- elseif string.lower(cmd) == "join" and not playersJoined[name] and mode == "gameStarted"then
- chooseTeam(name)
- elseif string.lower(cmd) == "leave" and playersJoined[name] and mode == "gameStarted" then
- leaveTeam(name)
- end
- end
- function chooseTeam(name)
- quantityPlayersJoined()
- if quantity.red < quantity.blue then
- joinOnTeam(name, teamRed, 0xEB4848)
- elseif quantity.blue < quantity.red then
- joinOnTeam(name, teamBlue, 0x2167ED)
- elseif quantity.red == quantity.blue and quantity.red ~= 3 then
- joinOnTeam(name, teamRed, 0xEB4848)
- else
- tfm.exec.chatMessage(trad.messageFullTeam, name)
- end
- end
- function joinOnTeam(name, teamName, color)
- for i = 1, #teamName do
- if teamName[i].player == "" then
- teamName[i].player = name
- playersJoined[name] = true
- playersActions[teamName[i].player] = {canCatch = false}
- setKeysEvent(teamName[i].player, true, false)
- tfm.exec.movePlayer(teamName[i].player, math.random(240, 700), 368)
- tfm.exec.setNameColor(teamName[i].player, color)
- windowUIPowersShow(teamName[i].player)
- delayCatchEVT(name)
- if color == 0xEB4848 then
- playerTeam[name].team = "Red"
- else
- playerTeam[name].team = "Blue"
- end
- break
- end
- end
- end
- function leaveTeam(name)
- if playerTeam[name].team == "Red" then
- for i = 1, 3 do
- if teamRed[i].player == name then
- disableSettingsPlayerOnTeam(i, name, teamRed)
- break
- end
- end
- elseif playerTeam[name].team == "Blue" then
- for i = 1, 3 do
- if teamBlue[i].player == name then
- disableSettingsPlayerOnTeam(i, name, teamBlue)
- break
- end
- end
- end
- end
- function disableSettingsPlayerOnTeam(index, name, teamName)
- if ballObject.owner == name then
- system.bindMouse(ballObject.owner, false)
- eventKeyBoardControl(ballObject.owner, false)
- removeTimer("powerShoot")
- gameStats.powerShootEvent = false
- tfm.exec.removeImage(idImage)
- tfm.exec.removeImage(ballObject.ID_image)
- ui.removeTextArea(999)
- ui.removeTextArea(1000)
- ui.removeTextArea(1001)
- ballObject.id = tfm.exec.addShamanObject(17, 0, 0, 0, 0, 0, true)
- 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)
- ballObject.ID_image = tfm.exec.addImage("17bd8be9691.png", "#"..ballObject.id, -15, -15, nil, 1, 1, _, 1)
- ballObject.Spawn = true
- ballObject.owner = ""
- end
- playersJoined[name] = false
- playersActions[teamName[index].player] = {canCatch = true}
- setKeysEvent(teamName[index].player, false, false)
- tfm.exec.movePlayer(teamName[index].player, 422, 90)
- tfm.exec.setNameColor(teamName[index].player, 0xA7A4A2)
- ui.removeTextArea(2400, name)
- teamName[index].player = ""
- end
- init()
Add Comment
Please, Sign In to add comment