Advertisement
Sossia

[Minigame] Fullball

Jul 25th, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.18 KB | None | 0 0
  1. -- variables important
  2. DataPlayer =  {} -- store player data
  3. deleteObjectShaman = {} -- Delete objects
  4. Maps = {7472840,7472843,7472870,7472872,7472873,7472895} -- Map list
  5. LivePlayers = 0 -- Store live players
  6. RoomPlayers = 0 -- Store players in room
  7. --Disable some automatic things.
  8. for _, s in next, {'AutoTimeLeft', 'PhysicalConsumables', 'AfkDeath', 'AutoShaman', 'AutoNewGame'} do
  9.     tfm.exec['disable' .. s]()
  10. end
  11. -- Help, Profile and shop
  12. ui.addTextArea(201, "<p align='center'><a href='event:profile'><B><R>P</B></a></p>", name, 680, 375, 29, 19, 0x313a4a, 0x313a4a, 1, true)
  13. ui.addTextArea(202, "<p align='center'><a href='event:shop'><B><T>S</B></a></p>", name, 722, 375, 29, 19, 0x313a4a, 0x313a4a, 1, true)
  14. ui.addTextArea(203, "<p align='center'><a href='event:help'><B><J>H</B></a></p>", name, 764, 375, 29, 19, 0x313a4a, 0x313a4a, 1, true)
  15. --  Starts when a player enters the room
  16. function eventNewPlayer(name)
  17.   RoomPlayers = RoomPlayers + 1
  18.   DataPlayer[name] = { --  Saves player data / Generates data when a player enters the room
  19.     ball_Name = "Beach ball", -- Name of the ball currently used by the player
  20.     ball_Appearance = 6, -- Current appearance of the ball
  21.     level = 0, -- Level player
  22.     time = os.time(),
  23.     coins = 0, -- Coins to buy new items
  24.     itemUsage = false, -- Checks whether the player is using the original or purchased items.
  25.     Usage = {jump = 0,tp = 0,},  
  26.     stored_purchases = {Chicken = false,Snowball = false,Baiacu = false,}, -- If the player already bought, but removed
  27.     stop_usage = {Chicken = false,Snowball = false,Baiacu = false,}, --Checks if player is using item
  28.     player_Experience = 0, -- Amount of experience gained at the end of a match
  29.   }
  30.   settingsKeyboard(name) -- Settings keyboard player
  31.   tfm.exec.respawnPlayer(name)
  32.   Out_Players(name)
  33. end
  34. -- Starts event new game
  35. function eventNewGame()
  36.   LivePlayers = 0 -- The variable returns to 0
  37.   for name in pairs(tfm.get.room.playerList) do -- All players
  38.     LivePlayers = LivePlayers + 1 -- Adds one more to the variable
  39.     DataPlayer[name].Usage.jump = 0
  40.     DataPlayer[name].Usage.tp = 0
  41.   end
  42.   tfm.exec.setGameTime(150) -- Set the playing time
  43.   ui.setMapName("<VP>#FullBall") -- Map name
  44. end
  45. -- Loop in game
  46. function eventLoop(current,remaining)
  47.   for _,obj in ipairs(deleteObjectShaman) do
  48.     if obj.time < os.time()-17000 then -- Remove shamans objects after 17 seconds
  49.       tfm.exec.removeObject(obj.id)
  50.       table.remove(deleteObjectShaman,_)
  51.     end
  52.   end
  53.   if LivePlayers == 0 or remaining <= 0 then -- If the number of live players = 0 or time = 0
  54.     tfm.exec.newGame(Maps[math.random(#Maps)]) -- Execute a new game
  55.   end
  56. end
  57. --
  58. function eventEmotePlayed(name,emote)
  59.   if emote == 9 then
  60.     if DataPlayer[name].Usage.jump < 3 then
  61.       tfm.exec.movePlayer(name,0,0,true,0,-50,true)
  62.       DataPlayer[name].Usage.jump = DataPlayer[name].Usage.jump + 1
  63.       tfm.exec.chatMessage("<VP>Jumps "..DataPlayer[name].Usage.jump.."",name)
  64.     else
  65.       tfm.exec.chatMessage("<VP>You're too tired, you can not jump anymore. Wait for the next round to be able to jump again.",name)
  66.     end
  67.   elseif emote == 0 then
  68.     if DataPlayer[name].Usage.tp < 2 then
  69.       tfm.exec.movePlayer(name, math.random(0,800), math.random(0,400))
  70.       DataPlayer[name].Usage.tp = DataPlayer[name].Usage.tp + 1
  71.       tfm.exec.chatMessage("<VP>Teleports "..DataPlayer[name].Usage.tp.."",name)
  72.     else
  73.       tfm.exec.chatMessage("<VP>Your teleporter machine broke! You can teleport again on the next round.",name)
  74.     end
  75.   end
  76. end
  77. --
  78. function Out_Players(name)
  79.   local i = 0
  80.   if RoomPlayers < 2 then
  81.     while i < 1 do
  82.       i = i + 1
  83.       tfm.exec.chatMessage("<ROSE>Would not it be more fun to play with more people? :(",name)
  84.     end
  85.   end
  86. end
  87. -- When player die
  88. function eventPlayerDied(name)
  89.   LivePlayers = LivePlayers - 1 -- The variable receives its own value - 1
  90.   tfm.exec.chatMessage("<ROSE>Ops! You died :(",name) --  Sends a message to the player when he dies
  91. end
  92. -- If the player leaves the room
  93. function eventPlayerLeft(name)
  94.   LivePlayers = LivePlayers - 1
  95.   RoomPlayers = RoomPlayers - 1
  96.   Out_Players(name)
  97. end
  98. -- Player won
  99. function eventPlayerWon(name) --  The event happens when a player enters the hole.
  100.   DataPlayer[name].player_Experience = DataPlayer[name].player_Experience + 15
  101.   DataPlayer[name].coins = DataPlayer[name].coins + 4
  102.   tfm.exec.chatMessage("<ROSE>Good job, you won.",name)
  103.   LivePlayers = LivePlayers - 1 -- Decrease the amount of live players. The variable is equal to itself - 1
  104.   newLevel(name) -- When the player enters, the function is played.
  105. end
  106. -- appearance of the ball
  107. function appearanceBall(name)
  108.   if DataPlayer[name].itemUsage == false then --
  109.     if DataPlayer[name].level <= 20 then -- Checks if the player's level is < or = 20
  110.       DataPlayer[name].ball_Appearance = 6
  111.       DataPlayer[name].ball_Name = "Beach ball"
  112.       newLevel(name)
  113.     elseif DataPlayer[name].level >= 21 and DataPlayer[name].level < 30 then -- Checks if the player's level is > or = 20 and < 30
  114.       DataPlayer[name].ball_Appearance = 601
  115.       DataPlayer[name].ball_Name = "Poke ball"
  116.       newLevel(name)
  117.     elseif DataPlayer[name].level >= 29 and DataPlayer[name].level < 60 then  -- Checks if the player's level is > or = 30
  118.       DataPlayer[name].ball_Appearance = 602
  119.       DataPlayer[name].ball_Name = "Skull ball"
  120.       newLevel(name)
  121.     elseif DataPlayer[name].level >= 60 then
  122.       DataPlayer[name].ball_Appearance = 604
  123.       DataPlayer[name].ball_Name = "Trumpet"
  124.       newLevel(name)      
  125.     end
  126.   end
  127. end
  128. -- Player reaches a new level
  129. function newLevel(name)
  130.   if DataPlayer[name].player_Experience >= 100 then -- If the player's experience is >= 100 he gains a new level
  131.     DataPlayer[name].player_Experience = 0 -- The variable that stores the value of the experiment returns to = 0
  132.     DataPlayer[name].level = DataPlayer[name].level + 1 -- The variable is = variable + 1
  133.     tfm.exec.chatMessage("<PT>You've reached a new level",name)
  134.   end
  135. end
  136. -- Keyboard settings
  137. function settingsKeyboard(name)
  138.   if k == 32 and tfm.get.room.playerList[name].isFacingRight == true and info[name].time < os.time()-1500 then
  139.     info[name].time = os.time()
  140.     tfm.exec.movePlayer(name,0,0,true,100,0,false)
  141.   elseif k == 32 and tfm.get.room.playerList[name].isFacingRight == false and info[name].time < os.time()-1500 then
  142.     info[name].time = os.time()
  143.     tfm.exec.movePlayer(name,0,0,true,-100,0,false)
  144.   end
  145. local facingLeft = {} -- Create a table facing left
  146. for name in pairs(tfm.get.room.playerList) do
  147.   for _,key in pairs{0,2,3} do system.bindKeyboard(name, key, true)
  148.     end
  149. end
  150. function eventKeyboard(name, key, down, x, y)
  151.   if key == 0 or key == 2 then
  152.     facingLeft[name] = key == 0
  153.   elseif key == 3 and DataPlayer[name].time < os.time()-1000 then
  154.     DataPlayer[name].time = os.time();
  155.     if facingLeft[name] then -- If the player is facing left
  156.         obj_id = tfm.exec.addShamanObject(DataPlayer[name].ball_Appearance, x - 40, y, 0, - 20)
  157.         appearanceBall(name) -- Update appearance ball
  158.       else -- If no
  159.         obj_id = tfm.exec.addShamanObject(DataPlayer[name].ball_Appearance, x + 40, y, 0, 20)
  160.         appearanceBall(name) -- Update appearance ball
  161.     end
  162.     table.insert(deleteObjectShaman,{id=obj_id,time=os.time()}) -- Remove the shamans objects
  163.     end
  164.   end
  165. end
  166. -- Events made by commands in chat
  167. function eventChatCommand(name, command)
  168.   if command == "help" then
  169.     tfm.exec.chatMessage("<ROSE>The object of the game is to use the items (balls, boxes or purchased consumables) to fill the spaces between the clouds and reach for the cheese. Items will disappear every 17 seconds after being placed. Your powers are hidden in the emotions confetti and dancing.",name)
  170.     tfm.exec.chatMessage("<VP>To find out how to get custom balls, type !balls and !emotes for you to see your skills",name)
  171.   elseif command == "balls" then
  172.     tfm.exec.chatMessage("<ROSE>If your level is less than 20, you will use the beach ball (normal).\nIf your level is higher than 20, you will use the poke ball.\nIf your level is higher than 30, you will use the skull ball.\nIf your level is higher than 60, you will use the Trumpet.\nBut if you buy an item in the store, customizing the balls will be disabled.",name)
  173.   elseif command == "emote" then
  174.     tfm.exec.chatMessage("<ROSE>Throw confetti and you'll make a big leap. But attention, you can only use 3x.\nDance and you will be teleported to somewhere on the map, You can use only 2x.",name)
  175.   end
  176.   system.disableChatCommandDisplay(command,true)
  177. end
  178.  
  179. -- TextAreas
  180. function eventTextAreaCallback(t,name,link)
  181.   if link == [[profile]] then
  182.     ui.addTextArea(10, "", name, 292, 128, 238, 144, 0x324650, 0x324650, 1, true)
  183.     ui.addTextArea(11, "<font size='15'><a href='event:closeprofile'><b><R>X</R></a>", name, 508, 130, 21, 27, 0x324650, 0x000000, 0, true)
  184.     ui.addTextArea(12, "<font size='20'><b><pt>Level</font>", name, 292, 129, 79, 26, 0x324650, 0x000000, 0, true)
  185.     ui.addTextArea(13, "<font size='14'><b>"..DataPlayer[name].level.."<font>", name, 294, 161, 86, 24, 0x314a4a, 0x313a4a, 1, true)
  186.     ui.addTextArea(14, "<font size='20'><b><BV>XP</font>", name, 396, 128, 79, 26, 0x324650, 0x000000, 0, true)
  187.     ui.addTextArea(15, "<font size='14'><b>"..DataPlayer[name].player_Experience.."/100<font>", name, 396, 161, 86, 24, 0x314a4a, 0x313a4a, 1, true)
  188.     ui.addTextArea(16, "<font size='20'><b><CEP>Ball</font>", name, 292, 192, 79, 26, 0x324650, 0x000000, 0, true)
  189.     ui.addTextArea(17, "<font size='14'><b>"..DataPlayer[name].ball_Name.."<font>", name, 294, 228, 86, 24, 0x314a4a, 0x313a4a, 1, true)
  190.     ui.addTextArea(18, "<font size='20'><b><V>Coins</font>", name, 396, 194, 79, 26, 0x324650, 0x000000, 0, true)
  191.     ui.addTextArea(19, "<font size='14'><b>"..DataPlayer[name].coins.."<font>", name, 396, 229, 86, 24, 0x314a4a, 0x313a4a, 1, true)
  192.   elseif link == [[closeprofile]] then
  193.     for i = 10,19 do --
  194.       ui.removeTextArea(i,name)
  195.     end
  196.   elseif link == [[shop]] then
  197.     ui.addTextArea(50, "<p align='center'><font size='25'><CH><B>Shop</font></p>", name, 195, 87, 412, 229, 0x313a4a, 0x313a4a, 1, true)
  198.     ui.addTextArea(51, "<font size='15'><a href='event:closeshop'><b><R>X</R></a>", name, 582, 87, 21, 27, 0x324650, 0x000000, 0, true)
  199.     ui.addTextArea(52, "<font size='15'><p align='center'><b><J>\n\nChicken</R>", name, 205, 136, 120, 100, 0x314a4a, 0x314a4a, 1, true)
  200.     ui.addTextArea(53, "<font size='15'><p align='center'><a href='event:buy_chicken'><b><R>50 coins</R></a>", name, 204, 253, 120, 24, 0x314a4a, 0x314a4a, 1, true)
  201.     ui.addTextArea(54, "<font size='15'><p align='center'><b><J>\n\nSnowball</R>", name, 340, 136, 120, 100, 0x314a4a, 0x314a4a, 1, true)
  202.     ui.addTextArea(55, "<font size='15'><p align='center'><a href='event:buy_snowball'><b><R>75 coins</R></a>", name, 340, 253, 120, 24, 0x314a4a, 0x314a4a, 1, true)
  203.     ui.addTextArea(56, "<font size='15'><p align='center'><b><J>\n\nBaiacu</R>", name, 475, 136, 120, 100, 0x314a4a, 0x314a4a, 1, true)
  204.     ui.addTextArea(57, "<font size='15'><p align='center'><a href='event:buy_baiacu'><b><R>100 coins</R></a>", name, 475, 253, 120, 24, 0x314a4a, 0x314a4a, 1, true)
  205.   elseif link == [[closeshop]] then
  206.     for i = 50,60 do
  207.       ui.removeTextArea(i,name)
  208.     end
  209. -- Buy chicken settings
  210.   elseif link == [[buy_chicken]] then
  211.     chicken(name)
  212.   elseif link == [[remove_chicken]] then
  213.     DataPlayer[name].itemUsage = false -- If the item is removed, the value of the variable returns false. This causes the appearanceBall() function to function again.
  214.     ui.updateTextArea(53,"<a href='event:use_chicken'>Use</a>",name)
  215.     ui.removeTextArea(58,name)
  216.   elseif link == [[use_chicken]] then
  217.     DataPlayer[name].itemUsage = true
  218.     DataPlayer[name].stored_purchases.Chicken = true -- Gives the variable a true value. This means that after obtaining the item it will be saved as "already bought" if the player wishes to remove. This will prevent they from having to buy whenever they want to use it.
  219.     DataPlayer[name].stop_usage.Snowball = false --
  220.     DataPlayer[name].stop_usage.Baiacu = false --
  221.     ui.updateTextArea(53,"<CE>Using",name) -- The text is reset to inform you that the item was obtained by the player.
  222.     ui.addTextArea(58, "<font size='15'><p align='center'><a href='event:remove_chicken'><b><R>remove</R></a>", name, 226, 291, 81, 22, 0x314a4a, 0x314a4a, 1, true)
  223.     if DataPlayer[name].coins >= 50 and DataPlayer[name].stop_usage.Snowball == false and DataPlayer[name].stop_usage.Baiacu == false then
  224.       DataPlayer[name].ball_Appearance = 33
  225.     end    
  226. -- Buy snowball settings
  227.   elseif link == [[buy_snowball]] then
  228.     snowball(name)
  229.   elseif link == [[remove_snowball]] then
  230.     DataPlayer[name].itemUsage = false
  231.     ui.updateTextArea(55,"<a href='event:use_snowball'>Use</a>",name)
  232.     ui.removeTextArea(59,name)
  233.   elseif link == [[use_snowball]] then
  234.     DataPlayer[name].itemUsage = true
  235.     DataPlayer[name].stored_purchases.Chicken = false
  236.     DataPlayer[name].stop_usage.Snowball = true
  237.     DataPlayer[name].stop_usage.Baiacu = false
  238.     ui.updateTextArea(55,"<CE>Using",name)
  239.     ui.addTextArea(59, "<font size='15'><p align='center'><a href='event:remove_snowball'><b><R>remove</R></a>", name, 360, 291, 81, 22, 0x314a4a, 0x314a4a, 1, true)          
  240.     if DataPlayer[name].coins >= 70 and DataPlayer[name].stop_usage.Chicken == false and DataPlayer[name].stop_usage.Baiacu == false then
  241.       DataPlayer[name].ball_Appearance = 34
  242.     end
  243. -- Buy baiacu settings
  244.   elseif link == [[buy_baiacu]] then
  245.     baiacu(name)
  246.   elseif link == [[remove_baiacu]] then
  247.     DataPlayer[name].itemUsage = false
  248.     ui.updateTextArea(57,"<a href='event:use_baiacu'>Use</a>",name)
  249.     ui.removeTextArea(60,name)
  250.   elseif link == [[use_baiacu]] then
  251.     DataPlayer[name].itemUsage = true
  252.     DataPlayer[name].stored_purchases.Chicken = false
  253.     DataPlayer[name].stop_usage.Snowball = false
  254.     DataPlayer[name].stop_usage.Baiacu = true
  255.     ui.updateTextArea(57,"<CE>Using",name)
  256.     ui.addTextArea(60, "<font size='15'><p align='center'><a href='event:remove_baiacu'><b><R>remove</R></a>", name, 494, 291, 81, 22, 0x314a4a, 0x314a4a, 1, true)
  257.     if DataPlayer[name].coins >= 70 and DataPlayer[name].stop_usage.Chicken == false and DataPlayer[name].stop_usage.Snowball == false then
  258.       DataPlayer[name].ball_Appearance = 65
  259.     end
  260. -- help        
  261.   elseif link == [[help]] then
  262.     tfm.exec.chatMessage("<ROSE>The object of the game is to use the items (balls, boxes or purchased consumables) to fill the spaces between the clouds and reach for the cheese. Items will disappear every 17 seconds after being placed. Your powers are hidden in the emotions confetti and dancing.",name)
  263.   end
  264. end
  265. -- function chicken usage
  266. function chicken(name) DataPlayer[name].itemUsage = true DataPlayer[name].stored_purchases.Chicken = true DataPlayer[name].stop_usage.Snowball = false DataPlayer[name].stop_usage.Baiacu = false if DataPlayer[name].coins >= 50 and DataPlayer[name].stop_usage.Snowball == false and DataPlayer[name].stop_usage.Baiacu == false then DataPlayer[name].coins = DataPlayer[name].coins - 50 DataPlayer[name].ball_Appearance = 33 tfm.exec.chatMessage("<PT>You're going to cast chickens! Watch out for the feathers!!",name) ui.updateTextArea(53,"<CE>Using",name) ui.addTextArea(58, "<font size='15'><p align='center'><a href='event:remove_chicken'><b><R>remove</R></a>", name, 226, 291, 81, 22, 0x314a4a, 0x314a4a, 1, true) else tfm.exec.chatMessage("<R>You didn't have enough coins to purchase this item.",name) end end
  267. -- function snowball usage
  268. function snowball(name) DataPlayer[name].itemUsage = true DataPlayer[name].stored_purchases.Chicken = false DataPlayer[name].stop_usage.Snowball = true DataPlayer[name].stop_usage.Baiacu = false if DataPlayer[name].coins >= 70 and DataPlayer[name].stop_usage.Chicken == false and DataPlayer[name].stop_usage.Baiacu == false then DataPlayer[name].coins = DataPlayer[name].coins - 70 DataPlayer[name].ball_Appearance = 34 tfm.exec.chatMessage("<PT>You will freeze everything! Wow",name) ui.updateTextArea(55,"<CE>Using",name) ui.addTextArea(59, "<font size='15'><p align='center'><a href='event:remove_snowball'><b><R>remove</R></a>", name, 360, 291, 81, 22, 0x314a4a, 0x314a4a, 1, true) else tfm.exec.chatMessage("<R>You didn't have enough coins to purchase this item.",name) end end
  269. -- function baiacu usage
  270. function baiacu(name) DataPlayer[name].itemUsage = true DataPlayer[name].stored_purchases.Chicken = false DataPlayer[name].stop_usage.Snowball = false DataPlayer[name].stop_usage.Baiacu = true if DataPlayer[name].coins >= 100 and DataPlayer[name].stop_usage.Chicken == false and DataPlayer[name].stop_usage.Snowball == false then DataPlayer[name].coins = DataPlayer[name].coins - 100 DataPlayer[name].ball_Appearance = 65 tfm.exec.chatMessage("<PT>Throw fish at them! Come on, man.",name) ui.updateTextArea(57,"<CE>Using",name) ui.addTextArea(60, "<font size='15'><p align='center'><a href='event:remove_baiacu'><b><R>remove</R></a>", name, 494, 291, 81, 22, 0x314a4a, 0x314a4a, 1, true) else tfm.exec.chatMessage("<R>You didn't have enough coins to purchase this item.",name) end end
  271. --
  272. table.foreach(tfm.get.room.playerList,eventNewPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement