Advertisement
Vels001

[TFM][Lua][Script]#bombsahoy.v1.1

Jan 28th, 2016
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.26 KB | None | 0 0
  1. -- #bombsahoy
  2. -- SETTINGS, leave these alone for defualt gameplay.
  3. G_MAP = "@6263573" -- The map we will play on.
  4. B_POWER = 50       -- The amount of force an explosion has.
  5. B_DISTANCE = 100   -- The distance the explosion will reach.
  6. B_AIRTIME = 5      -- The amount of time in the air, before a new player gets the bomb.
  7. B_HELDTIME = 5     -- The amount of time a player can hold the bomb, before it explodes.
  8. B_TIMER = 20       -- The amount of time until the bomb explodes.
  9. B_XVELOCITY = 4    -- The amount of force it will go, in the left or right direction, when thrown.
  10. B_YVELOCITY = -8   -- The amount of force it will go, in the up or down direction, when thrown.
  11.  
  12. --
  13. --
  14. --
  15.  
  16. GameState = "NONE"
  17. CurrentBomb = {}
  18. tfm.exec.disableAfkDeath()
  19. tfm.exec.disableAutoNewGame()
  20. tfm.exec.disableAutoScore()
  21. tfm.exec.disableAutoShaman()
  22. tfm.exec.disableAutoTimeLeft()
  23.  
  24. Bomb = {}
  25. Bomb.__index = Bomb
  26. function newBomb(x,y)
  27.     b = setmetatable({
  28.         player = "",
  29.         lastPlayer = "",
  30.         id = id,
  31.         timer = 0,
  32.         heldTimer = 0,
  33.         airTimer = 0,
  34.     }, Bomb)
  35.    
  36.     b:throw(x,y)
  37.    
  38.     return b
  39. end
  40. function Bomb:newPlayer()
  41.     local pl = {}
  42.     for n,p in pairs(tfm.get.room.playerList) do
  43.         if not p.isDead then
  44.             table.insert(pl, n)
  45.         end
  46.     end
  47.     self.player = pl[math.random(#pl)]
  48.     self.airTimer = 0
  49.     self.heldTimer = 0
  50.    
  51.     tfm.exec.removeObject(self.id)
  52.     tfm.exec.giveCheese(self.player)
  53. end
  54. function Bomb:throw(x, y)
  55.     local vx, vy = B_XVELOCITY, B_YVELOCITY
  56.     if x > 400 then vx = -vx end
  57.     self.lastPlayer = self.player
  58.     self.player = ""
  59.     self.heldTimer = 0
  60.     self.id = tfm.exec.addShamanObject(23, x, y, 0, vx, vy, false)
  61. end
  62. function Bomb:explode()
  63.     local x, y = 400, 200
  64.     if self.player == "" then
  65.         if self.lastPlayer ~= "" then
  66.             x, y = getPlayerLocation(self.lastPlayer)
  67.         end
  68.     else
  69.         x, y = getPlayerLocation(self.player)
  70.         tfm.exec.killPlayer(self.player)
  71.     end
  72.     tfm.exec.explosion(x, y, B_POWER, B_DISTANCE, false)
  73.     tfm.exec.displayParticle(12, x, y)
  74.     CurrentBomb = newBomb(400,200)
  75. end
  76.  
  77. function getPlayerLocation(playerName)
  78.     return tfm.get.room.playerList[playerName].x, tfm.get.room.playerList[playerName].y
  79. end
  80.  
  81. --
  82. --
  83.  
  84. function eventNewPlayer(playerName)
  85.     if GameState == "MORE PLAYERS" then
  86.         tfm.exec.newGame(G_MAP)
  87.     end
  88.     system.bindKeyboard(playerName, 32, true, true)
  89.     ui.addTextArea(0, "<b><p align='center'>Welcome!", playerName, 300, 370, 200, 50)
  90. end
  91.  
  92. function eventKeyboard(playerName, key, down, x, y)
  93.     if CurrentBomb.player == playerName then
  94.         tfm.exec.killPlayer(playerName)
  95.         tfm.exec.respawnPlayer(playerName)
  96.         tfm.exec.movePlayer(playerName, x, y)
  97.         CurrentBomb:throw(x,y-50)
  98.     end
  99. end
  100.  
  101. function eventNewGame()
  102.     local c = 0
  103.     for n,p in pairs(tfm.get.room.playerList) do
  104.         c = c + 1
  105.     end
  106.     if c < 2 then
  107.         GameState = "MORE PLAYERS"
  108.         print("<R>You need atleast 2 players!")
  109.         ui.updateTextArea(0, "<b><p align='center'><R>You need atleast 2 players!<N>", nil)
  110.         return
  111.     end
  112.  
  113.     GameState = "START"
  114.     for n,p in pairs(tfm.get.room.playerList) do
  115.         ui.updateTextArea(0, "<b><p align='center'>Get ready!", playerName)
  116.     end
  117. end
  118.  
  119. function eventPlayerDied(playerName)
  120.     if CurrentBomb.lastPlayer == playerName and CurrentBomb.player ~= playerName then
  121.         return false
  122.     end
  123.    
  124.     local a,pn = 0,""
  125.     ui.updateTextArea(0, "<b><p align='center'>x_x", playerName)
  126.     for n,p in pairs(tfm.get.room.playerList) do
  127.         if not p.isDead then
  128.             a = a + 1
  129.             pn = n
  130.         end
  131.     end
  132.     if a == 0 and GameState == "END" then
  133.         tfm.exec.newGame(G_MAP)
  134.     elseif a == 1 then
  135.         GameState = "END"
  136.         tfm.exec.setGameTime(10)
  137.         ui.updateTextArea(0, "<b><p align='center'>"..pn.." wins!", nil)
  138.         ui.updateTextArea(0, "<b><p align='center'>You win!", pn)
  139.     end
  140. end
  141.  
  142. function eventLoop(t,r)
  143.     if r <= 0 and GameState == "END" then
  144.         tfm.exec.newGame(G_MAP)
  145.     end
  146.    
  147.     if GameState == "START" then
  148.         if t >= 5000 then
  149.             GameState = "GAME"
  150.             CurrentBomb = newBomb(400+(math.random(2)==1 and 1 or 0), 200)
  151.         end
  152.     end
  153.    
  154.     if GameState == "GAME" then
  155.         CurrentBomb.timer = CurrentBomb.timer + 500
  156.         ui.updateTextArea(0, "<b><p align='center'>"..(B_TIMER - math.ceil(CurrentBomb.timer/1000)).."s", playerName)
  157.        
  158.         if CurrentBomb.player ~= "" then
  159.             CurrentBomb.heldTimer = CurrentBomb.heldTimer + 500
  160.             ui.updateTextArea(0, "<b><p align='center'> HURRY! "..(B_HELDTIME - math.ceil(CurrentBomb.heldTimer/1000)).."s!", CurrentBomb.player)
  161.         else
  162.             CurrentBomb.airTimer = CurrentBomb.airTimer + 500
  163.         end
  164.    
  165.         if CurrentBomb.timer > B_TIMER*1000 or CurrentBomb.heldTimer > B_HELDTIME*1000 then
  166.             CurrentBomb:explode()
  167.         end
  168.    
  169.         if CurrentBomb.airTimer > B_AIRTIME*1000 then
  170.             CurrentBomb:newPlayer()
  171.         end
  172.     end
  173. end
  174.  
  175. tfm.exec.newGame(G_MAP)
  176. for n,p in pairs(tfm.get.room.playerList) do eventNewPlayer(n) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement