Advertisement
Sossia

[Minigame] Loading

Aug 6th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.57 KB | None | 0 0
  1. -- variables important
  2. Data_Player = {} -- store player data
  3. deleteObjectShaman = {} -- Delete objects
  4. Maps = {7472840,7472843,7472870,7472872,7472873,7472895} -- Map list
  5. Players = 0 -- Store live players
  6. RoomPlayers = 0 -- Store players in room
  7.  
  8. --Disable some automatic things.
  9. for _, s in next, {'AutoTimeLeft', 'PhysicalConsumables', 'AfkDeath', 'AutoShaman', 'AutoNewGame'} do
  10.     tfm.exec['disable' .. s]()
  11. end
  12. -- Translations game
  13. 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?", }, }
  14. --
  15. function eventNewPlayer(name)
  16.   RoomPlayers = RoomPlayers + 1
  17.   Data_Player[name] = { --  Saves player data / Generates data when a player enters the room
  18.     points = 0, --
  19.     coins = 0,
  20.     Jump = 0,
  21.     eventSettings = false,
  22.     Ball = 0,
  23.     Cloud = 0,
  24.     time = os.time(),
  25.     Language = "",
  26.     starts = {jump = false, ball = false, cloud = false},
  27.     Usage = {jump = 0, ball = 0, cloud = 0},      
  28.   }
  29.   settingsKeyboard(name) -- Settings keyboard player
  30.   Points(name)
  31.   tfm.exec.respawnPlayer(name)
  32.   updatePoints_Coins(name)
  33.   ---
  34.   ui.addTextArea(0, "", name, 9, 372, 71, 19, 0x324f35, 0x324650, 0.4, true)
  35.   ui.addTextArea(1, "", name, 9, 372, 71, 19, 0x324f35, 0x324650, 0.4, true)
  36.   ui.addTextArea(2, "", name, 9, 372, 71, 19, 0x324f35, 0x324650, 0.4, true)
  37.   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)
  38.   ui.addTextArea(4, "<a href='event:open_shop'><B>Shop</a>", name, 754, 369, 36, 20, 0x324f35, 0x324650, 0.8, true)
  39.   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)
  40.   Data_Player[name].Language = translations[tfm.get.room.playerList[name].community] and tfm.get.room.playerList[name].community or 'en'
  41.   Out_Players(name)
  42. end
  43. -- Functions that update points. (Or the textareas)
  44. 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
  45. 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
  46.  
  47. function eventNewGame()
  48.   Players = 0 -- The variable returns to 0
  49.   for name in pairs(tfm.get.room.playerList) do -- All players
  50.     Players = Players + 1 -- Adds one more to the variable
  51.     Data_Player[name].coins = 0
  52.     Data_Player[name].points = 0
  53.     updatePoints_Coins(name)
  54.   end
  55.   tfm.exec.setGameTime(220) -- Set the playing time
  56. end
  57. --
  58. function eventLoop(current,remaining)
  59.   for _,obj in ipairs(deleteObjectShaman) do
  60.     if obj.time < os.time()-15000 then -- Remove shamans objects after 17 seconds
  61.       tfm.exec.removeObject(obj.id)
  62.       table.remove(deleteObjectShaman,_)
  63.     end
  64.   end
  65.   if Players == 0 or remaining <= 0 then -- If the number of live players = 0 or time = 0
  66.     tfm.exec.newGame(Maps[math.random(#Maps)]) -- Execute a new game
  67.   end
  68. end
  69. -- Events made by commands in chat
  70. function eventChatCommand(name, command)
  71.   if command == "help" then
  72.     tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].help.."",name)
  73.   end
  74. end
  75. --
  76. function Out_Players(name)
  77.   local i = 0
  78.   if RoomPlayers < 2 then
  79.     while i < 1 do
  80.       i = i + 1
  81.       tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].Players.."",name)
  82.     end
  83.   end
  84. end
  85. -- Player won
  86. function eventPlayerWon(name) --  The event happens when a player enters the hole.
  87.   tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].won.."",name)
  88.   Players = Players - 1 -- Decrease the amount of live players. The variable is equal to itself - 1
  89. end
  90. -- When player die
  91. function eventPlayerDied(name)
  92.   Players = Players - 1 -- The variable receives its own value - 1
  93.   tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].died.."",name) --  Sends a message to the player when he dies
  94. end
  95. -- If the player leaves the room
  96. function eventPlayerLeft(name)
  97.   Players = Players - 1
  98.   RoomPlayers = RoomPlayers - 1
  99.   Out_Players(name)
  100. end
  101. --
  102. function eventTextAreaCallback(id,name,link)
  103.   if link == [[buy_jump]] then
  104.     if Data_Player[name].coins > 20 and Data_Player[name].starts.ball == false and Data_Player[name].starts.cloud == false then
  105.       Data_Player[name].starts.jump = true -- Gives the value of true, which will mean that the player is currently using the item.
  106.       Points(name)
  107.       updatePoints_Coins(name)
  108.       Data_Player[name].Usage.jump = 0 --The value of the variable returns to 0
  109.       Data_Player[name].coins = Data_Player[name].coins - 20
  110.       tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].bought.."",name)
  111.       tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].bought_jump.."",name)
  112.     else
  113.       tfm.exec.chatMessage("<CE>"..translations[Data_Player[name].Language].noMoney.."",name)          
  114.     end
  115.     for i = 50,57 do
  116.       ui.removeTextArea(i,name)
  117.     end
  118.   elseif link == [[buy_ball]] then
  119.     if Data_Player[name].coins > 30 and Data_Player[name].starts.jump == false and Data_Player[name].starts.cloud == false then
  120.       Data_Player[name].starts.ball = true
  121.       Points(name)
  122.       Data_Player[name].coins = Data_Player[name].coins - 30
  123.       updatePoints_Coins(name)
  124.       tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].bought.."",name)
  125.       tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].bought_ball.."",name)
  126.     else  
  127.       tfm.exec.chatMessage("<CE>"..translations[Data_Player[name].Language].noMoney.."",name)          
  128.     end
  129.     for i = 50,57 do
  130.       ui.removeTextArea(i,name)
  131.     end    
  132.   elseif link == [[buy_cloud]] then
  133.     if Data_Player[name].coins > 40 and Data_Player[name].starts.jump == false and Data_Player[name].starts.ball == false then
  134.       Data_Player[name].starts.cloud = true
  135.       Points(name)
  136.       Data_Player[name].coins = Data_Player[name].coins - 40
  137.       updatePoints_Coins(name)
  138.       tfm.exec.chatMessage("<VP>"..translations[Data_Player[name].Language].bought.."",name)
  139.       tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].bought_cloud.."",name)
  140.     else  
  141.       tfm.exec.chatMessage("<CE>"..translations[Data_Player[name].Language].noMoney.."",name)          
  142.     end
  143.     for i = 50,57 do
  144.       ui.removeTextArea(i,name)
  145.     end
  146.   elseif link == [[open_shop]] then
  147.     ui.addTextArea(50, "<p align='center'><font size='25'><CH><B>Shop</font></p>", name, 195, 87, 412, 209, 0x313a4a, 0x313a4a, 1, true)
  148.     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)
  149.     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)
  150.     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)
  151.     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)
  152.     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)
  153.     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)
  154.     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)
  155.   elseif link == [[close_shop]] then
  156.     for i = 50,57 do
  157.       ui.removeTextArea(i,name)
  158.     end
  159.   elseif link == [[open_help]] then
  160.     tfm.exec.chatMessage("<ROSE>"..translations[Data_Player[name].Language].help.."",name)
  161.   end
  162. end
  163. -- Settings to keyboard
  164. function settingsKeyboard(name)
  165.   if k == 32 and tfm.get.room.playerList[name].isFacingRight == true and info[name].time < os.time()-1500 then
  166.     info[name].time = os.time()
  167.     tfm.exec.movePlayer(name,0,0,true,100,0,false)
  168.   elseif k == 32 and tfm.get.room.playerList[name].isFacingRight == false and info[name].time < os.time()-1500 then
  169.     info[name].time = os.time()
  170.     tfm.exec.movePlayer(name,0,0,true,-100,0,false)
  171.   end
  172. local facingLeft = {} -- Create a table facing left
  173. for name in pairs(tfm.get.room.playerList) do
  174.   for _,key in pairs{0,2,3,32,40,74,75} do system.bindKeyboard(name, key, true)
  175.     end
  176. end
  177. function eventKeyboard(name, key, down, x, y)
  178.   if key == 0 or key == 2 then
  179.     facingLeft[name] = key == 0
  180.   elseif key == 3 then
  181.     Points(name)
  182.     tfm.exec.displayParticle(29,x,y,-0.2,-0.2,0,0)
  183.     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.
  184.     updatePoints_Coins(name) -- The function is updated when the key is pressed.
  185.   elseif key == 32 then
  186.     if Data_Player[name].starts.jump == true then -- Verify that the "jump" power is = a true. Which means it has been activated.
  187.       if Data_Player[name].Usage.jump < 4 then -- Verify if the jump variable is less than 4.
  188.         tfm.exec.movePlayer(name,0,-1,true,0,-49,false)
  189.         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.
  190.         tfm.exec.chatMessage("<VP>Jumps "..Data_Player[name].Usage.jump.."",name)
  191.         ui.updateTextArea(0,"<B>Jump "..Data_Player[name].Usage.jump.."/4",name)
  192.       else
  193.         Data_Player[name].starts.jump = false -- If the value has already been exceeded the variable that "unlocks" receives the value of false to "block".
  194.         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.
  195.         ui.updateTextArea(0,"",name)
  196.       end
  197.     end
  198.   elseif key == 75 then
  199.     if Data_Player[name].starts.ball == true then
  200.       if Data_Player[name].Usage.ball < 30 then
  201.         local direcao = (facingLeft[name] and -1 or 1)
  202.         obj_id = tfm.exec.addShamanObject(6, x + (40 * direcao), y, 0, 20 * direcao)
  203.         Data_Player[name].Usage.ball = Data_Player[name].Usage.ball + 1
  204.         ui.updateTextArea(1,"<B>Ball "..Data_Player[name].Usage.ball.."/30",name)
  205.       else
  206.         Data_Player[name].starts.ball = false
  207.         Data_Player[name].Usage.ball = 0
  208.         ui.updateTextArea(1,"",name)
  209.       end
  210.    table.insert(deleteObjectShaman,{id=obj_id,time=os.time()}) -- Remove the shamans objects
  211.     end
  212.   elseif key == 74 then
  213.     if Data_Player[name].starts.cloud == true then
  214.       if Data_Player[name].Usage.cloud < 3 then
  215.         local direcao = (facingLeft[name] and -1 or 1)
  216.         obj_id = tfm.exec.addShamanObject(57, x + (40 * direcao), y, 0, 20 * direcao)
  217.         Data_Player[name].Usage.cloud = Data_Player[name].Usage.cloud + 1
  218.         ui.updateTextArea(2,"<B>Cloud "..Data_Player[name].Usage.cloud.."/3",name)
  219.       else
  220.         Data_Player[name].starts.cloud = false
  221.         Data_Player[name].Usage.cloud = 0
  222.         ui.updateTextArea(2,"",name)
  223.       end
  224.     end
  225.     table.insert(deleteObjectShaman,{id=obj_id,time=os.time()}) -- Remove the shamans objects
  226.     end
  227.   end
  228. end
  229. ---
  230. table.foreach(tfm.get.room.playerList,eventNewPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement