Advertisement
Guest User

Eliminatoria

a guest
Aug 22nd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.29 KB | None | 0 0
  1. local perm = { ['Thimop_is_back#5479'] = true } -- Admins
  2. local players = {}
  3.  
  4. local canFinish = false
  5. local kicking = false
  6. local startGame = false
  7. local finishGame = false
  8.  
  9. local maxPlayers = 100
  10. local playersInGame = 0
  11.  
  12. local mapName = '#Elimination'
  13. local mapCode = '17'
  14. local roundWinner = ''
  15. local mapWinner = ''
  16.  
  17. -- [[ Disable ]] --
  18. system.disableChatCommandDisplay(nil)
  19.  
  20. for _, v in next, {'AutoTimeLeft', 'AutoShaman', 'AutoNewGame', 'AutoScore', 'AfkDeath', 'PhysicalConsumables'} do
  21. tfm.exec['disable' .. v]()
  22. end
  23.  
  24. -- [[ Functions Lib ]] --
  25. local split = function(str, s)
  26. local res = {}
  27. for part in string.gmatch(str, "[^" .. s .. "]+") do
  28. table.insert(res, part)
  29. end
  30. return res
  31. end
  32.  
  33. local showPlayers = function(name, display)
  34. if (display == nil) then display = true end
  35.  
  36. local addTextArea = function(...) if (display) then ui.addTextArea(...) end end
  37.  
  38. if (playersInGame > 0) then
  39. local a = 1
  40.  
  41. local list = { "<p align='center'>" }
  42. local n, i, id = 0, 1, 1
  43.  
  44. local text = ''
  45.  
  46. for k in next, players do
  47. if (k ~= name) then
  48. local nick, tag = k:match('(.-)#(%d+)');tag = "<g><font size='9'>#" .. tag .. "</font></g>"
  49.  
  50. n = (n + 1)
  51. if (n >= 10) then
  52. i = (i + 1);list[i] = "<p align='center'>"
  53.  
  54. text = (kicking and "<a href='event:" .. k .. "'>" or '') .. nick .. tag .. '\n'
  55.  
  56. n = 1
  57.  
  58. id = (id + 1)
  59. else
  60. text = (kicking and "<a href='event:" .. k .. "'>" or '') .. nick .. tag .. '\n'
  61. end
  62.  
  63. list[i] = list[i] .. text
  64. end
  65. end
  66.  
  67. local x = 6
  68. for i = 1, #list do
  69. addTextArea(i, list[i], name, x, 80, 180, 310, 0x324650, 0x000000, .8, true)
  70.  
  71. x = (x + (i == 1 and 193 or 203))
  72. end
  73.  
  74. if (kicking) then
  75. addTextArea(0, "<p align='center'><font size='16'><b>Escolha quem eliminar", name, 5, 25, 790, 25, 0x324650, 0, .8)
  76. end
  77.  
  78. return #list
  79. end
  80. end
  81.  
  82. local start = function()
  83. playersInGame = 0
  84.  
  85. tfm.exec.newGame('<C><P Ca=""/><Z><S><S L="795" o="66666" H="56" X="401" Y="373" T="12" P="0,0,0.3,0.2,0,0,0,0" i="-4,-398,1688b86f4fa.jpg" /></S><D /><O /></Z></C>')
  86.  
  87. for k in next, perm do
  88. ui.addTextArea(-1, "<p align='center'><a href='event:start'><j>Começar", k, 5, 25, 150, 20, 0x324650, 0, .8)
  89. end
  90.  
  91. ui.addTextArea(0, "<p align='center'><a href='event:entry'><j>Participar", nil, 325, 25, 150, 20, 0x324650, 0, .8)
  92.  
  93. for k in next, tfm.get.room.playerList do
  94. tfm.exec.setPlayerScore(k, 0)
  95. end
  96.  
  97. showPlayers(nil)
  98. end
  99.  
  100. -- [[ API Functions ]] --
  101. function eventNewPlayer(name)
  102. if (not startGame) then
  103. local text = "<p align='center'><j>Você está participando."
  104. if (not players[name]) then
  105. text = "<p align='center'><a href='event:entry'><j>Participar"
  106. end
  107.  
  108. ui.addTextArea(0, text, name, 325, 25, 150, 20, 0x324650, 0, .8)
  109.  
  110. showPlayers(name)
  111. end
  112.  
  113. tfm.exec.setPlayerScore(name, 0)
  114. end
  115. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  116.  
  117. function eventNewGame()
  118. canFinish = false
  119. kicking = false
  120.  
  121. mapWinner = ''
  122.  
  123. if (startGame) then
  124. ui.removeTextArea(0);local a = showPlayers('?', false);for b = 1, a do ui.removeTextArea(b, name) end
  125.  
  126. tfm.exec.addPhysicObject(0, 380, -325, {type = 14, width = 40, height = 10})
  127. tfm.exec.addPhysicObject(1, 380, -365, {type = 14, width = 60, height = 10})
  128. tfm.exec.addPhysicObject(2, 355, -340, {type = 14, width = 40, height = 10, angle = -90})
  129. tfm.exec.addPhysicObject(3, 405, -340, {type = 14, width = 40, height = 10, angle = -90})
  130.  
  131. for k in next, tfm.get.room.playerList do
  132. if (not players[k]) then
  133. tfm.exec.movePlayer(k, 380, -340)
  134. end
  135. end
  136.  
  137. tfm.exec.setGameTime(63)
  138.  
  139. if (roundWinner ~= '') then
  140. if (finishGame) then
  141. if (players[roundWinner] and #players[roundWinner] > 0) then
  142. local text = 'Eliminou: '
  143.  
  144. for i = 1, #players[roundWinner] do
  145. local nick, tag = '<n>' .. players[roundWinner][i]:match('(.-)#[0-9]+$'), "<ch><font size='9'>" .. players[roundWinner][i]:match('#[0-9]+$')
  146. text = text .. nick .. tag .. (i < #players[roundWinner] and '<n>,</n> ' or '<n>.</n>')
  147. end
  148.  
  149. ui.addTextArea(0, text, nil, 5, 25, 200, nil, 0x324650, 0, .8)
  150. end
  151.  
  152. tfm.exec.setGameTime(30)
  153. end
  154. end
  155. else
  156. players = {}
  157.  
  158. tfm.exec.setGameTime(99999)
  159. end
  160.  
  161. mapName = (tfm.get.room.xmlMapInfo.author ~= '#Module' and tfm.get.room.xmlMapInfo.author or mapName)
  162. mapCode = tfm.get.room.currentMap or mapCode
  163. ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>| <n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
  164. end
  165.  
  166. function eventLoop(elapsed, remaining)
  167. local remaining = math.floor(remaining / 1000)
  168.  
  169. if (elapsed <= 1000) then
  170. tfm.exec.playEmote(roundWinner, 0)
  171. end
  172.  
  173. if (remaining < 0) then
  174. if (finishGame) then
  175. finishGame = false
  176. startGame = false
  177.  
  178. start()
  179.  
  180. return
  181. end
  182.  
  183. if (startGame) then
  184. if (canFinish and roundWinner ~= '') then
  185. finishGame = true
  186.  
  187. tfm.exec.newGame('<C><P /><Z><S><S i="-200,-250,16692e791eb.png" P=",,9999,,,,," L="400" H="10" Y="270" T="14" X="400" /><S P=",,9999,,,,," i="-66,-20,1669252905c.png" L="200" H="10" Y="300" T="14" X="400" /></S><D><DS Y="300" X="400" /></D><O /></Z></C>')
  188. else
  189. tfm.exec.newGame('#17')
  190. end
  191. else
  192. ui.removeTextArea(0)
  193.  
  194. start()
  195. end
  196. end
  197. end
  198.  
  199. function eventPlayerWon(name)
  200. if (startGame) then
  201. if (mapWinner == '') then
  202. mapWinner = name
  203.  
  204. local a = 0
  205. for k in next, players do
  206. a = (a + 1)
  207. end
  208. if (a > 2) then
  209. kicking = true
  210.  
  211. tfm.exec.setGameTime(10, false)
  212.  
  213. showPlayers(name)
  214. else
  215. for k in next, players do
  216. if (k ~= name) then
  217. players[k] = nil
  218.  
  219. break
  220. end
  221. end
  222.  
  223. canFinish = true
  224.  
  225. roundWinner = name
  226.  
  227. tfm.exec.setGameTime(4, false)
  228. end
  229.  
  230. tfm.exec.setPlayerScore(name, tfm.get.room.playerList[name].score + 1)
  231. end
  232. end
  233. end
  234.  
  235. function eventPlayerDied(name)
  236. local t = {}
  237.  
  238. for k, v in next, tfm.get.room.playerList do
  239. if (not v.isDead) then
  240. t[#t + 1] = k
  241. end
  242. end
  243.  
  244. for i = 1, #t do
  245. if (players[t[i]]) then
  246. return
  247. end
  248. end
  249.  
  250. if (startGame) then
  251. tfm.exec.newGame('#17')
  252. end
  253. end
  254.  
  255. function eventPlayerLeft(name)
  256. if (players[name]) then
  257. players[name] = nil
  258.  
  259. if (playersInGame > 0) then playersInGame = (playersInGame - 1) end
  260. ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>| <n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
  261. end
  262.  
  263. if (not startGame) then
  264. showPlayers(nil)
  265. end
  266.  
  267. if (kicking) then
  268. showPlayers(mapWinner)
  269. end
  270. end
  271.  
  272. function eventChatCommand(name, cmd)
  273. cmd = split(cmd, ' ')
  274.  
  275. -- [[ Adm Commands ]] --
  276. if (perm[name]) then
  277. if (cmd[1] == 'start') then
  278. local a = playersInGame
  279. if (a > 1) then
  280. for i = -1, a do
  281. ui.removeTextArea(i)
  282. end
  283.  
  284. startGame = true
  285.  
  286. tfm.exec.newGame('#17')
  287. end
  288. end
  289. end
  290. end
  291.  
  292. function eventTextAreaCallback(id, name, cb)
  293. if (cb == 'entry') then
  294. if (not players[name]) then
  295. players[name] = {}
  296.  
  297. playersInGame = (playersInGame + 1)
  298. ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>| <n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
  299. ui.updateTextArea(0, '<j>Você está participando.', name)
  300.  
  301. showPlayers(nil)
  302. end
  303. elseif (cb == 'start') then
  304. eventChatCommand(name, cb)
  305. elseif (players[cb] and kicking) then
  306. if (playersInGame > 0) then playersInGame = (playersInGame - 1) end
  307.  
  308. kicking = false
  309. players[cb] = nil
  310.  
  311. local a = 1
  312. for k in next, players do
  313. a = (a + 1)
  314. end
  315. for i = 1, a do
  316. ui.removeTextArea(i)
  317. end
  318.  
  319. players[name][#players[name] + 1] = cb
  320.  
  321. ui.addTextArea(0, "<p align='center'><font size='16'><b><v>" .. name .. " eliminou <r>" .. cb, nil, 5, 25, 790, 25, 0x324650, 0, .8)
  322.  
  323. ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>| <n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
  324.  
  325. tfm.exec.setGameTime(15, false)
  326. end
  327. end
  328.  
  329. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement