· 5 years ago · Mar 24, 2020, 11:56 PM
1#include <amxmodx>
2#include <amxmisc>
3#include <cstrike>
4#include <hamsandwich>
5#include <fakemeta>
6#include <fun>
7#include <engine>
8#include <fakemeta_util>
9#include <csx>
10#include <sqlx>
11
12#if AMXX_VERSION_NUM < 183
13
14 #assert AMX Mod X v1.8.3 or later library required!
15
16#endif
17
18#define HOSTNAME "MIX.NAME.RO"
19
20#define PREFIX "MIX"
21
22// Flagul care are acces sa administreze mix-ul
23#define FLAG ADMIN_KICK
24
25#define MIX_HOST ""
26#define MIX_USER ""
27#define MIX_PASSWORD ""
28#define MIX_DATABASE ""
29
30
31#define POINTS_KILL 1
32#define POINTS_DEATH -1
33#define POINTS_ACE 10
34#define POINTS_HS 1
35#define POINTS_MINI_ACE 5
36#define POINTS_MIX_PLAYED 20
37#define POINTS_MIX_LOST -10
38#define POINTS_MIX_WON 20
39#define POINTS_MIX_DRAW 5
40
41
42new const g_szInterpCommands[ ][ ] = {
43 "ex_interp 0.01",
44 "cl_cmdrate 105",
45 "rate 25000",
46 "cl_updaterate 100"
47};
48
49new Handle:g_hTuple;
50
51new const szTables[][] =
52{
53 "CREATE TABLE IF NOT EXISTS `mix_players` ( `player_id` varchar(32) NOT NULL, `player_name` varchar(64), `kills` int(16) NOT NULL, `deaths` int(16) NOT NULL, `headshots` int(16), `m_aces` int(16), `aces` int(16), `mix_played` int(16) NOT NULL, `mix_won` int(16) NOT NULL, `mix_lost` int(16) NOT NULL, `mix_draw` int(16) NOT NULL, `points` int(16) NOT NULL, `last_online` varchar(64), PRIMARY KEY (`player_id`) )",
54
55 "CREATE TABLE IF NOT EXISTS `mix_guns` ( `gun_id` int(32) NOT NULL, `kills` int(16), PRIMARY KEY (`gun_id`) )",
56
57 "CREATE TABLE IF NOT EXISTS `mix_games` ( `id` int(32) NOT NULL AUTO_INCREMENT, `map_name` varchar(64) NOT NULL, `date` varchar(64), `rez_ct` int(16), `rez_t` int(16), PRIMARY KEY (`id`) )"
58}
59
60new pKills[33], pDeaths[33], pHeadshots[33], pAces[33], pMiniAces[33], pMixPlayed[33], pMixLost[33], pMixDraw[33], pMixWon[33], pPoints[33], bool:pLoaded[33]
61
62#define isAdmin(%1) (get_user_flags(%1) & FLAG)
63
64new scoreT, scoreCT, serverPassword[64], tempCT, tempT, tempCount
65new bool:WarmUp = true, bool:KnifeRound, bool:passwordStatus, bool:canChat = true,bool:PrepareRound
66new Kills[33]
67
68new const BlockCmds[][] = {
69"amx_unban",
70"amx_rcon",
71"amx_cvar",
72"amxmodmenu"
73}
74
75new const Commands[][][] = {
76{"menu", "mainMenu"},
77{"mixmenu", "mainMenu"},
78{"live", "setLive"},
79{"rr", "restartRound"},
80{"restart", "restartRound"},
81{"warm", "warmUP"},
82{"warmup", "warmUP"},
83{"gg", "endGame"},
84{"stop", "endGame"},
85{"knife", "setKnife"},
86{"knf", "setKnife"},
87{"scor", "getScore"},
88{"sc", "getScore"},
89{"pw", "infoPassword"},
90{"prepare", "setPrepare"}
91}
92
93public plugin_init()
94{
95 new szFmt[64]
96 for(new i = 0; i < sizeof(BlockCmds); i++) {
97 register_concmd(BlockCmds[i], "BlockConsole")
98 }
99 for(new i = 0; i < sizeof(Commands); i++) {
100 format(szFmt, 63, "say .%s", Commands[i][0])
101 register_clcmd(szFmt, Commands[i][1])
102 format(szFmt, 63, "say /%s", Commands[i][0])
103 register_clcmd(szFmt, Commands[i][1])
104 format(szFmt, 63, "say !%s", Commands[i][0])
105 register_clcmd(szFmt, Commands[i][1])
106 format(szFmt, 63, "say_team .%s", Commands[i][0])
107 register_clcmd(szFmt, Commands[i][1])
108 format(szFmt, 63, "say_team /%s", Commands[i][0])
109 register_clcmd(szFmt, Commands[i][1])
110 format(szFmt, 63, "say_team !%s", Commands[i][0])
111 register_clcmd(szFmt, Commands[i][1])
112 }
113 register_clcmd ("say /setings", "set", FLAG);
114 register_clcmd ("say_team /setings", "set", FLAG);
115 register_clcmd("say .choose", "choosePlayers")
116 register_clcmd("say /choose", "choosePlayers")
117 register_concmd ( "amx_t", "swap_team", FLAG, "<name> - move player to t" );
118 register_concmd ( "amx_ct", "swap_team", FLAG, "<name> - move player to ct" );
119 register_concmd ( "amx_spec", "swap_team", FLAG, "<name> - move player to spec" );
120
121 register_clcmd("say .kick", "KickMenu")
122 register_clcmd("say .maps", "MapsMenu")
123 register_clcmd("say .leave", "LeaveMenu")
124 register_clcmd("say .chat", "ChatMenu")
125 register_clcmd("say .chaton", "ChatMenuNew")
126
127 register_clcmd("SetPassword", "_SetPassword")
128 register_clcmd("say", "hookSay")
129
130 server_cmd("sv_password ^"^"")
131
132 //register_event( "CurWeapon", "event_CurWeapon", "be","1=1" );
133 register_event("DeathMsg", "DeathEvent", "a");
134 RegisterHam(Ham_Spawn, "player", "PlayerSpawn", 1 );
135 register_logevent("RoundEnd", 2, "1=Round_End")
136 register_event("SendAudio", "t_win", "a", "2&%!MRAD_terwin")
137 register_event("SendAudio", "ct_win", "a", "2&%!MRAD_ctwin")
138 register_forward(FM_Voice_SetClientListening, "ClientListen");
139
140
141 server_cmd("hostname ^"%s^"", HOSTNAME);
142}
143public BanMenu(id)
144{
145 client_cmd(id, "amx_banmenu");
146}
147public KickMenu(id)
148{
149 client_cmd(id, "amx_kickmenu");
150}
151public MapsMenu(id)
152{
153 client_cmd(id, "amx_mapmenu");
154}
155public ChatMenu(id)
156{
157 if(!isAdmin(id)) return PLUGIN_HANDLED
158
159 canChat = false;
160
161 client_printcolor(id, "/y[/c%s/y] Chat is off!", PREFIX)
162
163 return PLUGIN_HANDLED
164}
165public ChatMenuNew(id)
166{
167 if(!isAdmin(id)) return PLUGIN_HANDLED
168
169 canChat = true;
170
171 client_printcolor(id, "/y[/c%s/y] Chat is on!", PREFIX)
172
173 return PLUGIN_HANDLED
174}
175public plugin_cfg()
176{
177 set_task(0.5, "MySQLx_Init");
178}
179
180public MySQLx_Init()
181{
182
183 g_hTuple = SQL_MakeDbTuple( MIX_HOST, MIX_USER, MIX_PASSWORD, MIX_DATABASE );
184
185 for ( new i = 0; i < sizeof szTables; i++ )
186 {
187 SQL_ThreadQuery( g_hTuple, "QuerySetData", szTables[i]);
188 }
189}
190
191public QuerySetData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
192{
193 if( iFailState == TQUERY_CONNECT_FAILED
194 || iFailState == TQUERY_QUERY_FAILED )
195 {
196 log_amx( "%s", szError );
197
198 return;
199 }
200}
201public ClientListen(pid /*receiver*/, id /*sender*/) {
202 if(pid == id) return 1;
203
204 if(is_user_connected(id)) {
205 new szTeam[2];
206 szTeam[0] = get_pdata_int(id, 114);
207 szTeam[1] = get_pdata_int(pid, 114);
208
209 if(szTeam[0] == szTeam[1] || WarmUp || KnifeRound || PrepareRound) {
210 engfunc(EngFunc_SetClientListening, pid, id, 1);
211 return 4;
212 }
213 engfunc(EngFunc_SetClientListening, pid, id, 0);
214 return 4;
215 }
216 return 1;
217}
218public client_connect(id)
219{
220 pKills[id] = 0;
221 pDeaths[id] = 0;
222 pHeadshots[id] = 0;
223 pAces[id] = 0;
224 pMiniAces[id] = 0;
225 pMixPlayed[id] = 0;
226 pMixLost[id] = 0;
227 pMixDraw[id] = 0;
228 pMixWon[id] = 0;
229 pPoints[id] = 0;
230 pLoaded[id] = false;
231 LoadPlayerData(id);
232}
233public InsertGame()
234{
235 new szQuery[3800];
236
237 //new year, month, day, hour, minute, second, current_date[128]
238 new map_name[64];
239
240 get_mapname(map_name, 63)
241
242 //date(year, month, day);
243 //time(hour, minute, second);
244
245 //format(current_date, 127, "%i-%i-%i %i:%i:%i", year, month, day, hour, minute, second);
246
247 formatex( szQuery, 3799, "REPLACE INTO `mix_games` (`map_name`, `date`, `rez_ct`, `rez_t`) VALUES ('%s', NOW(), '%d', '%d');", map_name, scoreCT, scoreT);
248 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
249}
250public InsertWeaponKill(wpnindex)
251{
252 new szQuery[3800];
253
254 formatex( szQuery, 3799, "INSERT INTO `mix_guns` (`gun_id`, `kills`) VALUES (%d, 1) ON DUPLICATE KEY UPDATE `kills` = `kills` + 1;", wpnindex);
255
256 log_amx(szQuery)
257 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
258}
259public SavePlayer(id)
260{
261 if(!pLoaded[id]) return PLUGIN_HANDLED;
262
263 if (pPoints[id] < 0)
264 pPoints[id] = 0;
265
266 new Name[64], steam[64];
267 get_user_name(id, Name, 63);
268
269 get_user_authid(id, steam, 63);
270
271 static szQuery[3800];
272 formatex( szQuery, 3799, "REPLACE INTO `mix_players` (`player_id`, `player_name`, `kills`, `deaths`, `headshots`, `aces`, `m_aces`, `mix_played`, `mix_lost`, `mix_won`, `mix_draw`, `points`, `last_online`) VALUES ('%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', NOW());", steam, GetSecureName(Name), pKills[id], pDeaths[id], pHeadshots[id], pAces[id], pMiniAces[id], pMixPlayed[id], pMixLost[id], pMixWon[id], pMixDraw[id], pPoints[id]);
273
274 #if AMXX_VERSION_NUM >= 183
275 SQL_SetCharset(g_hTuple,"utf8");
276 #endif
277
278 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
279
280 return PLUGIN_CONTINUE;
281}
282public LoadPlayerData(id)
283{
284 new steam[64];
285 get_user_authid(id, steam, 63);
286
287 static szQuery[ 256 ], iData[ 1 ];
288 formatex( szQuery, 255, "SELECT * FROM `mix_players` WHERE ( `player_id` = '%s' );", steam );
289
290 iData[ 0 ] = id;
291 SQL_ThreadQuery( g_hTuple, "QuerySelectData", szQuery, iData, 1 );
292
293 return PLUGIN_CONTINUE;
294}
295public QuerySelectData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
296{
297 if( iFailState == TQUERY_CONNECT_FAILED
298 || iFailState == TQUERY_QUERY_FAILED )
299 {
300 log_amx( "%s", szError );
301
302 return;
303 }
304 else
305 {
306 new id = iData[ 0 ];
307 new data_kills = SQL_FieldNameToNum(hQuery, "kills");
308 new data_deaths = SQL_FieldNameToNum(hQuery, "deaths");
309 new data_headshots = SQL_FieldNameToNum(hQuery, "headshots");
310 new data_aces = SQL_FieldNameToNum(hQuery, "aces");
311 new data_mini_aces = SQL_FieldNameToNum(hQuery, "m_aces");
312 new data_mix_played = SQL_FieldNameToNum(hQuery, "mix_played");
313 new data_mix_lost = SQL_FieldNameToNum(hQuery, "mix_lost");
314 new data_mix_draw = SQL_FieldNameToNum(hQuery, "mix_draw");
315 new data_mix_won = SQL_FieldNameToNum(hQuery, "mix_won");
316 new data_points = SQL_FieldNameToNum(hQuery, "points");
317 while (SQL_MoreResults(hQuery))
318 {
319 pKills[id] = SQL_ReadResult(hQuery, data_kills);
320 pDeaths[id] = SQL_ReadResult(hQuery, data_deaths);
321 pHeadshots[id] = SQL_ReadResult(hQuery, data_headshots);
322 pAces[id] = SQL_ReadResult(hQuery, data_aces);
323 pMiniAces[id] = SQL_ReadResult(hQuery, data_mini_aces);
324 pMixPlayed[id] = SQL_ReadResult(hQuery, data_mix_played);
325 pMixLost[id] = SQL_ReadResult(hQuery, data_mix_lost);
326 pMixDraw[id] = SQL_ReadResult(hQuery, data_mix_draw);
327 pMixWon[id] = SQL_ReadResult(hQuery, data_mix_won);
328 pPoints[id] = SQL_ReadResult(hQuery, data_points);
329
330 SQL_NextRow(hQuery);
331 }
332
333 pLoaded[id] = true;
334 }
335}
336public client_disconnected(id)
337{
338 if(!WarmUp && !PrepareRound)
339 {
340 if(1 <= get_user_team(id) <= 2)
341 client_printcolor(0, "/y[/c%s/y] Player: /g%s /yleft the game!", PREFIX, get_admin_name(id))
342 }
343}
344public t_win(id)
345{
346 if(!WarmUp && !KnifeRound && !PrepareRound) scoreT++
347 if(KnifeRound)
348 {
349 if(tempT)
350 {
351 showTeamMenu(tempT)
352 }
353 }
354}
355public ct_win(id)
356{
357 if(!WarmUp && !KnifeRound && !PrepareRound) scoreCT++
358 if(KnifeRound)
359 {
360 if(tempCT)
361 {
362 showTeamMenu(tempCT)
363 }
364 }
365}
366public PlayerSpawn(id)
367{
368 if(WarmUp && is_user_connected(id))
369 cs_set_user_money(id, 16000)
370 Kills[id] = 0
371 if(KnifeRound && is_user_connected(id))
372 {
373 strip_user_weapons(id);
374 give_item(id, "weapon_knife");
375 cs_set_user_money(id, 0)
376 }
377
378 return PLUGIN_HANDLED;
379}
380public RoundEnd()
381{
382 if(WarmUp) server_cmd("hostname ^"%s [Warm-up]^"", HOSTNAME);
383 else if(KnifeRound) server_cmd("hostname ^"%s [Knife Round]^"", HOSTNAME);
384 else if(PrepareRound) server_cmd("hostname ^"%s [Choose Players]^"", HOSTNAME);
385 else
386 {
387 if(scoreT == 16 || scoreCT == 16)
388 {
389 server_cmd("hostname ^"[Game is over - CT: %i | T: %i] %s^"", scoreCT, scoreT, HOSTNAME);
390 }
391 else if(scoreT == 15 || scoreCT == 15)
392 {
393 server_cmd("hostname ^"[Live (MB) - CT: %i | T: %i] %s^"", scoreCT, scoreT, HOSTNAME);
394 }
395 else
396 {
397 if(scoreCT+scoreT == 15)
398 {
399 server_cmd("hostname ^"[Live - CT: %i | T: %i] %s^"", scoreCT, scoreT, HOSTNAME);
400 }
401 else
402 {
403 server_cmd("hostname ^"[Live - CT: %i | T: %i] %s^"", scoreCT, scoreT, HOSTNAME);
404 }
405 }
406 }
407 if(!WarmUp && !KnifeRound && !PrepareRound) {
408 for(new i = 1; i <= 32; i++)
409 {
410 if(is_user_connected(i))
411 {
412 if(Kills[i] == 4)
413 {
414 client_printcolor(0, "/y[/c%s/y] Player: /g%s /ymade a /cMINI ACE", PREFIX, get_admin_name(i))
415 client_printcolor(0, "/y[/c%s/y] Player: /g%s /made a MINI ACE and get /g%i points!", PREFIX, get_admin_name(i), POINTS_MINI_ACE)
416 if(!WarmUp && !PrepareRound)
417
418 pMiniAces[i]++;
419 pPoints[i] += POINTS_MINI_ACE
420 SavePlayer(i);
421 }
422 else if(Kills[i] == 5)
423 {
424 client_printcolor(0, "/y[/c%s/y] Player: /g%s /ymade a /cACE", PREFIX, get_admin_name(i))
425 client_printcolor(0, "/y[/c%s/y] Player: /g%s /ymade a ACE and get /g%i points!", PREFIX, get_admin_name(i), POINTS_ACE)
426
427 pAces[i]++;
428 pPoints[i] += POINTS_ACE
429 SavePlayer(i);
430 }
431 }
432 }
433 if(scoreCT + scoreT == 15)
434 {
435 new temp = scoreCT
436 scoreCT = scoreT
437 scoreT = temp
438 client_printcolor(0, "/y[/c%s/y] Changeable commands!", PREFIX)
439 changeTeams()
440 server_cmd("sv_restart 5")
441 }
442 client_printcolor(0, "/y[/c%s/y] CT's: /g%i /y|| T's: /g%i", PREFIX, scoreCT, scoreT)
443 if(scoreT == 15 && scoreCT == 15) {
444 client_printcolor(0, "/y[/c%s/y] /gThe play is over. / yNo team lost!", PREFIX)
445 client_printcolor(0, "/y[/c%s/y] /gPlayers in each team for a draw : /g%i points!", PREFIX, POINTS_MIX_DRAW)
446 client_printcolor(0, "/y[/c%s/y] /gThe players in each team for the fact that the player played: /g%i points!", PREFIX, POINTS_MIX_PLAYED)
447 drawGame();
448 setEndGame()
449 }
450 else if(scoreT == 15) client_printcolor(0, "/y[/c%s/y]Decisive round for the team: Counter-Terrorists", PREFIX)
451 else if(scoreCT == 15) client_printcolor(0, "/y[/c%s/y]Decisive round for the team: Terrorists", PREFIX)
452 else if(scoreT == 16)
453 {
454
455 TeamWon(1);
456 client_printcolor(0, "/y[/c%s/y] /gGame complete. Won: /yTerrorists team!", PREFIX)
457 client_printcolor(0, "/y[/c%s/y] /gPlayers on the terrorist team for victory /g%i points!", PREFIX, POINTS_MIX_WON)
458 client_printcolor(0, "/y[/c%s/y] /gThe players on each team for being a good player /g%i points!", PREFIX, POINTS_MIX_PLAYED)
459 setEndGame()
460
461 }
462 else if(scoreCT == 16)
463 {
464 TeamWon(2);
465 client_printcolor(0, "/y[/c%s/y] /gGame complete. Won: /yCounter-Terrorists team!", PREFIX)
466 client_printcolor(0, "/y[/c%s/y] /gCounter-Terrorists players on the team for victory : /g%i points!", PREFIX, POINTS_MIX_WON)
467 client_printcolor(0, "/y[/c%s/y] /gThe players on each team for being a good player : /g%i points!", PREFIX, POINTS_MIX_PLAYED)
468 setEndGame()
469 }
470 }
471}
472public changeTeams()
473{
474 for(new i = 1; i <= 32; i++)
475 {
476 add_delay(i)
477 }
478}
479public changeTeam( id )
480{
481 if(is_user_connected(id))
482 {
483 switch( get_user_team( id ) )
484 {
485 case 2: cs_set_user_team( id, CS_TEAM_T );
486 case 1: cs_set_user_team( id, CS_TEAM_CT );
487 }
488 }
489}
490add_delay( id )
491{
492 switch( id )
493 {
494 case 1..5: set_task( 0.1, "changeTeam", id );
495 case 6..10: set_task( 0.2, "changeTeam", id );
496 case 11..15: set_task( 0.3, "changeTeam", id );
497 case 16..20: set_task( 0.4, "changeTeam", id );
498 case 21..25: set_task( 0.5, "changeTeam", id );
499 case 26..32: set_task( 0.6, "changeTeam", id );
500 }
501}
502public DeathEvent(victim, attacker, id)
503{
504 new attacker = read_data(1);
505 new victim = read_data(2);
506 new hs = read_data(3)
507
508 if(WarmUp) {
509 set_task(1.0, "RespawnPlayer", victim)
510 }
511 else if(1 <= victim <= 32 && 1 <= attacker <= 32)
512 {
513 Kills[attacker]++
514
515 if(!WarmUp && !PrepareRound)
516 {
517 pKills[attacker]++;
518 pPoints[attacker] += POINTS_KILL
519
520 if(hs)
521 {
522 pHeadshots[attacker]++;
523 pPoints[attacker] += POINTS_HS
524
525 }
526 pDeaths[victim]++;
527 pPoints[victim] += POINTS_DEATH
528
529 SavePlayer(victim);
530 SavePlayer(attacker);
531
532
533
534 new weapon_name[32]
535 read_data(4, weapon_name, 31)
536
537
538 if(containi(weapon_name, "ak47") != -1) InsertWeaponKill(CSW_AK47);
539 else if(containi(weapon_name, "m4a1") != -1) InsertWeaponKill(CSW_M4A1);
540 else if(containi(weapon_name, "deagle") != -1) InsertWeaponKill(CSW_DEAGLE);
541 else if(containi(weapon_name, "awp") != -1) InsertWeaponKill(CSW_AWP);
542 else if(containi(weapon_name, "usp") != -1) InsertWeaponKill(CSW_USP);
543 else if(containi(weapon_name, "glock") != -1) InsertWeaponKill(CSW_GLOCK18);
544 else if(containi(weapon_name, "he") != -1) InsertWeaponKill(CSW_HEGRENADE);
545 else if(containi(weapon_name, "knife") != -1) InsertWeaponKill(CSW_KNIFE);
546 else if(containi(weapon_name, "scout") != -1) InsertWeaponKill(CSW_SCOUT);
547 }
548
549 }
550}
551public RespawnPlayer(id)
552{
553 if(!is_user_alive(id) && is_user_connected(id) && 1 <= get_user_team(id) <= 2)
554 ExecuteHamB(Ham_CS_RoundRespawn, id)
555}
556public event_CurWeapon(id)
557{
558 if(KnifeRound && get_user_weapon(id) != CSW_KNIFE)
559 engclient_cmd(id, "weapon_knife")
560}
561public infoPassword(id)
562{
563 if(passwordStatus)
564 client_printcolor(id, "/y[/c%s/y] Server password: /g%s", PREFIX, serverPassword)
565 else
566 client_printcolor(id, "/y[/c%s/y] Server password is off!", PREFIX, serverPassword)
567 return PLUGIN_HANDLED
568}
569public hookSay(id)
570{
571 if(!canChat) {
572 client_printcolor(id, "/y[/c%s/y] Chat is currently off!", PREFIX)
573 client_printcolor(id, "/y[/c%s/y] Available commands: /g.rez .stats .top", PREFIX)
574 return PLUGIN_HANDLED;
575 }
576 return PLUGIN_CONTINUE;
577}
578public BlockConsole(id) return PLUGIN_HANDLED
579public mainMenu(id)
580{
581 if(!isAdmin(id)) return PLUGIN_HANDLED
582 new menu = menu_create("\w[\yMIX\w] \rHome menu", "onMainMenu")
583
584 new szMsg[64]
585
586 menu_additem(menu, "Management")
587
588 format(szMsg, 63, "\wChat \d[%s\d]", canChat ? "\yYes" : "\rNo")
589 menu_additem(menu, szMsg)
590
591 if(serverPassword[0]) format(szMsg, 63, "\wPassworld \d[\y%s\d]", serverPassword)
592 else format(szMsg, 63, "\wPassworld \d[\rNo\d]")
593 menu_additem(menu, szMsg)
594
595 menu_additem(menu, "Kick player")
596 menu_additem(menu, "Ban player")
597 menu_additem(menu, "Change the map")
598
599 menu_display(id, menu, 0)
600
601 return PLUGIN_HANDLED;
602}
603public onMainMenu(id, menu, item)
604{
605 switch(item)
606 {
607 case 0: actMix(id)
608 case 1:
609 {
610 canChat = !canChat
611 mainMenu(id)
612 return PLUGIN_HANDLED
613 }
614 case 2: optionsPassword(id)
615 case 3: client_cmd(id, "amx_kickmenu")
616 case 4: client_cmd(id, "amx_banmenu")
617 case 5: client_cmd(id, "amx_mapmenu")
618 }
619 menu_destroy(menu)
620 return PLUGIN_HANDLED
621}
622public optionsPassword(id)
623{
624 if(!isAdmin(id)) return PLUGIN_HANDLED
625 new szText[64]
626 if(strlen(serverPassword) > 0) format(szText, 63, "\w[\y%s\w] \rPassword \d(\y%s\d)", PREFIX, serverPassword)
627 else format(szText, 63, "\w[\y%s\w] \rPassword \d(\rNo\d)", PREFIX)
628 new menu = menu_create(szText, "onOptionsPassword")
629
630 format(szText, 63, "\wPassword \d[%s\d]", passwordStatus ? "\yOn" : "\rOff")
631
632 menu_additem(menu, szText)
633 menu_additem(menu, "Change password")
634 menu_additem(menu, "Delete the password")
635
636 menu_display(id, menu, 0)
637
638 return PLUGIN_HANDLED;
639}
640public onOptionsPassword(id, menu, item)
641{
642 switch(item)
643 {
644 case MENU_EXIT:
645 {
646 mainMenu(id)
647 return PLUGIN_HANDLED
648 }
649 case 0:
650 {
651 if(strlen(serverPassword) > 0) {
652 passwordStatus = !passwordStatus
653 if(passwordStatus) {
654 server_cmd("sv_password", serverPassword)
655 client_printcolor(0, "/y[/c%s/y] [/g%s/y] Server password: /g%s",PREFIX, get_admin_name(id), serverPassword)
656 }
657 else server_cmd("sv_password ^"^"")
658 }
659 else {
660 if(passwordStatus)
661 passwordStatus = false
662 client_printcolor(id, "/y[/c%s/y] No password set!", PREFIX)
663 //format(serverPassword, 63, "")
664 }
665
666 }
667 case 1: client_cmd(id, "messagemode SetPassword")
668 case 2: format(serverPassword, 63, "")
669 }
670 optionsPassword(id)
671 return PLUGIN_HANDLED
672}
673public _SetPassword(id) {
674 if(!isAdmin(id)) return
675 new szTemp[64]
676 read_args(szTemp, charsmax(szTemp))
677 remove_quotes(szTemp)
678 format(serverPassword, 63, szTemp)
679 optionsPassword(id)
680 if(passwordStatus)
681 {
682 server_cmd("sv_password %s", serverPassword)
683 client_printcolor(0, "/y[/c%s/y] [/g%s/y] Server password: /g%s",PREFIX, get_admin_name(id), szTemp)
684 }
685}
686public actMix(id)
687{
688 if(!isAdmin(id)) return PLUGIN_HANDLED
689 new menu = menu_create("\w[\yMIX\w] \rManagement", "onactMix")
690
691 menu_additem(menu, "Start Game")
692 menu_additem(menu, "Prepare round")
693 menu_additem(menu, "Warming up")
694 menu_additem(menu, "Knife round")
695 menu_additem(menu, "Reload round")
696 menu_additem(menu, "Finish the game…")
697
698 menu_display(id, menu, 0)
699
700 return PLUGIN_HANDLED;
701}
702public onactMix(id, menu, item)
703{
704 switch(item)
705 {
706 case 0: setLive(id)
707 case 1: setPrepare(id)
708 case 2: warmUP(id)
709 case 3: setKnife(id)
710 case 4: restartRound(id)
711 case 5: endGame(id)
712 }
713 menu_destroy(menu)
714}
715public setPrepare(id)
716{
717 if(!isAdmin(id)) return PLUGIN_HANDLED
718 if(get_playersnum() >= 10) {
719 server_cmd("sv_restart 1")
720
721 KnifeRound = false;
722 PrepareRound = true;
723 WarmUp = false;
724 scoreCT = 0;
725 scoreT = 0;
726 tempCount = 0;
727 tempCT = 0;
728 tempT = 0;
729
730 for(new i = 1; i <= 32; i++)
731 {
732 if(is_user_connected(id) && (1 <= get_user_team(i) <= 2)) {
733 if(is_user_alive(i))
734 user_silentkill(i)
735 cs_set_user_team(i, CS_TEAM_SPECTATOR)
736 }
737 }
738
739 client_printcolor(0, "/y[/c%s/y] [/g%s/y] The preparation has begun! The administrator will select leaders soon!", PREFIX, get_admin_name(id))
740 showPrepareMenu(id)
741 }
742 else
743 client_printcolor(id, "/y[/c%s/y] Preparation can't be started because of a missing player!", PREFIX)
744 return PLUGIN_HANDLED
745}
746public showPrepareMenu(id)
747{
748 if(!isAdmin(id)) return PLUGIN_HANDLED
749 new menu = menu_create("\w[\yMIX\w] \rChoose who will go to CT", "onPrepareCT")
750
751 new players[32], num
752 get_players(players, num, "ch")
753 new ui[32]
754
755 for(new i; i < num; i++)
756 {
757 format(ui, 31, "%d",get_user_userid(players[i]))
758 menu_additem(menu, get_admin_name(players[i]), ui)
759 }
760
761 menu_display(id, menu, 0)
762
763 return PLUGIN_HANDLED;
764}
765public onPrepareCT(id, menu, item)
766{
767 new szData[6], szName[64];
768 new _access, item_callback;
769
770 menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
771
772 new userid = str_to_num( szData );
773 new player = find_player( "k", userid );
774
775 switch(item)
776 {
777 case MENU_EXIT: {
778 if(PrepareRound) showPrepareMenu(id)
779 return PLUGIN_HANDLED;
780 }
781 default: if(PrepareRound && is_user_connected(player)) cs_set_user_team(player, CS_TEAM_CT)
782 }
783 if(PrepareRound) {
784 tempCT = player;
785 client_printcolor(0, "/y[/c%s/y] CT leader will: /g%s", PREFIX, szName)
786 client_printcolor(0, "/y[/c%s/y] The administrator will immediately select the T leader!", PREFIX)
787 showPrepareMenuT(id)
788 }
789 return PLUGIN_HANDLED;
790}
791public showPrepareMenuT(id)
792{
793 if(!isAdmin(id)) return PLUGIN_HANDLED
794 new menu = menu_create("\w[\yMIX\w] \rChoose who will go to T", "onPrepareT")
795
796 new players[32], num
797 get_players(players, num, "ceh", "SPECTATOR")
798 new ui[32]
799
800 for(new i; i < num; i++)
801 {
802 format(ui, 31, "%d",get_user_userid(players[i]))
803 menu_additem(menu, get_admin_name(players[i]), ui)
804 }
805
806 menu_display(id, menu, 0)
807
808 return PLUGIN_HANDLED;
809}
810public onPrepareT(id, menu, item)
811{
812 new szData[6], szName[64];
813 new _access, item_callback;
814
815 menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
816
817 new userid = str_to_num( szData );
818 new player = find_player( "k", userid );
819
820 switch(item)
821 {
822 case MENU_EXIT: {
823 if(PrepareRound) showPrepareMenuT(id)
824 return PLUGIN_HANDLED;
825 }
826 default: if(PrepareRound && is_user_connected(player)) cs_set_user_team(player, CS_TEAM_T)
827 }
828 if(PrepareRound) {
829 tempT = player;
830 client_printcolor(0, "/y[/c%s/y] T leader will: /g%s", PREFIX, szName)
831 client_printcolor(0, "/y[/c%s/y] Leaders start choosing players!", PREFIX)
832 client_printcolor(0, "/y[/c%s/y] /gTip: /yIf the leaderboard menu disappears, enter in the chat /c/choose", PREFIX)
833 ShowList(tempCT)
834 }
835 return PLUGIN_HANDLED;
836}
837public choosePlayers(id)
838{
839 /*new Where;*/
840 switch(tempCount)
841 {
842 // Ter
843 case 0,2,4,6: if(tempT == id) ShowList(id);
844 // CT
845 case 1,3,5,7: if(tempCT == id) ShowList(id);
846 }
847 return PLUGIN_HANDLED;
848}
849public showTeamMenu(id)
850{
851 new menu = menu_create("\w[\yMIX\w] \rSelect team", "onTeamChange")
852
853 menu_additem(menu, "Stay")
854 menu_additem(menu, "ChangetTeams")
855
856 menu_display(id, menu, 0)
857
858 return PLUGIN_HANDLED;
859}
860public onTeamChange(id, menu, item)
861{
862 switch(item)
863 {
864 case 0:
865 {
866 client_printcolor(0, "/y[/c%s/y] The solution: /gstay", PREFIX)
867 setServerLive(id)
868 }
869 case 1:
870 {
871 client_printcolor(0, "/y[/c%s/y] The solution: /gchange teams", PREFIX)
872 changeTeams()
873 set_task(2.0, "setServerLive", 1)
874 }
875 }
876}
877public ShowList(id)
878{
879 new menu = menu_create("\w[\yMIX\w] \rChoose a teammate", "onShowList")
880
881 new players[32], num
882 get_players(players, num, "ceh", "SPECTATOR")
883 new ui[32]
884
885 for(new i; i < num; i++)
886 {
887 format(ui, 31, "%d",get_user_userid(players[i]))
888 menu_additem(menu, get_admin_name(players[i]), ui)
889 }
890 menu_display(id, menu, 0)
891
892 return PLUGIN_HANDLED;
893}
894public onShowList(id, menu, item)
895{
896 new szData[6], szName[64];
897 new _access, item_callback;
898
899 new Where;
900 switch(tempCount)
901 {
902 case 0,2,4,6: Where = 0
903 case 1,3,5,7: Where = 1
904 default: Where = -1
905 }
906
907 menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
908
909 new userid = str_to_num( szData );
910 new player = find_player( "k", userid );
911
912 switch(item)
913 {
914 case MENU_EXIT: {
915 if(PrepareRound) ShowList(id)
916 return PLUGIN_HANDLED;
917 }
918 default: if(PrepareRound && is_user_connected(player))
919 {
920 if(Where == 0) cs_set_user_team(player, CS_TEAM_CT)
921 else cs_set_user_team(player, CS_TEAM_T)
922
923 }
924 }
925 if(PrepareRound) {
926 tempCount++;
927 client_printcolor(0, "/y[/c%s/y] [/g%s /ychose /g%s", PREFIX, get_admin_name(id), szName)
928 if(tempCount < 8)
929 ShowList(Where == 1 ? tempCT : tempT)
930 else
931 {
932 KnifeRound = true;
933 PrepareRound = false;
934 WarmUp = false;
935 scoreCT = 0;
936 scoreT = 0;
937
938 server_cmd("mp_roundtime 3.0")
939 server_cmd("mp_buytime 0.30")
940 server_cmd("mp_startmoney 16000")
941 server_cmd("mp_freezetime 2")
942
943 server_cmd("sv_restart 1")
944
945 client_printcolor(0, "/y[/c%s/y] Team selection is complete! Knife round!", PREFIX)
946
947 setServerLive(id)
948 }
949 }
950 return PLUGIN_HANDLED;
951}
952public restartRound(id)
953{
954 if(!isAdmin(id)) return PLUGIN_HANDLED
955 server_cmd("sv_restart 1")
956 client_printcolor(0, "/y[/c%s/y] [/g%s/y] A reloaded round!", PREFIX, get_admin_name(id))
957 return PLUGIN_HANDLED
958}
959public setServerLive(id)
960{
961 KnifeRound = false;
962 PrepareRound = false;
963 WarmUp = false;
964 scoreCT = 0;
965 scoreT = 0;
966
967 server_cmd("mp_roundtime 3.0")
968 server_cmd("mp_buytime 0.30")
969 server_cmd("mp_startmoney 800")
970 server_cmd("mp_freezetime 2")
971
972 server_cmd("sv_restart 1")
973
974 client_printcolor(0, "/y[/c%s/y] Game Started! Wish you a good game - Administration!", PREFIX)
975 return PLUGIN_HANDLED
976}
977
978public setLive(id)
979{
980 if(!isAdmin(id)) return PLUGIN_HANDLED
981
982 KnifeRound = false;
983 PrepareRound = false;
984 WarmUp = false;
985 scoreCT = 0;
986 scoreT = 0;
987
988 server_cmd("mp_roundtime 3.0")
989 server_cmd("mp_buytime 0.30")
990 server_cmd("mp_startmoney 800")
991 server_cmd("mp_freezetime 2")
992
993 server_cmd("sv_restart 1")
994
995 client_printcolor(0, "/y[/c%s /y] The game has started. I wish you a good game - Administration!", PREFIX, get_admin_name(id))
996 return PLUGIN_HANDLED
997}
998public warmUP(id)
999{
1000 if(!isAdmin(id)) return PLUGIN_HANDLED
1001
1002 passwordStatus = false;
1003 KnifeRound = false;
1004 PrepareRound = false;
1005 WarmUp = true;
1006 scoreCT = 0;
1007 scoreT = 0;
1008
1009 server_cmd("mp_roundtime 600")
1010 server_cmd("mp_buytime -1")
1011 server_cmd("mp_startmoney 16000")
1012 server_cmd("mp_freezetime 0")
1013 server_cmd("sv_password ^"^"")
1014
1015 server_cmd("sv_restart 1")
1016
1017 client_printcolor(0, "/y[/c%s /y] [/g%s /y] Start of heating!", PREFIX, get_admin_name(id))
1018 return PLUGIN_HANDLED
1019}
1020public setKnife(id)
1021{
1022 if(!isAdmin(id)) return PLUGIN_HANDLED
1023
1024 KnifeRound = true;
1025 PrepareRound = false;
1026 WarmUp = false;
1027 scoreCT = 0;
1028 scoreT = 0;
1029
1030 server_cmd("mp_roundtime 3.0")
1031 server_cmd("mp_buytime 0.30")
1032 server_cmd("mp_startmoney 800")
1033 server_cmd("mp_freezetime 2")
1034
1035 server_cmd("sv_restart 1")
1036
1037 client_printcolor(0, "/y[/c%s /y] [/g%s /y] The blades started! Good luck!", PREFIX, get_admin_name(id))
1038 return PLUGIN_HANDLED
1039}
1040public drawGame()
1041{
1042 for(new i = 1; i <= 32; i++)
1043 {
1044 if(is_user_connected(i) && (1 <= get_user_team(i) <= 2))
1045 {
1046 pMixPlayed[i]++;
1047 pPoints[i] += POINTS_MIX_PLAYED
1048 pMixDraw[i]++;
1049 pPoints[i] += POINTS_MIX_DRAW
1050 SavePlayer(i);
1051 }
1052 }
1053}
1054public TeamWon(team)
1055{
1056 for(new i = 1; i <= 32; i++)
1057 {
1058 if(is_user_connected(i) && (1 <= get_user_team(i) <= 2))
1059 {
1060 pMixPlayed[i]++;
1061 pPoints[i] += POINTS_MIX_PLAYED
1062
1063 if(get_user_team(i) == team)
1064 {
1065 pMixWon[i]++;
1066 pPoints[i] += POINTS_MIX_WON
1067 }
1068 else
1069 {
1070 pMixLost[i]++;
1071 pPoints[i] += POINTS_MIX_LOST
1072 }
1073 SavePlayer(i);
1074 }
1075 }
1076}
1077public setEndGame()
1078{
1079 InsertGame();
1080
1081 passwordStatus = false;
1082 KnifeRound = false;
1083 PrepareRound = false;
1084 WarmUp = true;
1085 canChat = true;
1086 scoreCT = 0;
1087 scoreT = 0;
1088
1089 server_cmd("mp_roundtime 600")
1090 server_cmd("mp_startmoney 16000")
1091 server_cmd("mp_buytime -1")
1092 server_cmd("mp_freezetime 0")
1093 server_cmd("sv_password ^"^"")
1094
1095 server_cmd("sv_restart 1")
1096
1097 client_printcolor(0, "/y[/c%s/y] Warm-up is on! Wait for the map to change!", PREFIX)
1098 return PLUGIN_HANDLED
1099}
1100public endGame(id)
1101{
1102 if(!isAdmin(id)) return PLUGIN_HANDLED
1103
1104 passwordStatus = false;
1105 KnifeRound = false;
1106 PrepareRound = false;
1107 WarmUp = true;
1108 canChat = true;
1109 scoreCT = 0;
1110 scoreT = 0;
1111
1112 server_cmd("mp_roundtime 600")
1113 server_cmd("mp_startmoney 16000")
1114 server_cmd("mp_buytime -1")
1115 server_cmd("mp_freezetime 0")
1116 server_cmd("sv_password ^"^"")
1117
1118 server_cmd("sv_restart 1")
1119
1120 client_printcolor(0, "/y[/c%s/y] [/g%s/y] Game over! Warm-up is on!", PREFIX, get_admin_name(id))
1121 return PLUGIN_HANDLED
1122}
1123public getScore(id) {
1124 if(WarmUp || KnifeRound || PrepareRound)
1125 client_printcolor(id, "/y[/c%s/y] Game is not playing right now!", PREFIX)
1126 else client_printcolor(id, "/y[/c%s/y] CT's: /g%i /y|| T's: /g%i", PREFIX, scoreCT, scoreT)
1127 return PLUGIN_HANDLED
1128}
1129public set( id )
1130{
1131 if(!isAdmin(id))
1132 {
1133
1134 static iSize = sizeof ( g_szInterpCommands );
1135
1136 for( new i = 0; i < iSize; i++ )
1137 client_cmd( 0, g_szInterpCommands[ i ] );
1138
1139 new szName[ 32 ];
1140 get_user_name( id, szName, sizeof ( szName ) -1 );
1141
1142 client_print ( 0, print_chat, "%s Admin %s set the mix settings for all players!", PREFIX, get_admin_name(id) );
1143 client_print ( 0, print_console, "%s The following settings have been updated to you: ex_interp 0.01/cl_updaterate 100/cl_cmdrate 105/rate 25000", PREFIX);
1144
1145 return PLUGIN_HANDLED;
1146 }
1147 return PLUGIN_HANDLED;
1148}
1149public swap_team ( id, level, cid ) {
1150 if( ! cmd_access ( id, level, cid, 2 ) )
1151 return PLUGIN_HANDLED;
1152
1153 new szArg[ 10 ], target[ 32 ], szPlayerName[ 32 ], szAdminName[ 32 ];
1154
1155 read_argv( 0, szArg, 9 );
1156 read_argv( 1, target, 31 );
1157
1158 new player = cmd_target ( id, target, 11 );
1159
1160 if( ! player ) {
1161
1162 client_print ( id, print_chat, "%s The specified player does not exist.", PREFIX);
1163 return PLUGIN_HANDLED;
1164
1165 }
1166
1167 get_user_name ( player, szPlayerName, 31 );
1168 get_user_name ( id, szAdminName, 31 );
1169
1170 switch ( szArg[ 4 ] ) {
1171 case 't':
1172 {
1173 user_silentkill ( player );
1174 cs_set_user_team ( player, 1 );
1175 client_print ( 0, print_chat, "%s Adminul %s move player %s to t.", PREFIX, szAdminName, szPlayerName );
1176 }
1177
1178
1179 case 'c':
1180 {
1181 user_silentkill ( player );
1182 cs_set_user_team ( player, 2 );
1183 client_print ( 0, print_chat, "%s Adminul %s move player %s to ct.", PREFIX, szAdminName, szPlayerName );
1184
1185 }
1186
1187 case 's':
1188 {
1189 if(is_user_alive(player))
1190 {
1191 user_silentkill ( player );
1192 cs_set_user_team ( player, 3 );
1193 client_print ( 0, print_chat, "%s Adminul %s move player %s to spec.", PREFIX, szAdminName, szPlayerName );
1194 }
1195 }
1196
1197 }
1198
1199 return PLUGIN_CONTINUE;
1200}
1201stock get_admin_name(id)
1202{
1203 new name[64]
1204 get_user_name(id, name, 63)
1205 return name
1206}
1207stock client_printcolor(const id, const input[], any:...)
1208{
1209 new count = 1, players[32];
1210 static msg[191];
1211 vformat(msg,190,input,3);
1212 replace_all(msg,190,"/g","^4");// green txt
1213 replace_all(msg,190,"/y","^1");// orange txt
1214 replace_all(msg,190,"/c","^3");// team txt
1215 replace_all(msg,190,"/w","^0");// team txt
1216 if (id) players[0] = id; else get_players(players,count,"ch");
1217 for (new i=0;i<count;i++)
1218 if (is_user_connected(players[i]))
1219 {
1220 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
1221 write_byte(players[i]);
1222 write_string(msg);
1223 message_end();
1224 }
1225}
1226GetSecureName(const name[])
1227{
1228 static secureName[64];
1229 copy(secureName, charsmax(secureName), name);
1230
1231 replace_all(secureName, charsmax(secureName), "\", "\\");
1232 replace_all(secureName, charsmax(secureName), "'", "\'");
1233 replace_all(secureName, charsmax(secureName), "`", "\`");
1234
1235 return secureName;
1236}