Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.71 KB | None | 0 0
  1. ---
  2. -- The racer #8 07/02/2015, escrito por Eshkation
  3. --
  4.  
  5. tfm.exec.disableAutoNewGame(true)
  6. tfm.exec.disableAutoShaman(true)
  7. tfm.exec.disableAfkDeath(true)
  8.  
  9. for index, command in pairs ({"admin", "game", "queue", "score", "pause"}) do
  10. system.disableChatCommandDisplay(command, true)
  11. end
  12.  
  13. local _S = {
  14. segments = {
  15. windows = {},
  16. },
  17. config = {
  18. pauseonleft = {"Pause on DC", true},
  19. killnonpart = {"Kill guests", true},
  20. firsts = {"Number of points", 10, 1},
  21. difference = {"Points difference", 2, 1},
  22. pausetime = {"Dwell time", 120, 60},
  23. gametime = {"Map time ", 60, 5},
  24. restartpause = {"Restart dwell", false},
  25. },
  26. players = {},
  27. command = string.format("%x", math.random(0x000000, 0xFFFFFF)),
  28. gameRunning = false,
  29. first = false,
  30. pause = 0,
  31. party = false,
  32. tick = os.time(),
  33. maps = {
  34. 6730473, 6572872, 6087537, 6070140, 6063528, 5922046, 5699298, 5654008, 5630711, 5515862, 5488573, 5382687, 5339441, 5309288, 5303681, 5096937, 5067265, 5045922, 5045485, 5044309, 5028454, 4945098, 4778991, 4747722, 4581354, 4551993, 4508416, 4477124, 4220406, 4148332, 4102732, 4091580, 4088129, 3992276, 3970909, 3953425, 3854268, 3847244, 3834905, 3801780, 3799507, 3778128, 3705931, 3702767, 3696662, 3691609, 3685486, 3685382, 3685352, 3683393, 3683294, 3639993, 3636268, 3631534, 3611702, 3603802, 3556690, 3556489, 3549840, 3453351, 3408247, 3399991, 3267620, 3175920, 3156569, 3123384, 3008155, 2840770, 2816067, 2813487, 2776889, 2725924, 2683170, 2582610, 2571671, 2522826, 2393139, 2331474, 2245005, 2223685, 2150335, 2141379, 2138401, 2134537, 2106576, 2101747, 2089069, 2076632, 2070768, 2030343, 2023552, 2012147, 1985019, 1975684, 1964800, 1964752, 1956555, 1956002, 1952851, 1951856, 1927270, 1914792, 1862823, 1856349, 1841744, 1813728, 1787239, 1787232, 1759287, 1749434, 1718723, 1694602, 1659716, 1659639, 1654903, 1654841, 1651658, 1632746, 1632706, 1632294, 1621611, 1619934, 1608638, 1605364, 1602654, 1601492, 1592767, 1583655, 1573213, 1564762, 1555532, 1539791, 1538895, 1512355, 1506007, 1453667, 1448760, 1425101, 1405496, 1405249, 1404528, 1375345, 1372941, 1371294, 1368222, 1364063, 1358446, 1341396, 1311059, 1256845, 1255148, 1250021, 1249601, 1216253, 1214182, 1208798, 1195842, 1142116, 1132639, 1085530, 1019378, 1017676, 1015436, 979179, 976786, 789128, 646800, 608459, 606666, 603381, 586688, 580031, 571512, 564033, 563484, 563303, 556253, 538116, 537776, 536235, 531569, 529844, 523046, 517697, 514982, 514510, 512927, 512291, 511187, 509082, 508796, 508106, 507325, 505963, 505109, 504704, 504409, 501428, 499687, 496945, 480023, 475151, 470727, 470687, 447556, 445167, 444490, 443309, 436447, 434887, 431887, 431142, 430736, 430145, 429897, 429822, 428517, 426638, 425806, 425600, 425044, 425030, 424795, 424361, 423672, 421717, 420806, 419374, 418658, 418293, 416142, 410532, 407294, 406982, 406486, 406266, 405075, 404440, 401945, 399633, 398942, 398011, 397938, 397501, 396861, 396347, 395607, 395585, 394890, 393851, 391868, 391831, 391693, 387638, 387290, 387270, 387012, 379866, 375381, 372970, 370850, 370444, 365774, 363822, 363625, 360365, 360201, 355676, 352381, 350251, 349140, 348801, 345312, 345257, 344865, 344361, 337774, 335507, 335458, 333277, 333071, 333068, 322771, 321906, 321814, 321712, 313091, 309057, 304356, 291628, 285752, 283715, 282434, 270819, 263182, 263163, 262239, 261172, 260338, 252759, 244699, 237297, 237278, 234959, 234039, 233345, 232699, 231694, 230741, 230510, 229944, 229814, 216439, 213933, 197219, 195720, 193936, 192566, 192391, 184110, 181312, 180469, 180255, 178545, 177236, 176263, 169892, 165843, 160762, 159351, 155168, 144468, 138678, 128522, 120152, 117548, 114122
  35. },
  36. queue = {}
  37. }
  38.  
  39. function _S.announceAdmin(player)
  40. if player then
  41. display(2, 1, string.format("<p align=\"center\">%s become tournament administrator!</font>", player))
  42. _S.displayMenu(player)
  43. end
  44. end
  45.  
  46. function _S.displayMenu(player)
  47. ui.addTextArea(1, "<a href=\"event:display options\">Options</a>", player, 5, 20, 50, 17, 0x323747, 0x1C1E26, 1, true)
  48. ui.addTextArea(2, "<a href=\"event:display players\">Guests</a>", player, 64, 20, 45, 17, 0x323747, 0x1C1E26, 1, true)
  49. end
  50.  
  51. function _S.newMap()
  52. tfm.exec.newGame(_S.queue[1] or _S.maps[math.random(#_S.maps)])
  53. table.remove(_S.queue, 1)
  54. end
  55.  
  56. function _S.updateScore()
  57. local text = ""
  58. local t = false
  59. for player, data in pairs(_S.players) do
  60. if data.ingame then
  61. t = not t
  62. if t then
  63. text = text..string.format("%s %s ", player, data.points)
  64. else
  65. text = text..string.format("x %s %s", data.points, player)
  66. end
  67. end
  68. end
  69. ui.addTextArea(-4, "<p align=\"center\"><font size=\"17\" color=\"#1C1E26\">"..text, nil, 0, 21, 800, nil, 0, 0, 0, true)
  70. ui.addTextArea(-3, "<p align=\"center\"><font size=\"17\" color=\"#1C1E26\">"..text, nil, 1, 20, 800, nil, 0, 0, 0, true)
  71. if _S.pause == 0 then
  72. ui.addTextArea(-1, "<p align=\"center\"><N><font size=\"17\">"..text, nil, 0, 20, 800, nil, 0, 0, 0, true)
  73. else
  74. ui.addTextArea(-1, "<p align=\"center\"><R><font size=\"17\">"..text, nil, 0, 20, 800, nil, 0, 0, 0, true)
  75. end
  76. for player, data in pairs(_S.players) do
  77. if data.admin then
  78. _S.displayMenu(player)
  79. end
  80. end
  81. end
  82.  
  83. function _S.getDifference(name)
  84. local diff = 0
  85. for player, data in pairs(_S.players) do
  86. if data.ingame and player ~= name then
  87. diff = diff+(_S.players[name].points-data.points)
  88. end
  89. end
  90. return diff
  91. end
  92.  
  93. function eventPlayerWon(player, time)
  94. if not _S.first and _S.players[player].ingame and _S.pause == 0 then
  95. _S.first = true
  96. _S.players[player].points = _S.players[player].points+1
  97. display(1, 2, string.format("<font size=\"30\"><N2>FIRST!</N2>\n<font size=\"16\">Score %s: %s", player, _S.players[player].points))
  98. local difference = _S.getDifference(player)
  99. _S.updateScore()
  100. tfm.exec.setGameTime(3, true)
  101. if difference >= _S.config.difference[2] and _S.players[player].points >= _S.config.firsts[2] then
  102. display(1, 2, string.format("<font size=\"30\"><N2>END OF THE GAME!</N2>\n<font size=\"16\">%s won with difference of %s points!", player, difference))
  103. _S.party = os.time()
  104. _S.gameRunning = false
  105. tfm.exec.newGame("@6575947")
  106. tfm.exec.setNameColor(player, 0xFFCB00)
  107. for player, data in pairs(_S.players) do
  108. data.ingame = false
  109. data.points = 0
  110. data.pause = false
  111. end
  112. end
  113. end
  114. end
  115.  
  116. function eventTextAreaCallback(id, player, callback)
  117. if callback == "display players" then
  118. local text = ""
  119. for player, data in pairs(tfm.get.room.playerList) do
  120. local pl = ""
  121. local t = false
  122. if _S.players[player].admin then
  123. pl = "[<VP>Owner</VP>]"
  124. t = true
  125. end
  126. if _S.players[player].ingame then
  127. pl = pl.."[<VP>Participants</VP>]"
  128. t = true
  129. end
  130. if not t then
  131. pl = pl.."[<G>Guests</G>]"
  132. end
  133. pl = pl.." "..player
  134. text = string.format("%s %s\n", text, pl)
  135. end
  136. text = text.." [<a href=\"event:closeText 3\"><R>CLOSE</R></a>]"
  137. ui.addTextArea(3, text, player, 64, 45, nil, 17, 0x323747, 0x1C1E26, 1, true)
  138.  
  139. elseif callback == "display options" then
  140. local text = "<br><p align=\"center\"><font size=\"20\"><J>O P T I O N S"
  141. ui.addTextArea(12, text, player, 199, 69, 322, 262, 0x323747, 0x1C1E26, 1, true)
  142. ui.addTextArea(11, "[<a href=\"event:closeText 12 11 10\"><R>CLOSE</R></a>]", player, 460, 75, nil, nil, nil, nil, 0, true)
  143. text = "<font face=\"Lucida Console\"><textformat tabstops=\"[80, 160, 200, 240]\">"
  144. local n = 0
  145. for config, data in pairs(_S.config) do
  146. if type(data[2]) == "number" then
  147. text = text..string.format("<N2>%s<N>:\t[<R><a href=\"event:setConfig %s %s\">-%s</a></R>]\t[<V>%s</V>]\t[<R><a href=\"event:setConfig %s %s\">+%s</a></R>]\n", data[1], config, data[2]-data[3], data[3], data[2], config, data[2]+data[3], data[3])
  148. elseif type(data[2]) == "boolean" then
  149. text = text..string.format("<N2>%s<N>:\t[<R><a href=\"event:setConfig %s true\">YES</a></R>]\t[<V>%s</V>]\t[<R><a href=\"event:setConfig %s false\">NO</a></R>]\n", data[1], config, data[2] == true and "YES" or "NO", config)
  150. end
  151. n = n+1
  152. end
  153. n = 13-n
  154. local t = ""
  155. for i = 0, n do t = t.."\n" end
  156. ui.addTextArea(10, text.."</textformat>"..t, player, 220, 140, nil, nil, 0x41475B, 0x1C1E26, 1, true)
  157.  
  158. elseif callback:sub(0, 9) == "closeText" then
  159. args = string.split(callback:sub(11), " ")
  160. for index, arg in pairs(args) do
  161. ui.removeTextArea(arg, player)
  162. end
  163.  
  164. elseif callback:sub(0, 9) == "setConfig" then
  165. args = string.split(callback:sub(11), " ")
  166. if _S.config[args[1]] then
  167. _S.config[args[1]][2] = tonumber(args[2]) or args[2] == "true" and true or false
  168. end
  169. eventTextAreaCallback(id, player, "display options")
  170. end
  171. end
  172.  
  173. function display(dp, id, text, player)
  174. local textWidth = #(text:gsub(" ",""))*3
  175. if dp == 1 then
  176. ui.addTextArea(id.."000", "<p align=\"center\"><font face=\"Verdana\">"..text, player, 5, 155, 790, nil, 0x323747, 0x1C1E26, 1, true)
  177. elseif dp == 2 then
  178. ui.addTextArea(id.."000", "<font face=\"Verdana\">"..text, player, 5, 382, nil, nil, 0x323747, 0x1C1E26, 1, true)
  179. end
  180. _S.segments.windows[id] = {stime = os.time()}
  181. end
  182.  
  183. function eventNewPlayer(player)
  184. if not _S.players[player] then
  185. _S.players[player] = {admin = false, ingame = false, points = 0, pause = false, pauseTick = false}
  186. end
  187. end
  188.  
  189. function eventNewGame()
  190. if _S.gameRunning then
  191. ui.removeTextArea(3)
  192. ui.removeTextArea(4)
  193. ui.removeTextArea(5)
  194. _S.first = false
  195. if _S.config.killnonpart[2] then
  196. for player, data in pairs(_S.players) do
  197. if not data.ingame then
  198. tfm.exec.killPlayer(player)
  199. end
  200. end
  201. end
  202. tfm.exec.setGameTime(_S.config.gametime[2])
  203. _S.updateScore()
  204. end
  205. end
  206.  
  207. function eventLoop(elapsed, remain)
  208. if _S.gameRunning then
  209. remain = remain/1000
  210. if remain < 0 then
  211. remain = 100
  212. _S.newMap()
  213. end
  214. end
  215. if _S.party then
  216. if _S.party > os.time()-60000 then
  217. for i = 5, 0, -1 do
  218. ids = {{11, 13, 9, 0}, {9, 0}, {11, 9}, {0, 4}, {4}, {13}, {13, 0}}
  219. x = math.random(800)
  220. y = math.random(400)
  221. id = ids[math.random(#ids)]
  222. defaultEffect(1, id, x, y, 35)
  223. end
  224. else
  225. _S.party = false
  226. end
  227. end
  228. for id, data in pairs(_S.segments.windows) do
  229. if data.stime < os.time()-5000 then
  230. ui.removeTextArea(id.."000")
  231. tfm.exec.removePhysicObject(id)
  232. id = nil
  233. end
  234. end
  235. if _S.pause > 0 and _S.tick < os.time()-1000 then
  236. _S.tick = os.time()
  237. local text = ""
  238. for player, data in pairs(_S.players) do
  239. if data.pause then
  240. data.pauseTick = data.pauseTick-1
  241. local timeStamp = string.format("%.2d:%.2d:%.2d", data.pauseTick/(60*60), data.pauseTick/60%60, data.pauseTick%60)
  242. text = text..string.format("%s <font size=\"12\">%s\n", player, timeStamp)
  243. if data.pauseTick == 0 then
  244. data.pause = false
  245. display(3, 1, string.format("<font size=\"30\"><N2>TEMPO ESGOTADO!</N2>\n<font size=\"16\">O tempo de %s esgotou!", player))
  246. _S.pause = _S.pause-1
  247. end
  248. end
  249. end
  250. if #text > 1 then
  251. ui.addTextArea(3, "<font size=\"15\" color=\"#1C1E26\">"..text, nil, 561, 20, 255, nil, 0x323747, 0x1C1E26, 0, true)
  252. ui.addTextArea(4, "<font size=\"15\" color=\"#1C1E26\">"..text, nil, 560, 21, 255, nil, 0x323747, 0x1C1E26, 0, true)
  253. ui.addTextArea(5, "<N><font size=\"15\">"..text, nil, 560, 20, 255, nil, 0x323747, 0x1C1E26, 0, true)
  254. else
  255. ui.removeTextArea(3)
  256. ui.removeTextArea(4)
  257. ui.removeTextArea(5)
  258. end
  259. end
  260. end
  261.  
  262. function eventChatCommand(player, command)
  263. if command == _S.command then
  264. _S.command = tostring(math.random())
  265. _S.players[player].admin = true
  266. _S.announceAdmin(player)
  267. end
  268. local args = string.split(command, " ")
  269. if _S.players[player].admin then
  270. if args[1] == "admin" and args[2] then
  271. local passivePlayer = string.title(args[2])
  272. _S.players[passivePlayer].admin = true
  273. _S.announceAdmin(passivePlayer)
  274.  
  275. elseif args[1] == "queue" and args[2] then
  276. table.insert(_S.queue, args[2])
  277. display(2, 1, string.format("Mapa %s adicionado na queue na posição #%s", args[2], #_S.queue), player)
  278.  
  279. elseif args[1] == "score" and args[2] then
  280. local passivePlayer = string.title(args[2])
  281. if tfm.get.room.playerList[passivePlayer] then
  282. if _S.players[passivePlayer].ingame then
  283. _S.players[passivePlayer].points = tonumber(args[3]) or _S.players[passivePlayer].points
  284. display(2, 1, string.format("%s mudou o placar de %s para %s!", player, passivePlayer, _S.players[passivePlayer].points), nil)
  285. end
  286. else
  287. display(2, 1, string.format("%s não se encontra na sala!", passivePlayer), player)
  288. end
  289. _S.updateScore()
  290.  
  291. elseif args[1] == "pause" and args[2] then
  292. local passivePlayer = string.title(args[2])
  293. if tfm.get.room.playerList[passivePlayer] then
  294. if _S.players[passivePlayer].pause then
  295. _S.players[passivePlayer].pause = false
  296. _S.pause = _S.pause-1
  297. ui.removeTextArea(3, nil)
  298. ui.removeTextArea(4, nil)
  299. ui.removeTextArea(5, nil)
  300. display(1, 1, string.format("<font size=\"30\"><N2>TEMPO RETOMADO!</N2>\n<font size=\"16\">%s retomou o tempo de %s", player, passivePlayer))
  301. for player, data in pairs(_S.players) do
  302. tfm.exec.killPlayer(player)
  303. end
  304. tfm.exec.setGameTime(3, true)
  305. else
  306. display(1, 1, string.format("<font size=\"30\"><N2>JOGO PAUSADO!</N2>\n<font size=\"16\">%s pausou o tempo para %s", player, passivePlayer))
  307. if not _S.config.restartpause then
  308. _S.players[passivePlayer].pauseTick = _S.players[player].pauseTick
  309. else
  310. _S.players[passivePlayer].pauseTick = _S.config.pausetime[2]
  311. end
  312. _S.players[passivePlayer].pause = true
  313. _S.pause = _S.pause+1
  314. end
  315. else
  316. display(2, 1, string.format("%s não se encontra na sala!", passivePlayer), player)
  317. end
  318. _S.updateScore()
  319.  
  320. elseif args[1] == "game" and args[3] then
  321. _S.party = false
  322. local player1 = string.title(args[2])
  323. local player2 = string.title(args[3])
  324. if tfm.get.room.playerList[player1] then
  325. if tfm.get.room.playerList[player2] then
  326. for player, data in pairs(_S.players) do
  327. if data then
  328. data.ingame = false
  329. data.points = 0
  330. data.pause = false
  331. end
  332. end
  333. _S.pause = 0
  334. _S.players[player1].ingame = true
  335. _S.players[player2].ingame = true
  336. _S.gameRunning = true
  337. tfm.exec.setGameTime(3, true)
  338. display(1, 1, string.format("<font size=\"30\"><N2>New Match by Awroth!</N2>\n<font size=\"16\">%s vs %s", player1, player2))
  339. else
  340. display(2, 1, string.format("%s não se encontra na sala!", player2), player)
  341. end
  342. else
  343. display(2, 1, string.format("%s não se encontra na sala!", player1), player)
  344. end
  345. end
  346. end
  347. end
  348.  
  349. function eventPlayerLeft(passivePlayer)
  350. if not _S.party then
  351. if _S.config.pauseonleft[2] then
  352. if _S.players[passivePlayer] and _S.players[passivePlayer].ingame then
  353. display(1, 1, string.format("<font size=\"30\"><N2>MATCH PAUSED!</N2>\n<font size=\"16\">%s pausou o tempo para %s", "System", passivePlayer))
  354. if not _S.config.restartpause then
  355. _S.players[passivePlayer].pauseTick = _S.players[player].pauseTick
  356. else
  357. _S.players[passivePlayer].pauseTick = _S.config.pausetime[2]
  358. end
  359. _S.players[passivePlayer].pause = true
  360. _S.pause = _S.pause+1
  361. end
  362. end
  363. end
  364. end
  365.  
  366. function string.title(s, n)
  367. return string.gsub(s, "(%S+)", function(char) return char:lower():gsub("%a", string.upper, 1) end, n)
  368. end
  369.  
  370. function string.split(s, pattern, n)
  371. local st = {}
  372. for sb in string.gmatch(s, "[^"..pattern.."]+") do
  373. if not n or n > -1 then
  374. table.insert(st,sb)
  375. else
  376. st[#st] = st[#st]..pattern..sb
  377. end
  378. n = n and n-1 or false
  379. end
  380. return st
  381. end
  382.  
  383. function INIT()
  384. print(string.format("<font color=\"#AAAAAA\">[=] Para poder iniciar os comandos do torneio, por favor digite este comando no chat: !%s</font>", _S.command))
  385. for player, _ in pairs(tfm.get.room.playerList) do
  386. eventNewPlayer(player)
  387. end
  388. tfm.exec.newGame("@6575947")
  389. end
  390.  
  391. defaultEffect=function(id,p,x,y,rand) -- thanks for the function santah
  392. local minDist = 1
  393. local outerBorder = 20
  394. local maxDist = 30
  395. local totalParticles = rand and 40 or (id == -1 and 35 or 75)
  396. for i = 1, totalParticles do
  397. if rand then
  398. id = p[math.random(#p)]
  399. end
  400. local dist = math.min(math.random(minDist, maxDist), outerBorder)
  401. local angle = math.random(0, 360)
  402. local r = math.rad(angle)
  403. local dx = math.cos(r)
  404. local dy = math.sin(r)
  405. local vx = dist * dx / 10
  406. local vy = dist * dy / 10
  407. local ax = -vx / dist / 15
  408. local ay = (-vy / dist / 15) + 0.05
  409. if id == -1 then
  410. tfm.exec.displayParticle(9, x + dx, y + dy, vx, vy, ax, ay, nil)
  411. tfm.exec.displayParticle(1, x + dx, y + dy, vx, vy, ax, ay, nil)
  412. else
  413. tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
  414. end
  415. end
  416. end
  417.  
  418.  
  419. INIT()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement