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