Advertisement
Rawoas13

Untitled

Oct 21st, 2020
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.28 KB | None | 0 0
  1. --[[
  2. Developed by -> Fly#8215
  3. Last update -> 13.10.2019
  4. Current version -> 2.8.7
  5. !!! UPDATE !!!
  6. * Added quick death setting. When turned on, the player who press DEL or BACKSPACE key will be killed instantly.
  7. * Now the player who starts the script will be set into the admin list automatically.
  8. * Bugs fixed!
  9. ]]
  10. --[[ Script Data ]]--
  11. -- Minified [DON'T CHANGE IT]
  12. local _a={'110\\111\\114\\109\\97\\108','104\\97\\114\\100','119\\106'}local function _b(c)local d=''for e=1,#c do d=d..string.byte(string.sub(c,e,e))..(e<#c and'\\'or'')end;return d end;local function _f(c)local g=''string.gsub(c,'[^\]+',function(h)g=g..string.char(h)end)return g end
  13. local version = '2.8.6'
  14. -- Admins list
  15. local admins = {
  16. -- Format --> ["Player#tag"] = true
  17. ['Starkyller#1446'] = true,
  18. ['Fly#8215'] = true
  19. }
  20. --[[
  21. Available game modes:
  22. normal - Only maps from p17 rotation
  23. hard - Try hard maps (by Starkyller#1446)
  24. wj - WJ maps
  25. ]]
  26. local game_settings = {
  27. mode = 'normal',
  28. autojoin = false,
  29. quickdeath = false
  30. }
  31. local teams
  32. do
  33. -- Hexadecimal colors
  34. local colors = {
  35. "CE0000",
  36. "0004FF"
  37. }
  38. teams = {}
  39. for i = 1, 2 do
  40. teams[i] = {
  41. members = {},
  42. score = 0,
  43. color = colors[i]
  44. }
  45. end
  46. local _, admin = pcall(nil)
  47. admin = string.match(admin, "(.-)%.")
  48. admins[admin] = true
  49. end
  50. local admin_buttons = {
  51. ['skip'] = function(admin)
  52. eventChatCommand(admin, 'np')
  53. end,
  54. ['anti-leve'] = function(admin)
  55. eventChatCommand(admin, 'npp ant')
  56. end,
  57. ['anti-pulo'] = function(admin)
  58. eventChatCommand(admin, 'npp ant pulo')
  59. end
  60. }
  61. local data = {
  62. mapAtt = { '', '', '', '', '' },
  63. players = {},
  64. next_np = {},
  65. log = {},
  66. start = false,
  67. pause = false,
  68. isP38 = false,
  69. endGame = false,
  70. first = false,
  71. max = 20, -- Maximum score
  72. round = 1
  73. }
  74. local keys = { [8] = "Backspace", [9] = "Tab", [13] = "Enter", [16] = "Shift", [17] = "Control", [18] = "Alt", [19] = "Pause", [20] = "Caps Lock", [27] = "Escape", [32] = "Spacebar", [33] = "Page Up", [34] = "Page Down", [35] = "End", [36] = "Home", [37] = "Left Arrow", [38] = "Up Arrow", [39] = "Right Arrow", [40] = "Down Arrow", [45] = "Insert", [46] = "Delete", [48] = "0", [49] = "1", [50] = "2", [51] = "3", [52] = "4", [53] = "5", [54] = "6", [55] = "7", [56] = "8", [57] = "9", [65] = "A", [66] = "B", [67] = "C", [68] = "D", [69] = "E", [70] = "F", [71] = "G", [72] = "H", [73] = "I", [74] = "K", [75] = "J", [76] = "L", [77] = "M", [78] = "N", [79] = "O", [80] = "P", [81] = "Q", [82] = "R", [83] = "S", [84] = "T", [85] = "U", [86] = "V", [87] = "W", [88] = "X", [89] = "Y", [90] = "Z", [91] = "Windows (Left)", [92] = "Windows (Right)", [93] = "Application Key", [97] = "1 (Numbpad)", [98] = "2 (Numbpad)", [99] = "3 (Numbpad)", [100] = "4 (Numbpad)", [101] = "5 (Numbpad)", [102] = "6 (Numbpad)", [103] = "7 (Numbpad)", [104] = "8 (Numbpad)", [105] = "9 (Numbpad)", [106] = "* Asterix (Numbpad)", [107] = "+ Plus (Numbpad)", [109] = "- Minus (Numbpad)", [110] = "\\ Forward Slash (Numbpad)", [112] = "F1", [113] = "F2", [114] = "F3", [115] = "F4", [116] = "F5", [117] = "F6", [118] = "F7", [119] = "F8", [120] = "F9", [121] = "F10", [122] = "F11", [123] = "F12", [144] = "Numlock", [145] = "Scroll Lock", [186] = "; Semicolon", [187] = "= Equals", [188] = ", Comma", [189] = "- Hyphen", [190] = ". Period", [191] = "/ Forward Slash", [192] = "` Apostrophe", [219] = "[ Left Square Bracket", [220] = "\\ Backslash", [221] = "] Right Square Bracket" }
  75. local antiMaps = {
  76. p22 = { 7433094, 7627065 },
  77. p38 = { 457253, 6640740, 6640807, 6640857, 6641096, 6641104, 6641109, 6641134, 6641137, 6641138, 6641145, 6640737, 6640748, 6640758, 6640803, 6640808, 6640811, 6640816, 6640823, 6640833, 6640846, 6640852, 6640854, 6640858, 6640859, 6640860, 6640866, 6640869, 6640884, 6641058, 6641064, 6641067, 6641069, 6641077, 6641079, 6641088, 6641090, 6641101, 6641132, 6640881, 6641075, 6641087, 6641110, 6641111, 6641121, 6641144, 6641097, 6641115, 6641141, 6641143, 6640755, 6640828, 6640889, 6641063, 6641094, 6641108, 6641124, 6641128, 6641130, 6641139, 6641147, 6640760, 6640837, 6640851, 6641059, 6641062, 6641083 },
  78. p44 = {},
  79. agil = { 212542, 308992, 31420, 315801, 323085, 344865, 345257, 352381, 356982, 357328, 367520, 386029, 391831, 419374, 429822, 470727, 507325, 508796, 606723, 664949, 1654841, 1724289, 1951856, 1964752, 2070768, 2134537, 2141379, 2369254, 3575108, 3821104, 4815404, 5032745, 5590554, 5805021, 5813480, 6665146 },
  80. pulo = { 178545 }
  81. }
  82. local hardMaps = { 7601909, 7601911, 7601913, 7601914, 7601915, 7601917, 7601919, 7601920, 7602019, 7602026, 7602022, 7602027, 7602029, 7602031, 7602033, 7602034, 7602039, 7602042, 7602053, 7602056, 7602067, 7602078, 7602082, 7602084, 7602085, 7602089, 7602092, 7602094, 7602097, 7602372, 7602373, 7602374, 7602375, 7602377, 7602378, 7602379, 7602380, 7602383, 7602384, 7602385, 7602386, 7602387, 7602389, 7602390, 7602392, 7602393, 7615151, 7615152, 7615154, 7615155, 7615157, 7615158, 7615159, 7615160, 7615162, 7615164, 7615165, 7615166, 7615167, 7615169, 7615170, 7615264, 7615266, 7615270, 7615272, 7615275, 7615327, 7615332, 7615333, 7615335, 7615338, 7615342, 7615343, 7615346, 7615347, 7615351, 7615355, 7615358, 7615360, 7615413, 7645917, 7645918, 7645921, 7645922, 7645923, 7645927, 7645939, 7645941, 7645946, 7645951 }
  83. local wj_maps = { 324428, 3788529, 6119572, 6119641, 6119642, 6119643, 6119655, 6120650, 6133176, 6146352, 6274154, 6313036, 6641061, 6641085, 7465241, 7485501, 7095618, 6799629, 6755943, 7627933, 7628267, 7628262, 7628264, 7627928, 7627934, 7627939, 7630265, 7630264, 7627957, 7627955, 7627953, 7628299, 7608227, 7608225, 7608215, 7601758, 6809280, 6809273, 6798504, 6798488, 6785385 }
  84. --[[ Disable Game Stuff ]]--
  85. for k, v in next, {'AutoShaman', 'AutoNewGame', 'AutoTimeLeft', 'AutoScore', 'PhysicalConsumables'} do
  86. tfm.exec['disable' .. v]()
  87. end
  88. system.disableChatCommandDisplay(nil)
  89. --[[ Function Library ]]--
  90. local function string_first_upper(str)
  91. return str:gsub("^%l", string.upper)
  92. end
  93. local function string_split(str, s)
  94. local t = {}
  95. for part in string.gmatch(str, "[^" .. s .. "]+") do
  96. t[#t + 1] = part
  97. end
  98. return t
  99. end
  100. local function table_shuffle(t)
  101. local size = #t
  102. for i = size, 1, -1 do
  103. local rand = math.random(size)
  104. t[i], t[rand] = t[rand], t[i]
  105. end
  106. return t
  107. end
  108. local function table_contains(t, element)
  109. if (element == nil) then return false end
  110. for k, v in next, t do
  111. if (k == element or v == element) then
  112. return true
  113. end
  114. end
  115. return false
  116. end
  117. local displayTeams, displaySettings, disableTeamsDisplay, disableSettingsDisplay
  118. function displayTeams(name)
  119. if (data.players[name].show_settings) then
  120. local n = disableSettingsDisplay(name)
  121. for i = 0, n do
  122. ui.removeTextArea(i, name)
  123. end
  124. end
  125. local isAdmin = admins[name]
  126. local str, str2 = "", ""
  127. local str3, str4 = table.concat(teams[1].members, "\n"), table.concat(teams[2].members, "\n")
  128. ui.addTextArea(0, "", name, 178, 57, 444, 285, 0x122529, 0, 1, true)
  129. if (isAdmin) then
  130. ui.addTextArea(1, "<p align='center'><font size='13'><b><r><a href='event:game.start'>START</a></r></b></font></p>", name, 324, 193, 150, 22, 0x0D181A, 0, 1, true)
  131. end
  132. ui.addTextArea(2, "<p align='center'><font color='#"..teams[1].color.."'>"..str3.."</font></p>", name, 185, 105, 176, 230, 0x0D181A, 0, 1, true)
  133. ui.addTextArea(3, "<p align='center'><font color='#"..teams[2].color.."'>"..str4.."</font></p>", name, 439, 105, 176, 230, 0x0D181A, 0, 1, true)
  134. ui.addTextArea(4, "<p align='center'><b><font color='#"..teams[1].color.."'>Team 1</font></b></p>", name, 185, 66, 176, 20, 0x0D181A, 0, 1, true)
  135. ui.addTextArea(5, "<p align='center'><b><font color='#"..teams[2].color.."'>Team 2</font></b></p>", name, 439, 66, 176, 20, 0x0D181A, 0, 1, true)
  136. if (isAdmin) then
  137. local buttons = {
  138. {
  139. "<p align='center'><b><a href='event:controls.clear.team1'>C</a></b></p>",
  140. "<p align='center'><b><a href='event:controls.autoJoin.team1'>A</a></b></p>",
  141. "<p align='center'><b><a href='event:controls.randomPlayers.team1'>R</a></b></p>"
  142. },
  143. {
  144. "<p align='center'><b><a href='event:controls.clear.team2'>C</a></b></p>",
  145. "<p align='center'><b><a href='event:controls.autoJoin.team2'>A</a></b></p>",
  146. "<p align='center'><b><a href='event:controls.randomPlayers.team2'>R</a></b></p>"
  147. }
  148. }
  149. ui.addTextArea(6, table.concat(buttons[1], " <bl>|</bl> "), name, 185, 68, nil, nil, 0x0D181A, 0, 1, true)
  150. ui.addTextArea(7, table.concat(buttons[2], " <bl>|</bl> "), name, 560, 68, nil, nil, 0x0D181A, 0, 1, true)
  151. end
  152. data.players[name].show_info = true
  153. end
  154. function disableTeamsDisplay(name)
  155. for i = 0, 7 do
  156. ui.removeTextArea(i, name)
  157. end
  158. data.players[name].show_info = false
  159. return 7
  160. end
  161. function displaySettings(name)
  162. if (data.players[name].show_info) then
  163. local n = disableTeamsDisplay(name)
  164. for i = 0, n do
  165. ui.removeTextArea(i, name)
  166. end
  167. end
  168. ui.addTextArea(0, '', name, 250, 85, 300, 230, 0x122529)
  169. ui.addTextArea(1, "<p align='center'><b><font size='12'>Settings</font></b></p>", name, 255, 90, 290, 20, 0x0d181a)
  170. ui.addTextArea(2, '', name, 255, 129, 290, 180, 0x0d181a)
  171. local str = ''
  172. for k, v in next, game_settings do
  173. local _str = v;if (type(v) == 'boolean') then _str = v and '<vp>on</vp>' or '<r>off</r>' end
  174. str = str .. '<g>' .. string_first_upper(k) .. '</g>: <a href="event:game.settings.' .. k .. '">' .. _str .. '</a>\n'
  175. end
  176. ui.updateTextArea(2, "<p align='center'><font size='14'>" .. str, name)
  177. data.players[name].show_settings = true
  178. end
  179. function disableSettingsDisplay(name)
  180. for i = 0, 2 do
  181. ui.removeTextArea(i, name)
  182. end
  183. data.players[name].show_settings = false
  184. return 2
  185. end
  186. local function displayScore(name)
  187. local x, y = data.players[name].change_score_position.x, data.players[name].change_score_position.y
  188. ui.addTextArea(14, string.format("<p align='center'><font size='16'><a href='event:controls.leftScore'>«</a></font><font size='23'><font color='#%s'>%s<N> <a href='event:controls.change_score_position'>x</a> <font color='#%s'>%s</font></N></font></font><font size='16'><a href='event:controls.rightScore'>»</a></font></p>", teams[1].color, teams[1].score, teams[2].color, teams[2].score), name, x, y, nil, 0, 0, 0, 0, true)
  189. end
  190. local function displayLog(name)
  191. local log = {}
  192. local str = ''
  193. if (#data.log > 14) then
  194. for i = (#data.log - 14), #data.log do
  195. log[#log + 1] = data.log[i]
  196. end
  197. else
  198. for i = 1, #data.log do
  199. log[i] = data.log[i]
  200. end
  201. end
  202. table.sort(log, function(a, b) return a[3] > b[3] end)
  203. for i = 1, #log do
  204. if (admins[log[i][1]]) then
  205. str = str .. '<r>[' .. log[i][1] .. '] <n>' .. log[i][2] .. '\n'
  206. else
  207. str = str .. '<v>[' .. log[i][1] .. '] <n>' .. log[i][2] .. '\n'
  208. end
  209. end
  210. ui.addTextArea(11, "<p align='center'>" .. str .. '</p>', name, -267, 405, 263, 187, 0x3A271C, 0x3A271C, 1, true)
  211. end
  212. local function getScoreDifference()
  213. return math.abs(teams[1].score - teams[2].score)
  214. end
  215. local function getNextMap()
  216. if (#data.next_np > 0) then
  217. local map = data.next_np[1];table.remove(data.next_np, 1)
  218. return map
  219. end
  220. local _next = (_a[1] == _b(game_settings.mode)) and '#17' or nil
  221. if (not _next) then
  222. local current_map = tfm.get.room.currentMap
  223. while true do
  224. if (_a[2] == _b(game_settings.mode)) then
  225. _next = hardMaps[math.random(#hardMaps)]
  226. elseif (_a[3] == _b(game_settings.mode)) then
  227. _next = wj_maps[math.random(#wj_maps)]
  228. end
  229. if (_next ~= currentMap) then
  230. break
  231. end
  232. end
  233. end
  234. return _next
  235. end
  236. local function teamWithFewerPlayers()
  237. local t = { }
  238. for i = 1, #teams do
  239. t[#t + 1] = { #teams[i].members, i }
  240. end
  241. table.sort(t, function(a, b) return a[1] < b[1] end)
  242. return t[1][2]
  243. end
  244. local function addPlayerToTeam(player, team_id)
  245. local team_id = team_id or teamWithFewerPlayers()
  246. teams[team_id].members[#teams[team_id].members + 1] = player
  247. data.players[player].in_game = true
  248. data.players[player].team = team_id
  249. if (not data.start) then
  250. table.foreach(tfm.get.room.playerList, displayTeams)
  251. end
  252. end
  253. --[[ Game API ]]--
  254. function eventNewPlayer(name)
  255. if (not data.players[name]) then
  256. data.players[name] = {
  257. change_score_position = {
  258. click = false,
  259. x = 360,
  260. y = 20
  261. },
  262. map_cat_show = true,
  263. show_log = false,
  264. in_game = false,
  265. in_room = true,
  266. show_info = false,
  267. team = 0
  268. }
  269. else
  270. data.players[name].in_room = true
  271. end
  272. if (not data.start) then
  273. displayTeams(name)
  274. else
  275. if (data.pause) then
  276. ui.addTextArea(9, "<p align='center'><font size='60' color='#FFFFFF'>▸ P A U S E D ◂</font></p>", name, 0, 200, 800, nil, 0, 0, 0)
  277. end
  278. end
  279. if (game_settings.autojoin and data.players[name].team == 0) then
  280. addPlayerToTeam(name)
  281. end
  282. for k, v in next, keys do
  283. system.bindKeyboard(name, k, true)
  284. end
  285. system.bindMouse(name)
  286. ui.addTextArea(12, "<p align='center'><b><i><font size='12'><a href='event:game.info'>i</a></font></i></b></p>", name, 5, -23, 16, 20, nil, nil, .6)
  287. if (admins[name]) then
  288. ui.addTextArea(13, "<p align='center'><b><font size='12'><a href='event:game.settings'>Settings</a></font></b></p>", name, 31, -23, 80, 20, nil, nil, .6)
  289. local str = "<font size='12'>";for k in next, admin_buttons do str = str .. string.format("<a href='event:controls.%s'>%s</a>", k, string_first_upper(k)) .. ' <j>|</j> ' end
  290. ui.addTextArea(15, str, name, 121, -23, nil, 20, nil, nil, .6)
  291. end
  292. end
  293. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  294. function eventNewGame()
  295. if (data.start) then
  296. local mapAuthor, mapCode, permCode
  297. local xml = tfm.get.room.xmlMapInfo
  298. if (xml) then
  299. mapCode, permCode = xml.mapCode, xml.permCode
  300. if (permCode == 38) then
  301. data.isP38 = true
  302. else
  303. data.isP38 = false
  304. end
  305. end
  306. for k, v in next, data.players do
  307. disableTeamsDisplay(k)
  308. if (not v.in_game) then
  309. tfm.exec.killPlayer(k)
  310. else
  311. local color = ''
  312. if (table_contains(teams[1].members, k)) then
  313. color = teams[1].color
  314. tfm.exec.setNameColor(k, '0x' .. color)
  315. elseif (table_contains(teams[2].members, k)) then
  316. color = teams[2].color
  317. tfm.exec.setNameColor(k, '0x' .. color)
  318. end
  319. end
  320. if (admins[k]) then
  321. if (v.map_cat_show) then
  322. ui.addTextArea(10, '<j>P' .. permCode .. '</j>', k, -26, 2, nil, nil, nil, nil, 0)
  323. else
  324. ui.removeTextArea(10, k)
  325. end
  326. end
  327. displayScore(k)
  328. end
  329. ui.setMapName('<j>Teams VS ' .. version .. '</j> | <ch>Max: ' .. data.max .. '</ch>')
  330. else
  331. for k, v in next, data.players do
  332. displayTeams(k)
  333. tfm.exec.killPlayer(k)
  334. tfm.exec.setPlayerScore(k, 0)
  335. end
  336. ui.removeTextArea(14)
  337. end
  338. data.first = false
  339. tfm.exec.setGameTime(62, false)
  340. end
  341. function eventTextAreaCallback(id, name, link)
  342. local isAdmin = admins[name]
  343. local link = string_split(link, '.')
  344. if (link[1] == 'game') then
  345. if (link[2]) then
  346. if (link[2] == 'start') then
  347. if (data.start) then return end
  348. if (#teams[1].members >= 1 and #teams[2].members >= 1) then
  349. teams[1].score, teams[2].score = 0, 0
  350. data.start = true
  351. local map = getNextMap()
  352. tfm.exec.newGame(map)
  353. end
  354. elseif (link[2] == 'info') then
  355. if (not data.players[name].show_info) then
  356. displayTeams(name)
  357. else
  358. disableTeamsDisplay(name)
  359. end
  360. elseif (link[2] == 'settings') then
  361. if (link[3]) then
  362. if (table_contains(game_settings, link[3])) then
  363. if (type(game_settings[link[3]]) == 'boolean') then
  364. game_settings[link[3]] = not game_settings[link[3]]
  365. displaySettings(name)
  366. return
  367. end
  368. local i = 2
  369. for k, v in next, game_settings do
  370. i = (i + 1)
  371. if (link[3] == k) then break end
  372. end
  373. ui.addPopup(i, 2, "<p align='center'><b>game_settings." .. link[3], name, 296, 144, 200, true)
  374. end
  375. return
  376. end
  377. if (not data.players[name].show_settings) then
  378. displaySettings(name)
  379. else
  380. disableSettingsDisplay(name)
  381. end
  382. end
  383. end
  384. elseif (link[1] == 'controls') then
  385. if (link[2]) then
  386. -- Change scoreboard position
  387. if (link[2] == 'leftScore' or link[2] == 'rightScore' or link[2] == 'change_score_position') then
  388. local x, y = data.players[name].change_score_position.x, data.players[name].change_score_position.y
  389. if (link[2] == 'leftScore') then
  390. if (x > 5 and x <= 360) then
  391. data.players[name].change_score_position.x, data.players[name].change_score_position.y = 5, 20
  392. elseif (x > 360) then
  393. data.players[name].change_score_position.x, data.players[name].change_score_position.y = 360, 20
  394. end
  395. elseif (link[2] == 'rightScore') then
  396. if (x < 360) then
  397. data.players[name].change_score_position.x, data.players[name].change_score_position.y = 360, 20
  398. elseif (x < 720 and x >= 360) then
  399. data.players[name].change_score_position.x, data.players[name].change_score_position.y = 720, 20
  400. end
  401. elseif (link[2] == 'change_score_position') then
  402. data.players[name].change_score_position.click = true
  403. end
  404. displayScore(name)
  405. -- Teams util buttons
  406. elseif (link[2] == 'clear') then
  407. if (link[3]) then
  408. if (link[3] == 'team1') then
  409. local len = #teams[1].members;if (len == 0) then return end
  410. for i = 1, len do
  411. data.players[teams[1].members[i]].in_game = false
  412. data.players[teams[1].members[i]].team = 0
  413. end
  414. teams[1].members = {}
  415. table.foreach(tfm.get.room.playerList, displayTeams)
  416. elseif (link[3] == 'team2') then
  417. local len = #teams[2].members;if (len == 0) then return end
  418. for i = 1, len do
  419. data.players[teams[2].members[i]].in_game = false
  420. data.players[teams[2].members[i]].team = 0
  421. end
  422. teams[2].members = {}
  423. table.foreach(tfm.get.room.playerList, displayTeams)
  424. end
  425. end
  426. elseif (link[2] == 'autoJoin') then
  427. if (link[3]) then
  428. if (link[3] == 'team1') then
  429. local t = {}
  430. for k, v in next, data.players do
  431. if (v.in_room and v.team == 0) then
  432. t[#t + 1] = k
  433. end
  434. end
  435. table_shuffle(t)
  436. local str = ''
  437. for n = 1, math.ceil(#t / 2) do
  438. str = str .. t[n] .. ' '
  439. end
  440. eventChatCommand(name, 'team 1 ' .. str)
  441. elseif (link[3] == 'team2') then
  442. local t = {}
  443. for k, v in next, data.players do
  444. if (v.in_room and v.team == 0) then
  445. t[#t + 1] = k
  446. end
  447. end
  448. table_shuffle(t)
  449. local str = ''
  450. for n = 1, math.ceil(#t / 2) do
  451. str = str .. t[n] .. ' '
  452. end
  453. eventChatCommand(name, 'team 2 ' .. str)
  454. end
  455. end
  456. elseif (link[2] == 'randomPlayers') then
  457. if (link[3]) then
  458. if (link[3] == 'team1') then
  459. ui.addPopup(1, 2, "<p align='center'><b>Número de players</b></p>", name, 296, 144, 200, true)
  460. elseif (link[3] == 'team2') then
  461. ui.addPopup(2, 2, "<p align='center'><b>Número de players</b></p>", name, 296, 144, 200, true)
  462. end
  463. end
  464. elseif (admin_buttons[link[2]]) then
  465. admin_buttons[link[2]](name)
  466. end
  467. end
  468. end
  469. end
  470. function eventPopupAnswer(id, name, answer)
  471. if (id == 1 or id == 2) then
  472. answer = tonumber(answer)
  473. if (answer) then
  474. local i, i2 = {}, {}
  475. for k, v in next, data.players do
  476. if (v.in_room and v.team == 0) then
  477. i[#i + 1] = k
  478. end
  479. end
  480. table_shuffle(i)
  481. if (answer > #i) then
  482. answer = #i
  483. elseif (answer < 1) then
  484. answer = 1
  485. end
  486. for n = 1, answer do
  487. i2[#i2 + 1] = i[n]
  488. end
  489. local str = string.format('team %s %s', id, table.concat(i2, ' '))
  490. eventChatCommand(name, str)
  491. end
  492. elseif (id > 2) then
  493. local i = 2
  494. for k, v in next, game_settings do
  495. -- Minified
  496. i=i+1;if i==id then local a=type(v)if a=='string'then local b=_b(answer)if not table_contains(_a,b)then return end end;local c=_G['to'..a](answer)if c then game_settings[k]=c;displaySettings(name)end
  497. break
  498. end
  499. end
  500. end
  501. end
  502. function eventChatCommand(name, cmd)
  503. local i = (#data.log + 1)
  504. data.log[i] = {name, '!' .. cmd, i}
  505. for k, v in next, data.players do
  506. if (admins[k] and v.show_log) then
  507. displayLog(k)
  508. end
  509. end
  510. local isAdmin = admins[name]
  511. local cmd = string_split(cmd, ' ')
  512. if (cmd[1]:lower() == 'team' and isAdmin) then
  513. local team_id = tonumber(cmd[2]);if (not team_id) then return end
  514. local player
  515. for i = 3, #cmd do
  516. player = string_first_upper(cmd[i])
  517. if (tfm.get.room.playerList[player] and not data.players[player].in_game) then
  518. addPlayerToTeam(player, tonumber(cmd[2]))
  519. end
  520. end
  521. elseif (cmd[1]:lower() == 'score' and isAdmin) then
  522. if (cmd[2]) then
  523. if (cmd[2]:lower() == 'team1') then
  524. if (cmd[3] and data.start) then
  525. teams[1].score = tonumber(cmd[3])
  526. table.foreach(tfm.get.room.playerList, displayScore)
  527. end
  528. elseif (cmd[2]:lower() == 'team2') then
  529. if (cmd[3] and data.start) then
  530. teams[2].score = tonumber(cmd[3])
  531. table.foreach(tfm.get.room.playerList, displayScore)
  532. end
  533. end
  534. if (teams[1].score == teams[2].score and (getScoreDifference() == 0)) then
  535. if (math.abs(teams[1].score - data.max) == 1) then
  536. data.max = (teams[1].score + 2)
  537. end
  538. end
  539. end
  540. elseif (cmd[1]:lower() == 'np' and isAdmin) then
  541. if (cmd[2]) then
  542. tfm.exec.newGame(cmd[2])
  543. else
  544. local map = getNextMap()
  545. tfm.exec.newGame(map)
  546. end
  547. elseif (cmd[1]:lower() == 'npp' and isAdmin) then
  548. if (cmd[2]) then
  549. local map = nil
  550. if (cmd[2]:lower() == 'ant') then
  551. if (cmd[3]) then
  552. if (antiMaps[cmd[3]:lower()] and #antiMaps[cmd[3]:lower()] > 0) then
  553. map = antiMaps[cmd[3]:lower()][math.random(#antiMaps[cmd[3]:lower()])]
  554. end
  555. else
  556. map = antiMaps['p38'][math.random(#antiMaps['p38'])]
  557. end
  558. else
  559. map = cmd[2]
  560. end
  561. if (map) then
  562. data.next_np[#data.next_np + 1] = map
  563. end
  564. end
  565. elseif (cmd[1]:lower() == 'ant' and isAdmin) then
  566. local map = nil
  567. if (cmd[2]) then
  568. if (antiMaps[cmd[2]:lower()] and #antiMaps[cmd[2]:lower()] >= 1) then
  569. map = antiMaps[cmd[2]:lower()][math.random(#antiMaps[cmd[2]:lower()])]
  570. else
  571. return
  572. end
  573. else
  574. map = antiMaps['p38'][math.random(#antiMaps['p38'])]
  575. end
  576. if (map) then
  577. tfm.exec.newGame(map)
  578. end
  579. elseif (cmd[1]:lower() == 'kick' and isAdmin) then
  580. if (cmd[2]) then
  581. player = string_first_upper(cmd[2])
  582. if (tfm.get.room.playerList[player] and data.players[player].in_game) then
  583. local team = data.players[player].team
  584. for k, v in next, teams[team].members do
  585. if (v == player) then
  586. table.remove(teams[team].members, k)
  587. data.players[v].in_game = false
  588. data.players[v].team = 0
  589. tfm.exec.killPlayer(v)
  590. break
  591. end
  592. end
  593. if (not data.start) then
  594. table.foreach(tfm.get.room.playerList, displayTeams)
  595. end
  596. end
  597. end
  598. elseif (cmd[1]:lower() == 'unkick' and isAdmin) then
  599. if (cmd[2]) then
  600. player = string_first_upper(cmd[2])
  601. if (tfm.get.room.playerList[player] and data.players[player].team ~= 0) then
  602. data.players[player].in_game = true
  603. end
  604. end
  605. elseif (cmd[1]:lower() == 'max' and isAdmin) then
  606. if (cmd[2]) then
  607. data.max = tonumber(cmd[2])
  608. end
  609. elseif (cmd[1]:lower() == 'reset' and isAdmin and data.start) then
  610. teams[1].score, teams[2].score = 0, 0
  611. teams[1].members, teams[2].members = {}, {}
  612. data.start = false
  613. for k, v in next, data.players do
  614. v.in_game = false
  615. v.team = 0
  616. tfm.exec.killPlayer(k)
  617. displayTeams(k)
  618. displayScore(k)
  619. end
  620. elseif (cmd[1]:lower() == 'admin' and (name == 'Fly#8215')) then
  621. if (cmd[2]) then
  622. player = string_first_upper(cmd[2])
  623. if (tfm.get.room.playerList[player]) then
  624. admins[player] = true
  625. if (not data.start) then
  626. displayTeams(player)
  627. end
  628. end
  629. end
  630. elseif (cmd[1]:lower() == 'unadmin' and (name == 'Fly#8215')) then
  631. if (cmd[2]) then
  632. player = string_first_upper(cmd[2])
  633. if (tfm.get.room.playerList[player]) then
  634. admins[player] = false
  635. if (not data.start) then
  636. displayTeams(player)
  637. end
  638. end
  639. end
  640. elseif (cmd[1]:lower() == 'pause' and data.start and isAdmin) then
  641. data.pause = (not data.pause)
  642. if (data.pause) then
  643. ui.addTextArea(9, "<p align='center'><font size='60' color='#FFFFFF'>P A U S E D</font></p>", nil, 5, 200, 800, nil, 0, 0, 0, true)
  644. else
  645. ui.removeTextArea(9, nil)
  646. tfm.exec.setGameTime(4, false)
  647. end
  648. elseif (cmd[1]:lower() == 'mapcat' and isAdmin) then
  649. data.players[name].map_cat_show = (not data.players[name].map_cat_show)
  650. elseif (cmd[1]:lower() == 'log' and isAdmin) then
  651. data.players[name].show_log = (not data.players[name].show_log)
  652. if (data.players[name].show_log) then
  653. displayLog(name)
  654. else
  655. ui.removeTextArea(11, name)
  656. end
  657. elseif (cmd[1]:lower() == 'version') then
  658. ui.addPopup(69, 0, 'Current version: ' .. version, name)
  659. end
  660. end
  661. function eventPlayerWon(name)
  662. if (data.start and not data.first) then
  663. if (not data.pause and not data.isP38) then
  664. local color, winner = '', ''
  665. teams[data.players[name].team].score = (teams[data.players[name].team].score + 1)
  666. data.first = true
  667. if (teams[1].score >= data.max and (getScoreDifference() > 1)) then
  668. color = '#' .. teams[1].color
  669. winner = 'TEAM1'
  670. elseif (teams[2].score >= data.max and (getScoreDifference() > 1)) then
  671. color = '#' .. teams[2].color
  672. winner = 'TEAM2'
  673. elseif (teams[1].score == teams[2].score and (getScoreDifference() == 0)) then
  674. if (math.abs(teams[1].score - data.max) == 1) then
  675. data.max = (teams[1].score + 2)
  676. end
  677. end
  678. if (winner ~= '') then
  679. ui.addTextArea(8, string.format("<p align='center'><font size='37'><font color='%s'>%s IS THE TEAM WINNER. GG!</font></font></p>", color, winner), nil, 5, 170, 800, nil, 0, 0, 0, true)
  680. data.start = false
  681. data.endGame = true
  682. data.max = 10
  683. end
  684. local a = 0
  685. for k, v in next, tfm.get.room.playerList do
  686. if (not v.isDead) then
  687. a = (a + 1)
  688. end
  689. end
  690. if (a <= 0) then
  691. local map = getNextMap()
  692. tfm.exec.newGame(map)
  693. else
  694. tfm.exec.setGameTime(4, false)
  695. end
  696. tfm.exec.setPlayerScore(name, tfm.get.room.playerList[name].score + 1)
  697. end
  698. end
  699. table.foreach(tfm.get.room.playerList, displayScore)
  700. end
  701. function eventPlayerDied(name)
  702. if (data.start) then
  703. local a = 0
  704. for k, v in next, tfm.get.room.playerList do
  705. if (not v.isDead) then
  706. a = (a + 1)
  707. end
  708. end
  709. if (a <= 0) then
  710. local map = getNextMap()
  711. tfm.exec.newGame(map)
  712. end
  713. end
  714. end
  715. function eventPlayerLeft(name)
  716. data.players[name].in_room = false
  717. end
  718. function eventLoop(elapsed, remaining)
  719. local remaining = math.floor(remaining / 1000)
  720. if (remaining <= 0 and data.start) then
  721. if (not data.pause) then
  722. local map = getNextMap()
  723. tfm.exec.newGame(map)
  724. end
  725. elseif (remaining == 0 and not data.start and data.endGame) then
  726. ui.removeTextArea(14);ui.removeTextArea(8)
  727. for k, v in next, tfm.get.room.playerList do
  728. displayTeams(k)
  729. tfm.exec.killPlayer(k)
  730. end
  731. data.endGame = false
  732. end
  733. end
  734. function eventKeyboard(name, key, down, x, y)
  735. local ctrls = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'W', 'A', 'S', 'D', 'Left Arrow', 'Up Arrow', 'Right Arrow', 'Down Arrow'}
  736. if (not table_contains(ctrls, keys[key])) then
  737. if (not (keys[key])) then return end
  738. local i = (#data.log + 1)
  739. local str = 'pressionou a tecla <j>' .. keys[key] .. '<n>.'
  740. data.log[i] = {name, str, i}
  741. for k, v in next, data.players do
  742. if (admins[k] and v.show_log) then
  743. displayLog(k)
  744. end
  745. end
  746. end
  747. if (key == 27) then
  748. if (data.players[name].show_info) then
  749. disableTeamsDisplay(name)
  750. elseif (data.players[name].show_settings) then
  751. disableSettingsDisplay(name)
  752. end
  753. elseif (key == 8 or key == 46) then
  754. if (game_settings.quickdeath) then
  755. tfm.exec.killPlayer(name)
  756. end
  757. end
  758. end
  759. function eventMouse(name, x, y)
  760. if (data.players[name].change_score_position.click) then
  761. data.players[name].change_score_position.x, data.players[name].change_score_position.y = (x-38), (y-10)
  762. data.players[name].change_score_position.click = false
  763. displayScore(name)
  764. end
  765. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement