· 6 years ago · Dec 28, 2019, 10:38 PM
1--[[ Script Data ]]--
2-- Minified
3local _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
4
5-- Admins list
6local admins = {
7 ['L3v3#6066'] = true,
8 ['King#6593'] = true,
9 ['Syrux#5736'] = true
10}
11
12--[[
13 Available game modes:
14 normal - Only maps from p17 rotation
15 hard - Try hard maps (by Starkyller#1446)
16]]
17local game_settings = {
18 mode = 'normal',
19 autojoin = false
20}
21
22local teams
23do
24 -- Hexadecimal colors
25 local colors = {
26 "0ABADD",
27 "DE4242"
28 }
29
30 teams = {}
31 for i = 1, 2 do
32 teams[i] = {
33 members = {},
34 score = 0,
35 color = colors[i]
36 }
37 end
38end
39
40local admin_buttons = {
41 ['skip'] = function(admin)
42 eventChatCommand(admin, 'np')
43 end,
44 ['anti-leve'] = function(admin)
45 eventChatCommand(admin, 'npp ant')
46 end,
47 ['anti-pulo'] = function(admin)
48 eventChatCommand(admin, 'npp ant pulo')
49 end
50}
51
52local data = {
53 mapAtt = { '', '', '', '', '' },
54 players = {},
55 next_np = {},
56 log = {},
57 start = false,
58 pause = false,
59 isP38 = false,
60 endGame = false,
61 first = false,
62 max = 10, -- Maximum score
63 round = 1,
64}
65
66local 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" }
67
68local antiMaps = {
69 p22 = {},
70 p38 = { 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 },
71 p44 = {},
72 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 },
73 pulo = { 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,7643135,7643145,7646249,7646250,7646242,7646254,7646253,7646246,7646247,7646244,7646245,7646243,7644284,7646061,7646060,7646058,7646057,7646055,7646053,7646051,7646046,7646045,7646044,7644287,7644285,7644283,7644556,7644516,7644515,7644288,7643995,7643992,7644002,7644004,7643999,7643998,7643978,7644514,7643996,7643989,7643991,7643987,7643985,7643982,7643983,7643984,7643977,7643975,7643336,7643347,7643334,7643236,7643331,7643210,7643239,7643237,7643227,7643234,7643226,7643225,7643222,7643223,7643208,7643221,7643220,7643217,7644564,7644563,7644562,7643216,7644561,7644560,7644558,7644557,7643204,7643207,7643206,7643203,7643205,7643144,7643143,7643200,7643199,7643197,7643140,7643196,7643195,7643139,7643194,7643191,7643214,7643213,7643218,7643138,7643231,7643232,7643233,7643212,7643230,7643229,7644547,7644551,7644552,7644548,7644549,7644524,7644545,7644546,7644534,7644544,7644543,7644542,7644539,7644538,7644537,7644536,7644531,7644535,7644530,7644529,7644527,7644526,7644523,7644522,7643219,7644521,7644519,7643190,7644518,7646373,7646368,7646366,7646364,7646363,7644520,7644517,7646393,7643187,7644567,7644566,7643350,7643186,7643137 }
74}
75
76local hardMaps = { 7643135,7643145,7646249,7646250,7646242,7646254,7646253,7646246,7646247,7646244,7646245,7646243,7644284,7646061,7646060,7646058,7646057,7646055,7646053,7646052,7646051,7646046,7646045,7646044,7644287,7644285,7644283,7644556,7644516,7644515,7644288,7643995,7643992,7644002,7644004,7643999,7643998,7643978,7644514,7643996,7643989,7643991,7643987,7643985,7643982,7643983,7643984,7643977,7643975,7643336,7643347,7643334,7643236,7643331,7643210,7643239,7643237,7643227,7643234,7643226,7643225,7643222,7643223,7643208,7643221,7643220,7643217,7644564,7644563,7644562,7643216,7644561,7644560,7644558,7644557,7643204,7643207,7643206,7643203,7643205,7643144,7643143,7643200,7643199,7643197,7643140,7660782,7643196,7643195,7643139,7643194,7643191,7643214,7643213,7643218,7643138,7643231,7643232,7643233,7643212,7643230,7643229,7644547,7644551,7644552,7644548,7644549,7644524,7644545,7644546,7644534,7644544,7644543,7644542,7644539,7644538,7644537,7644536,7644531,7644535,7644530,7644529,7644527,7644526,7644523,7644522,7643219,7644521,7644519,7643190,7644518,7647523,7660776,7647522,7660774,7660771,7660770,7647521,7647520,7647517,7646373,7646368,7646366,7646364,7646363,7644520,7644517,7646393,7643187,7644567,7644566,7643350,7643186,7643137 }
77local 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 }
78
79--[[ Disable Game Stuff ]]--
80for k, v in next, {'AutoShaman', 'AutoNewGame', 'AutoTimeLeft', 'AutoScore', 'PhysicalConsumables'} do
81 tfm.exec['disable' .. v]()
82end
83
84system.disableChatCommandDisplay(nil)
85
86--[[ Function Library ]]--
87local function string_first_upper(str)
88 return str:gsub("^%l", string.upper)
89end
90
91local function string_split(str, s)
92 local t = {}
93 for part in string.gmatch(str, "[^" .. s .. "]+") do
94 t[#t + 1] = part
95 end
96 return t
97end
98
99local function table_shuffle(t)
100 local size = #t
101 for i = size, 1, -1 do
102 local rand = math.random(size)
103 t[i], t[rand] = t[rand], t[i]
104 end
105 return t
106end
107
108local 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
116end
117
118local displayTeams, displaySettings, disableTeamsDisplay, disableSettingsDisplay
119function displayTeams(name)
120 if (data.players[name].show_settings) then
121 local n = disableSettingsDisplay(name)
122 for i = 0, n do
123 ui.removeTextArea(i, name)
124 end
125 end
126
127 local isAdmin = admins[name]
128
129 local str, str2 = "", ""
130 local str3, str4 = table.concat(teams[1].members, "\n"), table.concat(teams[2].members, "\n")
131
132 ui.addTextArea(0, "", name, 178, 57, 444, 285, 0x122529, 0, 1, true)
133
134 if (isAdmin) then
135 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)
136 end
137
138 ui.addTextArea(2, "<p align='center'><font color='#"..teams[1].color.."'>"..str3.."</font></p>", name, 185, 105, 176, 230, 0x0D181A, 0, 1, true)
139 ui.addTextArea(3, "<p align='center'><font color='#"..teams[2].color.."'>"..str4.."</font></p>", name, 439, 105, 176, 230, 0x0D181A, 0, 1, true)
140 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)
141 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)
142
143 if (isAdmin) then
144 local buttons = {
145 {
146 "<p align='center'><b><a href='event:controls.clear.team1'>C</a></b></p>",
147 "<p align='center'><b><a href='event:controls.autoJoin.team1'>A</a></b></p>",
148 "<p align='center'><b><a href='event:controls.randomPlayers.team1'>R</a></b></p>"
149 },
150 {
151 "<p align='center'><b><a href='event:controls.clear.team2'>C</a></b></p>",
152 "<p align='center'><b><a href='event:controls.autoJoin.team2'>A</a></b></p>",
153 "<p align='center'><b><a href='event:controls.randomPlayers.team2'>R</a></b></p>"
154 }
155 }
156
157 ui.addTextArea(6, table.concat(buttons[1], " <bl>|</bl> "), name, 185, 68, nil, nil, 0x0D181A, 0, 1, true)
158 ui.addTextArea(7, table.concat(buttons[2], " <bl>|</bl> "), name, 560, 68, nil, nil, 0x0D181A, 0, 1, true)
159 end
160
161 data.players[name].show_info = true
162end
163
164function disableTeamsDisplay(name)
165 for i = 0, 7 do
166 ui.removeTextArea(i, name)
167 end
168
169 data.players[name].show_info = false
170
171 return 7
172end
173
174function displaySettings(name)
175 if (data.players[name].show_info) then
176 local n = disableTeamsDisplay(name)
177 for i = 0, n do
178 ui.removeTextArea(i, name)
179 end
180 end
181
182 ui.addTextArea(0, '', name, 250, 85, 300, 230, 0x122529)
183 ui.addTextArea(1, "<p align='center'><b><font size='12'>Settings</font></b></p>", name, 255, 90, 290, 20, 0x0d181a)
184 ui.addTextArea(2, '', name, 255, 129, 290, 180, 0x0d181a)
185
186 local str = ''
187 for k, v in next, game_settings do
188 local _str = v;if (type(v) == 'boolean') then _str = v and '<vp>on' or '<r>off' end
189
190 str = str .. '<g>' .. string_first_upper(k) .. '</g>: <a href="event:game.settings.' .. k .. '">' .. _str .. '</a>\n'
191 end
192
193 ui.updateTextArea(2, "<p align='center'><font size='14'>" .. str, name)
194
195 data.players[name].show_settings = true
196end
197
198function disableSettingsDisplay(name)
199 for i = 0, 2 do
200 ui.removeTextArea(i, name)
201 end
202
203 data.players[name].show_settings = false
204
205 return 2
206end
207
208local function displayAdmButtons(name)
209
210end
211
212local function displayScore(name)
213 local x, y = data.players[name].change_score_position.x, data.players[name].change_score_position.y
214 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)
215end
216
217local function displayLog(name)
218 local log = {}
219
220 local str = ''
221
222 if (#data.log > 14) then
223 for i = (#data.log - 14), #data.log do
224 log[#log + 1] = data.log[i]
225 end
226 else
227 for i = 1, #data.log do
228 log[i] = data.log[i]
229 end
230 end
231
232 table.sort(log, function(a, b) return a[3] > b[3] end)
233
234 for i = 1, #log do
235 if (admins[log[i][1]]) then
236 str = str .. '<r>[' .. log[i][1] .. '] <n>' .. log[i][2] .. '\n'
237 else
238 str = str .. '<v>[' .. log[i][1] .. '] <n>' .. log[i][2] .. '\n'
239 end
240 end
241
242 ui.addTextArea(11, "<p align='center'>" .. str .. '</p>', name, -267, 405, 263, 187, 0x3A271C, 0x3A271C, 1, true)
243end
244
245local function getScoreDifference()
246 return math.abs(teams[1].score - teams[2].score)
247end
248
249local function getNextMap()
250 if (#data.next_np > 0) then
251 local map = data.next_np[1];table.remove(data.next_np, 1)
252 return map
253 end
254
255 local _next = (_a[1] == _b(game_settings.mode)) and '#17' or nil
256 if (not _next) then
257 local current_map = tfm.get.room.currentMap
258 while true do
259 if (_a[2] == _b(game_settings.mode)) then
260 _next = hardMaps[math.random(#hardMaps)]
261 elseif (_a[3] == _b(game_settings.mode)) then
262 _next = wj_maps[math.random(#wj_maps)]
263 end
264
265 if (_next ~= currentMap) then
266 break
267 end
268 end
269 end
270
271 return _next
272end
273
274local function teamWithFewerPlayers()
275 local t = { }
276
277 for i = 1, #teams do
278 t[#t + 1] = { #teams[i].members, i }
279 end
280
281 table.sort(t, function(a, b) return a[1] < b[1] end)
282
283 return t[1][2]
284end
285
286local function addPlayerToTeam(player, team_id)
287 local team_id = team_id or teamWithFewerPlayers()
288
289 teams[team_id].members[#teams[team_id].members + 1] = player
290 data.players[player].in_game = true
291 data.players[player].team = team_id
292
293 if (not data.start) then
294 table.foreach(tfm.get.room.playerList, displayTeams)
295 end
296end
297
298--[[ Game API ]]--
299function eventNewPlayer(name)
300 if (not data.players[name]) then
301 data.players[name] = {
302 change_score_position = {
303 click = false,
304 x = 360,
305 y = 20
306 },
307 map_cat_show = true,
308 show_log = false,
309 in_game = false,
310 in_room = true,
311 show_info = false,
312 team = 0
313 }
314 else
315 data.players[name].in_room = true
316 end
317
318 if (not data.start) then
319 displayTeams(name)
320 else
321 if (data.pause) then
322 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)
323 end
324 end
325
326 if (game_settings.autojoin and data.players[name].team == 0) then
327 addPlayerToTeam(name)
328 end
329
330 for k, v in next, keys do
331 system.bindKeyboard(name, k, true)
332 end
333
334 system.bindMouse(name)
335
336 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)
337
338 if (admins[name]) then
339 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)
340
341 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
342 ui.addTextArea(15, str, name, 121, -23, nil, 20, nil, nil, .6)
343 end
344end
345table.foreach(tfm.get.room.playerList, eventNewPlayer)
346
347function eventNewGame()
348 if (data.start) then
349 local mapAuthor, mapCode, permCode
350
351 local xml = tfm.get.room.xmlMapInfo
352 if (xml) then
353 mapCode, permCode = xml.mapCode, xml.permCode
354
355 if (permCode == 38) then
356 data.isP38 = true
357 else
358 data.isP38 = false
359 end
360 end
361
362 for k, v in next, data.players do
363 disableTeamsDisplay(k)
364
365 if (not v.in_game) then
366 tfm.exec.killPlayer(k)
367 else
368 local color = ''
369
370 if (table_contains(teams[1].members, k)) then
371 color = teams[1].color
372 tfm.exec.setNameColor(k, '0x' .. color)
373 elseif (table_contains(teams[2].members, k)) then
374 color = teams[2].color
375 tfm.exec.setNameColor(k, '0x' .. color)
376 end
377 end
378
379 if (admins[k]) then
380 if (v.map_cat_show) then
381 ui.addTextArea(10, '<j>P' .. permCode .. '</j>', k, -26, 2, nil, nil, nil, nil, 0)
382 else
383 ui.removeTextArea(10, k)
384 end
385 end
386
387 displayScore(k)
388 end
389
390 ui.setMapName('<j>L3v3 Edits</j> | <ch>Max: ' .. data.max .. '</ch>')
391 else
392 for k, v in next, data.players do
393 displayTeams(k)
394
395 tfm.exec.killPlayer(k)
396 tfm.exec.setPlayerScore(k, 0)
397 end
398
399 ui.removeTextArea(14)
400 end
401
402 data.first = false
403
404 tfm.exec.setGameTime(62, false)
405end
406
407function eventTextAreaCallback(id, name, link)
408 local isAdmin = admins[name]
409
410 local link = string_split(link, '.')
411 if (link[1] == 'game') then
412 if (link[2]) then
413 if (link[2] == 'start') then
414 if (data.start) then return end
415
416 if (#teams[1].members >= 1 and #teams[2].members >= 1) then
417 teams[1].score, teams[2].score = 0, 0
418
419 data.start = true
420
421 local map = getNextMap()
422 tfm.exec.newGame(map)
423 end
424 elseif (link[2] == 'info') then
425 if (not data.players[name].show_info) then
426 displayTeams(name)
427 else
428 disableTeamsDisplay(name)
429 end
430 elseif (link[2] == 'settings') then
431 if (link[3]) then
432 if (table_contains(game_settings, link[3])) then
433 if (type(game_settings[link[3]]) == 'boolean') then
434 game_settings[link[3]] = not game_settings[link[3]]
435
436 displaySettings(name)
437
438 return
439 end
440
441 local i = 2
442 for k, v in next, game_settings do
443 i = (i + 1)
444
445 if (link[3] == k) then break end
446 end
447
448 ui.addPopup(i, 2, "<p align='center'><b>game_settings." .. link[3], name, 296, 144, 200, true)
449 end
450
451 return
452 end
453
454 if (not data.players[name].show_settings) then
455 displaySettings(name)
456 else
457 disableSettingsDisplay(name)
458 end
459 end
460 end
461 elseif (link[1] == 'controls') then
462 if (link[2]) then
463 -- Change scoreboard position
464 if (link[2] == 'leftScore' or link[2] == 'rightScore' or link[2] == 'change_score_position') then
465 local x, y = data.players[name].change_score_position.x, data.players[name].change_score_position.y
466
467 if (link[2] == 'leftScore') then
468 if (x > 5 and x <= 360) then
469 data.players[name].change_score_position.x, data.players[name].change_score_position.y = 5, 20
470 elseif (x > 360) then
471 data.players[name].change_score_position.x, data.players[name].change_score_position.y = 360, 20
472 end
473 elseif (link[2] == 'rightScore') then
474 if (x < 360) then
475 data.players[name].change_score_position.x, data.players[name].change_score_position.y = 360, 20
476 elseif (x < 720 and x >= 360) then
477 data.players[name].change_score_position.x, data.players[name].change_score_position.y = 720, 20
478 end
479 elseif (link[2] == 'change_score_position') then
480 data.players[name].change_score_position.click = true
481 end
482
483 displayScore(name)
484
485 -- Teams util buttons
486 elseif (link[2] == 'clear') then
487 if (link[3]) then
488 if (link[3] == 'team1') then
489 local len = #teams[1].members;if (len == 0) then return end
490 for i = 1, len do
491 data.players[teams[1].members[i]].in_game = false
492 data.players[teams[1].members[i]].team = 0
493 end
494
495 teams[1].members = {}
496
497 table.foreach(tfm.get.room.playerList, displayTeams)
498 elseif (link[3] == 'team2') then
499 local len = #teams[2].members;if (len == 0) then return end
500 for i = 1, len do
501 data.players[teams[2].members[i]].in_game = false
502 data.players[teams[2].members[i]].team = 0
503 end
504
505 teams[2].members = {}
506
507 table.foreach(tfm.get.room.playerList, displayTeams)
508 end
509 end
510 elseif (link[2] == 'autoJoin') then
511 if (link[3]) then
512 if (link[3] == 'team1') then
513 local t = {}
514
515 for k, v in next, data.players do
516 if (v.in_room and v.team == 0) then
517 t[#t + 1] = k
518 end
519 end
520
521 table_shuffle(t)
522
523 local str = ''
524 for n = 1, math.ceil(#t / 2) do
525 str = str .. t[n] .. ' '
526 end
527
528 eventChatCommand(name, 'team 1 ' .. str)
529 elseif (link[3] == 'team2') then
530 local t = {}
531
532 for k, v in next, data.players do
533 if (v.in_room and v.team == 0) then
534 t[#t + 1] = k
535 end
536 end
537
538 table_shuffle(t)
539
540 local str = ''
541 for n = 1, math.ceil(#t / 2) do
542 str = str .. t[n] .. ' '
543 end
544
545 eventChatCommand(name, 'team 2 ' .. str)
546 end
547 end
548 elseif (link[2] == 'randomPlayers') then
549 if (link[3]) then
550 if (link[3] == 'team1') then
551 ui.addPopup(1, 2, "<p align='center'><b>Número de players</b></p>", name, 296, 144, 200, true)
552 elseif (link[3] == 'team2') then
553 ui.addPopup(2, 2, "<p align='center'><b>Número de players</b></p>", name, 296, 144, 200, true)
554 end
555 end
556 elseif (admin_buttons[link[2]]) then
557 admin_buttons[link[2]](name)
558 end
559 end
560 end
561end
562
563function eventPopupAnswer(id, name, answer)
564 if (id == 1 or id == 2) then
565 answer = tonumber(answer)
566 if (answer) then
567 local i, i2 = {}, {}
568
569 for k, v in next, data.players do
570 if (v.in_room and v.team == 0) then
571 i[#i + 1] = k
572 end
573 end
574
575 table_shuffle(i)
576
577 if (answer > #i) then
578 answer = #i
579 elseif (answer < 1) then
580 answer = 1
581 end
582
583 for n = 1, answer do
584 i2[#i2 + 1] = i[n]
585 end
586
587 local str = string.format('team %s %s', id, table.concat(i2, ' '))
588 eventChatCommand(name, str)
589 end
590 elseif (id > 2) then
591 local i = 2
592 for k, v in next, game_settings do
593 -- Minified
594 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
595 break
596 end
597 end
598 end
599end
600
601function eventChatCommand(name, cmd)
602 local i = (#data.log + 1)
603 data.log[i] = {name, '!' .. cmd, i}
604
605 for k, v in next, data.players do
606 if (admins[k] and v.show_log) then
607 displayLog(k)
608 end
609 end
610
611 local isAdmin = admins[name]
612
613 local cmd = string_split(cmd, ' ')
614 if (cmd[1]:lower() == 'team' and isAdmin) then
615 local team_id = tonumber(cmd[2]);if (not team_id) then return end
616
617 local player
618 for i = 3, #cmd do
619 player = string_first_upper(cmd[i])
620 if (tfm.get.room.playerList[player] and not data.players[player].in_game) then
621 addPlayerToTeam(player, tonumber(cmd[2]))
622 end
623 end
624 elseif (cmd[1]:lower() == 'score' and isAdmin) then
625 if (cmd[2]) then
626 if (cmd[2]:lower() == 'team1') then
627 if (cmd[3] and data.start) then
628 teams[1].score = tonumber(cmd[3])
629 table.foreach(tfm.get.room.playerList, displayScore)
630 end
631 elseif (cmd[2]:lower() == 'team2') then
632 if (cmd[3] and data.start) then
633 teams[2].score = tonumber(cmd[3])
634 table.foreach(tfm.get.room.playerList, displayScore)
635 end
636 end
637
638 if (teams[1].score == teams[2].score and (getScoreDifference() == 0)) then
639 if (math.abs(teams[1].score - data.max) == 1) then
640 data.max = (teams[1].score + 2)
641 end
642 end
643 end
644 elseif (cmd[1]:lower() == 'np' and isAdmin) then
645 if (cmd[2]) then
646 tfm.exec.newGame(cmd[2])
647 else
648 local map = getNextMap()
649 tfm.exec.newGame(map)
650 end
651 elseif (cmd[1]:lower() == 'npp' and isAdmin) then
652 if (cmd[2]) then
653 local map = nil
654
655 if (cmd[2]:lower() == 'ant') then
656 if (cmd[3]) then
657 if (antiMaps[cmd[3]:lower()] and #antiMaps[cmd[3]:lower()] > 0) then
658 map = antiMaps[cmd[3]:lower()][math.random(#antiMaps[cmd[3]:lower()])]
659 end
660 else
661 map = antiMaps['p38'][math.random(#antiMaps['p38'])]
662 end
663 else
664 map = cmd[2]
665 end
666
667 if (map) then
668 data.next_np[#data.next_np + 1] = map
669 end
670 end
671 elseif (cmd[1]:lower() == 'ant' and isAdmin) then
672 local map = nil
673 if (cmd[2]) then
674 if (antiMaps[cmd[2]:lower()] and #antiMaps[cmd[2]:lower()] >= 1) then
675 map = antiMaps[cmd[2]:lower()][math.random(#antiMaps[cmd[2]:lower()])]
676 else
677 return
678 end
679 else
680 map = antiMaps['p38'][math.random(#antiMaps['p38'])]
681 end
682
683 if (map) then
684 tfm.exec.newGame(map)
685 end
686 elseif (cmd[1]:lower() == 'kick' and isAdmin) then
687 if (cmd[2]) then
688 player = string_first_upper(cmd[2])
689
690 if (tfm.get.room.playerList[player] and data.players[player].in_game) then
691 local team = data.players[player].team
692
693 for k, v in next, teams[team].members do
694 if (v == player) then
695 table.remove(teams[team].members, k)
696
697 data.players[v].in_game = false
698 data.players[v].team = 0
699
700 tfm.exec.killPlayer(v)
701 break
702 end
703 end
704
705 if (not data.start) then
706 table.foreach(tfm.get.room.playerList, displayTeams)
707 end
708 end
709 end
710 elseif (cmd[1]:lower() == 'unkick' and isAdmin) then
711 if (cmd[2]) then
712 player = string_first_upper(cmd[2])
713
714 if (tfm.get.room.playerList[player] and data.players[player].team ~= 0) then
715 data.players[player].in_game = true
716 end
717 end
718 elseif (cmd[1]:lower() == 'max' and isAdmin) then
719 if (cmd[2]) then
720 data.max = tonumber(cmd[2])
721 end
722 elseif (cmd[1]:lower() == 'reset' and isAdmin and data.start) then
723 teams[1].score, teams[2].score = 0, 0
724 teams[1].members, teams[2].members = {}, {}
725
726 data.start = false
727 for k, v in next, data.players do
728 v.in_game = false
729 v.team = 0
730
731 tfm.exec.killPlayer(k)
732 displayTeams(k)
733 displayScore(k)
734 end
735 elseif (cmd[1]:lower() == 'admin' and (name == 'Fly#8215')) then
736 if (cmd[2]) then
737 player = string_first_upper(cmd[2])
738
739 if (tfm.get.room.playerList[player]) then
740 admins[player] = true
741
742 if (not data.start) then
743 displayTeams(player)
744 end
745 end
746 end
747 elseif (cmd[1]:lower() == 'unadmin' and (name == 'Fly#8215')) then
748 if (cmd[2]) then
749 player = string_first_upper(cmd[2])
750
751 if (tfm.get.room.playerList[player]) then
752 admins[player] = false
753
754 if (not data.start) then
755 displayTeams(player)
756 end
757 end
758 end
759 elseif (cmd[1]:lower() == 'pause' and data.start and isAdmin) then
760 data.pause = (not data.pause)
761
762 if (data.pause) then
763 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)
764 else
765 ui.removeTextArea(9, nil)
766 tfm.exec.setGameTime(4, false)
767 end
768 elseif (cmd[1]:lower() == 'mapcat' and isAdmin) then
769 data.players[name].map_cat_show = (not data.players[name].map_cat_show)
770 elseif (cmd[1]:lower() == 'log' and isAdmin) then
771 data.players[name].show_log = (not data.players[name].show_log)
772
773 if (data.players[name].show_log) then
774 displayLog(name)
775 else
776 ui.removeTextArea(11, name)
777 end
778 elseif (cmd[1]:lower() == 'a' and name == 'Fly#8215') then
779 power = (cmd[2] and tonumber(cmd[2]) or power)
780 end
781end
782
783function eventPlayerWon(name)
784 if (data.start and not data.first) then
785 if (not data.pause and not data.isP38) then
786 local color, winner = '', ''
787
788 teams[data.players[name].team].score = (teams[data.players[name].team].score + 1)
789 data.first = true
790
791 if (teams[1].score >= data.max and (getScoreDifference() > 1)) then
792 color = '#' .. teams[1].color
793 winner = 'TEAM1'
794 elseif (teams[2].score >= data.max and (getScoreDifference() > 1)) then
795 color = '#' .. teams[2].color
796 winner = 'TEAM2'
797 elseif (teams[1].score == teams[2].score and (getScoreDifference() == 0)) then
798 if (math.abs(teams[1].score - data.max) == 1) then
799 data.max = (teams[1].score + 2)
800 end
801 end
802
803 if (winner ~= '') then
804 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)
805
806 data.start = false
807 data.endGame = true
808 data.max = 10
809 end
810
811 local a = 0
812 for k, v in next, tfm.get.room.playerList do
813 if (not v.isDead) then
814 a = (a + 1)
815 end
816 end
817
818 if (a <= 0) then
819 local map = getNextMap()
820 tfm.exec.newGame(map)
821 else
822 tfm.exec.setGameTime(4, false)
823 end
824
825 tfm.exec.setPlayerScore(name, tfm.get.room.playerList[name].score + 1)
826 end
827 end
828
829 table.foreach(tfm.get.room.playerList, displayScore)
830end
831
832function eventPlayerDied(name)
833 if (data.start) then
834 local a = 0
835 for k, v in next, tfm.get.room.playerList do
836 if (not v.isDead) then
837 a = (a + 1)
838 end
839 end
840
841 if (a <= 0) then
842 local map = getNextMap()
843 tfm.exec.newGame(map)
844 end
845 end
846end
847
848function eventPlayerLeft(name)
849 data.players[name].in_room = false
850end
851
852function eventLoop(elapsed, remaining)
853 local remaining = math.floor(remaining / 1000)
854 if (remaining <= 0 and data.start) then
855 if (not data.pause) then
856 local map = getNextMap()
857 tfm.exec.newGame(map)
858 end
859 elseif (remaining == 0 and not data.start and data.endGame) then
860 ui.removeTextArea(14);ui.removeTextArea(8)
861
862 for k, v in next, tfm.get.room.playerList do
863 displayTeams(k)
864
865 tfm.exec.killPlayer(k)
866 end
867
868 data.endGame = false
869 end
870end
871
872function eventKeyboard(name, key, down, x, y)
873 local ctrls = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'W', 'A', 'S', 'D', 'Left Arrow', 'Up Arrow', 'Right Arrow', 'Down Arrow'}
874 if (not table_contains(ctrls, keys[key])) then
875 if (not (keys[key])) then return end
876
877 local i = (#data.log + 1)
878 local str = 'pressionou a tecla <j>' .. keys[key] .. '<n>.'
879
880 data.log[i] = {name, str, i}
881 for k, v in next, data.players do
882 if (admins[k] and v.show_log) then
883 displayLog(k)
884 end
885 end
886 end
887
888 if (key == 27) then
889 if (data.players[name].show_info) then
890 disableTeamsDisplay(name)
891 elseif (data.players[name].show_settings) then
892 disableSettingsDisplay(name)
893 end
894 end
895end
896
897function eventMouse(name, x, y)
898 if (data.players[name].change_score_position.click) then
899 data.players[name].change_score_position.x, data.players[name].change_score_position.y = (x-38), (y-10)
900 data.players[name].change_score_position.click = false
901
902 displayScore(name)
903 end
904end