Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.96 KB | None | 0 0
  1. ---
  2. -- RACING 3VS3
  3. -- Escrito por Eshkation 23/06/2016
  4. -- the cake is not a lie
  5. ---
  6.  
  7. tfm.exec.disableAutoShaman()
  8. tfm.exec.disableAutoNewGame()
  9. tfm.exec.disableAutoTimeLeft()
  10.  
  11. local ADMINISTRADOR = "Osaisinho" -- CHANGE TO YOUR NICKNAME, SO YOU WILL BE GAME ADMIN
  12. local WINS = 10 -- POINTS TO WIN THE GAME
  13. system.disableChatCommandDisplay("np", true)
  14. system.disableChatCommandDisplay("pause", true)
  15.  
  16. --[[
  17. After running the script, use the command !team1 Players and !team2 Players to set both players in the specified team
  18. Then you just need to press GO!
  19. Type !np @mapcode to run the next map.
  20. Type !score team1/team2 number to change its score.
  21. Type !pause to pause/unpause the game.
  22. ]]
  23.  
  24. local teams = {
  25. [1] = {},
  26. [2] = {},
  27. }
  28. local points = {
  29. [1] = 0,
  30. [2] = 0,
  31. }
  32. local isfirst = false
  33. local gameRunning = false
  34. local winTime = false
  35. local playersInGame = {}
  36. local maps = {
  37. 114122, 116630, 148424, 150692, 156510, 165843, 166705, 180191, 180274, 180619, 196433, 198715, 208058, 208162, 209708, 212542, 213697, 217900, 223986, 226883, 227851, 229830, 231905, 232451, 232791, 236146, 239826, 239880, 241211, 242708, 245223, 246790, 255542, 258717, 260377, 261720, 266930, 271523, 277731, 281730, 286333, 287268, 299002, 299971, 305677, 308694, 308992, 309029, 314159, 315801, 317754, 323085, 323366, 332210, 332290, 339896, 340069, 341239, 343971, 344865, 345257, 348801, 349140, 352381, 355957, 356982, 357328, 359521, 363638, 365464, 365652, 367520, 381569, 381669, 386029, 391693, 391831, 393851, 401778, 405295, 405955, 410813, 412657, 414460, 414899, 416015, 418293, 418658, 419374, 421717, 423672, 424795, 425030, 425600, 429822, 429897, 430145, 431142, 431887, 434887, 445167, 447556, 470727, 471053, 477370, 499687, 501711, 504409, 505109, 507325, 508106, 508796, 509082, 512927, 514982, 531569, 536235, 563484, 571512, 594883, 595447, 606723, 611320, 616433, 664949, 694900, 737841, 813156, 849224, 982242, 1015582, 1033170, 1051384, 1058681, 1142116, 1195842, 1208798, 1214182, 1216253, 1255148, 1311059, 1364063, 1375345, 1448760, 1506007, 1512355, 1538895, 1601492, 1608638, 1619934, 1654841, 1663380, 1663415, 1689382, 1702169, 1724289, 1749434, 1768347, 1787232, 1813728, 1851968, 1856349, 1862823, 1927270, 1951856, 1956002, 1964752, 2012147, 2030343, 2070768, 2134537, 2141379, 2150335, 2221510, 2245005, 2331474, 2369254, 2683170, 2726034, 2796001, 2813487, 2816067, 3008155, 3156569, 3213562, 3444803, 3518418, 3537419, 3548376, 3548406, 3572407, 3575034, 3575108, 3620542, 3638794, 3654416, 3669435, 3676555, 3680223, 3685382, 3688419, 3700684, 3705931, 3716560, 3821104, 3889414, 4000001, 4234556, 4645670, 4707191, 4815404, 4911122, 4915220, 4946442, 5000090, 5024682, 5030579, 5032745, 5272513, 5346212, 5349806, 5408572, 5452432, 5495901, 5557858, 5590554, 5591416, 5712914, 5805021, 5813480, 5813783, 5861874, 5886041, 5972342, 6069526, 6112855, 6114810, 6172897, 6226519, 6276662, 6300594
  38. }
  39. local colors = {
  40. [1] = "ff6347",
  41. [2] = "19b5fe"
  42. }
  43. local queue = {}
  44.  
  45. function newMap()
  46. local mapcode = maps[math.random(#maps)]
  47. if #queue > 0 then
  48. mapcode = queue[1]
  49. table.remove(queue, 1)
  50. end
  51. tfm.exec.newGame(mapcode)
  52. for player, data in pairs(tfm.get.room.playerList) do
  53. if not playersInGame[player] then
  54. tfm.exec.killPlayer(player)
  55. end
  56. end
  57. tfm.exec.setGameTime(60)
  58. end
  59.  
  60. function eventPlayerWon(player)
  61. if not isfirst then
  62. isfirst = true
  63. tfm.exec.setGameTime(5)
  64. if table.contains(teams[1], player) then
  65. tfm.exec.setGameTime(5)
  66. for i = 0, 3 do
  67. defaultEffect(9, {13}, math.random(800), math.random(400), 20)
  68. end
  69. points[1] = points[1]+1
  70. elseif table.contains(teams[2], player) then
  71. tfm.exec.setGameTime(5)
  72. for i = 0, 3 do
  73. defaultEffect(9, {9}, math.random(800), math.random(400), 20)
  74. end
  75. points[2] = points[2]+1
  76. else
  77. isfirst = false
  78. end
  79. winner = false
  80. if points[1] >= WINS then
  81. winner = 1
  82. elseif points[2] >= WINS then
  83. winner = 2
  84. end
  85. if winner then
  86. gameRunning = false
  87. winTime = os.time()
  88. local names = {
  89. "Night's watch",
  90. "Apace"
  91. }
  92. ui.addTextArea(20, string.format("<p align='center'><font size='37' color='#000000'>Team %s is the winner!\nGood job!", names[winner]), nil, 0, 171, 800, 500, 0, 0, 0, true)
  93. ui.addTextArea(21, string.format("<p align='center'><font size='37' color='#000000'>Team %s is the winner!\nGood job!", names[winner]), nil, 1, 170, 800, 500, 0, 0, 0, true)
  94. ui.addTextArea(22, string.format("<p align='center'><font size='37'><font color='#FFFFFF'>Team <font color='#%s'>%s</font> is the winner!\nGood job!", colors[winner], names[winner]), nil, 1, 170, 800, 500, 0, 0, 0, true)
  95. end
  96. displayScore()
  97. end
  98. end
  99.  
  100. function eventLoop(elapsed, remain)
  101. if gameRunning then
  102. remain = remain/1000
  103. if remain < 0 then
  104. remain = 100
  105. newMap()
  106. end
  107. else
  108. if winTime then
  109. if winTime > os.time()-30000 then
  110. for i = 0, 2 do
  111. defaultEffect(9, {11, 9, 0, 13}, math.random(800), math.random(400), 80)
  112. end
  113. else
  114. winTime = false
  115. ui.removeTextArea(20)
  116. ui.removeTextArea(21)
  117. ui.removeTextArea(22)
  118. displayTeams()
  119. teams = {
  120. [1] = {},
  121. [2] = {},
  122. }
  123. points = {
  124. [1] = 0,
  125. [2] = 0,
  126. }
  127. playersInGame = {}
  128. end
  129. end
  130. end
  131. end
  132.  
  133. function string.title(s)
  134. return string.gsub(s, "%a", function(c)
  135. return string.upper(c)
  136. end, 1)
  137. end
  138.  
  139. function eventChatCommand(player, command)
  140. if player:lower() == ADMINISTRADOR:lower() then
  141. args = string.split(command, " ")
  142. if args[1] == "team1" then
  143. table.remove(args, 1)
  144. teams[1] = {}
  145. points[1] = 0
  146. for index, player in pairs(args) do
  147. player = string.title(player)
  148. table.insert(teams[1], player)
  149. playersInGame[player] = true
  150. end
  151. displayTeams()
  152.  
  153. elseif args[1] == "team2" then
  154. table.remove(args, 1)
  155. teams[2] = {}
  156. points[2] = 0
  157. for index, player in pairs(args) do
  158. player = string.title(player)
  159. table.insert(teams[2], player)
  160. playersInGame[player] = true
  161. end
  162. displayTeams()
  163.  
  164. elseif args[1] == "score" then
  165. if args[2] and args[3] then
  166. local team = tonumber(args[2]:match("team(%d+)") or 0)
  167. if team > 0 and team < 3 then
  168. local newScore = tonumber(args[3]) or points[team]
  169. points[team] = newScore
  170. displayScore()
  171. end
  172. end
  173. elseif args[1] == "np" then
  174. if args[2] then
  175. table.insert(queue, args[2])
  176. end
  177. elseif args[1] == "pause" then
  178. gameRunning = not gameRunning
  179. if not gameRunning then
  180. ui.addTextArea(90, "<p align='center'><font size='25'><R>P A U S E D", nil, 0, 200, 800, nil, 0, 0, 0, true)
  181. tfm.exec.disableAutoTimeLeft(true)
  182. else
  183. ui.removeTextArea(90)
  184. tfm.exec.disableAutoTimeLeft(false)
  185. end
  186. end
  187. end
  188. end
  189.  
  190. function eventNewGame()
  191. if gameRunning then
  192. isfirst = false
  193. for i, p in pairs(teams[1]) do
  194. tfm.exec.setNameColor(p, "0x"..colors[1])
  195. end
  196. for i, p in pairs(teams[2]) do
  197. tfm.exec.setNameColor(p, "0x"..colors[2])
  198. end
  199. displayScore()
  200. end
  201. end
  202.  
  203. function displayScore()
  204. ui.addTextArea(17, string.format("<p align='center'><font size='23' color='#000000'>%s x %s", points[1], points[2]), nil, 0, 21, 800, 30, 0, 0, 0, true)
  205. ui.addTextArea(18, string.format("<p align='center'><font size='23' color='#000000'>%s x %s", points[1], points[2]), nil, 1, 20, 800, 30, 0, 0, 0, true)
  206. ui.addTextArea(19, string.format("<p align='center'><font size='23'><font color='#%s'>%s<N> x <font color='#%s'>%s", colors[1], points[1], colors[2], points[2]), nil, 0, 20, 800, 30, 0, 0, 0, true)
  207. end
  208.  
  209. function displayTeams()
  210. ui.addTextArea(1, "", nil, 199, 69, 400, 260, 0x5A7A8B, 0x5A7A8B, 1, true)
  211. ui.addTextArea(2, "", nil, 201, 71, 400, 260, 0x0E1417, 0x0E1417, 1, true)
  212. ui.addTextArea(3, "", nil, 200, 70, 400, 260, 0x324650, 0x324650, 1, true)
  213. ui.addTextArea(4, "", nil, 209, 79, 142, 22, 0x324650, 0x5A7A8B, 1, true)
  214. ui.addTextArea(5, "<p align='center'><V>Team 1", nil, 210, 80, 140, 20, 0x324650, 0x324650, 1, true)
  215. ui.addTextArea(6, "", nil, 449, 79, 142, 22, 0x324650, 0x5A7A8B, 1, true)
  216. ui.addTextArea(7, "<p align='center'><V>Team 2", nil, 450, 80, 140, 20, 0x324650, 0x324650, 1, true)
  217. ui.addTextArea(8, "<p align='center'><font color='#5A7A8B'>|</font>", nil, 210, 102, 140, 200, 0, 0, 0, true)
  218. ui.addTextArea(9, "<p align='center'><font color='#5A7A8B'>|</font>", nil, 450, 102, 140, 200, 0, 0, 0, true)
  219. ui.addTextArea(10, "", nil, 209, 120, 140, 200, 0x5A7A8B, 0x5A7A8B, 1, true)
  220. ui.addTextArea(11, "<p align='center'><font color='#"..colors[1].."'>"..table.concat(teams[1], "\n"), nil, 210, 121, 138, 198, 0x324650, 0x324650, 1, true)
  221. ui.addTextArea(12, "", nil, 451, 120, 140, 200, 0x5A7A8B, 0x5A7A8B, 1, true)
  222. ui.addTextArea(13, "<p align='center'><font color='#"..colors[2].."'>"..table.concat(teams[2], "\n"), nil, 452, 121, 138, 198, 0x324650, 0x324650, 1, true)
  223. ui.addTextArea(14, "<p align='center'><font color='#5A7A8B'>____ ____</font>", nil, 330, 200, 140, 200, 0, 0, 0, true)
  224. ui.addTextArea(15, "", nil, 380, 202, 40, 20, 0x5A7A8B, 0x5A7A8B, 1, true)
  225. ui.addTextArea(16, "<p align='center'><V>VS", nil, 381, 203, 38, 18, 0x324650, 0x324650, 1, true)
  226. ui.addTextArea(16, "<p align='center'><V><a href='event:iniciarJogo'>GO", ADMINISTRADOR, 381, 203, 38, 18, 0x324650, 0x324650, 1, true)
  227. end
  228.  
  229. function eventTextAreaCallback(id, player, callback)
  230. if callback == 'iniciarJogo' then
  231. if #teams[2] > 0 and #teams[1] > 0 then
  232. gameRunning = true
  233. for i = 1, 16 do
  234. ui.removeTextArea(i)
  235. end
  236. defaultEffect(9, {9}, 400, 212, 80)
  237. newMap()
  238. end
  239. end
  240. end
  241.  
  242. function string.split(s, pattern, n)
  243. local st = {}
  244. for sb in string.gmatch(s, "[^"..pattern.."]+") do
  245. if not n or n > -1 then
  246. table.insert(st,sb)
  247. else
  248. st[#st] = st[#st]..pattern..sb
  249. end
  250. n = n and n-1 or false
  251. end
  252. return st
  253. end
  254.  
  255. function table.contains(tableT, element)
  256. for _, value in pairs(tableT) do
  257. if value == element then
  258. return true
  259. end
  260. end
  261. return false
  262. end
  263.  
  264. defaultEffect=function(id,p,x,y,rand) -- thanks for the function santah
  265. local minDist = 1
  266. local outerBorder = 20
  267. local maxDist = 30
  268. local totalParticles = rand and 40 or (id == -1 and 35 or 75)
  269. for i = 1, totalParticles do
  270. if rand then
  271. id = p[math.random(#p)]
  272. end
  273. local dist = math.min(math.random(minDist, maxDist), outerBorder)
  274. local angle = math.random(0, 360)
  275. local r = math.rad(angle)
  276. local dx = math.cos(r)
  277. local dy = math.sin(r)
  278. local vx = dist * dx / 10
  279. local vy = dist * dy / 10
  280. local ax = -vx / dist / 15
  281. local ay = (-vy / dist / 15) + 0.05
  282. if id == -1 then
  283. tfm.exec.displayParticle(9, x + dx, y + dy, vx, vy, ax, ay, nil)
  284. tfm.exec.displayParticle(1, x + dx, y + dy, vx, vy, ax, ay, nil)
  285. else
  286. tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
  287. end
  288. end
  289. end
  290.  
  291. displayTeams()
  292.  
  293. function eventPlayerDied()
  294. local alive = 0
  295. for k,v in pairs(tfm.get.room.playerList) do
  296. if not v.isDead then
  297. alive = alive+1
  298. end
  299. end
  300. if alive < 2 then
  301. tfm.exec.setGameTime(5)
  302. end
  303. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement