Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- variables important
- Data_Player = {} -- store player data
- deleteObjectShaman = {} -- Delete objects
- Maps = {7472840,7472843,7472870,7472872,7472873,7472895} -- Map list
- Players = 0 -- Store live players
- RoomPlayers = 0 -- Store players in room
- --Disable some automatic things.
- for _, s in next, {'AutoTimeLeft', 'PhysicalConsumables', 'AfkDeath', 'AutoShaman', 'AutoNewGame'} do
- tfm.exec['disable' .. s]()
- end
- -- Translations game
- translations = {br = {help = "Abaixe-se para ganhar pontos.\nQuando seus pontos forem maiores que 10, você ganhará moedas. Suas moedas são o valor de seus pontos dividido.\nUse suas moedas para comprar poderes especiais.", bought = "Bom trabalho! Use o poder comprado!", power_jump = "Salto", power_ball = "Bola", power_cloud = "Nuvem", bought_jump = "Pressione a tecla [Barra de espaço] para pular.", bought_ball = "Pressione a tecla [K] para soltar bolas.", bought_cloud = "Pressione a tecla [J] para adicionar uma nuvem.", noMoney = "Você não tem moedas suficientes para fazer a compra ou você já comprou outro item.", died = "Ops! Você morreu!", coins = "Moedas", won = "Parabéns! Você completou o mapa.", Players = "Não seria mais divertido brincar com mais pessoas?", }, en = {help = "Lower yourself to get points.\nWhen your points are greater than 10, you will earn coins.Your coins is the value of your points divided.Use your coins to buy special powers.", bought = "Good job! Use the power purchased!", power_jump = "Jump", power_ball = "Ball", power_cloud = "Cloud", bought_jump = "Press the [Spacebar] key to jump.", bought_ball = "Press the [K] key to release balls.", bought_cloud = "Press the [J] key to add a cloud.", noMoney = "You didn't have enough coins to make the purchase or you already bought another item.", died = "Ops! You died :(", coins = "Coins", won = "Good job! You won", Players = "Would not it be more fun to play with more people?", }, }
- --
- function eventNewPlayer(name)
- RoomPlayers = RoomPlayers + 1
- Data_Player[name] = { -- Saves player data / Generates data when a player enters the room
- points = 0, --
- coins = 0,
- Jump = 0,
- eventSettings = false,
- Ball = 0,
- Cloud = 0,
- time = os.time(),
- Language = "",
- starts = {jump = false, ball = false, cloud = false},
- Usage = {jump = 0, ball = 0, cloud = 0},
- }
- settingsKeyboard(name) -- Settings keyboard player
- Points(name)
- tfm.exec.respawnPlayer(name)
- updatePoints_Coins(name)
- ---
- ui.addTextArea(0, "", name, 9, 372, 71, 19, 0x324f35, 0x324650, 0.4, true)
- ui.addTextArea(1, "", name, 9, 372, 71, 19, 0x324f35, 0x324650, 0.4, true)
- ui.addTextArea(2, "", name, 9, 372, 71, 19, 0x324f35, 0x324650, 0.4, true)
- ui.addTextArea(3, "<p align='center'><J><B>P:(<VP></VP>) <pt><B>C:(<CE></CE>)", name, 9, 28, 156, 20, 0x324f35, 0x324f35, 0.8, true)
- ui.addTextArea(4, "<a href='event:open_shop'><B>Shop</a>", name, 754, 369, 36, 20, 0x324f35, 0x324650, 0.8, true)
- ui.addTextArea(5, "<p align='center'><a href='event:open_help'><B>H</a></p>", name, 728, 369, 15, 20, 0x324f35, 0x324650, 0.8, true)
- Data_Player[name].Language = translations[tfm.get.room.playerList[name].community] and tfm.get.room.playerList[name].community or 'en'
- Out_Players(name)
- end
- -- Functions that update points. (Or the textareas)
- function updatePoints_Coins(name) ui.updateTextArea(3,"<p align='center'><J><B>P:(<VP>"..Data_Player[name].points.."</VP>) <pt><B>C:(<CE>"..Data_Player[name].coins.."</CE>)",name) end
- function Points(name) if Data_Player[name].points > 10 then Data_Player[name].coins = Data_Player[name].coins + math.floor(Data_Player[name].points/2) Data_Player[name].points = 0 end if Data_Player[name].starts.jump == true then ui.updateTextArea(0,"<B><CH>Jump "..Data_Player[name].Usage.jump.."/4",name) end if Data_Player[name].starts.ball == true then ui.updateTextArea(1,"<B><CH>Ball "..Data_Player[name].Usage.ball.."/30",name) end if Data_Player[name].starts.cloud == true then ui.updateTextArea(2,"<B><CH>Cloud "..Data_Player[name].Usage.cloud.."/3",name) end end
- function eventNewGame()
- Players = 0 -- The variable returns to 0
- for name in pairs(tfm.get.room.playerList) do -- All players
- Players = Players + 1 -- Adds one more to the variable
- Data_Player[name].coins = 0
- Data_Player[name].points = 0
- updatePoints_Coins(name)
- end
- tfm.exec.setGameTime(220) -- Set the playing time
- end
- --
- function eventLoop(current,remaining)
- for _,obj in ipairs(deleteObjectShaman) do
- if obj.time < os.time()-15000 then -- Remove shamans objects after 17 seconds
- tfm.exec.removeObject(obj.id)
- table.remove(deleteObjectShaman,_)
- end
- end
- if Players == 0 or remaining <= 0 then -- If the number of live players = 0 or time = 0
- tfm.exec.newGame(Maps[math.random(#Maps)]) -- Execute a new game
- end
- end
- -- Events made by commands in chat
- function eventChatCommand(name, command)
- if command == "help" then
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].help.."",name)
- end
- end
- --
- function Out_Players(name)
- local i = 0
- if RoomPlayers < 2 then
- while i < 1 do
- i = i + 1
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].Players.."",name)
- end
- end
- end
- -- Player won
- function eventPlayerWon(name) -- The event happens when a player enters the hole.
- tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].won.."",name)
- Players = Players - 1 -- Decrease the amount of live players. The variable is equal to itself - 1
- end
- -- When player die
- function eventPlayerDied(name)
- Players = Players - 1 -- The variable receives its own value - 1
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].died.."",name) -- Sends a message to the player when he dies
- end
- -- If the player leaves the room
- function eventPlayerLeft(name)
- Players = Players - 1
- RoomPlayers = RoomPlayers - 1
- Out_Players(name)
- end
- --
- function eventTextAreaCallback(id,name,link)
- if link == [[buy_jump]] then
- if Data_Player[name].coins > 20 and Data_Player[name].starts.ball == false and Data_Player[name].starts.cloud == false then
- Data_Player[name].starts.jump = true -- Gives the value of true, which will mean that the player is currently using the item.
- Points(name)
- updatePoints_Coins(name)
- Data_Player[name].Usage.jump = 0 --The value of the variable returns to 0
- Data_Player[name].coins = Data_Player[name].coins - 20
- tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].bought.."",name)
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].bought_jump.."",name)
- else
- tfm.exec.chatMessage("<CE>"..translations[Data_Player[name].Language].noMoney.."",name)
- end
- for i = 50,57 do
- ui.removeTextArea(i,name)
- end
- elseif link == [[buy_ball]] then
- if Data_Player[name].coins > 30 and Data_Player[name].starts.jump == false and Data_Player[name].starts.cloud == false then
- Data_Player[name].starts.ball = true
- Points(name)
- Data_Player[name].coins = Data_Player[name].coins - 30
- updatePoints_Coins(name)
- tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].bought.."",name)
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].bought_ball.."",name)
- else
- tfm.exec.chatMessage("<CE>"..translations[Data_Player[name].Language].noMoney.."",name)
- end
- for i = 50,57 do
- ui.removeTextArea(i,name)
- end
- elseif link == [[buy_cloud]] then
- if Data_Player[name].coins > 40 and Data_Player[name].starts.jump == false and Data_Player[name].starts.ball == false then
- Data_Player[name].starts.cloud = true
- Points(name)
- Data_Player[name].coins = Data_Player[name].coins - 40
- updatePoints_Coins(name)
- tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].bought.."",name)
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].bought_cloud.."",name)
- else
- tfm.exec.chatMessage("<CE>"..translations[Data_Player[name].Language].noMoney.."",name)
- end
- for i = 50,57 do
- ui.removeTextArea(i,name)
- end
- elseif link == [[open_shop]] then
- ui.addTextArea(50, "<p align='center'><font size='25'><CH><B>Shop</font></p>", name, 195, 87, 412, 209, 0x313a4a, 0x313a4a, 1, true)
- ui.addTextArea(51, "<p align='center'><font size='15'><a href='event:close_shop'><b><CH>X</R></a></p>", name, 580, 87, 27, 27, 0x324650, 0x000000, 0, true)
- ui.addTextArea(52, "<font size='15'><p align='center'><b><J>\n\n"..translations[Data_Player[name].Language].power_jump.."</R>", name, 205, 136, 120, 100, 0x314a4a, 0x314a4a, 1, true)
- ui.addTextArea(53, "<font size='15'><p align='center'><a href='event:buy_jump'><b><R>20 "..translations[Data_Player[name].Language].coins.."</R></a>", name, 204, 253, 120, 24, 0x314a4a, 0x314a4a, 1, true)
- ui.addTextArea(54, "<font size='15'><p align='center'><b><J>\n\n"..translations[Data_Player[name].Language].power_ball.."</R>", name, 340, 136, 120, 100, 0x314a4a, 0x314a4a, 1, true)
- ui.addTextArea(55, "<font size='15'><p align='center'><a href='event:buy_ball'><b><R>30 "..translations[Data_Player[name].Language].coins.."</R></a>", name, 340, 253, 120, 24, 0x314a4a, 0x314a4a, 1, true)
- ui.addTextArea(56, "<font size='15'><p align='center'><b><J>\n\n"..translations[Data_Player[name].Language].power_cloud.."</R>", name, 475, 136, 120, 100, 0x314a4a, 0x314a4a, 1, true)
- ui.addTextArea(57, "<font size='15'><p align='center'><a href='event:buy_cloud'><b><R>40 "..translations[Data_Player[name].Language].coins.."</R></a>", name, 475, 253, 120, 24, 0x314a4a, 0x314a4a, 1, true)
- elseif link == [[close_shop]] then
- for i = 50,57 do
- ui.removeTextArea(i,name)
- end
- elseif link == [[open_help]] then
- tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].help.."",name)
- end
- end
- -- Settings to keyboard
- function settingsKeyboard(name)
- if k == 32 and tfm.get.room.playerList[name].isFacingRight == true and info[name].time < os.time()-1500 then
- info[name].time = os.time()
- tfm.exec.movePlayer(name,0,0,true,100,0,false)
- elseif k == 32 and tfm.get.room.playerList[name].isFacingRight == false and info[name].time < os.time()-1500 then
- info[name].time = os.time()
- tfm.exec.movePlayer(name,0,0,true,-100,0,false)
- end
- local facingLeft = {} -- Create a table facing left
- for name in pairs(tfm.get.room.playerList) do
- for _,key in pairs{0,2,3,32,40,74,75} do system.bindKeyboard(name, key, true)
- end
- end
- function eventKeyboard(name, key, down, x, y)
- if key == 0 or key == 2 then
- facingLeft[name] = key == 0
- elseif key == 3 then
- Points(name)
- tfm.exec.displayParticle(29,x,y,-0.2,-0.2,0,0)
- Data_Player[name].points = Data_Player[name].points + 1 -- When the player lowers, he gains points. This is done because the variable is equal to itself + 1 whenever the key is pressed.
- updatePoints_Coins(name) -- The function is updated when the key is pressed.
- elseif key == 32 then
- if Data_Player[name].starts.jump == true then -- Verify that the "jump" power is = a true. Which means it has been activated.
- if Data_Player[name].Usage.jump < 4 then -- Verify if the jump variable is less than 4.
- tfm.exec.movePlayer(name,0,-1,true,0,-49,false)
- Data_Player[name].Usage.jump = Data_Player[name].Usage.jump + 1 -- The variable increases its value each time the player presses the key to reach the limit.
- tfm.exec.chatMessage("<VP>Jumps "..Data_Player[name].Usage.jump.."",name)
- ui.updateTextArea(0,"<B>Jump "..Data_Player[name].Usage.jump.."/4",name)
- else
- Data_Player[name].starts.jump = false -- If the value has already been exceeded the variable that "unlocks" receives the value of false to "block".
- Data_Player[name].Usage.jump = 0 -- The value of the variable that verifies how many times the player has used your power, the variable returns to 0. This prevents that, in case the player uses your power again, it block because the variable has already crossed the limits.
- ui.updateTextArea(0,"",name)
- end
- end
- elseif key == 75 then
- if Data_Player[name].starts.ball == true then
- if Data_Player[name].Usage.ball < 30 then
- local direcao = (facingLeft[name] and -1 or 1)
- obj_id = tfm.exec.addShamanObject(6, x + (40 * direcao), y, 0, 20 * direcao)
- Data_Player[name].Usage.ball = Data_Player[name].Usage.ball + 1
- ui.updateTextArea(1,"<B>Ball "..Data_Player[name].Usage.ball.."/30",name)
- else
- Data_Player[name].starts.ball = false
- Data_Player[name].Usage.ball = 0
- ui.updateTextArea(1,"",name)
- end
- table.insert(deleteObjectShaman,{id=obj_id,time=os.time()}) -- Remove the shamans objects
- end
- elseif key == 74 then
- if Data_Player[name].starts.cloud == true then
- if Data_Player[name].Usage.cloud < 3 then
- local direcao = (facingLeft[name] and -1 or 1)
- obj_id = tfm.exec.addShamanObject(57, x + (40 * direcao), y, 0, 20 * direcao)
- Data_Player[name].Usage.cloud = Data_Player[name].Usage.cloud + 1
- ui.updateTextArea(2,"<B>Cloud "..Data_Player[name].Usage.cloud.."/3",name)
- else
- Data_Player[name].starts.cloud = false
- Data_Player[name].Usage.cloud = 0
- ui.updateTextArea(2,"",name)
- end
- end
- table.insert(deleteObjectShaman,{id=obj_id,time=os.time()}) -- Remove the shamans objects
- end
- end
- end
- ---
- table.foreach(tfm.get.room.playerList,eventNewPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement