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