Advertisement
Dudugz-Contistente

Untitled

Aug 24th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. tfm.exec.disableAutoShaman()
  2. tfm.exec.disableAutoNewGame()
  3. tfm.exec.disableAutoTimeLeft()
  4.  
  5. game = {}
  6. game.maps = {6697343,7097916,6775837,7155011,7186973}
  7. game.canStart = false
  8. game.isStarted = false
  9. game.isFinished = false
  10. game.potato = nil
  11. game.explosionTime = 15
  12. game.currentTime = game.explosionTime * 2
  13. game.playerCount = 0
  14. game.isRoom = tfm.get.room.name:sub(1,2):find("#") and true or false
  15. game.potatoImage = nil
  16.  
  17.  
  18.  
  19. lang = {
  20. en = {
  21. ["minPlayers"] = "<R>É necessário pelo menos 2 jogadores :(",
  22. ["welcome"] = "<N>Bem-vindo ao batata feio para <B>guerras(wars)</B>/<B>x1</B>.",
  23. ["gotPotato"] = "<V>%s <BL>está com a batata!",
  24. ["finishedRound"] = "<BL>Acabou! <V>%s <BL>é o vencedor!",
  25. ["time"] = "<J>%s <BL>- %s | <N>Tempo : <V>%i segundos",
  26. ["help"] = "<BL><p align='center'><font size='26'>Ajuda</font></p><N><br>Batata quente é a clássica brincadeira de infância agora no Transformice!<br><br>O rato com mais pontos a cada mapa terá a batata!<br>O rato com a batata deve passá-la para outro rato apertando <J>ESPAÇO <N>perto dele.<br>Após 15 segundos o rato que estiver com a batata morrerá!<br>O útlimo a sobreviver ganhará a partida.<br><br>Desenvolvido por Laagaadoo.<br><BL><p align='center'><a href='event:closeHelp'>Fechar</a></p>"
  27. }
  28. }
  29.  
  30. function game.setPotato(name)
  31. if not game.isFinished then
  32. if game.potato then
  33. tfm.exec.setNameColor(game.potato, 0)
  34. system.bindKeyboard(game.potato, 32, false, false)
  35. if game.isRoom then
  36. tfm.exec.removeImage(game.potatoImage)
  37. end
  38. end
  39.  
  40. game.potato = name
  41. if game.isRoom then
  42. game.potatoImage = tfm.exec.addImage("155bc34f15d.png", "$"..name, 2, -6)
  43. end
  44. tfm.exec.setNameColor(name, 0xFFFF00)
  45. system.bindKeyboard(name, 32, true, true)
  46.  
  47. sendMessage(translate("gotPotato"):format(name))
  48. end
  49. end
  50.  
  51. function game.newGame()
  52. tfm.exec.newGame(game.maps[math.random(#game.maps)])
  53. tfm.exec.setGameTime(360)
  54. end
  55.  
  56. function game.highScore()
  57. local hs, hsName = -1, nil
  58. for name, player in pairs(tfm.get.room.playerList) do
  59. if player.score > hs and not player.isDead then
  60. hs = player.score
  61. hsName = name
  62. end
  63. end
  64. return hsName
  65. end
  66.  
  67. sendMessage = function(message, name)
  68. if game.isRoom then
  69. tfm.exec.chatMessage(message, name)
  70. else
  71. print(message)
  72. end
  73. end
  74.  
  75. translate = function(message)
  76. return lang[tfm.get.room.community] and lang[tfm.get.room.community][message] or lang.en[message]
  77. end
  78.  
  79. eventNewGame = function()
  80. game.isStarted = false
  81. game.isFinished = false
  82. game.currentTime = game.explosionTime * 2
  83. end
  84.  
  85. eventNewPlayer = function(name)
  86. game.playerCount = game.playerCount + 1
  87. ui.addTextArea(0, "", name, 6, 29, 20, 20, 0x5b3c27, 0x5b3c27, 1, true)
  88. ui.addTextArea(1, "", name, 7, 30, 20, 20, 0x241c15, 0x241c15, 1, true)
  89. ui.addTextArea(2, "<p align='center'><font size='12'><a href='event:showHelp'>?</a></font></p>", name, 7, 30, 19, 19, 0x3e2c1f, 0x3e2c1f, 1, true)
  90.  
  91. if game.playerCount > 1 then
  92. game.canStart = true
  93. end
  94.  
  95. if game.isRoom then
  96. sendMessage(translate("welcome"), name)
  97. tfm.exec.lowerSyncDelay(name)
  98. end
  99. end
  100.  
  101. eventPlayerLeft = function(name)
  102. game.playerCount = game.playerCount - 1
  103.  
  104. if game.playerCount < 2 then
  105. game.canStart = false
  106. end
  107. end
  108.  
  109. eventTextAreaCallback = function(id, name, callback)
  110. if callback == "showHelp" then
  111. ui.addTextArea(3, translate("help"), name, 233.5, 86, 333, 228, 0x3e2c1f, 0x3e2c1f, 1, true)
  112. elseif callback == "closeHelp" then
  113. ui.removeTextArea(id, name)
  114. end
  115. end
  116.  
  117. eventKeyboard = function(name, key, down, x, y)
  118. if key == 32 then
  119. if name == game.potato then
  120. for target, player in pairs(tfm.get.room.playerList) do
  121. if (target ~= name) and not player.isDead then
  122. if x >= player.x - 15 and x <= player.x + 15 and y >= player.y - 15 and y <= player.y + 15 then
  123. game.setPotato(target)
  124. break
  125. end
  126. end
  127. end
  128. end
  129. end
  130. end
  131.  
  132. eventPlayerDied = function(name)
  133. if name == game.potato and not game.isFinished then
  134. game.setPotato(game.highScore())
  135. end
  136. end
  137.  
  138. eventLoop = function(current, remaining)
  139. if game.canStart then
  140. if game.isStarted then
  141. local alive, namesAlive = 0, {}
  142.  
  143. for name, player in pairs(tfm.get.room.playerList) do
  144. if not player.isDead then
  145. alive = alive + 1
  146. namesAlive[#namesAlive+1] = name
  147. end
  148. end
  149.  
  150. if alive == 1 then
  151. game.isFinished = true
  152. tfm.exec.giveCheese(namesAlive[1])
  153. tfm.exec.playerVictory(namesAlive[1])
  154. tfm.exec.setGameTime(6)
  155. sendMessage(translate("finishedRound"):format(namesAlive[1]))
  156. end
  157.  
  158. if remaining <= 0 then game.newGame() end
  159.  
  160. if not game.isFinished then
  161. ui.addTextArea(10, "<p align=\"center\"><font size=\"25\"><J><B>".. math.floor(game.currentTime/2) .." (tfm.get.room.xmlMapInfo.author, tfm.get.room.currentMap, math.floor(game.currentTime/2)", nil, 376, 355, 46, 39, 0x000001, 0x000000, 0.8, true)
  162. game.currentTime = game.currentTime - 1
  163.  
  164. local particles = {2, 13}
  165. for i = 1, 2 do
  166. tfm.exec.displayParticle(particles[math.random(#particles)], tfm.get.room.playerList[game.potato].x, tfm.get.room.playerList[game.potato].y - math.random(5, 15), math.random(-1, 1), math.random(-1, 1))
  167. end
  168.  
  169. if game.currentTime == 0 then
  170. if alive == 2 then
  171. game.currentTime = game.explosionTime * 2
  172. tfm.exec.killPlayer(game.potato)
  173.  
  174. local i = 1
  175. while(game.potato == namesAlive[i]) do
  176. i = i + 1
  177. end
  178.  
  179. game.isFinished = true
  180. tfm.exec.giveCheese(namesAlive[i])
  181. tfm.exec.playerVictory(namesAlive[i])
  182. tfm.exec.setGameTime(6)
  183. sendMessage(translate("finishedRound"):format(namesAlive[i]))
  184. else
  185. game.currentTime = game.explosionTime * 2
  186. tfm.exec.killPlayer(game.potato)
  187. end
  188. end
  189. end
  190. else
  191. if current >= 5000 then
  192. game.setPotato(game.highScore())
  193. game.isStarted = true
  194.  
  195. tfm.exec.setPlayerScore(game.potato, 0)
  196. end
  197. end
  198. end
  199. end
  200.  
  201. for name in pairs(tfm.get.room.playerList) do
  202. eventNewPlayer(name)
  203. tfm.exec.setPlayerScore(name, 0)
  204. end
  205.  
  206. if game.canStart then
  207. game.newGame()
  208. else
  209. sendMessage(translate("minPlayers"))
  210. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement