· 7 years ago · Jan 20, 2019, 05:40 PM
1#pragma semicolon 1
2
3#include <sourcemod>
4#include <sdktools>
5#include <geoip>
6#include <cstrike>
7#include <warmod>
8#include <warmod_configs>
9#undef REQUIRE_PLUGIN
10#include <adminmenu>
11#include <updater>
12#include <tEasyFTP>
13#undef REQUIRE_EXTENSIONS
14#include <bzip2>
15#include <zip>
16
17#pragma newdecls required
18
19bool SQL_DEBUG = false;
20
21
22int g_player_list[MAXPLAYERS + 1];
23bool g_cancel_list[MAXPLAYERS + 1];
24int g_scores[2][2];
25int g_scores_overtime[2][256][2];
26int g_overtime_count = 0;
27
28/* miscellaneous */
29char g_map[64];
30char date[32];
31char startHour[4];
32char startMin[4];
33float g_match_start;
34
35/* SQL and Last Match settings */
36Handle hDatabase = INVALID_HANDLE;
37ConVar wm_upload_results;
38ConVar wm_table_name;
39//ConVar wm_table_name_players;
40ConVar wm_table_round_stats;
41int lt_match_length;
42char lt_map[64];
43int lt_max_rounds;
44int lt_overtime_max_rounds;
45int lt_overtime_count;
46int lt_played_out;
47char lt_t_name[64];
48int lt_t_overall_score;
49int lt_t_first_half_score;
50int lt_t_second_half_score;
51int lt_t_overtime_score;
52char lt_ct_name[64];
53int lt_ct_overall_score;
54int lt_ct_first_half_score;
55int lt_ct_second_half_score;
56int lt_ct_overtime_score;
57char lt_log_file_name[128];
58//char sql_steamid64[MAXPLAYERS + 1][64];
59//char sql_player_name[MAXPLAYERS + 1][64];
60//int sql_player_team[MAXPLAYERS + 1];
61//int sql_player_count;
62int match_id;
63
64// Offsets
65int g_iAccount = -1;
66
67/* stats */
68bool g_log_warmod_dir = false;
69char g_log_filename[128];
70Handle g_log_file = INVALID_HANDLE;
71char g_log_veto_filename[128];
72Handle g_log_veto_file = INVALID_HANDLE;
73char weapon_list[][] = {"ak47", "m4a1_silencer", "m4a1_silencer_off", "m4a1", "galilar", "famas", "awp", "p250", "cz75a", "glock", "hkp2000", "usp_silencer", "usp_silencer_off", "ump45", "p90", "bizon", "mp7", "nova", "knife", "elite", "fiveseven", "deagle", "revolver", "tec9", "ssg08", "scar20", "aug", "sg556", "g3sg1", "mac10", "mp9", "mag7", "negev", "m249", "sawedoff", "incgrenade", "flashbang", "smokegrenade", "hegrenade", "molotov", "decoy", "taser"};
74int weapon_stats[MAXPLAYERS + 1][NUM_WEAPONS][LOG_HIT_NUM];
75int clutch_stats[MAXPLAYERS + 1][CLUTCH_NUM];
76int assist_stats[MAXPLAYERS + 1][ASSIST_NUM];
77int round_health[MAXPLAYERS + 1];
78int g_round = 1;
79char last_weapon[MAXPLAYERS + 1][64];
80char force_team_t[10][64];
81char force_team_ct[10][64];
82int force_team_t_count = 0;
83int force_team_ct_count = 0;
84bool g_planted = false;
85Handle g_stats_trace_timer = INVALID_HANDLE;
86ConVar wm_competition;
87ConVar wm_event;
88char g_competition[255];
89char g_event[255];
90char g_server[255];
91
92/* forwards */
93Handle g_f_on_lo3 = INVALID_HANDLE;
94Handle g_f_on_round_end = INVALID_HANDLE;
95Handle g_f_on_half_time = INVALID_HANDLE;
96Handle g_f_on_reset_half = INVALID_HANDLE;
97Handle g_f_on_reset_match = INVALID_HANDLE;
98Handle g_f_on_end_match = INVALID_HANDLE;
99Handle g_f_livewire_log_event = INVALID_HANDLE;
100
101/* cvars */
102ConVar wm_active;
103ConVar wm_stats_enabled;
104ConVar wm_stats_method;
105ConVar wm_stats_trace;
106ConVar wm_stats_trace_delay;
107ConVar wm_rcon_only;
108ConVar wm_lock_teams;
109ConVar wm_min_ready;
110ConVar wm_max_players;
111ConVar wm_match_config;
112ConVar wm_reset_config;
113ConVar wm_reset_config_delay;
114ConVar wm_warmup_config;
115ConVar wm_prac_config;
116ConVar wm_playout_config;
117ConVar wm_overtime_config;
118ConVar wm_default_config;
119ConVar wm_knife_config;
120ConVar wm_half_time_break;
121ConVar wm_over_time_break;
122ConVar wm_round_money;
123ConVar wm_ingame_scores;
124ConVar mp_maxrounds;
125ConVar wm_block_warm_up_grenades;
126ConVar wm_knife_auto_start;
127ConVar wm_knife_hegrenade;
128ConVar wm_knife_flashbang;
129ConVar wm_knife_smokegrenade;
130ConVar wm_knife_zeus;
131ConVar wm_knife_armor;
132ConVar wm_knife_helmet;
133ConVar wm_require_names;
134ConVar wm_require_logos;
135ConVar wm_logos_menu_only;
136ConVar wm_show_info;
137ConVar wm_auto_ready;
138ConVar wm_auto_knife;
139ConVar mp_overtime_enable;
140ConVar mp_overtime_maxrounds;
141ConVar tv_enable;
142ConVar wm_auto_record;
143ConVar wm_save_dir;
144ConVar wm_prefix_logs;
145ConVar wm_warmup_respawn;
146ConVar wm_chat_prefix;
147ConVar mp_match_can_clinch;
148ConVar mp_teamname_1;
149ConVar mp_teamname_2;
150ConVar mp_teamlogo_1;
151ConVar mp_teamlogo_2;
152ConVar mp_teamflag_1;
153ConVar mp_teamflag_2;
154ConVar wm_ready_tag;
155ConVar wm_ready_panel;
156
157
158ConVar mp_startmoney;
159ConVar hostname;
160
161/* ready system */
162Handle g_m_ready_up = INVALID_HANDLE;
163bool g_ready_enabled = false;
164
165/* switches */
166bool g_active = true;
167bool g_start = false;
168bool g_match = false;
169bool g_max_lock = false;
170bool g_live = false;
171bool g_log_live = false;
172bool g_restore = false;
173bool g_half_swap = true;
174bool g_first_half = true;
175bool g_overtime = false;
176bool g_t_money = false;
177bool g_t_score = false;
178bool g_t_knife = true;
179bool g_t_had_knife = false;
180bool g_second_half_first = false;
181bool g_setNameLimiter = true;
182bool g_DispInfoLimiter = true;
183bool LiveOn2 = false;
184bool LiveOn1 = false;
185bool LiveOn3Text = false;
186bool KnifeOn2 = false;
187bool KnifeOn1 = false;
188bool KnifeOn3Text = false;
189bool g_p_ct_name = false;
190bool g_p_t_name = false;
191int g_knife_winner = 0;
192bool g_knife_vote = false;
193bool captain_file_checked_t = false;
194bool captain_file_checked_ct = false;
195
196/* FTP Auto upload code [By Thrawn from tAutoDemoUpload] */
197ConVar wm_autodemoupload_enable;
198ConVar wm_autodemoupload_bzip2;
199ConVar wm_autodemoupload_ftptargetdemo;
200ConVar wm_autodemoupload_ftptargetlog;
201char g_sFtpTargetDemo[255];
202char g_sFtpTargetLog[255];
203ConVar wm_autodemoupload_delete;
204char g_sDemoPath[PLATFORM_MAX_PATH];
205char g_sDemoName[64];
206char g_sLogPath[PLATFORM_MAX_PATH];
207bool g_bRecording = false;
208ConVar wm_autodemoupload_completed;
209bool g_MatchComplete = false;
210
211/* Warmod safemode */
212ConVar wm_warmod_safemode;
213
214/* modes */
215int g_overtime_mode = 0;
216
217/* chat prefix */
218char CHAT_PREFIX[64];
219
220/* teams */
221char g_t_name[64];
222char g_t_name_escaped[64]; // pre-escaped for warmod logs
223char g_ct_name[64];
224char g_ct_name_escaped[64]; // pre-escaped for warmod logs
225
226/* clan tag */
227char g_clanTags[MAXPLAYERS +1 ][MAX_NAME_LENGTH];
228bool g_clanTagsChecked[MAXPLAYERS + 1] = false;
229
230/* Config Offers */
231bool default_offer_ct = false;
232bool default_offer_t = false;
233Handle g_h_stored_timer_def = INVALID_HANDLE;
234
235bool overtime_offer_ct = false;
236bool overtime_offer_t = false;
237Handle g_h_stored_timer_ot = INVALID_HANDLE;
238
239bool playout_offer_ct = false;
240bool playout_offer_t = false;
241Handle g_h_stored_timer_pl = INVALID_HANDLE;
242
243
244/* Pause and Unpause */
245bool g_pause_freezetime = false;
246bool g_pause_offered_t = false;
247bool g_pause_offered_ct = false;
248bool g_auto_pause = false;
249bool FreezeTime = false;
250
251ConVar sv_pausable;
252ConVar sv_matchpause_auto_5v5;
253ConVar wm_auto_pause;
254ConVar wm_auto_unpause;
255ConVar wm_auto_unpause_delay;
256ConVar wm_pause_confirm;
257ConVar wm_unpause_confirm;
258ConVar wm_pause_limit;
259int g_t_pause_count = 0;
260int g_ct_pause_count = 0;
261Handle g_h_stored_timer = INVALID_HANDLE;
262Handle g_h_stored_timer_p = INVALID_HANDLE;
263
264char g_c_backup[128];
265
266/* Veto Settings */
267ConVar wm_pugsetup_maplist_file;
268ConVar wm_pugsetup_randomize_maps;
269Handle g_MapNames = INVALID_HANDLE;
270Handle g_MapVetoed = INVALID_HANDLE;
271ConVar wm_veto;
272ConVar wm_veto_bo3;
273ConVar wm_veto_random;
274ConVar wm_veto_select;
275ConVar wm_veto_knife;
276ConVar tv_delaymapchange;
277ConVar tv_delay;
278ConVar mp_match_end_restart;
279ConVar wm_captain_from_file;
280int g_bo3_count = -1;
281int g_bo5_count = -1;
282int g_ChosenMapBo2[2] = -1;
283int g_ChosenMapBo3[3] = -1;
284int g_ChosenMapBo5[5] = -1;
285int g_ChosenMap = -1;
286int g_MapListCount = 0;
287bool g_veto_s = false;
288bool g_t_veto = false;
289bool g_veto_active = false;
290bool g_veto_bo5_active = false;
291bool g_veto_bo3_active = false;
292bool g_veto_bo2_active = false;
293int g_veto_map_number = 0;
294int g_veto_number = 0;
295int g_capt1 = -1;
296int g_capt2 = -1;
297bool veto_offer_ct = false;
298bool veto_offer_t = false;
299Handle g_h_stored_timer_v = INVALID_HANDLE;
300
301/* Print Damage */
302int g_DamageDone[MAXPLAYERS+1][MAXPLAYERS+1];
303int g_DamageDoneHits[MAXPLAYERS+1][MAXPLAYERS+1];
304bool g_GotKill[MAXPLAYERS+1][MAXPLAYERS+1];
305ConVar wm_damageprint_auto_color;
306ConVar wm_damageprint_enabled;
307ConVar wm_damageprint_format;
308
309/* Teams */
310bool team_switch = false;
311ConVar wm_name_fix;
312
313/* BanOn Disconnect */
314bool g_disconnect[MAXPLAYERS + 1] = false;
315ConVar wm_ban_on_disconnect;
316ConVar wm_ban_percentage;
317ConVar sv_kick_ban_duration;
318
319/* Random Team Names and Logos */
320static char g_teamName[][] = {"3DMAX", "Astana Dragons", "Bravado Gaming", "Cloud9", "Counter Logic Gaming", "Clan Mystik", "compLexity", "Copenhagen Wolves", "dAT Team", "Team Dignitas", "Epsilon eSports", "ESC Gaming", "Flipsid3 Tactics", "fnatic", "HellRaisers", "iBUYPOWER", "Team Wolf", "Keyd Stars", "London Conspiracy", "Team LDLC.com", "LGB eSports", "mousesports", "MyXMG", "Natus Vincere", "Ninjas in Pyjamas", "Team EnVyUs", "PENTA Sports", "Planetkey Dynamics", "Reason Gaming", "Team SoloMid", "Titan", "Vox Eminor", "VeryGames", "Virtus.Pro"};
321static char g_teamTag[][] = {"3DMAX", "Astana Dragons", "Bravado", "Cloud9", "CLG", "Clan Mystik", "compLexity", "CPH Wolves", "dAT Team", "Dignitas", "Epsilon", "ESC", "Flipsid3", "fnatic", "HellRaisers", "iBUYPOWER", "Team Wolf", "Keyd Stars", "Ldn-Con", "Team LDLC", "LGB", "mousesports", "MyXMG", "Na`Vi", "NiP", "Team EnVyUs", "PENTA", "Planetkey", "Reason", "TSM", "Titan", "Vox Eminor", "VeryGames", "Virtus.Pro"};
322static char g_teamLogo[][] = {"3dm", "ad", "bravg", "c9", "clg", "cm", "col", "cw", "dat", "dig", "eps", "esc", "flip", "fntc", "hlr", "ibp", "indw", "keyd", "lc", "ldlc", "lgb", "mss", "myxmg", "navi", "nip", "nv", "penta", "pkd", "rgg", "tsm", "tit", "ve", "vg", "vp"};
323int g_teamNumber_ct = 0;
324int g_teamNumber_t = 0;
325bool g_tag_set = false;
326ConVar wm_random_team_names;
327
328bool g_first_load = true;
329int g_map_loaded = 0;
330/* admin menu */
331Handle g_h_menu = INVALID_HANDLE;
332
333/* Plugin info */
334#define UPDATE_URL "https://warmod.bitbucket.io/updatefile.txt"
335#define WM_VERSION "17.08.12.1053"
336#define WM_DESCRIPTION "An automative service for CS:GO competition matches"
337
338public Plugin myinfo = {
339 name = "[BFG] WarMod",
340 author = "Versatile_BFG",
341 description = WM_DESCRIPTION,
342 version = WM_VERSION,
343 url = "www.sourcemod.net"
344};
345
346public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
347{
348 MarkNativeAsOptional("Zip_Open");
349 MarkNativeAsOptional("Zip_AddFile");
350 MarkNativeAsOptional("EasyFTP_UploadFile");
351 RegPluginLibrary("warmod");
352 return APLRes_Success;
353}
354
355public void OnPluginStart()
356{
357 //auto update
358 if (LibraryExists("updater"))
359 {
360 Updater_AddPlugin(UPDATE_URL);
361 }
362
363 g_first_load = true;
364
365 CheckConFigFiles(WM_VERSION);
366
367 LoadTranslations("warmod.phrases");
368 LoadTranslations("common.phrases");
369 LoadTranslations("basebans.phrases");
370
371 AutoExecConfig();
372
373 Handle topmenu;
374 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
375 {
376 OnAdminMenuReady(topmenu);
377 }
378
379 g_f_on_lo3 = CreateGlobalForward("OnLiveOn3", ET_Ignore);
380 g_f_on_round_end = CreateGlobalForward("OnRoundEnd", ET_Ignore, Param_String, Param_Cell, Param_Cell, Param_String);
381 g_f_on_half_time = CreateGlobalForward("OnHalfTime", ET_Ignore, Param_String, Param_Cell, Param_Cell, Param_String);
382 g_f_on_reset_half = CreateGlobalForward("OnResetHalf", ET_Ignore);
383 g_f_on_reset_match = CreateGlobalForward("OnResetMatch", ET_Ignore);
384 g_f_on_end_match = CreateGlobalForward("OnEndMatch", ET_Ignore, Param_String, Param_Cell, Param_Cell, Param_String);
385 g_f_livewire_log_event = CreateGlobalForward("LiveWireLogEvent", ET_Ignore, Param_String);
386
387 AddCommandListener(Command_JoinTeam, "jointeam");
388 AddCommandListener(UnpauseMatch, "mp_unpause_match");
389 AddCommandListener(MatchRestore, "mp_backup_restore_load_file");
390
391 RegConsoleCmd("score", ConsoleScore);
392 RegConsoleCmd("wm_version", WMVersion);
393 RegConsoleCmd("buy", RestrictBuy);
394 RegConsoleCmd("jointeam", ChooseTeam);
395 RegConsoleCmd("spectate", ChooseTeam);
396 RegConsoleCmd("wm_readylist", ReadyList);
397 RegConsoleCmd("wmrl", ReadyList);
398 RegConsoleCmd("wm_cash", AskTeamMoney);
399
400 RegConsoleCmd("sm_name", SetName, "Sets the name for the team. Only active when wm_require_names 1 and at start of match");
401 RegConsoleCmd("sm_logo", SetLogo, "Sets the logo and name for the team. Only active when wm_require_logos 1 and at start of match");
402
403 RegConsoleCmd("sm_ready", ReadyUp, "Readies up the client");
404 RegConsoleCmd("sm_r", ReadyUp, "Readies up the client");
405 RegConsoleCmd("sm_rdy", ReadyUp, "Readies up the client");
406 RegConsoleCmd("sm_unready", ReadyDown, "Readies down the client");
407 RegConsoleCmd("sm_ur", ReadyDown, "Readies down the client");
408 RegConsoleCmd("sm_urdy", ReadyDown, "Readies down the client");
409 RegConsoleCmd("sm_info", ReadyInfoPriv, "Shows ready info");
410 RegConsoleCmd("sm_i", ReadyInfoPriv, "Shows ready info");
411 RegConsoleCmd("sm_score", ShowScore, "Shows score to client");
412 RegConsoleCmd("sm_s", ShowScore, "Shows score to client");
413 RegConsoleCmd("sm_stay", Stay, "Stay command for knife round");
414 RegConsoleCmd("sm_switch", Switch, "Switch command for knife round");
415 RegConsoleCmd("sm_swap", Switch, "Switch command for knife round");
416 RegConsoleCmd("sm_pause", Pause, "Pauses the match");
417 RegConsoleCmd("sm_unpause", Unpause, "Resumes the match");
418
419 RegConsoleCmd("sm_playout", PlayOut_Offer, "Sets the match to be in play out mode");
420 RegConsoleCmd("sm_pl", PlayOut_Offer, "Sets the match to be in play out mode");
421 RegConsoleCmd("sm_hardprac", PlayOut_Offer, "Sets the match to be in play out mode");
422 RegConsoleCmd("sm_hp", PlayOut_Offer, "Sets the match to be in play out mode");
423
424 RegConsoleCmd("sm_overtime", OverTime_Offer, "Sets the match to be in overtime mode");
425 RegConsoleCmd("sm_ot", OverTime_Offer, "Sets the match to be in overtime mode");
426
427 RegConsoleCmd("sm_normal", Default_Offer, "Sets the match to be in default mode");
428 RegConsoleCmd("sm_norm", Default_Offer, "Sets the match to be in default mode");
429 RegConsoleCmd("sm_default", Default_Offer, "Sets the match to be in default mode");
430 RegConsoleCmd("sm_def", Default_Offer, "Sets the match to be in default mode");
431
432 /* Veto cmds */
433 RegConsoleCmd("sm_vetobo1", Veto_Bo1, "Ask for a Bo1 Veto");
434 RegConsoleCmd("sm_vetobo2", Veto_Bo2, "Ask for a Bo2 Veto");
435 RegConsoleCmd("sm_vetobo3", Veto_Bo3, "Ask for a Bo3 Veto");
436 RegConsoleCmd("sm_vetobo5", Veto_Bo5, "Ask for a Bo5 Veto");
437 RegConsoleCmd("sm_veto", Veto_Setup, "Ask for Veto");
438 RegConsoleCmd("sm_veto1", Veto_Bo1, "Ask for a Bo1 Veto");
439 RegConsoleCmd("sm_veto2", Veto_Bo2, "Ask for a Bo2 Veto");
440 RegConsoleCmd("sm_veto3", Veto_Bo3, "Ask for a Bo3 Veto");
441 RegConsoleCmd("sm_veto5", Veto_Bo5, "Ask for a Bo5 Veto");
442 RegConsoleCmd("sm_vetomaps", Veto_Bo3_Maps, "Veto Bo3 Maps");
443
444 /* admin commands */
445
446 RegAdminCmd("notlive", NotLive, ADMFLAG_CUSTOM1, "Declares half not live and restarts the round");
447 RegAdminCmd("nl", NotLive, ADMFLAG_CUSTOM1, "Declares half not live and restarts the round");
448 RegAdminCmd("cancelhalf", NotLive, ADMFLAG_CUSTOM1, "Declares half not live and restarts the round");
449 RegAdminCmd("ch", NotLive, ADMFLAG_CUSTOM1, "Declares half not live and restarts the round");
450
451 RegAdminCmd("cancelmatch", CancelMatch, ADMFLAG_CUSTOM1, "Declares match not live and restarts round");
452 RegAdminCmd("cm", CancelMatch, ADMFLAG_CUSTOM1, "Declares match not live and restarts round");
453
454 RegAdminCmd("readyup", ReadyToggle, ADMFLAG_CUSTOM1, "Starts or stops the ReadyUp System");
455 RegAdminCmd("ru", ReadyToggle, ADMFLAG_CUSTOM1, "Starts or stops the ReadyUp System");
456
457 RegAdminCmd("t", ChangeT, ADMFLAG_CUSTOM1, "Team starting terrorists - Designed for score purposes");
458 RegAdminCmd("ct", ChangeCT, ADMFLAG_CUSTOM1, "Team starting counter-terrorists - Designed for score purposes");
459 RegAdminCmd("sst", SetScoreT, ADMFLAG_CUSTOM1, "Setting terrorists score");
460 RegAdminCmd("ssct", SetScoreCT, ADMFLAG_CUSTOM1, "Setting counter-terrorists scores");
461
462 RegAdminCmd("aswap", SwapAll, ADMFLAG_CUSTOM1, "Swap all players to the opposite team");
463
464 RegAdminCmd("prac", Practice, ADMFLAG_CUSTOM1, "Puts server into a practice mode state");
465 RegAdminCmd("warmup", WarmUp, ADMFLAG_CUSTOM1, "Puts server into a warm up state");
466
467 RegAdminCmd("pwd", ChangePassword, ADMFLAG_PASSWORD, "Set or display the sv_password console variable");
468 RegAdminCmd("pw", ChangePassword, ADMFLAG_PASSWORD, "Set or display the sv_password console variable");
469
470 RegAdminCmd("active", ActiveToggle, ADMFLAG_CUSTOM1, "Toggle the wm_active console variable");
471
472 RegAdminCmd("minready", ChangeMinReady, ADMFLAG_CUSTOM1, "Set or display the wm_min_ready console variable");
473
474 RegAdminCmd("maxrounds", ChangeMaxRounds, ADMFLAG_CUSTOM1, "Set or display the wm_max_rounds console variable");
475
476 RegAdminCmd("knife", KnifeOn3, ADMFLAG_CUSTOM1, "Remove all weapons except knife and lo3");
477 RegAdminCmd("ko3", KnifeOn3, ADMFLAG_CUSTOM1, "Remove all weapons except knife and lo3");
478
479 RegAdminCmd("cancelknife", CancelKnife, ADMFLAG_CUSTOM1, "Declares knife not live and restarts round");
480 RegAdminCmd("ck", CancelKnife, ADMFLAG_CUSTOM1, "Declares knife not live and restarts round");
481
482 RegAdminCmd("forceallready", ForceAllReady, ADMFLAG_CUSTOM1, "Forces all players to become ready");
483 RegAdminCmd("far", ForceAllReady, ADMFLAG_CUSTOM1, "Forces all players to become ready");
484 RegAdminCmd("forceallunready", ForceAllUnready, ADMFLAG_CUSTOM1, "Forces all players to become unready");
485 RegAdminCmd("faur", ForceAllUnready, ADMFLAG_CUSTOM1, "Forces all players to become unready");
486 RegAdminCmd("forceallspectate", ForceAllSpectate, ADMFLAG_CUSTOM1, "Forces all players to become a spectator");
487 RegAdminCmd("fas", ForceAllSpectate, ADMFLAG_CUSTOM1, "Forces all players to become a spectator");
488
489 RegAdminCmd("lo3", ForceStart, ADMFLAG_CUSTOM1, "Starts the match regardless of player and ready count");
490 RegAdminCmd("forcestart", ForceStart, ADMFLAG_CUSTOM1, "Starts the match regardless of player and ready count");
491 RegAdminCmd("fs", ForceStart, ADMFLAG_CUSTOM1, "Starts the match regardless of player and ready count");
492 RegAdminCmd("forceend", ForceEnd, ADMFLAG_CUSTOM1, "Ends the match regardless of status");
493 RegAdminCmd("fe", ForceEnd, ADMFLAG_CUSTOM1, "Ends the match regardless of status");
494
495 RegAdminCmd("readyon", ReadyOn, ADMFLAG_CUSTOM1, "Turns on or restarts the ReadyUp System");
496 RegAdminCmd("ron", ReadyOn, ADMFLAG_CUSTOM1, "Turns on or restarts the ReadyUp System");
497 RegAdminCmd("readyoff", ReadyOff, ADMFLAG_CUSTOM1, "Turns off the ReadyUp System if enabled");
498 RegAdminCmd("roff", ReadyOff, ADMFLAG_CUSTOM1, "Turns off the ReadyUp System if enabled");
499
500 RegAdminCmd("updatecfgs", UpdateCFGs, ADMFLAG_CUSTOM1, "Updates configs with the latest format");
501
502 // server commands
503 RegServerCmd("wm_status", WarMod_Status);
504 RegServerCmd("wm_forceteam", ForceTeam, "Force the SteamID64 client to a team");
505 RegServerCmd("wm_clear_forceteam_all", ClearForceTeamAll, "Clears the list for forced teams");
506 RegServerCmd("wm_clear_forceteam_t", ClearForceTeamT, "Clears the list for forced terrorist team");
507 RegServerCmd("wm_clear_forceteam_ct", ClearForceTeamCT, "Clears the list for forced counter-terrorist team");
508 RegServerCmd("wm_forcename", ForceClientName, "Force the SteamID64 client's name");
509
510 /* Warmod Convars */
511 wm_active = CreateConVar("wm_active", "1", "Enable or disable WarMod as active", FCVAR_NOTIFY, true, 0.0, true, 1.0);
512 wm_warmod_safemode = CreateConVar("wm_warmod_safemode", "0", "This disables features that usually break on a CS:GO update", FCVAR_NOTIFY, true, 0.0, true, 1.0);
513 wm_rcon_only = CreateConVar("wm_rcon_only", "0", "Enable or disable admin commands to be only executed via RCON or console", FCVAR_NONE, true, 0.0, true, 1.0);
514 CreateConVar("wm_version_notify", WM_VERSION, WM_DESCRIPTION, FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
515
516 wm_chat_prefix = CreateConVar("wm_chat_prefix", "WarMod_BFG", "Change the chat prefix. Default is WarMod_BFG", FCVAR_PROTECTED);
517 wm_ready_panel = CreateConVar("wm_ready_panel", "1", "Enable Ready Panel or text based system, Text = 0, Panel = 1", FCVAR_NOTIFY, true, 0.0, true, 1.0);
518 wm_ready_tag = CreateConVar("wm_ready_tag", "1", "Enable or disable the ready & not ready clan tags", FCVAR_NOTIFY, true, 0.0, true, 1.0);
519 wm_lock_teams = CreateConVar("wm_lock_teams", "1", "Enable or disable locked teams when a match is running", FCVAR_NOTIFY, true, 0.0, true, 1.0);
520 wm_min_ready = CreateConVar("wm_min_ready", "10", "Sets the minimum required ready players to Live on 3", FCVAR_NOTIFY);
521 wm_max_players = CreateConVar("wm_max_players", "10", "Sets the maximum players allowed on both teams combined, others will be forced to spectator (0 = unlimited)", FCVAR_NOTIFY, true, 0.0);
522 wm_half_time_break = CreateConVar("wm_half_time_break", "0", "Pause game at halftime for a break, No break = 0, break = 1", FCVAR_NONE, true, 0.0, true, 1.0);
523 wm_over_time_break = CreateConVar("wm_over_time_break", "0", "Pause game at overtime for a break, No break = 0, break = 1", FCVAR_NONE, true, 0.0, true, 1.0);
524 wm_round_money = CreateConVar("wm_round_money", "1", "Enable or disable a client's team mates money to be displayed at the start of a round (to him only)", FCVAR_NONE, true, 0.0, true, 1.0);
525 wm_ingame_scores = CreateConVar("wm_ingame_scores", "1", "Enable or disable ingame scores to be showed at the end of each round", FCVAR_NOTIFY, true, 0.0, true, 1.0);
526 wm_require_names = CreateConVar("wm_require_names", "0", "Enable or disable the requirement of set team names for lo3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
527 wm_require_logos = CreateConVar("wm_require_logos", "0", "Enable or disable the requirement of set team logos for lo3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
528 wm_logos_menu_only = CreateConVar("wm_logos_menu_only", "0", "Set to use the Menu only for Logo Selection", FCVAR_NOTIFY, true, 0.0, true, 1.0);
529 wm_random_team_names = CreateConVar("wm_random_team_names", "0", "Enable or disable the random set of a pro team name for the match", FCVAR_NOTIFY, true, 0.0, true, 1.0);
530 wm_show_info = CreateConVar("wm_show_info", "1", "Enable or disable the display of the Ready System to players", FCVAR_NOTIFY, true, 0.0, true, 1.0);
531 wm_auto_ready = CreateConVar("wm_auto_ready", "1", "Enable or disable the ready system being automatically enabled on map change", FCVAR_NOTIFY, true, 0.0, true, 1.0);
532
533 /* Ban Convars */
534 wm_ban_on_disconnect = CreateConVar("wm_ban_on_disconnect", "0", "Enable or disable players banned on disconnect if match is live", FCVAR_NOTIFY, true, 0.0, true, 1.0);
535 wm_ban_percentage = CreateConVar("wm_ban_percentage", "0.75", "Percentage of wm_max_players that will be banned on disconnect", FCVAR_NOTIFY, true, 0.0, true, 1.0);
536 sv_kick_ban_duration = FindConVar("sv_kick_ban_duration");
537
538 /* Stats & Demo Convars */
539 tv_enable = FindConVar("tv_enable");
540 wm_stats_enabled = CreateConVar("wm_stats_enabled", "1", "Enable or disable statistical logging", FCVAR_NOTIFY, true, 0.0, true, 1.0);
541 wm_stats_method = CreateConVar("wm_stats_method", "2", "Sets the stats logging method: 0 = UDP stream/server logs, 1 = WarMod logs, 2 = both", FCVAR_NOTIFY, true, 0.0, true, 2.0);
542 wm_stats_trace = CreateConVar("wm_stats_trace", "0", "Enable or disable updating all player positions, every wm_stats_trace_delay seconds", FCVAR_NOTIFY, true, 0.0, true, 1.0);
543 wm_stats_trace_delay = CreateConVar("wm_stats_trace_delay", "5", "The amount of time between sending player position updates", FCVAR_NOTIFY, true, 0.0);
544 wm_auto_record = CreateConVar("wm_auto_record", "1", "Enable or disable auto SourceTV demo record on Live on 3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
545 wm_save_dir = CreateConVar("wm_save_dir", "warmod", "Directory to store SourceTV demos and WarMod logs");
546 wm_prefix_logs = CreateConVar("wm_prefix_logs", "1", "Enable or disable the prefixing of \"_\" to uncompleted match SourceTV demos and WarMod logs", FCVAR_NOTIFY, true, 0.0, true, 1.0);
547 wm_competition = CreateConVar("wm_competition", "WarMod BFG", "Name of host for a competition. eg. ESEA, Cybergamer, CEVO, ESL");
548 wm_event = CreateConVar("wm_event", "scrim", "Name of event. eg. Season #, ODC #, Ladder");
549
550 /* SQL Settings */
551 wm_upload_results = CreateConVar("wm_upload_results", "0", "Enable or disable the uploading of match results via MySQL", FCVAR_NOTIFY, true, 0.0, true, 1.0);
552 wm_table_name = CreateConVar("wm_table_name", "wm_results", "The MySQL table name to store match results in");
553 //wm_table_name_players = CreateConVar("wm_table_name_players", "wm_players", "The MySQL table name to store match players in");
554 wm_table_round_stats = CreateConVar("wm_table_round_stats", "wm_round_stats", "The MySQL table name to store round stats in");
555
556 /* Config Convars */
557 wm_match_config = CreateConVar("wm_match_config", "warmod/ruleset_default.cfg", "Sets the match config to load on Live on 3");
558 wm_reset_config = CreateConVar("wm_reset_config", "warmod/on_match_end.cfg", "Sets the config to load at the end/reset of a match");
559 wm_reset_config_delay = CreateConVar("wm_reset_config_delay", "1", "The amount of time before executing the reset config after a match", FCVAR_NOTIFY, true, 0.0);
560 wm_prac_config = CreateConVar("wm_prac_config", "warmod/prac.cfg", "Sets the config to load up for practice");
561 wm_playout_config = CreateConVar("wm_playout_config", "warmod/ruleset_playout.cfg", "Sets the play out match config to load on Live on 3");
562 wm_overtime_config = CreateConVar("wm_overtime_config", "warmod/ruleset_overtime.cfg", "Sets the overtime match config to load on Live on 3");
563 wm_default_config = CreateConVar("wm_default_config", "warmod/ruleset_default.cfg", "Sets the default match config to load on Live on 3");
564 wm_knife_config = CreateConVar("wm_knife_config", "warmod/ruleset_knife.cfg", "Sets the knife config to load on Knife on 3");
565
566 /* Warmup Convars */
567 wm_warmup_config = CreateConVar("wm_warmup_config", "warmod/ruleset_warmup.cfg", "Sets the config to load up for warmup");
568 wm_block_warm_up_grenades = CreateConVar("wm_block_warm_up_grenades", "0", "Enable or disable grenade blocking in warmup", FCVAR_NOTIFY, true, 0.0, true, 1.0);
569 wm_warmup_respawn = CreateConVar("wm_warmup_respawn", "0", "Enable or disable the respawning of players in warmup", FCVAR_NOTIFY, true, 0.0, true, 1.0);
570
571 /* Knife Convars */
572 wm_auto_knife = CreateConVar("wm_auto_knife", "0", "Enable or disable the knife round before going live", FCVAR_NOTIFY, true, 0.0, true, 1.0);
573 wm_knife_auto_start = CreateConVar("wm_knife_auto_start", "0", "Enable or disable after knife round to be forced lived", FCVAR_NOTIFY, true, 0.0, true, 1.0);
574 wm_knife_hegrenade = CreateConVar("wm_knife_hegrenade", "0", "Enable or disable giving a player a hegrenade on Knife on 3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
575 wm_knife_flashbang = CreateConVar("wm_knife_flashbang", "0", "Sets how many flashbangs to give a player on Knife on 3", FCVAR_NOTIFY, true, 0.0, true, 2.0);
576 wm_knife_smokegrenade = CreateConVar("wm_knife_smokegrenade", "0", "Enable or disable giving a player a smokegrenade on Knife on 3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
577 wm_knife_zeus = CreateConVar("wm_knife_zeus", "0", "Enable or disable giving a player a zeus on Knife on 3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
578 wm_knife_armor = CreateConVar("wm_knife_armor", "1", "Enable or disable giving a player Armor on Knife on 3", FCVAR_NOTIFY, true, 0.0, true, 1.0);
579 wm_knife_helmet = CreateConVar("wm_knife_helmet", "0", "Enable or disable giving a player a Helmet on Knife on 3 [requires armor active]", FCVAR_NOTIFY, true, 0.0, true, 1.0);
580 wm_name_fix = CreateConVar("wm_name_fix", "0", "Fix name swap after knife round", FCVAR_NOTIFY, true, 0.0, true, 1.0);
581
582 /* FTP Upload Convars */
583 wm_autodemoupload_enable = CreateConVar("wm_autodemoupload_enable", "1", "Automatically upload demos when finished recording.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
584 wm_autodemoupload_bzip2 = CreateConVar("wm_autodemoupload_bzip2", "9", "Compression level. If set > 0 demos will be compressed before uploading. (Requires bzip2 extension.)", FCVAR_NOTIFY, true, 0.0, true, 9.0);
585 wm_autodemoupload_delete = CreateConVar("wm_autodemoupload_delete", "0", "Delete the demo (and the bz2) if upload was successful.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
586 wm_autodemoupload_ftptargetdemo = CreateConVar("wm_autodemoupload_ftptargetdemo", "demos", "The ftp target to use for demo uploads.");
587 wm_autodemoupload_ftptargetlog = CreateConVar("wm_autodemoupload_ftptargetlog", "logs", "The ftp target to use for log uploads.");
588 wm_autodemoupload_completed = CreateConVar("wm_autodemoupload_completed", "1", "Only upload demos when match is completed.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
589
590 /* Pause Convars */
591 sv_pausable = FindConVar("sv_pausable");
592 sv_matchpause_auto_5v5 = FindConVar("sv_matchpause_auto_5v5");
593 wm_auto_pause = CreateConVar("wm_auto_pause", "0", "Will pause server if team players equals less than half of wm_max_players: 0 = off, 1 = on", FCVAR_NOTIFY, true, 0.0, true, 1.0);
594 wm_pause_confirm = CreateConVar("wm_pause_confirm", "1", "Wait for other team to confirm pause: 0 = off, 1 = on", FCVAR_NOTIFY, true, 0.0, true, 1.0);
595 wm_unpause_confirm = CreateConVar("wm_unpause_confirm", "1", "Wait for other team to confirm unpause: 0 = off, 1 = on", FCVAR_NOTIFY, true, 0.0, true, 1.0);
596 wm_auto_unpause = CreateConVar("wm_auto_unpause", "1", "Sets auto unpause: 0 = off, 1 = on", FCVAR_NOTIFY, true, 0.0, true, 1.0);
597 wm_auto_unpause_delay = CreateConVar("wm_auto_unpause_delay", "180", "Sets the seconds to wait before auto unpause", FCVAR_NOTIFY, true, 0.0);
598 wm_pause_limit = CreateConVar("wm_pause_limit", "1", "Sets max pause count per team per half", FCVAR_NOTIFY, true, 0.0);
599
600 /* Veto Convars */
601 wm_pugsetup_maplist_file = CreateConVar("wm_pugsetup_maplist_file", "warmod/veto_maps_list.txt", "Veto Map List to read from", FCVAR_NOTIFY);
602 wm_pugsetup_randomize_maps = CreateConVar("wm_pugsetup_randomize_maps", "1", "When maps are shown in the map vote/veto, should their order be randomized?", FCVAR_NOTIFY);
603 wm_veto = CreateConVar("wm_veto", "1", "Veto Style: 0 = off, 1 = Bo1, 2 = Bo2, 3 = Bo3, 5 = Bo5", FCVAR_NOTIFY, true, 0.0, true, 5.0);
604 wm_veto_knife = CreateConVar("wm_veto_knife", "1", "Requires a knife round to determine who votes first: 0 = off, 1 = on", FCVAR_NOTIFY, true, 0.0, true, 1.0);
605 wm_veto_bo3 = CreateConVar("wm_veto_bo3", "0", "Veto Style: 0 = Normal, 1 = New", FCVAR_NOTIFY, true, 0.0, true, 1.0);
606 wm_veto_random = CreateConVar("wm_veto_random", "0", "After the vetoing is done, will a map be picked at random?", FCVAR_NOTIFY, true, 0.0, true, 1.0);
607 wm_veto_select = CreateConVar("wm_veto_select", "1", "On last two maps of Veto Bo1 will it be select map to play: 0 = No, 1 = Yes", FCVAR_NOTIFY, true, 0.0, true, 1.0);
608 wm_captain_from_file = CreateConVar("wm_captain_from_file", "0", "Get team captains from file? 0 = No, 1 = Yes", FCVAR_NOTIFY, true, 0.0, true, 1.0);
609
610 /* Damage Printer */
611 wm_damageprint_auto_color = CreateConVar("wm_damageprint_auto_color", "1", "Whether colors are automatically inserted for damage values, changing depending on if the damage resulted in a kill");
612 wm_damageprint_enabled = CreateConVar("wm_damageprint_enabled", "0", "Whether to enabled damage print to client on round end");
613 wm_damageprint_format = CreateConVar("wm_damageprint_format", "--> ({DMG_TO} dmg / {HITS_TO} hits) to ({DMG_FROM} dmg / {HITS_FROM} hits) from {NAME} ({HEALTH} HP)", "Format of the damage output string. Avaliable tags are in the default, color tags such as {LIGHT_RED} and {GREEN} also work.");
614
615 g_MapNames = CreateArray(PLATFORM_MAX_PATH);
616
617 g_iAccount = FindSendPropInfo("CCSPlayer", "m_iAccount");
618 hostname = FindConVar("hostname");
619
620 mp_startmoney = FindConVar("mp_startmoney");
621 mp_match_can_clinch = FindConVar("mp_match_can_clinch");
622 mp_maxrounds = FindConVar("mp_maxrounds");
623 mp_overtime_enable = FindConVar("mp_overtime_enable");
624 mp_overtime_maxrounds = FindConVar("mp_overtime_maxrounds");
625 mp_teamname_1 = FindConVar("mp_teamname_1");
626 mp_teamname_2 = FindConVar("mp_teamname_2");
627 mp_teamlogo_1 = FindConVar("mp_teamlogo_1");
628 mp_teamlogo_2 = FindConVar("mp_teamlogo_2");
629 mp_teamflag_1 = FindConVar("mp_teamflag_1");
630 mp_teamflag_2 = FindConVar("mp_teamflag_2");
631
632 tv_delaymapchange = FindConVar("tv_delaymapchange");
633 tv_delay = FindConVar("tv_delay");
634 mp_match_end_restart = FindConVar("mp_match_end_restart");
635
636 HookConVarChange(wm_active, OnActiveChange);
637 HookConVarChange(wm_min_ready, OnMinReadyChange);
638 HookConVarChange(wm_stats_trace, OnStatsTraceChange);
639 HookConVarChange(wm_stats_trace_delay, OnStatsTraceDelayChange);
640 HookConVarChange(wm_auto_ready, OnAutoReadyChange);
641 HookConVarChange(mp_teamname_2, OnTChange);
642 HookConVarChange(mp_teamname_1, OnCTChange);
643
644 HookConVarChange(sv_matchpause_auto_5v5, Cvar_Changed);
645 HookConVarChange(wm_autodemoupload_ftptargetdemo, Cvar_Changed);
646 HookConVarChange(wm_autodemoupload_ftptargetlog, Cvar_Changed);
647 HookConVarChange(wm_chat_prefix, Cvar_Changed);
648 HookConVarChange(wm_competition, Cvar_Changed);
649 HookConVarChange(wm_event, Cvar_Changed);
650 HookConVarChange(hostname, Cvar_Changed);
651
652 HookConVarChange(FindConVar("mp_restartgame"), Event_Round_Restart);
653
654 HookEvent("round_start", Event_Round_Start);
655 HookEvent("round_end", Event_Round_End);
656 HookEvent("round_freeze_end", Event_Round_Freeze_End);
657
658 HookEvent("player_blind", Event_Player_Blind);
659 HookEvent("player_hurt", Event_Player_Hurt);
660 HookEvent("player_death", Event_Player_Death);
661 HookEvent("player_changename", Event_Player_Name);
662 HookEvent("player_disconnect", Event_Player_Disc_Pre, EventHookMode_Pre);
663 HookEvent("player_team", Event_Player_Team);
664 HookEvent("player_team", Event_Player_Team_Post, EventHookMode_Post);
665 HookEvent("player_spawned", Event_Player_Spawned);
666
667 HookEvent("bomb_pickup", Event_Bomb_PickUp);
668 HookEvent("bomb_dropped", Event_Bomb_Dropped);
669 HookEvent("bomb_beginplant", Event_Bomb_Plant_Begin);
670 HookEvent("bomb_abortplant", Event_Bomb_Plant_Abort);
671 HookEvent("bomb_planted", Event_Bomb_Planted);
672 HookEvent("bomb_begindefuse", Event_Bomb_Defuse_Begin);
673 HookEvent("bomb_abortdefuse", Event_Bomb_Defuse_Abort);
674 HookEvent("bomb_defused", Event_Bomb_Defused);
675
676 HookEvent("weapon_fire", Event_Weapon_Fire);
677
678 HookEvent("flashbang_detonate", Event_Detonate_Flash);
679 HookEvent("smokegrenade_detonate", Event_Detonate_Smoke);
680 HookEvent("hegrenade_detonate", Event_Detonate_HeGrenade);
681 HookEvent("molotov_detonate", Event_Detonate_Molotov);
682 HookEvent("decoy_detonate", Event_Detonate_Decoy);
683
684 HookEvent("item_pickup", Event_Item_Pickup);
685
686 CreateTimer(15.0, HelpText, 0, TIMER_REPEAT);
687}
688
689public void OnLibraryAdded(const char[]name)
690{
691 if (StrEqual(name, "updater"))
692 {
693 Updater_AddPlugin(UPDATE_URL);
694 }
695}
696
697public void OnConfigsExecuted()
698{
699 GetConVarString(wm_chat_prefix, CHAT_PREFIX, sizeof(CHAT_PREFIX));
700 GetConVarString(wm_event, g_event, sizeof(g_event));
701 GetConVarString(wm_competition, g_competition, sizeof(g_competition));
702 GetConVarString(hostname, g_server, sizeof(g_server));
703
704 GetConVarString(wm_autodemoupload_ftptargetdemo, g_sFtpTargetDemo, sizeof(g_sFtpTargetDemo));
705 GetConVarString(wm_autodemoupload_ftptargetlog, g_sFtpTargetLog, sizeof(g_sFtpTargetLog));
706 if (GetConVarBool(sv_matchpause_auto_5v5))
707 {
708 ServerCommand("wm_auto_pause 1");
709 ServerCommand("sv_matchpause_auto_5v5 0");
710 }
711}
712
713public void OnMapStart()
714{
715 g_map_loaded++;
716 ServerCommand("exec warmod/on_map_load.cfg");
717 AddTeamLogosToDownloadTable();
718 char g_MapName[64];
719 char g_WorkShopID[64];
720 char g_CurMap[128];
721 GetCurrentMap(g_CurMap, sizeof(g_CurMap));
722 if (StrContains(g_CurMap, "workshop", false) != -1)
723 {
724 GetCurrentWorkshopMap(g_MapName, sizeof(g_MapName), g_WorkShopID, sizeof(g_WorkShopID));
725 LogMessage("Current Map: %s, Workshop ID: %s, Warmod Version: %s", g_MapName, g_WorkShopID, WM_VERSION);
726 }
727 else
728 {
729 strcopy(g_map, sizeof(g_map), g_CurMap);
730 LogMessage("Current Map: %s, Warmod Version: %s", g_CurMap, WM_VERSION);
731 }
732 StringToLower(g_map, sizeof(g_map));
733
734 if (!GetConVarBool(mp_match_end_restart) && ((g_veto_bo3_active && g_veto_map_number < 3) || (g_veto_bo5_active && g_veto_map_number < 5) || (g_veto_bo2_active && g_veto_map_number < 2)))
735 {
736 if (g_veto_bo3_active)
737 {
738 g_ChosenMap = g_ChosenMapBo3[g_veto_map_number];
739 }
740 else if (g_veto_bo5_active)
741 {
742 g_ChosenMap = g_ChosenMapBo5[g_veto_map_number];
743 }
744 else
745 {
746 g_ChosenMap = g_ChosenMapBo2[g_veto_map_number];
747 }
748
749 g_veto_map_number++;
750
751 char map[PLATFORM_MAX_PATH];
752 GetArrayString(g_MapNames, g_ChosenMap, map, sizeof(map));
753 ServerCommand("nextlevel %s", map);
754 }
755
756 if (GetConVarBool(wm_stats_trace))
757 {
758 // start trace timer
759 g_stats_trace_timer = CreateTimer(GetConVarFloat(wm_stats_trace_delay), Stats_Trace, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
760 }
761
762 if (hDatabase == INVALID_HANDLE) {
763 StartSQL(0);
764 }
765
766 // reset any matches
767 ResetMatch(true, false);
768 g_bRecording = false;
769
770 // Veto
771 g_MapVetoed = CreateArray();
772 g_veto_s = false;
773 g_veto_number = 0;
774 g_t_knife = false;
775}
776
777public void OnMapEnd()
778{
779 CloseHandle(g_MapVetoed);
780}
781
782public void OnLibraryRemoved(const char[]name)
783{
784 if (StrEqual(name, "adminmenu"))
785 {
786 g_h_menu = INVALID_HANDLE;
787 }
788}
789
790public void OnAdminMenuReady(Handle topmenu)
791{
792 if (topmenu == g_h_menu)
793 {
794 return;
795 }
796
797 g_h_menu = topmenu;
798 TopMenuObject new_menu = AddToTopMenu(g_h_menu, "WarModCommands", TopMenuObject_Category, MenuHandler, INVALID_TOPMENUOBJECT);
799
800 if (new_menu == INVALID_TOPMENUOBJECT)
801 {
802 return;
803 }
804
805 // add menu items
806 AddToTopMenu(g_h_menu, "forcestart", TopMenuObject_Item, MenuHandler, new_menu, "forcestart", ADMFLAG_CUSTOM1);
807 AddToTopMenu(g_h_menu, "readyup", TopMenuObject_Item, MenuHandler, new_menu, "readyup", ADMFLAG_CUSTOM1);
808 AddToTopMenu(g_h_menu, "knife", TopMenuObject_Item, MenuHandler, new_menu, "knife", ADMFLAG_CUSTOM1);
809 AddToTopMenu(g_h_menu, "cancelhalf", TopMenuObject_Item, MenuHandler, new_menu, "cancelhalf", ADMFLAG_CUSTOM1);
810 AddToTopMenu(g_h_menu, "cancelmatch", TopMenuObject_Item, MenuHandler, new_menu, "cancelmatch", ADMFLAG_CUSTOM1);
811 AddToTopMenu(g_h_menu, "forceallready", TopMenuObject_Item, MenuHandler, new_menu, "forceallready", ADMFLAG_CUSTOM1);
812 AddToTopMenu(g_h_menu, "forceallunready", TopMenuObject_Item, MenuHandler, new_menu, "forceallunready", ADMFLAG_CUSTOM1);
813 AddToTopMenu(g_h_menu, "forceallspectate", TopMenuObject_Item, MenuHandler, new_menu, "forceallspectate", ADMFLAG_CUSTOM1);
814 AddToTopMenu(g_h_menu, "toggleactive", TopMenuObject_Item, MenuHandler, new_menu, "toggleactive", ADMFLAG_CUSTOM1);
815}
816
817public Action UpdateCFGs(int client, int args)
818{
819 Update_Configs(WM_VERSION);
820 return Plugin_Handled;
821}
822
823public void OnClientPostAdminCheck(int client)
824{
825 if (client == 0)
826 {
827 return;
828 }
829
830 char ip_address[32];
831 GetClientIP(client, ip_address, sizeof(ip_address));
832 IsFakeClient(client);
833 if (!IsActive(0, true))
834 {
835 // warmod is disabled
836 return;
837 }
838
839 if (GetConVarBool(wm_stats_enabled) && client != 0)
840 {
841 char log_string[384];
842 CS_GetLogString(client, log_string, sizeof(log_string));
843
844 char country[4];
845 GeoipCode2(ip_address, country);
846
847 EscapeString(ip_address, sizeof(ip_address));
848 LogEvent("{\"event\": \"player_connect\", \"player\": %s, \"address\": \"%s\", \"country\": \"%s\"}", log_string, ip_address, country);
849 }
850}
851
852public void OnClientPutInServer(int client)
853{
854 // reset client state
855 g_player_list[client] = PLAYER_DISC;
856 g_cancel_list[client] = false;
857 g_disconnect[client] = false;
858 g_clanTagsChecked[client] = false;
859}
860
861public void OnClientDisconnect(int client)
862{
863 // reset client state
864 g_player_list[client] = PLAYER_DISC;
865 g_cancel_list[client] = false;
866 g_clanTagsChecked[client] = false;
867
868 // log player stats
869 if (g_live && GameRules_GetProp("m_bFreezePeriod") == 0 && (GetTTotalScore() + GetCTTotalScore()) != 0) {
870 LogPlayerStats(client);
871 }
872
873 if (!IsActive(client, true))
874 {
875 // warmod is disabled
876 return;
877 }
878
879 if (g_ready_enabled && !g_live)
880 {
881 // display ready system
882 ShowInfo(client, true, false, 0);
883 }
884
885 if ((g_match) && GetConVarBool(wm_auto_pause))
886 {
887 AutoPause();
888 }
889
890 if ((g_match || g_t_knife) && GetConVarBool(wm_ban_on_disconnect) && g_disconnect[client] == true)
891 {
892 int count = CS_GetPlayerListCount();
893 float percent = GetConVarFloat(wm_ban_percentage);
894
895 if (count > (GetConVarInt(wm_max_players) * percent))
896 {
897 char reason[32] = "Disconnected from live match";
898 char authid[32];
899 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
900
901 ServerCommand("sm_addban %i %s %s", GetConVarInt(sv_kick_ban_duration), authid, reason);
902 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Banned player reason", authid, GetConVarInt(sv_kick_ban_duration), reason);
903 g_disconnect[client] = false;
904 }
905 }
906}
907
908void ResetMatch(bool silent, bool complete) {
909 if (g_match) {
910 Call_StartForward(g_f_on_reset_match);
911 Call_Finish();
912 if (GetConVarBool(wm_stats_enabled)) {
913 char event_name[] = "match_reset";
914 LogSimpleEvent(event_name, sizeof(event_name));
915 }
916 // end of log
917 char event_name[] = "log_end";
918 LogSimpleEvent(event_name, sizeof(event_name));
919 }
920
921 if (!complete) {
922 //stop demo from uploading
923 g_MatchComplete = false;
924 }
925
926 if (g_match) {
927 // execute relevant server config
928 CreateTimer(GetConVarFloat(wm_reset_config_delay), Timer_DelayedResetConfig);
929 }
930
931 if (g_log_file != INVALID_HANDLE) {
932 // close log file
933 FlushFile(g_log_file);
934 CloseHandle(g_log_file);
935 g_log_file = INVALID_HANDLE;
936 }
937
938 if (g_log_veto_file != INVALID_HANDLE) {
939 // close log file
940 FlushFile(g_log_veto_file);
941 CloseHandle(g_log_veto_file);
942 g_log_veto_file = INVALID_HANDLE;
943 }
944
945 // reset state
946 g_start = false;
947 g_match = false;
948 g_max_lock = false;
949 g_live = false;
950 g_log_live = false;
951 g_half_swap = true;
952 g_first_half = true;
953 g_second_half_first = false;
954 g_t_money = false;
955 g_t_score = false;
956 g_t_knife = false;
957 g_t_had_knife = false;
958 g_tag_set = false;
959 g_setNameLimiter = true;
960 g_DispInfoLimiter = true;
961 SetAllCancelled(false);
962 ReadyChangeAll(0, false, true);
963 ResetMatchScores();
964 if (!g_first_load && g_map_loaded > 2) {
965 ResetTeams();
966 }
967 g_first_load = false;
968 g_overtime = false;
969 g_overtime_count = 0;
970 g_t_pause_count = 0;
971 g_ct_pause_count = 0;
972 g_round = 1;
973
974 LiveOn2 = false;
975 LiveOn1 = false;
976 LiveOn3Text = false;
977 KnifeOn2 = false;
978 KnifeOn1 = false;
979 KnifeOn3Text = false;
980
981 g_t_veto = false;
982 veto_offer_ct = false;
983 veto_offer_t = false;
984 g_veto_active = false;
985
986 default_offer_ct = false;
987 default_offer_t = false;
988
989 overtime_offer_ct = false;
990 overtime_offer_t = false;
991
992 playout_offer_ct = false;
993 playout_offer_t = false;
994
995 team_switch = false;
996
997 g_auto_pause = false;
998 ServerCommand("mp_unpause_match 1");
999 if (g_h_stored_timer != INVALID_HANDLE)
1000 {
1001 KillTimer(g_h_stored_timer);
1002 g_h_stored_timer = INVALID_HANDLE;
1003 }
1004 if (g_h_stored_timer_p != INVALID_HANDLE)
1005 {
1006 KillTimer(g_h_stored_timer_p);
1007 g_h_stored_timer_p = INVALID_HANDLE;
1008 }
1009 if (g_h_stored_timer_pl != INVALID_HANDLE)
1010 {
1011 KillTimer(g_h_stored_timer_pl);
1012 g_h_stored_timer_pl = INVALID_HANDLE;
1013 }
1014 if (g_h_stored_timer_ot != INVALID_HANDLE)
1015 {
1016 KillTimer(g_h_stored_timer_ot);
1017 g_h_stored_timer_ot = INVALID_HANDLE;
1018 }
1019 if (g_h_stored_timer_def != INVALID_HANDLE)
1020 {
1021 KillTimer(g_h_stored_timer_def);
1022 g_h_stored_timer_def = INVALID_HANDLE;
1023 }
1024 UpdateStatus();
1025
1026 // stop tv recording after 5 seconds
1027 CreateTimer(5.0, StopRecord);
1028 CreateTimer(5.0, LogFileUpload);
1029// CreateTimer(10.0, SQL_Player_Info_Clear);
1030
1031 if (GetConVarBool(wm_auto_ready))
1032 {
1033 // enable ready system
1034 ReadySystem(true);
1035 ShowInfo(0, true, false, 0);
1036 // update status code
1037 UpdateStatus();
1038 }
1039 else if (g_ready_enabled)
1040 {
1041 // disable ready system
1042 ReadySystem(false);
1043 ShowInfo(0, false, false, 1);
1044 }
1045
1046 if (!silent)
1047 {
1048 // message display to players
1049 for (int x = 1; x <= 3; x++)
1050 {
1051 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Match Reset");
1052 }
1053 // restart round
1054 ServerCommand("mp_restartgame 1");
1055 }
1056}
1057
1058void ResetHalf(bool silent)
1059{
1060 if (g_match)
1061 {
1062 Call_StartForward(g_f_on_reset_half);
1063 Call_Finish();
1064 if (GetConVarBool(wm_stats_enabled))
1065 {
1066 char event_name[] = "match_half_reset";
1067 LogSimpleEvent(event_name, sizeof(event_name));
1068 }
1069 }
1070 if (!g_first_half)
1071 {
1072 g_half_swap = true;
1073 }
1074
1075 // reset half state
1076 g_live = false;
1077 g_t_money = false;
1078 g_t_score = false;
1079 g_t_knife = false;
1080 SetAllCancelled(false);
1081 ReadyChangeAll(0, false, true);
1082 ResetHalfScores();
1083 UpdateStatus();
1084 g_t_pause_count = 0;
1085 g_ct_pause_count = 0;
1086
1087 ServerCommand("mp_unpause_match 1");
1088 if (g_h_stored_timer != INVALID_HANDLE)
1089 {
1090 KillTimer(g_h_stored_timer);
1091 g_h_stored_timer = INVALID_HANDLE;
1092 }
1093 if (g_h_stored_timer_p != INVALID_HANDLE)
1094 {
1095 KillTimer(g_h_stored_timer_p);
1096 g_h_stored_timer_p = INVALID_HANDLE;
1097 }
1098
1099 if (GetConVarBool(wm_auto_ready))
1100 {
1101 // display ready system
1102 ReadySystem(true);
1103 ShowInfo(0, true, false, 0);
1104 UpdateStatus();
1105 }
1106 else
1107 {
1108 // disable ready system
1109 ReadySystem(false);
1110 ShowInfo(0, false, false, 1);
1111 }
1112
1113 if (!silent)
1114 {
1115 // display message for players
1116 for (int x = 1; x <= 3; x++)
1117 {
1118 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Half Reset");
1119 }
1120 // restart round
1121 ServerCommand("mp_restartgame 1");
1122 }
1123}
1124
1125void ResetTeams()
1126{
1127 // set team names to default
1128 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
1129 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_t_name);
1130 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
1131 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
1132 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_ct_name);
1133 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
1134 ServerCommand("mp_teamname_2 %s", g_t_name);
1135 ServerCommand("mp_teamname_1 %s", g_ct_name);
1136}
1137
1138void ResetMatchScores()
1139{
1140 // reset match scores
1141 g_scores[SCORE_T][SCORE_FIRST_HALF] = 0;
1142 g_scores[SCORE_T][SCORE_SECOND_HALF] = 0;
1143
1144 g_scores[SCORE_CT][SCORE_FIRST_HALF] = 0;
1145 g_scores[SCORE_CT][SCORE_SECOND_HALF] = 0;
1146
1147 // reset overtime scores
1148 for (int i = 0; i <= g_overtime_count; i++)
1149 {
1150 g_scores_overtime[SCORE_T][i][SCORE_FIRST_HALF] = 0;
1151 g_scores_overtime[SCORE_T][i][SCORE_SECOND_HALF] = 0;
1152
1153 g_scores_overtime[SCORE_CT][i][SCORE_FIRST_HALF] = 0;
1154 g_scores_overtime[SCORE_CT][i][SCORE_SECOND_HALF] = 0;
1155 }
1156}
1157
1158void ResetHalfScores()
1159{
1160 // reset scores for the current half
1161 if (!g_overtime)
1162 {
1163 // not overtime
1164 if (g_first_half)
1165 {
1166 // first half
1167 g_scores[SCORE_T][SCORE_FIRST_HALF] = 0;
1168 g_scores[SCORE_CT][SCORE_FIRST_HALF] = 0;
1169 }
1170 else
1171 {
1172 // second half
1173 g_scores[SCORE_T][SCORE_SECOND_HALF] = 0;
1174 g_scores[SCORE_CT][SCORE_SECOND_HALF] = 0;
1175 }
1176 }
1177 else
1178 {
1179 // overtime
1180 if (g_first_half)
1181 {
1182 // first half overtime
1183 g_scores_overtime[SCORE_T][g_overtime_count][SCORE_FIRST_HALF] = 0;
1184 g_scores_overtime[SCORE_CT][g_overtime_count][SCORE_FIRST_HALF] = 0;
1185 }
1186 else
1187 {
1188 // second half overtime
1189 g_scores_overtime[SCORE_T][g_overtime_count][SCORE_SECOND_HALF] = 0;
1190 g_scores_overtime[SCORE_CT][g_overtime_count][SCORE_SECOND_HALF] = 0;
1191 }
1192 }
1193}
1194
1195public Action ReadyToggle(int client, int args)
1196{
1197 if (!IsActive(client, false))
1198 {
1199 // warmod is disabled
1200 return Plugin_Handled;
1201 }
1202
1203 if (!IsAdminCmd(client, false))
1204 {
1205 // not allowed, rcon only
1206 return Plugin_Handled;
1207 }
1208
1209 if (IsLive(client, false))
1210 {
1211 // match is live
1212 return Plugin_Handled;
1213 }
1214
1215 // change ready state
1216 ReadyChangeAll(client, false, true);
1217 SetAllCancelled(false);
1218
1219 if (!IsReadyEnabled(client, true))
1220 {
1221 // display ready system
1222 ReadySystem(true);
1223 ShowInfo(client, true, false, 0);
1224 if (client != 0)
1225 {
1226 PrintToConsole(client, "[%s] %t", CHAT_PREFIX, "Ready System Enabled");
1227 }
1228 else
1229 {
1230 PrintToServer("[%s] %T", CHAT_PREFIX, "Ready System Enabled", LANG_SERVER);
1231 }
1232 // check if anyone is ready
1233 CheckReady();
1234 }
1235 else
1236 {
1237 // disable ready system
1238 ShowInfo(client, false, false, 1);
1239 ReadySystem(false);
1240 if (client != 0)
1241 {
1242 PrintToConsole(client, "[%s] %t", CHAT_PREFIX, "Ready System Disabled");
1243 }
1244 else
1245 {
1246 PrintToServer("[%s] %T", CHAT_PREFIX, "Ready System Disabled", LANG_SERVER);
1247 }
1248 }
1249
1250 LogAction(client, -1, "\"ready_toggle\" (player \"%L\")", client);
1251
1252 return Plugin_Handled;
1253}
1254
1255public Action ActiveToggle(int client, int args)
1256{
1257 if (!IsAdminCmd(client, false))
1258 {
1259 // not allowed, rcon only
1260 return Plugin_Handled;
1261 }
1262
1263 if (GetConVarBool(wm_active))
1264 {
1265 // disable warmod
1266 SetConVarBool(wm_active, false);
1267 if (client != 0)
1268 {
1269 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Inactive");
1270 }
1271 else
1272 {
1273 PrintToServer("[%s] %T", CHAT_PREFIX, "Set Inactive", LANG_SERVER);
1274 }
1275 }
1276 else
1277 {
1278 // enable warmod
1279 SetConVarBool(wm_active, true);
1280 if (client != 0)
1281 {
1282 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Active");
1283 }
1284 else
1285 {
1286 PrintToServer("[%s] %T", CHAT_PREFIX, "Set Active", LANG_SERVER);
1287 }
1288 }
1289
1290 LogAction(client, -1, "\"active_toggle\" (player \"%L\")", client);
1291
1292 return Plugin_Handled;
1293}
1294
1295//Pause and Unpause Commands + timers
1296static void AutoPause()
1297{
1298 if (g_match && !g_auto_pause)
1299 {
1300 if (GetTeamClientCount(CS_TEAM_CT) < (GetConVarInt(wm_max_players)/2))
1301 {
1302 char name[64];
1303 if (StrEqual(g_ct_name, ""))
1304 {
1305 Format(name, sizeof(name), DEFAULT_CT_NAME);
1306 }
1307 else
1308 {
1309 Format(name, sizeof(name), g_ct_name);
1310 }
1311 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Auto Pause Notice", LANG_SERVER, name);
1312 if (GameRules_GetProp("m_bFreezePeriod") == 1)
1313 {
1314 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Auto Unpause Notice", LANG_SERVER, name);
1315 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
1316 ServerCommand("mp_pause_match 1");
1317 g_auto_pause = false;
1318 }
1319 else
1320 {
1321 g_auto_pause = true;
1322 }
1323 }
1324 else if (GetTeamClientCount(CS_TEAM_T) < (GetConVarInt(wm_max_players)/2))
1325 {
1326 char name[64];
1327 if (StrEqual(g_t_name, ""))
1328 {
1329 Format(name, sizeof(name), DEFAULT_T_NAME);
1330 }
1331 else
1332 {
1333 Format(name, sizeof(name), g_t_name);
1334 }
1335 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Auto Pause Notice", LANG_SERVER, name);
1336 if (GameRules_GetProp("m_bFreezePeriod") == 1)
1337 {
1338 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Auto Unpause Notice", LANG_SERVER, name);
1339 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
1340 ServerCommand("mp_pause_match 1");
1341 g_auto_pause = false;
1342 }
1343 else
1344 {
1345 g_auto_pause = true;
1346 }
1347 }
1348 }
1349}
1350
1351public Action Pause(int client, int args)
1352{
1353 if (client == 0){
1354 return Plugin_Handled;
1355 }
1356
1357 if (GetConVarBool(sv_pausable) && g_live)
1358 {
1359 if (GetConVarBool(wm_pause_confirm))
1360 {
1361 if (GetClientTeam(client) == 2 && g_pause_offered_ct == true)
1362 {
1363 if (g_h_stored_timer_p != INVALID_HANDLE)
1364 {
1365 KillTimer(g_h_stored_timer_p);
1366 g_h_stored_timer_p = INVALID_HANDLE;
1367 }
1368
1369 g_pause_offered_ct = false;
1370 g_ct_pause_count++;
1371
1372 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Freeze Time", LANG_SERVER);
1373 g_pause_freezetime = true;
1374
1375 if (FreezeTime)
1376 {
1377 //Pause command fire on round end May change to on round start
1378 if (g_pause_freezetime == true)
1379 {
1380 g_pause_freezetime = false;
1381 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
1382 if (GetConVarBool(wm_auto_unpause))
1383 {
1384 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %i %T", CHAT_PREFIX, GetConVarInt(wm_auto_unpause_delay), "Unpause Timer", LANG_SERVER);
1385 g_h_stored_timer = CreateTimer(GetConVarFloat(wm_auto_unpause_delay), UnPauseTimer);
1386 }
1387 ServerCommand("mp_pause_match 1");
1388 }
1389 }
1390 return Plugin_Handled;
1391 }
1392 else if (GetClientTeam(client) == 3 && g_pause_offered_t == true)
1393 {
1394 if (g_h_stored_timer_p != INVALID_HANDLE)
1395 {
1396 KillTimer(g_h_stored_timer_p);
1397 g_h_stored_timer_p = INVALID_HANDLE;
1398 }
1399 g_pause_offered_t = false;
1400 g_t_pause_count++;
1401
1402 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Round End", LANG_SERVER);
1403 g_pause_freezetime = true;
1404
1405
1406 if (FreezeTime)
1407 {
1408 //Pause command fire on round end May change to on round start
1409 if (g_pause_freezetime == true)
1410 {
1411 g_pause_freezetime = false;
1412 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
1413 if (GetConVarBool(wm_auto_unpause))
1414 {
1415 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %i %T", CHAT_PREFIX, GetConVarInt(wm_auto_unpause_delay), "Unpause Timer", LANG_SERVER);
1416 g_h_stored_timer = CreateTimer(GetConVarFloat(wm_auto_unpause_delay), UnPauseTimer);
1417 }
1418 ServerCommand("mp_pause_match 1");
1419 }
1420 }
1421 return Plugin_Handled;
1422 }
1423 else if (GetClientTeam(client) == 2 && g_t_pause_count == GetConVarInt(wm_pause_limit))
1424 {
1425 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Limit", LANG_SERVER);
1426 }
1427 else if (GetClientTeam(client) == 3 && g_ct_pause_count == GetConVarInt(wm_pause_limit))
1428 {
1429 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Limit", LANG_SERVER);
1430 }
1431 else if (GetClientTeam(client) < 2 )
1432 {
1433 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Non-player", LANG_SERVER);
1434 }
1435 else if (GetClientTeam(client) == 3 && g_ct_pause_count != GetConVarInt(wm_pause_limit) && g_pause_offered_ct == false)
1436 {
1437 g_pause_offered_ct = true;
1438 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_ct_name, "Pause Offer", LANG_SERVER);
1439 g_h_stored_timer_p = CreateTimer(30.0, PauseTimeout);
1440 }
1441 else if (GetClientTeam(client) == 2 && g_t_pause_count != GetConVarInt(wm_pause_limit) && g_pause_offered_t == false)
1442 {
1443 g_pause_offered_t = true;
1444 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_t_name, "Pause Offer", LANG_SERVER);
1445 g_h_stored_timer_p = CreateTimer(30.0, PauseTimeout);
1446 }
1447 }
1448 else if (GetClientTeam(client) == 3 && g_ct_pause_count != GetConVarInt(wm_pause_limit) && !GetConVarBool(wm_pause_confirm))
1449 {
1450 char player_name[64];
1451 char authid[32];
1452
1453 GetClientName(client, player_name, sizeof(player_name));
1454 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
1455
1456 EscapeString(player_name, sizeof(player_name));
1457 EscapeString(authid, sizeof(authid));
1458
1459 g_ct_pause_count++;
1460 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s - %s has paused the match", CHAT_PREFIX, player_name, g_ct_name);
1461 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Freeze Time", LANG_SERVER);
1462 g_pause_freezetime = true;
1463
1464
1465 LogEvent("{\"event\": \"match_paused\", \"round\": %i, \"team\": 3, \"name\": \"%s\", \"steamId\": \"%s\"}", g_round, player_name, authid);
1466
1467 if (FreezeTime)
1468 {
1469 //Pause command fire on round end May change to on round start
1470 if (g_pause_freezetime == true)
1471 {
1472 g_pause_freezetime = false;
1473 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
1474 if (GetConVarBool(wm_auto_unpause))
1475 {
1476 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %i %T", CHAT_PREFIX, GetConVarInt(wm_auto_unpause_delay), "Unpause Timer", LANG_SERVER);
1477 g_h_stored_timer = CreateTimer(GetConVarFloat(wm_auto_unpause_delay), UnPauseTimer);
1478 }
1479 ServerCommand("mp_pause_match 1");
1480 }
1481 }
1482 return Plugin_Handled;
1483 }
1484 else if (GetClientTeam(client) == 2 && g_t_pause_count != GetConVarInt(wm_pause_limit) && GetConVarBool(wm_pause_confirm) == false)
1485 {
1486 char player_name[64];
1487 char authid[32];
1488
1489 GetClientName(client, player_name, sizeof(player_name));
1490 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
1491
1492 EscapeString(player_name, sizeof(player_name));
1493 EscapeString(authid, sizeof(authid));
1494
1495 g_t_pause_count++;
1496 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s - %s has paused the match", CHAT_PREFIX, player_name, g_t_name);
1497 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Freeze Time", LANG_SERVER);
1498 g_pause_freezetime = true;
1499
1500
1501 LogEvent("{\"event\": \"match_paused\", \"round\": %i, \"team\": 2, \"name\": \"%s\", \"steamId\": \"%s\"}", g_round, player_name, authid);
1502
1503 if (FreezeTime)
1504 {
1505 //Pause command fire on round end May change to on round start
1506 if (g_pause_freezetime == true)
1507 {
1508 g_pause_freezetime = false;
1509 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
1510 if (GetConVarBool(wm_auto_unpause))
1511 {
1512 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %i %T", CHAT_PREFIX, GetConVarInt(wm_auto_unpause_delay), "Unpause Timer", LANG_SERVER);
1513 g_h_stored_timer = CreateTimer(GetConVarFloat(wm_auto_unpause_delay), UnPauseTimer);
1514 }
1515 ServerCommand("mp_pause_match 1");
1516 }
1517 }
1518 return Plugin_Handled;
1519 }
1520 else if (GetClientTeam(client) == 2 && g_t_pause_count == GetConVarInt(wm_pause_limit))
1521 {
1522 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Limit", LANG_SERVER);
1523 }
1524 else if (GetClientTeam(client) == 3 && g_ct_pause_count == GetConVarInt(wm_pause_limit))
1525 {
1526 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Limit", LANG_SERVER);
1527 }
1528 else if (GetClientTeam(client) < 2)
1529 {
1530 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Non-player", LANG_SERVER);
1531 }
1532 }
1533 else if (!g_live)
1534 {
1535 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Match Not In Progress", LANG_SERVER);
1536 }
1537 else
1538 {
1539 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Not Enabled", LANG_SERVER);
1540 }
1541
1542 return Plugin_Handled;
1543}
1544
1545public Action Unpause(int client, int args)
1546{
1547 if (IsPaused() && client != 0) {
1548 if (GetConVarBool(wm_unpause_confirm))
1549 {
1550 if (GetClientTeam(client) == 3 && g_pause_offered_ct == false && g_pause_offered_t == false)
1551 {
1552 g_pause_offered_ct = true;
1553 for (int i = 1; i <= MaxClients; i++)
1554 {
1555 if (IsValidClient(i))
1556 {
1557 PrintToConsole(i, "[%s] %s %T", CHAT_PREFIX, g_ct_name, "Unpause Offer", LANG_SERVER);
1558 }
1559 }
1560 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_ct_name, "Unpause Offer", LANG_SERVER);
1561 }
1562 else if (GetClientTeam(client) == 2 && g_pause_offered_t == false && g_pause_offered_ct == false)
1563 {
1564 g_pause_offered_t = true;
1565 for (int i = 1; i <= MaxClients; i++)
1566 {
1567 if (IsValidClient(i))
1568 {
1569 PrintToConsole(i, "[%s] %s %T", CHAT_PREFIX, g_t_name, "Unpause Offer", LANG_SERVER);
1570 }
1571 }
1572 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_t_name, "Unpause Offer", LANG_SERVER);
1573 }
1574 else if (GetClientTeam(client) == 2 && g_pause_offered_ct == true)
1575 {
1576 g_pause_offered_ct = false;
1577
1578 ServerCommand("mp_unpause_match 1");
1579 if (g_h_stored_timer != INVALID_HANDLE)
1580 {
1581 KillTimer(g_h_stored_timer);
1582 g_h_stored_timer = INVALID_HANDLE;
1583 }
1584 }
1585 else if (GetClientTeam(client) == 3 && g_pause_offered_t == true)
1586 {
1587 g_pause_offered_t = false;
1588
1589 ServerCommand("mp_unpause_match 1");
1590 if (g_h_stored_timer != INVALID_HANDLE)
1591 {
1592 KillTimer(g_h_stored_timer);
1593 g_h_stored_timer = INVALID_HANDLE;
1594 }
1595 }
1596 else if (GetClientTeam(client) < 2 )
1597 {
1598 PrintToConsole(client, "[%s] %T", CHAT_PREFIX, "Unpause Non-player", LANG_SERVER);
1599 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Non-player", LANG_SERVER);
1600 }
1601 }
1602 else
1603 {
1604 if (GetClientTeam(client) == 2)
1605 {
1606 char player_name[64];
1607 char authid[32];
1608
1609 GetClientName(client, player_name, sizeof(player_name));
1610 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
1611
1612 EscapeString(player_name, sizeof(player_name));
1613 EscapeString(authid, sizeof(authid));
1614
1615 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s - %s %T", CHAT_PREFIX, player_name, g_t_name, "Unpaused Match", LANG_SERVER);
1616
1617 ServerCommand("mp_unpause_match 1");
1618 if (g_h_stored_timer != INVALID_HANDLE)
1619 {
1620 KillTimer(g_h_stored_timer);
1621 g_h_stored_timer = INVALID_HANDLE;
1622 }
1623
1624 LogEvent("{\"event\": \"match_resumed\", \"round\": %i, \"team\": 2, \"name\": \"%s\", \"steamId\": \"%s\"}", g_round, player_name, authid);
1625 }
1626 else if (GetClientTeam(client) == 3)
1627 {
1628 char player_name[64];
1629 char authid[32];
1630
1631 GetClientName(client, player_name, sizeof(player_name));
1632 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
1633
1634 EscapeString(player_name, sizeof(player_name));
1635 EscapeString(authid, sizeof(authid));
1636
1637 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s - %s %T", CHAT_PREFIX, player_name, g_ct_name, "Unpaused Match", LANG_SERVER);
1638
1639 ServerCommand("mp_unpause_match 1");
1640 if (g_h_stored_timer != INVALID_HANDLE)
1641 {
1642 KillTimer(g_h_stored_timer);
1643 g_h_stored_timer = INVALID_HANDLE;
1644 }
1645 LogEvent("{\"event\": \"match_resumed\", \"round\": %i, \"team\": 3, \"name\": \"%s\", \"steamId\": \"%s\"}", g_round, player_name, authid);
1646 }
1647 else if (GetClientTeam(client) < 2 )
1648 {
1649 PrintToConsole(client, "[%s] %T", CHAT_PREFIX, "Unpause Non-player", LANG_SERVER);
1650 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Non-player", LANG_SERVER);
1651 }
1652 }
1653 }
1654 return Plugin_Handled;
1655}
1656
1657public Action UnpauseMatch(int client, const char[]command, int args)
1658{
1659 g_h_stored_timer = INVALID_HANDLE;
1660 g_pause_offered_ct = false;
1661 g_pause_offered_t = false;
1662 return Plugin_Continue;
1663}
1664
1665public Action PauseTimeout(Handle timer)
1666{
1667 g_h_stored_timer_p = INVALID_HANDLE;
1668 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Pause Not Confirmed", LANG_SERVER);
1669 g_pause_offered_ct = false;
1670 g_pause_offered_t = false;
1671}
1672
1673public Action UnPauseTimer(Handle timer)
1674{
1675 g_h_stored_timer = INVALID_HANDLE;
1676 if (IsPaused())
1677 {
1678 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Auto", LANG_SERVER);
1679 }
1680 ServerCommand("mp_unpause_match 1");
1681 g_pause_offered_ct = false;
1682 g_pause_offered_t = false;
1683}
1684
1685public Action ResetMatchTimer(Handle timer)
1686{
1687 ResetMatch(true, true);
1688}
1689
1690stock bool IsValidClient(int client)
1691{
1692 if (client <= 0 || client > MaxClients)
1693 {
1694 return false;
1695 }
1696
1697 if (!IsClientInGame(client))
1698 {
1699 return false;
1700 }
1701
1702 if (IsFakeClient(client))
1703 {
1704 return false;
1705 }
1706
1707 if (!IsClientConnected(client))
1708 {
1709 return false;
1710 }
1711
1712 if (IsClientSourceTV(client) || IsClientReplay(client))
1713 {
1714 return false;
1715 }
1716
1717 return true;
1718}
1719
1720public Action ChangeMinReady(int client, int args)
1721{
1722 if (!IsActive(client, false))
1723 {
1724 // warmod is disabled
1725 return Plugin_Handled;
1726 }
1727
1728 if (!IsAdminCmd(client, false))
1729 {
1730 // not allowed, rcon only
1731 return Plugin_Handled;
1732 }
1733
1734 char arg[128];
1735 int minready;
1736
1737 if (GetCmdArgs() > 0)
1738 {
1739 // setter
1740 GetCmdArg(1, arg, sizeof(arg));
1741 minready = StringToInt(arg);
1742 SetConVarInt(wm_min_ready, minready);
1743 if (client != 0)
1744 {
1745 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Minready", minready);
1746 }
1747 else
1748 {
1749 PrintToServer("[%s] %T", CHAT_PREFIX, "Set Minready", LANG_SERVER, minready);
1750 }
1751 LogAction(client, -1, "\"set_min_ready\" (player \"%L\") (min_ready \"%d\")", client, minready);
1752 }
1753 else
1754 {
1755 // getter
1756 if (client != 0)
1757 {
1758 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 wm_min_ready = %d", CHAT_PREFIX, GetConVarInt(wm_min_ready));
1759 }
1760 else
1761 {
1762 PrintToServer("[%s] - wm_min_ready = %d", CHAT_PREFIX, GetConVarInt(wm_min_ready));
1763 }
1764 }
1765
1766 return Plugin_Handled;
1767}
1768
1769public Action ChangeMaxRounds(int client, int args)
1770{
1771 if (!IsActive(client, false))
1772 {
1773 // warmod is disabled
1774 return Plugin_Handled;
1775 }
1776
1777 if (!IsAdminCmd(client, false))
1778 {
1779 // not allowed, rcon only
1780 return Plugin_Handled;
1781 }
1782
1783 char arg[128];
1784 int maxrounds;
1785
1786 if (GetCmdArgs() > 0)
1787 {
1788 // setter
1789 GetCmdArg(1, arg, sizeof(arg));
1790 maxrounds = StringToInt(arg);
1791 int rounds = (maxrounds*2);
1792 ServerCommand("mp_maxrounds %i", rounds);
1793 if (client != 0)
1794 {
1795 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Maxrounds", maxrounds);
1796 }
1797 else
1798 {
1799 PrintToServer("[%s] %T", CHAT_PREFIX, "Set Maxrounds", LANG_SERVER, maxrounds);
1800 }
1801 LogAction(client, -1, "\"set_max_rounds\" (player \"%L\") (max_rounds \"%d\")", client, maxrounds);
1802 }
1803
1804 return Plugin_Handled;
1805}
1806
1807public Action ChangePassword(int client, int args)
1808{
1809 if (!IsActive(client, false))
1810 {
1811 // warmod is disabled
1812 return Plugin_Handled;
1813 }
1814
1815 if (!IsAdminCmd(client, false))
1816 {
1817 // not allowed, rcon only
1818 return Plugin_Handled;
1819 }
1820
1821 char new_password[128];
1822
1823 if (GetCmdArgs() > 0)
1824 {
1825 // setter
1826 GetCmdArg(1, new_password, sizeof(new_password));
1827 ServerCommand("sv_password \"%s\"", new_password);
1828
1829 if (client != 0)
1830 {
1831 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Password", new_password);
1832 }
1833 else
1834 {
1835 PrintToServer("[%s] %T", CHAT_PREFIX, "Set Password", LANG_SERVER, new_password);
1836 }
1837
1838 LogAction(client, -1, "\"set_password\" (player \"%L\")", client);
1839 }
1840 else
1841 {
1842 // getter
1843 char passwd[128];
1844 GetConVarString(FindConVar("sv_password"), passwd, sizeof(passwd));
1845 if (client != 0)
1846 {
1847 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 sv_password = '%s'", CHAT_PREFIX, passwd);
1848 }
1849 else
1850 {
1851 PrintToServer("[%s] - sv_password = '%s'", CHAT_PREFIX, passwd);
1852 }
1853 }
1854
1855 return Plugin_Handled;
1856}
1857
1858public Action ReadyUp(int client, int args)
1859{
1860 if (!IsActive(client, false))
1861 {
1862 // warmod is disabled
1863 return Plugin_Handled;
1864 }
1865
1866 if (!IsReadyEnabled(client, false) || client == 0)
1867 {
1868 // ready system not enabled or client is the console
1869 return Plugin_Handled;
1870 }
1871
1872 if (IsLive(client, false))
1873 {
1874 // match already live
1875 return Plugin_Handled;
1876 }
1877
1878 if (g_player_list[client] != PLAYER_READY)
1879 {
1880 if (GetClientTeam(client) > 1)
1881 {
1882 // set player as ready
1883 ReadyServ(client, true, false, true, false);
1884 }
1885 else
1886 {
1887 // player is not on a valid team
1888 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Not on Team");
1889 }
1890 }
1891 else
1892 {
1893 // player is already ready
1894 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Already Ready");
1895 }
1896 return Plugin_Handled;
1897}
1898
1899public Action ReadyDown(int client, int args)
1900{
1901 if (!IsActive(client, false))
1902 {
1903 // warmod is disabled
1904 return Plugin_Handled;
1905 }
1906
1907 if (!IsReadyEnabled(client, false) || client == 0)
1908 {
1909 // ready system not enabled or client is the console
1910 return Plugin_Handled;
1911 }
1912
1913 if (IsLive(client, false))
1914 {
1915 return Plugin_Handled;
1916 }
1917
1918 if (g_player_list[client] != PLAYER_UNREADY)
1919 {
1920 if (GetClientTeam(client) > 1)
1921 {
1922 // set player as ready
1923 ReadyServ(client, false, false, true, false);
1924 }
1925 else
1926 {
1927 // player is not on a valid team
1928 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Not on Team");
1929 }
1930 }
1931 else
1932 {
1933 // player is already ready
1934 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Already Not Ready");
1935 }
1936 return Plugin_Handled;
1937}
1938
1939public Action ForceAllReady(int client, int args)
1940{
1941 if (!IsActive(client, false))
1942 {
1943 // warmod is disabled
1944 return Plugin_Handled;
1945 }
1946
1947 if (!IsAdminCmd(client, false))
1948 {
1949 // not allowed, rcon only
1950 return Plugin_Handled;
1951 }
1952
1953 if (g_ready_enabled)
1954 {
1955 // force all players to ready
1956 ReadyChangeAll(client, true, true);
1957 // check if there is enough players
1958 CheckReady();
1959
1960 if (client != 0)
1961 {
1962 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Forced Ready");
1963 }
1964 else
1965 {
1966 PrintToConsole(client, "[%s] %T", CHAT_PREFIX, "Forced Ready", LANG_SERVER);
1967 }
1968
1969 // display ready system
1970 ShowInfo(client, true, false, 0);
1971 }
1972 else
1973 {
1974 if (client != 0)
1975 {
1976 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Ready System Disabled2");
1977 }
1978 else
1979 {
1980 PrintToConsole(client, "[%s] %T", CHAT_PREFIX, "Ready System Disabled2", LANG_SERVER);
1981 }
1982 }
1983
1984 LogAction(client, -1, "\"force_all_ready\" (player \"%L\")", client);
1985
1986 return Plugin_Handled;
1987}
1988
1989public Action ForceAllUnready(int client, int args)
1990{
1991 if (!IsActive(client, false))
1992 {
1993 // warmod is disabled
1994 return Plugin_Handled;
1995 }
1996
1997 if (!IsAdminCmd(client, false))
1998 {
1999 // not allowed, rcon only
2000 return Plugin_Handled;
2001 }
2002
2003 if (g_ready_enabled)
2004 {
2005 // force all players to unready
2006 ReadyChangeAll(client, false, true);
2007 CheckReady();
2008
2009 if (client != 0)
2010 {
2011 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Forced Not Ready");
2012 }
2013 else
2014 {
2015 PrintToServer("[%s] %T", CHAT_PREFIX, "Forced Not Ready", LANG_SERVER);
2016 }
2017
2018 // display readym system
2019 ShowInfo(client, true, false, 0);
2020 }
2021 else
2022 {
2023 if (client != 0)
2024 {
2025 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Ready System Disabled2");
2026 }
2027 else
2028 {
2029 PrintToServer("[%s] %T", CHAT_PREFIX, "Ready System Disabled2", LANG_SERVER);
2030 }
2031 }
2032
2033 LogAction(client, -1, "\"force_all_unready\" (player \"%L\")", client);
2034
2035 return Plugin_Handled;
2036}
2037
2038public Action ForceAllSpectate(int client, int args)
2039{
2040 if (!IsActive(client, false))
2041 {
2042 // warmod is disabled
2043 return Plugin_Handled;
2044 }
2045
2046 if (!IsAdminCmd(client, false))
2047 {
2048 // not allowed, rcon only
2049 return Plugin_Handled;
2050 }
2051
2052 // reset half and restart
2053 ForceSpectate();
2054 ResetHalf(true);
2055 ShowInfo(0, false, false, 1);
2056 SetAllCancelled(false);
2057 ReadySystem(false);
2058
2059 LogAction(client, -1, "\"force__all_spec\" (player \"%L\")", client);
2060
2061 return Plugin_Handled;
2062}
2063
2064void ForceSpectate()
2065{
2066 for (int i = 1; i <= MaxClients; i++)
2067 {
2068 if (IsClientInGame(i) && !IsFakeClient(i))
2069 {
2070 if (GetClientTeam(i) != 1)
2071 {
2072 ChangeClientTeam(i, 1);
2073 }
2074 else
2075 {
2076 PrintToChat(i, "You are already a spectator.");
2077 }
2078 }
2079 }
2080}
2081
2082public Action PlayOut_Offer(int client, int args)
2083{
2084 if (client == 0)
2085 {
2086 PlayOut(client, args);
2087 return Plugin_Handled;
2088 }
2089
2090 if (!IsActive(client, false))
2091 {
2092 // warmod is disabled
2093 return Plugin_Handled;
2094 }
2095
2096 if (GetClientTeam(client) == 2)
2097 {
2098 if (playout_offer_t)
2099 {
2100 return Plugin_Handled;
2101 }
2102 playout_offer_t = true;
2103 }
2104 else if (GetClientTeam(client) == 3)
2105 {
2106 if (playout_offer_ct)
2107 {
2108 return Plugin_Handled;
2109 }
2110 playout_offer_ct = true;
2111 }
2112 else
2113 {
2114 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Non-player", LANG_SERVER);
2115 return Plugin_Handled;
2116 }
2117
2118 if (playout_offer_ct && playout_offer_t)
2119 {
2120 if (g_h_stored_timer_pl != INVALID_HANDLE)
2121 {
2122 KillTimer(g_h_stored_timer_pl);
2123 g_h_stored_timer_pl = INVALID_HANDLE;
2124 }
2125
2126 char match_config[64];
2127 GetConVarString(wm_playout_config, match_config, sizeof(match_config));
2128
2129 if (!StrEqual(match_config, ""))
2130 {
2131 ServerCommand("exec %s", match_config);
2132 }
2133 g_h_stored_timer_pl = CreateTimer(30.0, PlayOutTimeout);
2134 return Plugin_Handled;
2135 }
2136 else if (playout_offer_ct && !playout_offer_t)
2137 {
2138 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorist %T", CHAT_PREFIX, "PlayOut Offer", LANG_SERVER);
2139 g_h_stored_timer_pl = CreateTimer(30.0, PlayOutTimeout);
2140 }
2141 else if (!playout_offer_ct && playout_offer_t)
2142 {
2143 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorist %T", CHAT_PREFIX, "PlayOut Offer", LANG_SERVER);
2144 g_h_stored_timer_pl = CreateTimer(30.0, PlayOutTimeout);
2145 }
2146 return Plugin_Handled;
2147}
2148
2149public Action PlayOutTimeout(Handle timer)
2150{
2151 g_h_stored_timer_pl = INVALID_HANDLE;
2152 if (!playout_offer_ct || !playout_offer_t)
2153 {
2154 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "PlayOut Offer Not Confirmed", LANG_SERVER);
2155 }
2156 playout_offer_t = false;
2157 playout_offer_ct = false;
2158}
2159
2160public Action PlayOut(int client, int args)
2161{
2162 if (!IsActive(client, false))
2163 {
2164 // warmod is disabled
2165 return Plugin_Handled;
2166 }
2167
2168 char match_config[64];
2169 GetConVarString(wm_playout_config, match_config, sizeof(match_config));
2170
2171 if (!StrEqual(match_config, ""))
2172 {
2173 ServerCommand("exec %s", match_config);
2174 }
2175 return Plugin_Handled;
2176}
2177
2178public Action OverTime_Offer(int client, int args)
2179{
2180 if (client == 0)
2181 {
2182 OverTime(client, args);
2183 return Plugin_Handled;
2184 }
2185
2186 if (!IsActive(client, false))
2187 {
2188 // warmod is disabled
2189 return Plugin_Handled;
2190 }
2191
2192 if (GetClientTeam(client) == 2)
2193 {
2194 if (overtime_offer_t)
2195 {
2196 return Plugin_Handled;
2197 }
2198 overtime_offer_t = true;
2199 }
2200 else if (GetClientTeam(client) == 3)
2201 {
2202 if (overtime_offer_ct)
2203 {
2204 return Plugin_Handled;
2205 }
2206 overtime_offer_ct = true;
2207 }
2208 else
2209 {
2210 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Non-player", LANG_SERVER);
2211 return Plugin_Handled;
2212 }
2213
2214 if (overtime_offer_ct && overtime_offer_t)
2215 {
2216 if (g_h_stored_timer_ot != INVALID_HANDLE)
2217 {
2218 KillTimer(g_h_stored_timer_ot);
2219 g_h_stored_timer_ot = INVALID_HANDLE;
2220 }
2221
2222 char match_config[64];
2223 GetConVarString(wm_overtime_config, match_config, sizeof(match_config));
2224
2225 if (!StrEqual(match_config, ""))
2226 {
2227 ServerCommand("exec %s", match_config);
2228 }
2229 g_h_stored_timer_ot = CreateTimer(30.0, OverTimeTimeout);
2230 return Plugin_Handled;
2231 }
2232 else if (overtime_offer_ct && !overtime_offer_t)
2233 {
2234 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorist %T", CHAT_PREFIX, "OverTime Offer", LANG_SERVER);
2235 g_h_stored_timer_ot = CreateTimer(30.0, OverTimeTimeout);
2236 }
2237 else if (!overtime_offer_ct && overtime_offer_t)
2238 {
2239 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorist %T", CHAT_PREFIX, "OverTime Offer", LANG_SERVER);
2240 g_h_stored_timer_ot = CreateTimer(30.0, OverTimeTimeout);
2241 }
2242 return Plugin_Handled;
2243}
2244
2245public Action OverTimeTimeout(Handle timer)
2246{
2247 g_h_stored_timer_ot = INVALID_HANDLE;
2248 if (!overtime_offer_ct || !overtime_offer_t)
2249 {
2250 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "OverTime Offer Not Confirmed", LANG_SERVER);
2251 }
2252 overtime_offer_t = false;
2253 overtime_offer_ct = false;
2254}
2255
2256public Action OverTime(int client, int args)
2257{
2258 if (!IsActive(client, false))
2259 {
2260 // warmod is disabled
2261 return Plugin_Handled;
2262 }
2263
2264 if (!IsAdminCmd(client, false))
2265 {
2266 // not allowed, rcon only
2267 return Plugin_Handled;
2268 }
2269
2270 char match_config[64];
2271 GetConVarString(wm_overtime_config, match_config, sizeof(match_config));
2272
2273 if (!g_live && !StrEqual(match_config, ""))
2274 {
2275 ServerCommand("exec %s", match_config);
2276 }
2277 return Plugin_Handled;
2278}
2279
2280public Action Default_Offer(int client, int args)
2281{
2282 if (client == 0)
2283 {
2284 Default(client, args);
2285 return Plugin_Handled;
2286 }
2287
2288 if (!IsActive(client, false))
2289 {
2290 // warmod is disabled
2291 return Plugin_Handled;
2292 }
2293
2294 if (GetClientTeam(client) == 2)
2295 {
2296 if (default_offer_t)
2297 {
2298 return Plugin_Handled;
2299 }
2300 default_offer_t = true;
2301 }
2302 else if (GetClientTeam(client) == 3)
2303 {
2304 if (default_offer_ct)
2305 {
2306 return Plugin_Handled;
2307 }
2308 default_offer_ct = true;
2309 }
2310 else
2311 {
2312 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Non-player", LANG_SERVER);
2313 return Plugin_Handled;
2314 }
2315
2316 if (default_offer_ct && default_offer_t)
2317 {
2318 if (g_h_stored_timer_def != INVALID_HANDLE)
2319 {
2320 KillTimer(g_h_stored_timer_def);
2321 g_h_stored_timer_def = INVALID_HANDLE;
2322 }
2323
2324 char match_config[64];
2325 GetConVarString(wm_default_config, match_config, sizeof(match_config));
2326
2327 if (!StrEqual(match_config, ""))
2328 {
2329 ServerCommand("exec %s", match_config);
2330 }
2331
2332 g_h_stored_timer_def = CreateTimer(30.0, DefaultTimeout);
2333 return Plugin_Handled;
2334 }
2335 else if (default_offer_ct && !default_offer_t)
2336 {
2337 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorist %T", CHAT_PREFIX, "Default Offer", LANG_SERVER);
2338 g_h_stored_timer_def = CreateTimer(30.0, DefaultTimeout);
2339 }
2340 else if (!default_offer_ct && default_offer_t)
2341 {
2342 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorist %T", CHAT_PREFIX, "Default Offer", LANG_SERVER);
2343 g_h_stored_timer_def = CreateTimer(30.0, DefaultTimeout);
2344 }
2345 return Plugin_Handled;
2346}
2347
2348public Action DefaultTimeout(Handle timer)
2349{
2350 g_h_stored_timer_def = INVALID_HANDLE;
2351 if (!default_offer_ct || !default_offer_t)
2352 {
2353 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Default Offer Not Confirmed", LANG_SERVER);
2354 }
2355 default_offer_t = false;
2356 default_offer_ct = false;
2357}
2358
2359public Action Default(int client, int args)
2360{
2361 if (!IsActive(client, false))
2362 {
2363 // warmod is disabled
2364 return Plugin_Handled;
2365 }
2366
2367 if (!IsAdminCmd(client, false))
2368 {
2369 // not allowed, rcon only
2370 return Plugin_Handled;
2371 }
2372
2373 char match_config[64];
2374 GetConVarString(wm_default_config, match_config, sizeof(match_config));
2375
2376 if (!g_live && !StrEqual(match_config, ""))
2377 {
2378 ServerCommand("exec %s", match_config);
2379 }
2380 return Plugin_Handled;
2381}
2382
2383public Action ForceStart(int client, int args)
2384{
2385 if (!IsActive(client, false))
2386 {
2387 // warmod is disabled
2388 return Plugin_Handled;
2389 }
2390
2391 if (!IsAdminCmd(client, false))
2392 {
2393 // not allowed, rcon only
2394 return Plugin_Handled;
2395 }
2396
2397 if (!g_t_had_knife && !g_match && GetConVarBool(wm_auto_knife))
2398 {
2399 ShowInfo(0, false, false, 1);
2400 SetAllCancelled(false);
2401 ReadySystem(false);
2402 KnifeOn3(0, 0);
2403 LogAction(client, -1, "\"force_start\" (player \"%L\")", client);
2404 return Plugin_Handled;
2405 }
2406
2407 if (g_restore)
2408 {
2409 ShowInfo(0, false, false, 1);
2410 SetAllCancelled(false);
2411 ReadySystem(false);
2412 LiveOn3(true);
2413 LogAction(client, -1, "\"force_start\" (player \"%L\")", client);
2414 return Plugin_Handled;
2415 }
2416 // reset half and restart
2417 ResetHalf(true);
2418 ShowInfo(0, false, false, 1);
2419 SetAllCancelled(false);
2420 ReadySystem(false);
2421 ServerCommand("mp_warmup_end");
2422 LiveOn3(true);
2423
2424 LogAction(client, -1, "\"force_start\" (player \"%L\")", client);
2425
2426 return Plugin_Handled;
2427}
2428
2429public Action ForceEnd(int client, int args)
2430{
2431 if (!IsActive(client, false))
2432 {
2433 // warmod is disabled
2434 return Plugin_Handled;
2435 }
2436
2437 if (!IsAdminCmd(client, false))
2438 {
2439 // not allowed, rcon only
2440 return Plugin_Handled;
2441 }
2442
2443 if (GetConVarBool(wm_stats_enabled))
2444 {
2445 char event_name[] = "force_end";
2446 LogSimpleEvent(event_name, sizeof(event_name));
2447 }
2448
2449 // reset match
2450 ResetMatch(true, false);
2451
2452 LogAction(client, -1, "\"force_end\" (player \"%L\")", client);
2453
2454 return Plugin_Handled;
2455}
2456
2457public Action ReadyOn(int client, int args)
2458{
2459 if (!IsActive(client, false))
2460 {
2461 // warmod is disabled
2462 return Plugin_Handled;
2463 }
2464
2465 if (!IsAdminCmd(client, false))
2466 {
2467 // not allowed, rcon only
2468 return Plugin_Handled;
2469 }
2470
2471 if (IsLive(client, false))
2472 {
2473 return Plugin_Handled;
2474 }
2475
2476 // reset ready system
2477 ReadyChangeAll(client, false, true);
2478 SetAllCancelled(false);
2479
2480 // enable ready system
2481 ReadySystem(true);
2482 ShowInfo(client, true, false, 0);
2483 if (client != 0)
2484 {
2485 PrintToConsole(client, "[%s] %t", CHAT_PREFIX, "Ready System Enabled");
2486 }
2487 else
2488 {
2489 PrintToServer("[%s] %T", CHAT_PREFIX, "Ready System Enabled", LANG_SERVER);
2490 }
2491 CheckReady();
2492
2493 LogAction(client, -1, "\"ready_on\" (player \"%L\")", client);
2494
2495 return Plugin_Handled;
2496}
2497
2498public Action ReadyOff(int client, int args)
2499{
2500 if (!IsActive(client, false))
2501 {
2502 // warmod is disabled
2503 return Plugin_Handled;
2504 }
2505
2506 if (!IsAdminCmd(client, false))
2507 {
2508 // not allowed, rcon only
2509 return Plugin_Handled;
2510 }
2511
2512 if (IsLive(client, false))
2513 {
2514 return Plugin_Handled;
2515 }
2516
2517 // reset ready system
2518 ReadyChangeAll(client, false, true);
2519 SetAllCancelled(false);
2520
2521 if (IsReadyEnabled(client, true))
2522 {
2523 // disable ready sytem
2524 ShowInfo(client, false, false, 1);
2525 ReadySystem(false);
2526 }
2527
2528 if (client != 0)
2529 {
2530 PrintToConsole(client, "[%s] %t", CHAT_PREFIX, "Ready System Disabled");
2531 }
2532 else
2533 {
2534 PrintToServer("[%s] %T", CHAT_PREFIX, "Ready System Disabled", LANG_SERVER);
2535 }
2536
2537 LogAction(client, -1, "\"ready_off\" (player \"%L\")", client);
2538
2539 return Plugin_Handled;
2540}
2541
2542public Action ConsoleScore(int client, int args) {
2543 // display score
2544 if (g_match) {
2545 if (g_live) {
2546 if (client != 0) {
2547 PrintToConsole(client, "[%s] %t:", CHAT_PREFIX, "Match Is Live");
2548 } else {
2549 PrintToServer("[%s] %T:", CHAT_PREFIX, "Match Is Live", LANG_SERVER);
2550 }
2551 }
2552 PrintToConsole(client, "[%s] %s [%d] vs [%d] %s - MR%d", CHAT_PREFIX, g_t_name, GetTScore(), GetCTScore(), g_ct_name, (GetConVarInt(mp_maxrounds)/2));
2553 if (g_overtime){
2554 PrintToConsole(client, "[%s] %t(%d): %s [%d] vs [%d] %s - MR%d", CHAT_PREFIX, "Score Overtime", g_overtime_count + 1, g_t_name, GetTOTScore(), GetCTOTScore(), g_ct_name, (GetConVarInt(mp_overtime_maxrounds)/2));
2555 }
2556 } else {
2557 if (client != 0) {
2558 PrintToConsole(client, "[%s] %t", CHAT_PREFIX, "Match Not In Progress");
2559 if (lt_t_overall_score + lt_ct_overall_score > 0) {
2560 PrintToConsole(client, "[%s] Previous: %s [%d] vs [%d] %s - Map: %s - MR%d", CHAT_PREFIX, lt_t_name, lt_t_overall_score, lt_ct_overall_score, lt_ct_name, lt_map, lt_max_rounds);
2561 }
2562 } else {
2563 PrintToServer("[%s] %T", CHAT_PREFIX, "Match Not In Progress", LANG_SERVER);
2564 if (lt_t_overall_score + lt_ct_overall_score > 0) {
2565 PrintToServer("[%s] Previous: %s [%d] vs [%d] %s - Map: %s - MR%d", CHAT_PREFIX, lt_t_name, lt_t_overall_score, lt_ct_overall_score, lt_ct_name, lt_map, lt_max_rounds);
2566 }
2567 }
2568 }
2569
2570 return Plugin_Handled;
2571}
2572
2573// work in progress
2574public Action SetScoreT(int client, int args)
2575{
2576 if (IsAdminCmd(client, false))
2577 {
2578 char argstring[16];
2579 GetCmdArgString(argstring, sizeof(argstring));
2580 int intToUse;
2581
2582 if (strlen(argstring) < 1)
2583 {
2584 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Choose a score between 0 and 30", CHAT_PREFIX);
2585 }
2586 else
2587 {
2588 if (isNumeric(argstring))
2589 {
2590 intToUse = StringToInt(argstring);
2591 }
2592 else
2593 {
2594 intToUse = -1;
2595 }
2596
2597 if (g_live)
2598 {
2599 if (intToUse > 30 || intToUse < 0)
2600 {
2601 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Choose a score between 0 and 30", CHAT_PREFIX);
2602 }
2603 else
2604 {
2605 if (!GetConVarBool(wm_warmod_safemode))
2606 {
2607 CS_SetTeamScore(CS_TEAM_T, intToUse);
2608 SetTeamScore(CS_TEAM_T, intToUse);
2609 g_scores[SCORE_T][SCORE_FIRST_HALF] = intToUse;
2610 PrintToChatAll("\x01 \x09[\x04%s\x09] \x02Terrorists \x01score changed to \x04%d", CHAT_PREFIX, intToUse);
2611 }
2612 else
2613 {
2614 PrintToChatAll("\x01 \x09[\x04%s\x09] %t", CHAT_PREFIX, "Safe Mode");
2615 }
2616 }
2617 }
2618 }
2619 }
2620 return Plugin_Handled;
2621}
2622
2623public Action SetScoreCT(int client, int args)
2624{
2625 if (IsAdminCmd(client, false))
2626 {
2627 char argstring[16];
2628 GetCmdArgString(argstring, sizeof(argstring));
2629 int intToUse;
2630
2631 if (strlen(argstring) < 1)
2632 {
2633 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Choose a score between 0 and 30", CHAT_PREFIX);
2634 }
2635 else
2636 {
2637 if (isNumeric(argstring))
2638 {
2639 intToUse = StringToInt(argstring);
2640 }
2641 else
2642 {
2643 intToUse = -1;
2644 }
2645
2646 if (g_live)
2647 {
2648 if (intToUse > 30 || intToUse < 0)
2649 {
2650 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Choose a score between 0 and 30", CHAT_PREFIX);
2651 }
2652 else
2653 {
2654 if (!GetConVarBool(wm_warmod_safemode))
2655 {
2656 CS_SetTeamScore(CS_TEAM_CT, intToUse);
2657 SetTeamScore(CS_TEAM_CT, intToUse);
2658 g_scores[SCORE_CT][SCORE_FIRST_HALF] = intToUse;
2659 PrintToChatAll("\x01 \x09[\x04%s\x09] \x0CCounter Terrorists \x01score changed to \x04%d", CHAT_PREFIX, intToUse);
2660 }
2661 else
2662 {
2663 PrintToChatAll("\x01 \x09[\x04%s\x09] %t", CHAT_PREFIX, "Safe Mode");
2664 }
2665 }
2666 }
2667 }
2668 }
2669 return Plugin_Handled;
2670}
2671
2672public Action ShowScore(int client, int args) {
2673 if (!IsActive(client, false)) {
2674 // warmod is disabled
2675 return Plugin_Handled;
2676 }
2677
2678 if (client == 0) {
2679 ConsoleScore(client, args);
2680 return Plugin_Handled;
2681 }
2682
2683 if (g_match) {
2684 // display score
2685 if (!g_overtime) {
2686 DisplayScore(client, 0, true);
2687 } else {
2688 DisplayScore(client, 1, true);
2689 }
2690 } else {
2691 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Match Not In Progress");
2692 if (lt_t_overall_score + lt_ct_overall_score > 0) {
2693 DisplayScore(client, 3, true);
2694 }
2695 }
2696
2697 return Plugin_Handled;
2698}
2699
2700void DisplayScore(int client, int msgindex, bool priv)
2701{
2702 char temp[64];
2703 GetConVarString(mp_teamname_1, temp, sizeof(temp));
2704 if (StrEqual(temp, DEFAULT_T_NAME, false) || StrEqual(temp, DEFAULT_CT_NAME, false)) {
2705 ServerCommand("mp_teamname_1 \"\"");
2706 }
2707
2708 if (StrEqual(g_ct_name, DEFAULT_T_NAME, false)) {
2709 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
2710 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), "%s", g_ct_name);
2711 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
2712 }
2713
2714 GetConVarString(mp_teamname_2, temp, sizeof(temp));
2715 if (StrEqual(temp, DEFAULT_CT_NAME, false) || StrEqual(temp, DEFAULT_T_NAME, false)) {
2716 ServerCommand("mp_teamname_2 \"\"");
2717 }
2718
2719 if (StrEqual(g_t_name, DEFAULT_CT_NAME, false)) {
2720 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
2721 Format(g_t_name_escaped, sizeof(g_t_name_escaped), "%s", g_t_name);
2722 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
2723 }
2724
2725 if (!GetConVarBool(wm_ingame_scores)) {
2726 return;
2727 }
2728
2729 if (msgindex == 0) // standard play score
2730 {
2731 char score_msg[192];
2732 GetScoreMsg(client, score_msg, sizeof(score_msg), GetTScore(), GetCTScore());
2733 if (priv) {
2734 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %s", CHAT_PREFIX, score_msg);
2735 } else {
2736 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s", CHAT_PREFIX, score_msg);
2737 }
2738 }
2739 else if (msgindex == 1) // overtime play score
2740 {
2741 char score_msg[192];
2742 GetScoreMsg(client, score_msg, sizeof(score_msg), GetTOTScore(), GetCTOTScore());
2743 if (priv) {
2744 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t%s", CHAT_PREFIX, "Score Overtime", score_msg);
2745 } else {
2746 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t%s", CHAT_PREFIX, "Score Overtime", score_msg);
2747 }
2748 }
2749 else if (msgindex == 2) // overall play score
2750 {
2751 char score_msg[192];
2752 GetScoreMsg(client, score_msg, sizeof(score_msg), GetTTotalScore(), GetCTTotalScore());
2753 if (priv) {
2754 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t%s", CHAT_PREFIX, "Score Overall", score_msg);
2755 } else {
2756 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t%s", CHAT_PREFIX, "Score Overall", score_msg);
2757 }
2758 }
2759 else if (msgindex == 3) // overall play score
2760 {
2761 char score_msg[192];
2762 Format(score_msg, sizeof(score_msg), "Previous: %s \x04%d\x03-\x04%d \x01%s", lt_t_name, lt_t_overall_score, lt_ct_overall_score, lt_ct_name);
2763 if (priv) {
2764 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %s", CHAT_PREFIX, score_msg);
2765 } else {
2766 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s", CHAT_PREFIX, score_msg);
2767 }
2768 }
2769}
2770
2771public void GetScoreMsg(int client, char[] result, int maxlen, int t_score, int ct_score) {
2772 SetGlobalTransTarget(client);
2773 if (StrEqual(g_t_name, "")) {
2774 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
2775 }
2776 if (StrEqual(g_ct_name, "")) {
2777 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
2778 }
2779 if (t_score > ct_score) {
2780 Format(result, maxlen, "\x02%t \x04%d\x03-\x04%d", "T Winning", g_t_name, t_score, ct_score);
2781 } else if (t_score == ct_score) {
2782 Format(result, maxlen, "\x01%t \x04%d\03-\x04%d", "Tied", t_score, ct_score);
2783 } else {
2784 Format(result, maxlen, "\x0C%t \x04%d\x03-\x04%d", "CT Winning", g_ct_name, ct_score, t_score);
2785 }
2786}
2787
2788public Action ReadyInfoPriv(int client, int args)
2789{
2790 if (!IsActive(client, false))
2791 {
2792 // warmod is disabled
2793 return Plugin_Handled;
2794 }
2795
2796 if (!IsReadyEnabled(client, false))
2797 {
2798 return Plugin_Handled;
2799 }
2800
2801 if (client != 0 && !g_live)
2802 {
2803 g_cancel_list[client] = false;
2804 ShowInfo(client, true, true, 0);
2805 }
2806 return Plugin_Handled;
2807}
2808
2809public Action Event_Round_Start(Handle event, const char[]name, bool dontBroadcast)
2810{
2811 Event_Round_Start_CMD();
2812 for (int i = 1; i <= MaxClients; i++) {
2813 if (IsClientInGame(i) && GetClientTeam(i) > 1) {
2814 FreezeTimeSpawn(i);
2815 }
2816 }
2817// Round_Start_Player_Names();
2818}
2819
2820public void Event_Round_Start_CMD()
2821{
2822 if (!IsActive(0, true))
2823 {
2824 return;
2825 }
2826
2827 LiveText();
2828
2829 FreezeTime = true;
2830
2831 //Pause command fire on round end May change to on round start
2832 if (g_pause_freezetime == true)
2833 {
2834 g_pause_freezetime = false;
2835 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
2836 if (GetConVarBool(wm_auto_unpause))
2837 {
2838 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %i %T", CHAT_PREFIX, GetConVarInt(wm_auto_unpause_delay), "Unpause Timer", LANG_SERVER);
2839 g_h_stored_timer = CreateTimer(GetConVarFloat(wm_auto_unpause_delay), UnPauseTimer);
2840 }
2841
2842 ServerCommand("mp_pause_match 1");
2843 }
2844
2845 if (g_auto_pause)
2846 {
2847 g_auto_pause = false;
2848
2849 if (GetTeamClientCount(CS_TEAM_CT) < (GetConVarInt(wm_max_players)/2))
2850 {
2851 char name[64];
2852 if (StrEqual(g_ct_name, ""))
2853 {
2854 Format(name, sizeof(name), DEFAULT_CT_NAME);
2855 }
2856 else
2857 {
2858 Format(name, sizeof(name), g_ct_name);
2859 }
2860 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Auto Unpause Notice", LANG_SERVER, name);
2861 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
2862 ServerCommand("mp_pause_match 1");
2863 }
2864 else if (GetTeamClientCount(CS_TEAM_T) < (GetConVarInt(wm_max_players)/2))
2865 {
2866 char name[64];
2867 if (StrEqual(g_t_name, ""))
2868 {
2869 Format(name, sizeof(name), DEFAULT_T_NAME);
2870 }
2871 else
2872 {
2873 Format(name, sizeof(name), g_t_name);
2874 }
2875 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Auto Unpause Notice", LANG_SERVER, name);
2876 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Unpause Notice", LANG_SERVER);
2877 ServerCommand("mp_pause_match 1");
2878 }
2879 }
2880
2881 if (GetConVarBool(wm_stats_enabled))
2882 {
2883 if (g_t_knife)
2884 {
2885 LogEvent("{\"event\": \"knife_round_start\", \"freezeTime\": %d}", GetConVarInt(FindConVar("mp_freezetime")));
2886 }
2887 else
2888 {
2889 LogEvent("{\"event\": \"round_start\", \"freezeTime\": %d}", GetConVarInt(FindConVar("mp_freezetime")));
2890 LogMoney();
2891 }
2892 }
2893
2894 if (g_second_half_first)
2895 {
2896 LiveOn3Override();
2897 g_second_half_first = false;
2898 }
2899
2900 g_planted = false;
2901
2902 ResetClutchStats();
2903
2904 if (!g_t_score)
2905 {
2906 g_t_score = true;
2907 }
2908
2909 if (g_t_knife)
2910 {
2911 // give player specified grenades
2912 for (int i = 1; i <= MaxClients; i++)
2913 {
2914 if (IsClientInGame(i) && GetClientTeam(i) > 1)
2915 {
2916 SetEntData(i, g_iAccount, 0);
2917 CS_StripButKnife(i);
2918 if (GetConVarBool(wm_knife_hegrenade))
2919 {
2920 GivePlayerItem(i, "weapon_hegrenade");
2921 }
2922 if (GetConVarInt(wm_knife_flashbang) >= 1)
2923 {
2924 GivePlayerItem(i, "weapon_flashbang");
2925 if (GetConVarInt(wm_knife_flashbang) >= 2)
2926 {
2927 GivePlayerItem(i, "weapon_flashbang");
2928 }
2929 }
2930 if (GetConVarBool(wm_knife_smokegrenade))
2931 {
2932 GivePlayerItem(i, "weapon_smokegrenade");
2933 }
2934 if (GetConVarBool(wm_knife_zeus))
2935 {
2936 GivePlayerItem(i, "weapon_taser");
2937 }
2938 if (GetConVarBool(wm_knife_armor))
2939 {
2940 SetEntProp(i, Prop_Send, "m_ArmorValue", 100);
2941 if (GetConVarBool(wm_knife_helmet))
2942 {
2943 SetEntProp(i, Prop_Send, "m_bHasHelmet", 1);
2944 }
2945 }
2946 }
2947 }
2948 }
2949
2950 if (g_t_money == true && GetConVarBool(wm_round_money))
2951 {
2952 int the_money[MAXPLAYERS + 1];
2953 int num_players;
2954
2955 // sort by money
2956 for (int i = 1; i <= MaxClients; i++)
2957 {
2958 if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1)
2959 {
2960 the_money[num_players] = i;
2961 num_players++;
2962 }
2963 }
2964
2965 SortCustom1D(the_money, num_players, SortMoney);
2966
2967 char player_name[64];
2968 char player_money[10];
2969 char has_weapon[1];
2970 int pri_weapon;
2971
2972 // display team players money
2973 for (int i = 1; i <= MaxClients; i++)
2974 {
2975 for (int x = 0; x < num_players; x++)
2976 {
2977 GetClientName(the_money[x], player_name, sizeof(player_name));
2978 if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == GetClientTeam(the_money[x]))
2979 {
2980 pri_weapon = GetPlayerWeaponSlot(the_money[x], 0);
2981 if (pri_weapon == -1)
2982 {
2983 has_weapon = ">";
2984 }
2985 else
2986 {
2987 has_weapon = "\0";
2988 }
2989 IntToMoney(GetEntData(the_money[x], g_iAccount), player_money, sizeof(player_money));
2990 PrintToChat(i, "\x01$%s \x04%s> \x03%s", player_money, has_weapon, player_name);
2991 }
2992 }
2993 }
2994 }
2995 CreateTimer(0.9, SetRandomTeamNameTag);
2996}
2997
2998public Action SetRandomTeamNameTag(Handle timer)
2999{
3000 if (!GetConVarBool(wm_warmod_safemode) && g_live && !g_tag_set && GetConVarBool(wm_random_team_names))
3001 {
3002 for (int i = 1; i <= MaxClients; i++)
3003 {
3004 if (IsValidClient(i) && GetClientTeam(i) == 3)
3005 {
3006 if (g_first_half && !g_overtime)
3007 {
3008 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_ct]);
3009 }
3010 else if (!g_first_half && !g_overtime)
3011 {
3012 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_t]);
3013 }
3014 else if (g_first_half && g_overtime && (IsEven(g_overtime_count) || g_overtime_count == 0))
3015 {
3016 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_t]);
3017 }
3018 else
3019 {
3020 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_ct]);
3021 }
3022 }
3023 else if (IsValidClient(i) && GetClientTeam(i) == 2)
3024 {
3025 if (g_first_half && !g_overtime)
3026 {
3027 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_t]);
3028 }
3029 else if (!g_first_half && !g_overtime)
3030 {
3031 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_ct]);
3032 }
3033 else if (g_first_half && g_overtime && (IsEven(g_overtime_count) || g_overtime_count == 0))
3034 {
3035 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_ct]);
3036 }
3037 else
3038 {
3039 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_t]);
3040 }
3041 }
3042 }
3043 g_tag_set = true;
3044 }
3045}
3046
3047public Action AskTeamMoney(int client, int args)
3048{
3049 // show team money
3050 ShowTeamMoney(client);
3051 return Plugin_Handled;
3052}
3053
3054stock void ShowTeamMoney(int client)
3055{
3056
3057 if (client == 0)
3058 {
3059 return;
3060 }
3061
3062 // show team money
3063 int the_money[MAXPLAYERS + 1];
3064 int num_players;
3065
3066 for (int i = 1; i <= MaxClients; i++)
3067 {
3068 if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1)
3069 {
3070 the_money[num_players] = i;
3071 num_players++;
3072 }
3073 }
3074
3075 SortCustom1D(the_money, num_players, SortMoney);
3076
3077 char player_name[64];
3078 char player_money[10];
3079 char has_weapon[1];
3080 int pri_weapon;
3081
3082 PrintToChat(client, "\x01--------");
3083 for (int x = 0; x < num_players; x++)
3084 {
3085 GetClientName(the_money[x], player_name, sizeof(player_name));
3086 if (IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == GetClientTeam(the_money[x]))
3087 {
3088 pri_weapon = GetPlayerWeaponSlot(the_money[x], 0);
3089 if (pri_weapon == -1)
3090 {
3091 has_weapon = ">";
3092 }
3093 else
3094 {
3095 has_weapon = "\0";
3096 }
3097 IntToMoney(GetEntData(the_money[x], g_iAccount), player_money, sizeof(player_money));
3098 PrintToChat(client, "\x01$%s \x04%s> \x03%s", player_money, has_weapon, player_name);
3099 }
3100 }
3101}
3102
3103stock void GetCurrentWorkshopMap(char[] g_MapName, int iMapBuf, char[] g_WorkShopID, int iWorkShopBuf)
3104{
3105 char g_CurMap[128];
3106 char g_CurMapSplit[2][64];
3107
3108 GetCurrentMap(g_CurMap, sizeof(g_CurMap));
3109
3110 ReplaceString(g_CurMap, sizeof(g_CurMap), "workshop/", "", false);
3111
3112 ExplodeString(g_CurMap, "/", g_CurMapSplit, 2, 64);
3113
3114 strcopy(g_WorkShopID, iWorkShopBuf, g_CurMapSplit[0]);
3115 strcopy(g_MapName, iMapBuf, g_CurMapSplit[1]);
3116 strcopy(g_map, iMapBuf, g_CurMapSplit[1]);
3117}
3118
3119public Action LogPlayerStatsTimer (Handle timer, int winner) {
3120 for (int i = 1; i <= MaxClients; i++) {
3121 if (IsClientInGame(i) && GetClientTeam(i) == winner) {
3122 clutch_stats[i][CLUTCH_WON] = 1;
3123 }
3124 if (g_live) {
3125 LogPlayerStats(i);
3126 }
3127 }
3128}
3129
3130public Action Event_Round_End(Handle event, const char[]name, bool dontBroadcast)
3131{
3132 if (!IsActive(0, true))
3133 {
3134 return;
3135 }
3136
3137 int winner = GetEventInt(event, "winner");
3138
3139 // stats
3140 if (GetConVarBool(wm_stats_enabled))
3141 {
3142 CreateTimer(4.0, LogPlayerStatsTimer, winner);
3143 /*for (int i = 1; i <= MaxClients; i++)
3144 {
3145 if (IsClientInGame(i) && GetClientTeam(i) == winner)
3146 {
3147 clutch_stats[i][CLUTCH_WON] = 1;
3148 }
3149 if (g_live) {
3150 LogPlayerStats(i);
3151 }
3152 }*/
3153 if (g_t_knife)
3154 {
3155 LogEvent("{\"event\": \"knife_round_end\", \"round\": %i, \"winner\": %d, \"reason\": %d}", g_round, winner, GetEventInt(event, "reason"));
3156 }
3157 else
3158 {
3159 LogEvent("{\"event\": \"round_end\", \"round\": %i, \"winner\": %d, \"reason\": %d}", g_round, winner, GetEventInt(event, "reason"));
3160 }
3161 }
3162
3163 if (winner > 1 && g_t_score)
3164 {
3165 if (g_t_knife)
3166 {
3167 if (g_t_veto)
3168 {
3169 g_t_veto = false;
3170 g_t_knife = false;
3171 SetCaptains();
3172 CreateMapVeto(winner);
3173 }
3174 else
3175 {
3176 if (winner == 2)
3177 {
3178 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_t_name, "Knife Vote Team", LANG_SERVER);
3179 }
3180 else
3181 {
3182 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_ct_name, "Knife Vote Team", LANG_SERVER);
3183 }
3184
3185 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife Vote");
3186 g_knife_winner = GetEventInt(event, "winner");
3187 g_knife_vote = true;
3188 g_t_knife = false;
3189 g_t_had_knife = true;
3190 ServerCommand("mp_pause_match 1");
3191 UpdateStatus();
3192 }
3193 }
3194
3195 if (!g_live)
3196 {
3197 return;
3198 }
3199
3200 if (!g_t_money)
3201 {
3202 g_t_money = true;
3203 }
3204
3205 AddScore(winner);
3206 CheckScores();
3207 UpdateStatus();
3208 Call_StartForward(g_f_on_round_end);
3209 Call_PushString(g_ct_name);
3210 Call_PushCell(GetCTTotalScore());
3211 Call_PushCell(GetTTotalScore());
3212 Call_PushString(g_t_name);
3213 Call_Finish();
3214 if (wm_damageprint_enabled.IntValue == 1) {
3215 for (int i = 1; i <= MaxClients; i++) {
3216 if (IsValidClient(i)) {
3217 PrintDamageInfo(i);
3218 }
3219 }
3220 }
3221 }
3222}
3223
3224public void Event_Round_Restart(Handle cvar, const char[]oldVal, const char[]newVal)
3225{
3226 if (!IsActive(0, true))
3227 {
3228 return;
3229 }
3230
3231 // stats
3232 if (GetConVarBool(wm_stats_enabled) && !StrEqual(newVal, "0"))
3233 {
3234 for (int i = 1; i <= MaxClients; i++)
3235 {
3236 ResetPlayerStats(i);
3237 clutch_stats[i][CLUTCH_LAST] = 0;
3238 clutch_stats[i][CLUTCH_VERSUS] = 0;
3239 clutch_stats[i][CLUTCH_FRAGS] = 0;
3240 clutch_stats[i][CLUTCH_WON] = 0;
3241 }
3242 LogEvent("{\"event\": \"round_restart\", \"delay\": %d}", StringToInt(newVal));
3243 }
3244}
3245
3246public Action Event_Round_Freeze_End(Handle event, const char[]name, bool dontBroadcast)
3247{
3248 if (!IsActive(0, true))
3249 {
3250 return;
3251 }
3252
3253 FreezeTime = false;
3254
3255 // stats
3256 if (GetConVarBool(wm_stats_enabled))
3257 {
3258 if (g_t_knife)
3259 {
3260 char event_name[] = "knife_round_freeze_end";
3261 LogSimpleEvent(event_name, sizeof(event_name));
3262 }
3263 else
3264 {
3265 char event_name[] = "round_freeze_end";
3266 LogSimpleEvent(event_name, sizeof(event_name));
3267 }
3268 }
3269}
3270
3271public Action Event_Player_Blind(Handle event, const char[]name, bool dontBroadcast)
3272{
3273 if (!IsActive(0, true))
3274 {
3275 return;
3276 }
3277
3278 // stats
3279 if (GetConVarBool(wm_stats_enabled))
3280 {
3281 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3282 if (client > 0)
3283 {
3284 char log_string[384];
3285 CS_GetAdvLogString(client, log_string, sizeof(log_string));
3286 LogEvent("{\"event\": \"player_blind\", \"round\": %i, \"player\": %s, \"duration\": %.2f}", g_round, log_string, GetEntPropFloat(client, Prop_Send, "m_flFlashDuration"));
3287 }
3288 }
3289}
3290
3291public Action Event_Player_Hurt(Handle event, const char[]name, bool dontBroadcast)
3292{
3293 if (!IsActive(0, true))
3294 {
3295 return;
3296 }
3297
3298 // stats
3299 if (GetConVarBool(wm_stats_enabled))
3300 {
3301 int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
3302 int victim = GetClientOfUserId(GetEventInt(event, "userid"));
3303 int damage = GetEventInt(event, "dmg_health");
3304 int damage_armor = GetEventInt(event, "dmg_armor");
3305 int hitgroup = GetEventInt(event, "hitgroup");
3306 int vHealth = GetEventInt(event, "health");
3307 char weapon[64];
3308 GetEventString(event, "weapon", weapon, sizeof(weapon));
3309
3310 if (StrEqual(weapon, "m4a1"))
3311 {
3312 int iWeapon = GetPlayerWeaponSlot(attacker, CS_SLOT_PRIMARY);
3313 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3314 if (pWeapon == 60)
3315 {
3316 weapon = "m4a1_silencer";
3317 }
3318 }
3319 else if (StrEqual(weapon, "hkp2000") || StrEqual(weapon, "p250") || StrEqual(weapon, "fiveseven") || StrEqual(weapon, "tec9") || StrEqual(weapon, "deagle"))
3320 {
3321 int iWeapon = GetPlayerWeaponSlot(attacker, CS_SLOT_SECONDARY);
3322 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3323 if (pWeapon == 61)
3324 {
3325 weapon = "usp_silencer";
3326 }
3327 else if (pWeapon == 63)
3328 {
3329 weapon = "cz75a";
3330 }
3331 else if (pWeapon == 64)
3332 {
3333 weapon = "revolver";
3334 }
3335 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
3336 int iWeapon = GetPlayerWeaponSlot(attacker, CS_SLOT_KNIFE);
3337 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3338 if (pWeapon == 500 || pWeapon == 505 || pWeapon == 506 || pWeapon == 507 || pWeapon == 508 || pWeapon == 509 || pWeapon == 512 || pWeapon == 515 || pWeapon == 516 || pWeapon == 59 || pWeapon == 42)
3339 {
3340 weapon = "knife";
3341 }
3342 }
3343
3344 if (StrEqual(weapon, "m4a1_silencer_off")) {
3345 weapon = "m4a1_silencer";
3346 } else if (StrEqual(weapon, "usp_silencer_off")) {
3347 weapon = "usp_silencer";
3348 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
3349 weapon = "knife";
3350 }
3351
3352 if (attacker > 0)
3353 {
3354 int weapon_index = GetWeaponIndex(weapon);
3355 if (victim > 0)
3356 {
3357 GetClientWeapon(victim, last_weapon[victim], 64);
3358 ReplaceString(last_weapon[victim], 64, "weapon_", "");
3359 char attacker_log_string[384];
3360 char victim_log_string[384];
3361 CS_GetAdvLogString(attacker, attacker_log_string, sizeof(attacker_log_string));
3362 CS_GetAdvLogString(victim, victim_log_string, sizeof(victim_log_string));
3363 EscapeString(weapon, sizeof(weapon));
3364 if (g_t_knife)
3365 {
3366 LogEvent("{\"event\": \"knife_player_hurt\", \"round\": %i, \"attacker\": %s, \"victim\": %s, \"weapon\": \"%s\", \"damage\": %d, \"damageArmor\": %d, \"hitGroup\": %d}", g_round, attacker_log_string, victim_log_string, weapon, damage, damage_armor, hitgroup);
3367 }
3368 else
3369 {
3370 LogEvent("{\"event\": \"player_hurt\", \"round\": %i, \"attacker\": %s, \"victim\": %s, \"weapon\": \"%s\", \"damage\": %d, \"damageArmor\": %d, \"hitGroup\": %d}", g_round, attacker_log_string, victim_log_string, weapon, damage, damage_armor, hitgroup);
3371 }
3372 g_DamageDone[attacker][victim] += damage;
3373 g_DamageDoneHits[attacker][victim]++;
3374 }
3375 if (weapon_index > -1)
3376 {
3377 if (GetClientTeam(attacker) == GetClientTeam(victim)) {
3378 weapon_stats[attacker][weapon_index][LOG_HIT_TEAM_HITS]++;
3379 if (vHealth == 0) {
3380 weapon_stats[attacker][weapon_index][LOG_HIT_TEAM_DAMAGE] += round_health[victim];
3381 } else {
3382 weapon_stats[attacker][weapon_index][LOG_HIT_TEAM_DAMAGE] += damage;
3383 }
3384 } else {
3385 weapon_stats[attacker][weapon_index][LOG_HIT_HITS]++;
3386 if (vHealth == 0) {
3387 weapon_stats[attacker][weapon_index][LOG_HIT_DAMAGE] += round_health[victim];
3388 } else {
3389 weapon_stats[attacker][weapon_index][LOG_HIT_DAMAGE] += damage;
3390 }
3391 }
3392
3393 if (hitgroup < 8)
3394 {
3395 weapon_stats[attacker][weapon_index][hitgroup + LOG_HIT_OFFSET]++;
3396 }
3397 }
3398 }
3399 round_health[victim] = vHealth;
3400 }
3401}
3402
3403public Action Event_Player_Death(Handle event, const char[]name, bool dontBroadcast)
3404{
3405 if (!IsActive(0, true))
3406 {
3407 return;
3408 }
3409
3410 int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
3411 int assister = GetClientOfUserId(GetEventInt(event, "assister"));
3412 int victim = GetClientOfUserId(GetEventInt(event, "userid"));
3413 bool headshot = GetEventBool(event, "headshot");
3414 char weapon[64];
3415 GetEventString(event, "weapon", weapon, sizeof(weapon));
3416 if (StrEqual(weapon, "m4a1"))
3417 {
3418 int iWeapon = GetPlayerWeaponSlot(attacker, CS_SLOT_PRIMARY);
3419 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3420 if (pWeapon == 60)
3421 {
3422 weapon = "m4a1_silencer";
3423 }
3424 }
3425 else if (StrEqual(weapon, "hkp2000") || StrEqual(weapon, "p250") || StrEqual(weapon, "fiveseven") || StrEqual(weapon, "tec9") || StrEqual(weapon, "deagle"))
3426 {
3427 int iWeapon = GetPlayerWeaponSlot(attacker, CS_SLOT_SECONDARY);
3428 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3429 if (pWeapon == 61)
3430 {
3431 weapon = "usp_silencer";
3432 }
3433 else if (pWeapon == 63)
3434 {
3435 weapon = "cz75a";
3436 }
3437 else if (pWeapon == 64)
3438 {
3439 weapon = "revolver";
3440 }
3441 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
3442 int iWeapon = GetPlayerWeaponSlot(attacker, CS_SLOT_KNIFE);
3443 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3444 if (pWeapon == 500 || pWeapon == 505 || pWeapon == 506 || pWeapon == 507 || pWeapon == 508 || pWeapon == 509 || pWeapon == 512 || pWeapon == 515 || pWeapon == 516 || pWeapon == 59 || pWeapon == 42)
3445 {
3446 weapon = "knife";
3447 }
3448 }
3449
3450 if (StrEqual(weapon, "m4a1_silencer_off")) {
3451 weapon = "m4a1_silencer";
3452 } else if (StrEqual(weapon, "usp_silencer_off")) {
3453 weapon = "usp_silencer";
3454 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
3455 weapon = "knife";
3456 }
3457
3458 int victim_team = GetClientTeam(victim);
3459
3460 // stats
3461 if (GetConVarBool(wm_stats_enabled))
3462 {
3463 if (attacker > 0 && victim > 0 && attacker != victim)
3464 {
3465 // normal frag
3466 char attacker_log_string[384];
3467 char assister_log_string[384];
3468 char victim_log_string[384];
3469 CS_GetAdvLogString(attacker, attacker_log_string, sizeof(attacker_log_string));
3470 CS_GetAdvLogString(assister, assister_log_string, sizeof(assister_log_string));
3471 CS_GetAdvLogString(victim, victim_log_string, sizeof(victim_log_string));
3472 EscapeString(weapon, sizeof(weapon));
3473 if (g_t_knife)
3474 {
3475 LogEvent("{\"event\": \"knife_player_death\", \"round\": %i, \"attacker\": %s, \"assister\": %s, \"victim\": %s, \"weapon\": \"%s\", \"headshot\": %d}", g_round, attacker_log_string, assister_log_string, victim_log_string, weapon, headshot);
3476 }
3477 else
3478 {
3479 LogEvent("{\"event\": \"player_death\", \"round\": %i, \"attacker\": %s, \"assister\": %s, \"victim\": %s, \"weapon\": \"%s\", \"headshot\": %d}", g_round, attacker_log_string, assister_log_string, victim_log_string, weapon, headshot);
3480 }
3481 }
3482 else if (victim > 0 && victim == attacker || StrEqual(weapon, "worldspawn"))
3483 {
3484 // suicide
3485 char log_string[384];
3486 char assister_log_string[384];
3487 CS_GetAdvLogString(assister, assister_log_string, sizeof(assister_log_string));
3488 CS_GetAdvLogString(victim, log_string, sizeof(log_string));
3489 ReplaceString(weapon, sizeof(weapon), "worldspawn", "world");
3490 EscapeString(weapon, sizeof(weapon));
3491 if (g_t_knife)
3492 {
3493 LogEvent("{\"event\": \"knife_player_suicide\", \"round\": %i, \"player\": %s, \"assister\": %s, \"weapon\": \"%s\"}", g_round, log_string, assister_log_string, weapon);
3494 }
3495 else
3496 {
3497 LogEvent("{\"event\": \"player_suicide\", \"round\": %i, \"player\": %s, \"assister\": %s, \"weapon\": \"%s\"}", g_round, log_string, assister_log_string, weapon);
3498 }
3499 }
3500 if (victim > 0)
3501 {
3502 // record weapon stats
3503 int weapon_index = GetWeaponIndex(weapon);
3504 if (attacker > 0)
3505 {
3506 int attacker_team = GetClientTeam(attacker);
3507 if (weapon_index > -1)
3508 {
3509 if (headshot == true)
3510 {
3511 weapon_stats[attacker][weapon_index][LOG_HIT_HEADSHOTS]++;
3512 }
3513 if (attacker_team == victim_team) {
3514 weapon_stats[attacker][weapon_index][LOG_HIT_TEAMKILLS]++;
3515 } else {
3516 weapon_stats[attacker][weapon_index][LOG_HIT_KILLS]++;
3517 }
3518 }
3519 int victim_num_alive = GetNumAlive(victim_team);
3520 int attacker_num_alive = GetNumAlive(attacker_team);
3521 if (victim_num_alive == 0)
3522 {
3523 clutch_stats[victim][CLUTCH_LAST] = 1;
3524 if (clutch_stats[victim][CLUTCH_VERSUS] == 0)
3525 {
3526 clutch_stats[victim][CLUTCH_VERSUS] = attacker_num_alive;
3527 }
3528 }
3529 if (attacker_num_alive == 1)
3530 {
3531 if (attacker_team != victim_team)
3532 {
3533 clutch_stats[attacker][CLUTCH_FRAGS]++;
3534 if (clutch_stats[attacker][CLUTCH_LAST] == 0)
3535 {
3536 clutch_stats[attacker][CLUTCH_VERSUS] = victim_num_alive + 1;
3537 }
3538 clutch_stats[attacker][CLUTCH_LAST] = 1;
3539 }
3540 }
3541 g_GotKill[attacker][victim] = true;
3542 }
3543
3544 int victim_weapon_index = GetWeaponIndex(last_weapon[victim]);
3545 if (victim_weapon_index > -1)
3546 {
3547 weapon_stats[victim][victim_weapon_index][LOG_HIT_DEATHS]++;
3548 }
3549 }
3550 if (assister > 0)
3551 {
3552 if (GetClientTeam(assister) == GetClientTeam(victim))
3553 {
3554 assist_stats[assister][ASSIST_COUNT_TK]++;
3555 }
3556 else
3557 {
3558 assist_stats[assister][ASSIST_COUNT]++;
3559 }
3560 }
3561 }
3562
3563 if (!g_match && !g_t_knife && GetConVarBool(wm_warmup_respawn))
3564 {
3565 // respawn if warmup
3566 CreateTimer(0.1, RespawnPlayer, victim);
3567 }
3568}
3569
3570public Action Event_Player_Name(Handle event, const char[]name, bool dontBroadcast)
3571{
3572 if (!IsActive(0, true))
3573 {
3574 return;
3575 }
3576
3577 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3578 // stats
3579 if (GetConVarBool(wm_stats_enabled))
3580 {
3581 char log_string[384];
3582 CS_GetLogString(client, log_string, sizeof(log_string));
3583 char newName[64];
3584 GetEventString(event, "newname", newName, sizeof(newName));
3585 EscapeString(newName, sizeof(newName));
3586 if (g_t_knife)
3587 {
3588 LogEvent("{\"event\": \"knife_player_name\", \"player\": %s, \"newName\": \"%s\"}", log_string, newName);
3589 }
3590 else
3591 {
3592 LogEvent("{\"event\": \"player_name\", \"player\": %s, \"newName\": \"%s\"}", log_string, newName);
3593 }
3594 }
3595 if (g_ready_enabled && !g_live)
3596 {
3597 CreateTimer(0.1, UpdateInfo);
3598 }
3599}
3600
3601public Action Event_Player_Disc_Pre(Handle event, const char[]name, bool dontBroadcast)
3602{
3603 if (!IsActive(0, true))
3604 {
3605 return;
3606 }
3607
3608 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3609 char reason[128];
3610 GetEventString(event, "reason", reason, sizeof(reason));
3611
3612 g_clanTagsChecked[client] = false;
3613
3614 if ((g_match || g_t_knife) && GetConVarBool(wm_ban_on_disconnect) && StrEqual(reason, "Disconnect") && GetClientTeam(client) > 1)
3615 {
3616 float percent = GetConVarFloat(wm_ban_percentage);
3617 int count = CS_GetPlayerListCount();
3618 if (count > (GetConVarInt(wm_max_players) * percent))
3619 {
3620 g_disconnect[client] = true;
3621 }
3622 }
3623
3624 // stats
3625 if (GetConVarBool(wm_stats_enabled) && client != 0)
3626 {
3627 char log_string[384];
3628 CS_GetLogString(client, log_string, sizeof(log_string));
3629 EscapeString(reason, sizeof(reason));
3630 if (g_t_knife)
3631 {
3632 LogEvent("{\"event\": \"knife_player_disconnect\", \"round\": %i, \"player\": %s, \"reason\": \"%s\"}", g_round, log_string, reason);
3633 }
3634 else
3635 {
3636 LogEvent("{\"event\": \"player_disconnect\", \"round\": %i, \"player\": %s, \"reason\": \"%s\"}", g_round, log_string, reason);
3637 }
3638 }
3639}
3640
3641public Action Event_Player_Team_Post (Handle event, const char[]name, bool dontBroadcast) {
3642 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3643 FreezeTimeSpawn(client);
3644}
3645
3646public void FreezeTimeSpawn(int client) {
3647 int team = GetClientTeam(client);
3648
3649 if (g_live && GameRules_GetProp("m_bFreezePeriod") == 1 && !IsPlayerAlive(client) && (team == CS_TEAM_CT || team == CS_TEAM_T)) {
3650 CS_RespawnPlayer(client);
3651 }
3652}
3653
3654public Action Event_Player_Team(Handle event, const char[]name, bool dontBroadcast)
3655{
3656 if (!IsActive(0, true))
3657 {
3658 return;
3659 }
3660
3661 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3662 int old_team = GetEventInt(event, "oldteam");
3663 int new_team = GetEventInt(event, "team");
3664
3665 // stats
3666 if (GetConVarBool(wm_stats_enabled))
3667 {
3668 char log_string[384];
3669 CS_GetLogString(client, log_string, sizeof(log_string));
3670 LogEvent("{\"event\": \"player_team\", \"round\": %i, \"player\": %s, \"oldTeam\": %d, \"newTeam\": %d}", g_round, log_string, old_team, new_team);
3671 }
3672
3673 if (old_team < 2)
3674 {
3675 // came from spec/joining server
3676 CreateTimer(4.0, ShowPluginInfo, client);
3677 if (!g_live && g_ready_enabled && !GetEventBool(event, "disconnect") && !IsFakeClient(client))
3678 {
3679 CreateTimer(4.0, UpdateInfo);
3680 }
3681 }
3682
3683 if (old_team == 0)
3684 {
3685 // joining server
3686 CreateTimer(2.0, HelpText, client, TIMER_FLAG_NO_MAPCHANGE);
3687
3688 }
3689
3690 if (!g_live && g_ready_enabled && !GetEventBool(event, "disconnect") && !IsFakeClient(client))
3691 {
3692 // show ready system if applicable
3693 if (new_team != CS_TEAM_SPECTATOR)
3694 {
3695 if (g_player_list[client] == PLAYER_READY)
3696 {
3697 ReadyServ(client, false, false, true, false);
3698 }
3699 else
3700 {
3701 ReadyServ(client, false, true, true, false);
3702 }
3703 }
3704 else
3705 {
3706 g_player_list[client] = PLAYER_DISC;
3707 ShowInfo(client, true, false, 0);
3708 }
3709 }
3710
3711 if (new_team > 1 && !g_match && !g_t_knife && GetConVarBool(wm_warmup_respawn))
3712 {
3713 // spawn player if warmup
3714 CreateTimer(0.1, RespawnPlayer, client);
3715 }
3716}
3717
3718public Action Event_Player_Spawned(Handle event, const char[] name, bool dontBroadcast)
3719{
3720 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3721
3722 if (g_t_knife)
3723 {
3724 // give player specified grenades
3725 if (IsClientInGame(client) && GetClientTeam(client) > 1)
3726 {
3727 SetEntData(client, g_iAccount, 0);
3728 CS_StripButKnife(client);
3729 if (GetConVarBool(wm_knife_hegrenade))
3730 {
3731 GivePlayerItem(client, "weapon_hegrenade");
3732 }
3733 if (GetConVarInt(wm_knife_flashbang) >= 1)
3734 {
3735 GivePlayerItem(client, "weapon_flashbang");
3736 if (GetConVarInt(wm_knife_flashbang) >= 2)
3737 {
3738 GivePlayerItem(client, "weapon_flashbang");
3739 }
3740 }
3741 if (GetConVarBool(wm_knife_smokegrenade))
3742 {
3743 GivePlayerItem(client, "weapon_smokegrenade");
3744 }
3745 if (GetConVarBool(wm_knife_zeus))
3746 {
3747 GivePlayerItem(client, "weapon_taser");
3748 }
3749 if (GetConVarBool(wm_knife_armor))
3750 {
3751 SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
3752 if (GetConVarBool(wm_knife_helmet))
3753 {
3754 SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
3755 }
3756 }
3757 }
3758 }
3759}
3760
3761public Action Event_Bomb_PickUp(Handle event, const char[] name, bool dontBroadcast)
3762{
3763 if (!IsActive(0, true))
3764 {
3765 return;
3766 }
3767
3768 // stats
3769 if (GetConVarBool(wm_stats_enabled))
3770 {
3771 char log_string[384];
3772 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3773 if (g_t_knife)
3774 {
3775 LogEvent("{\"event\": \"knife_bomb_pickup\", \"round\": %i, \"player\": %s}", g_round, log_string);
3776 }
3777 else
3778 {
3779 LogEvent("{\"event\": \"bomb_pickup\", \"round\": %i, \"player\": %s}", g_round, log_string);
3780 }
3781 }
3782}
3783
3784public Action Event_Bomb_Dropped(Handle event, const char[]name, bool dontBroadcast)
3785{
3786 if (!IsActive(0, true))
3787 {
3788 return;
3789 }
3790
3791 // stats
3792 if (GetConVarBool(wm_stats_enabled))
3793 {
3794 char log_string[384];
3795 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3796 if (g_t_knife)
3797 {
3798 LogEvent("{\"event\": \"knife_bomb_dropped\", \"round\": %i, \"player\": %s}", g_round, log_string);
3799 }
3800 else
3801 {
3802 LogEvent("{\"event\": \"bomb_dropped\", \"round\": %i, \"player\": %s}", g_round, log_string);
3803 }
3804 }
3805}
3806
3807public Action Event_Bomb_Plant_Begin(Handle event, const char[]name, bool dontBroadcast)
3808{
3809 if (!IsActive(0, true))
3810 {
3811 return;
3812 }
3813
3814 // stats
3815 if (GetConVarBool(wm_stats_enabled))
3816 {
3817 char log_string[384];
3818 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3819 LogEvent("{\"event\": \"bomb_plant_begin\", \"round\": %i, \"player\": %s, \"site\": %d}", g_round, log_string, GetEventInt(event, "site"));
3820 }
3821}
3822
3823public Action Event_Bomb_Plant_Abort(Handle event, const char[]name, bool dontBroadcast)
3824{
3825 if (!IsActive(0, true))
3826 {
3827 return;
3828 }
3829
3830 // stats
3831 if (GetConVarBool(wm_stats_enabled))
3832 {
3833 char log_string[384];
3834 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3835 LogEvent("{\"event\": \"bomb_plant_abort\", \"round\": %i, \"player\": %s, \"site\": %d}", g_round, log_string, GetEventInt(event, "site"));
3836 }
3837}
3838
3839public Action Event_Bomb_Planted(Handle event, const char[]name, bool dontBroadcast)
3840{
3841 g_planted = true;
3842
3843 if (!IsActive(0, true))
3844 {
3845 return;
3846 }
3847
3848 // stats
3849 if (GetConVarBool(wm_stats_enabled))
3850 {
3851 char log_string[384];
3852 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3853 LogEvent("{\"event\": \"bomb_planted\", \"round\": %i, \"player\": %s, \"site\": %d}", g_round, log_string, GetEventInt(event, "site"));
3854 }
3855}
3856
3857public Action Event_Bomb_Defuse_Begin(Handle event, const char[]name, bool dontBroadcast)
3858{
3859 if (!IsActive(0, true))
3860 {
3861 return;
3862 }
3863
3864 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3865
3866 // stats
3867 if (GetConVarBool(wm_stats_enabled))
3868 {
3869 char log_string[384];
3870 CS_GetAdvLogString(client, log_string, sizeof(log_string));
3871 LogEvent("{\"event\": \"bomb_defuse_begin\", \"round\": %i, \"player\": %s, \"kit\": %d}", g_round, log_string, GetEventInt(event, "site"), GetEventBool(event, "haskit"));
3872 }
3873}
3874
3875public Action Event_Bomb_Defuse_Abort(Handle event, const char[]name, bool dontBroadcast)
3876{
3877 if (!IsActive(0, true))
3878 {
3879 return;
3880 }
3881
3882 // stats
3883 if (GetConVarBool(wm_stats_enabled))
3884 {
3885 char log_string[384];
3886 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3887 LogEvent("{\"event\": \"bomb_defuse_abort\", \"round\": %i, \"player\": %s}", g_round, log_string);
3888 }
3889}
3890
3891public Action Event_Bomb_Defused(Handle event, const char[]name, bool dontBroadcast)
3892{
3893 if (!IsActive(0, true))
3894 {
3895 return;
3896 }
3897
3898 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3899
3900 // stats
3901 if (GetConVarBool(wm_stats_enabled))
3902 {
3903 char log_string[384];
3904 CS_GetAdvLogString(client, log_string, sizeof(log_string));
3905 LogEvent("{\"event\": \"bomb_defused\", \"round\": %i, \"player\": %s, \"site\": %d}", g_round, log_string, GetEventInt(event, "site"));
3906 }
3907}
3908
3909public Action Event_Weapon_Fire(Handle event, const char[]name, bool dontBroadcast)
3910{
3911 if (!IsActive(0, true))
3912 {
3913 return;
3914 }
3915
3916 // stats
3917 if (GetConVarBool(wm_stats_enabled))
3918 {
3919 int client = GetClientOfUserId(GetEventInt(event, "userid"));
3920 if (client > 0)
3921 {
3922 char weapon[64];
3923 GetEventString(event, "weapon", weapon, sizeof(weapon));
3924 if (StrEqual(weapon, "m4a1"))
3925 {
3926 int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY);
3927 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3928 if (pWeapon == 60)
3929 {
3930 weapon = "m4a1_silencer";
3931 }
3932 }
3933 else if (StrEqual(weapon, "hkp2000") || StrEqual(weapon, "p250") || StrEqual(weapon, "fiveseven") || StrEqual(weapon, "tec9") || StrEqual(weapon, "deagle"))
3934 {
3935 int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
3936 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3937 if (pWeapon == 61)
3938 {
3939 weapon = "usp_silencer";
3940 }
3941 else if (pWeapon == 63)
3942 {
3943 weapon = "cz75a";
3944 }
3945 else if (pWeapon == 64)
3946 {
3947 weapon = "revolver";
3948 }
3949 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
3950 int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
3951 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
3952 if (pWeapon == 500 || pWeapon == 505 || pWeapon == 506 || pWeapon == 507 || pWeapon == 508 || pWeapon == 509 || pWeapon == 512 || pWeapon == 515 || pWeapon == 516 || pWeapon == 59 || pWeapon == 42)
3953 {
3954 weapon = "knife";
3955 }
3956 }
3957
3958 if (StrEqual(weapon, "m4a1_silencer_off")) {
3959 weapon = "m4a1_silencer";
3960 } else if (StrEqual(weapon, "usp_silencer_off")) {
3961 weapon = "usp_silencer";
3962 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
3963 weapon = "knife";
3964 }
3965
3966 int weapon_index = GetWeaponIndex(weapon);
3967 if (weapon_index > -1)
3968 {
3969 weapon_stats[client][weapon_index][LOG_HIT_SHOTS]++;
3970 }
3971 }
3972 }
3973}
3974
3975public Action Event_Detonate_Flash(Handle event, const char[]name, bool dontBroadcast)
3976{
3977 if (!IsActive(0, true))
3978 {
3979 return;
3980 }
3981
3982 // stats
3983 if (GetConVarBool(wm_stats_enabled))
3984 {
3985 char log_string[384];
3986 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
3987 LogEvent("{\"event\": \"grenade_detonate\", \"round\": %i, \"player\": %s, \"grenade\": \"flashbang\"}", g_round, log_string);
3988 }
3989}
3990
3991public Action Event_Detonate_Smoke(Handle event, const char[]name, bool dontBroadcast)
3992{
3993 if (!IsActive(0, true))
3994 {
3995 return;
3996 }
3997
3998 // stats
3999 if (GetConVarBool(wm_stats_enabled))
4000 {
4001 char log_string[384];
4002 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
4003 LogEvent("{\"event\": \"grenade_detonate\", \"round\": %i, \"player\": %s, \"grenade\": \"smokegrenade\"}", g_round, log_string);
4004 }
4005}
4006
4007public Action Event_Detonate_HeGrenade(Handle event, const char[]name, bool dontBroadcast)
4008{
4009 if (!IsActive(0, true))
4010 {
4011 return;
4012 }
4013
4014 // stats
4015 if (GetConVarBool(wm_stats_enabled))
4016 {
4017 char log_string[384];
4018 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
4019 LogEvent("{\"event\": \"grenade_detonate\", \"round\": %i, \"player\": %s, \"grenade\": \"hegrenade\"}", g_round, log_string);
4020 }
4021}
4022
4023public Action Event_Detonate_Molotov(Handle event, char[] name, bool dontBroadcast)
4024{
4025 if (!IsActive(0, true))
4026 {
4027 return;
4028 }
4029
4030 // stats
4031 if (GetConVarBool(wm_stats_enabled))
4032 {
4033 char log_string[384];
4034 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
4035 LogEvent("{\"event\": \"grenade_detonate\", \"round\": %i, \"player\": %s, \"grenade\": \"molotov\"}", g_round, log_string);
4036 }
4037}
4038
4039public Action Event_Detonate_Decoy(Handle event, char[] name, bool dontBroadcast)
4040{
4041 if (!IsActive(0, true))
4042 {
4043 return;
4044 }
4045
4046 // stats
4047 if (GetConVarBool(wm_stats_enabled))
4048 {
4049 char log_string[384];
4050 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
4051 LogEvent("{\"event\": \"grenade_detonate\", \"round\": %i, \"player\": %s, \"grenade\": \"decoy\"}", g_round, log_string);
4052 }
4053}
4054
4055public Action Event_Item_Pickup(Handle event, const char[]name, bool dontBroadcast)
4056{
4057 if (!IsActive(0, true))
4058 {
4059 return;
4060 }
4061
4062 // stats
4063 if (GetConVarBool(wm_stats_enabled))
4064 {
4065 char log_string[384];
4066 CS_GetAdvLogString(GetClientOfUserId(GetEventInt(event, "userid")), log_string, sizeof(log_string));
4067 char item[64];
4068 GetEventString(event, "item", item, sizeof(item));
4069 EscapeString(item, sizeof(item));
4070 if (g_t_knife)
4071 {
4072 LogEvent("{\"event\": \"knife_item_pickup\", \"round\": %i, \"player\": %s, \"item\": \"%s\"}", g_round, log_string, item);
4073 }
4074 else
4075 {
4076 LogEvent("{\"event\": \"item_pickup\", \"round\": %i, \"player\": %s, \"item\": \"%s\"}", g_round, log_string, item);
4077 }
4078 }
4079}
4080
4081void AddScore(int team)
4082{
4083 if (!g_overtime)
4084 {
4085 if (team == CS_TEAM_T)
4086 {
4087 if (g_first_half)
4088 {
4089 g_scores[SCORE_T][SCORE_FIRST_HALF]++;
4090 }
4091 else
4092 {
4093 g_scores[SCORE_T][SCORE_SECOND_HALF]++;
4094 }
4095 }
4096
4097 if (team == CS_TEAM_CT)
4098 {
4099 if (g_first_half)
4100 {
4101 g_scores[SCORE_CT][SCORE_FIRST_HALF]++;
4102 }
4103 else
4104 {
4105 g_scores[SCORE_CT][SCORE_SECOND_HALF]++;
4106 }
4107 }
4108 }
4109 else
4110 {
4111 if (team == CS_TEAM_T)
4112 {
4113 if (g_first_half)
4114 {
4115 g_scores_overtime[SCORE_T][g_overtime_count][SCORE_FIRST_HALF]++;
4116 }
4117 else
4118 {
4119 g_scores_overtime[SCORE_T][g_overtime_count][SCORE_SECOND_HALF]++;
4120 }
4121 }
4122
4123 if (team == CS_TEAM_CT)
4124 {
4125 if (g_first_half)
4126 {
4127 g_scores_overtime[SCORE_CT][g_overtime_count][SCORE_FIRST_HALF]++;
4128 }
4129 else
4130 {
4131 g_scores_overtime[SCORE_CT][g_overtime_count][SCORE_SECOND_HALF]++;
4132 }
4133 }
4134 }
4135
4136 if (GetConVarBool(wm_upload_results)) {
4137 MySQL_UploadResultsRound();
4138 }
4139
4140 // stats
4141 if (GetConVarBool(wm_stats_enabled))
4142 {
4143 char serverstring[384];
4144 GetServerString(serverstring, sizeof(serverstring));
4145 LogEvent("{\"event\": \"score_update\", \"map\": \"%s\", \"round\": %i, \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}], \"settings\": {\"max_rounds\": %d, \"overtime_enabled\": %d, \"overtime_max_rounds\": %d}, \"server\": %s}", g_map, g_round, g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore(), GetConVarInt(mp_maxrounds), GetConVarInt(mp_overtime_enable), GetConVarInt(mp_overtime_maxrounds), serverstring);
4146 g_round = GetTTotalScore() + GetCTTotalScore() + 1;
4147 }
4148}
4149
4150void CheckScores()
4151{
4152 if (!g_overtime)
4153 {
4154 if (GetScore() == (GetConVarInt(mp_maxrounds)/2)) // half time
4155 {
4156 if (!g_first_half)
4157 {
4158 return;
4159 }
4160
4161 Call_StartForward(g_f_on_half_time);
4162 Call_PushString(g_ct_name);
4163 Call_PushCell(GetCTTotalScore());
4164 Call_PushCell(GetTTotalScore());
4165 Call_PushString(g_t_name);
4166 Call_Finish();
4167
4168 if (GetConVarBool(wm_stats_enabled))
4169 {
4170 LogEvent("{\"event\": \"half_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4171 }
4172 DisplayScore(0, 0, false);
4173
4174 if (team_switch) {
4175 team_switch = false;
4176 } else {
4177 team_switch = true;
4178 }
4179
4180 g_t_money = false;
4181 g_first_half = false;
4182 SwitchScores();
4183 g_t_pause_count = 0;
4184 g_ct_pause_count = 0;
4185 g_tag_set = false;
4186
4187 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4188 {
4189 SwitchTeamNames();
4190 }
4191 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4192 {
4193 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
4194 SwitchTeamNames();
4195 }
4196 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
4197 {
4198 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
4199 SwitchTeamNames();
4200 }
4201
4202 // char half_time_config[128];
4203 // GetConVarString(g_h_half_time_config, half_time_config, sizeof(half_time_config));
4204 // ServerCommand("exec %s", half_time_config);
4205 if (GetConVarBool(wm_half_time_break))
4206 {
4207 g_half_swap = false;
4208 g_live = false;
4209 SetAllCancelled(false);
4210 ReadyChangeAll(0, false, true);
4211 ReadySystem(true);
4212 ShowInfo(0, true, false, 0);
4213 ServerCommand("mp_halftime_pausetimer 1");
4214 }
4215 }
4216 else if (GetTScore() == (GetConVarInt(mp_maxrounds)/2) && GetCTScore() == (GetConVarInt(mp_maxrounds)/2)) // complete draw
4217 {
4218 if (GetConVarBool(mp_overtime_enable))
4219 {
4220 // max rounds overtime
4221 if (GetConVarBool(wm_stats_enabled))
4222 {
4223 LogEvent("{\"event\": \"over_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4224 }
4225 DisplayScore(0, 0, false);
4226 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Over Time", (GetConVarInt(mp_overtime_maxrounds)/2));
4227 // g_live = false;
4228 g_t_money = false;
4229 g_overtime = true;
4230 g_overtime_mode = 1;
4231 g_first_half = true;
4232 g_tag_set = false;
4233
4234 if (GetConVarBool(wm_half_time_break) || GetConVarBool(wm_over_time_break))
4235 {
4236 g_half_swap = false;
4237 g_live = false;
4238 SetAllCancelled(false);
4239 ReadyChangeAll(0, false, true);
4240 ReadySystem(true);
4241 ShowInfo(0, true, false, 0);
4242 ServerCommand("mp_overtime_halftime_pausetimer 1");
4243 }
4244 }
4245 else
4246 {
4247 Call_StartForward(g_f_on_end_match);
4248 Call_PushString(g_ct_name);
4249 Call_PushCell(GetCTTotalScore());
4250 Call_PushCell(GetTTotalScore());
4251 Call_PushString(g_t_name);
4252 Call_Finish();
4253
4254 if (GetConVarBool(wm_stats_enabled))
4255 {
4256 LogEvent("{\"event\": \"full_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4257 g_round = GetTTotalScore() + GetCTTotalScore();
4258 }
4259 if (GetConVarBool(wm_prefix_logs))
4260 {
4261 CreateTimer(5.0, RenameLogs);
4262 }
4263 DisplayScore(0, 0, false);
4264 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Full Time");
4265/*
4266 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4267 {
4268 SwitchTeamNames();
4269 }
4270 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4271 {
4272 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
4273 SwitchTeamNames();
4274 }
4275 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
4276 {
4277 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
4278 SwitchTeamNames();
4279 }
4280
4281 SwitchScores();
4282*/
4283 SetLastMatchScores();
4284
4285 if (GetConVarBool(wm_upload_results)) {
4286 if (hDatabase == INVALID_HANDLE) {
4287 StartSQL(1);
4288 } else {
4289 MySQL_UploadResults();
4290 }
4291 }
4292
4293 if (GetConVarBool(mp_match_end_restart) && ((g_veto_bo3_active && g_veto_map_number < 3) || (g_veto_bo5_active && g_veto_map_number < 5) || (g_veto_bo2_active && g_veto_map_number < 2)))
4294 {
4295 VetoMapChange();
4296 }
4297
4298 CreateTimer(4.0, ResetMatchTimer);
4299 }
4300 }
4301 else if (GetScore() == GetConVarInt(mp_maxrounds)) // full time (all rounds have been played out)
4302 {
4303 Call_StartForward(g_f_on_end_match);
4304 Call_PushString(g_ct_name);
4305 Call_PushCell(GetCTTotalScore());
4306 Call_PushCell(GetTTotalScore());
4307 Call_PushString(g_t_name);
4308 Call_Finish();
4309
4310 if (GetConVarBool(wm_stats_enabled))
4311 {
4312 LogEvent("{\"event\": \"full_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4313 g_round = GetTTotalScore() + GetCTTotalScore();
4314 }
4315 if (GetConVarBool(wm_prefix_logs))
4316 {
4317 CreateTimer(5.0, RenameLogs);
4318 }
4319 DisplayScore(0, 0, false);
4320 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Full Time");
4321/*
4322 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4323 {
4324 SwitchTeamNames();
4325 }
4326 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4327 {
4328 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
4329 SwitchTeamNames();
4330 }
4331 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
4332 {
4333 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
4334 SwitchTeamNames();
4335 }
4336
4337 SwitchScores();
4338*/
4339 SetLastMatchScores();
4340
4341 if (GetConVarBool(wm_upload_results)) {
4342 if (hDatabase == INVALID_HANDLE) {
4343 StartSQL(1);
4344 } else {
4345 MySQL_UploadResults();
4346 }
4347 }
4348
4349 if (GetConVarBool(mp_match_end_restart) && ((g_veto_bo3_active && g_veto_map_number < 3) || (g_veto_bo5_active && g_veto_map_number < 5) || (g_veto_bo2_active && g_veto_map_number < 2)))
4350 {
4351 VetoMapChange();
4352 }
4353
4354 CreateTimer(4.0, ResetMatchTimer);
4355 }
4356 else if (GetTScore() == (GetConVarInt(mp_maxrounds)/2) + 1 || GetCTScore() == (GetConVarInt(mp_maxrounds)/2) + 1) // full time
4357 {
4358 DisplayScore(0, 0, false);
4359 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Full Time");
4360
4361 if (GetConVarBool(mp_match_can_clinch))
4362 {
4363 Call_StartForward(g_f_on_end_match);
4364 Call_PushString(g_ct_name);
4365 Call_PushCell(GetCTTotalScore());
4366 Call_PushCell(GetTTotalScore());
4367 Call_PushString(g_t_name);
4368 Call_Finish();
4369
4370 if (GetConVarBool(wm_stats_enabled))
4371 {
4372 LogEvent("{\"event\": \"full_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4373 g_round = GetTTotalScore() + GetCTTotalScore();
4374 }
4375 if (GetConVarBool(wm_prefix_logs))
4376 {
4377 CreateTimer(5.0, RenameLogs);
4378 }
4379
4380/* if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4381 {
4382 SwitchTeamNames();
4383 }
4384 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4385 {
4386 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
4387 SwitchTeamNames();
4388 }
4389 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
4390 {
4391 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
4392 SwitchTeamNames();
4393 }
4394
4395 SwitchScores();
4396*/
4397 SetLastMatchScores();
4398
4399 if (GetConVarBool(wm_upload_results)) {
4400 if (hDatabase == INVALID_HANDLE) {
4401 StartSQL(1);
4402 } else {
4403 MySQL_UploadResults();
4404 }
4405 }
4406
4407 if (GetConVarBool(mp_match_end_restart) && ((g_veto_bo3_active && g_veto_map_number < 3) || (g_veto_bo5_active && g_veto_map_number < 5) || (g_veto_bo2_active && g_veto_map_number < 2)))
4408 {
4409 VetoMapChange();
4410 }
4411
4412 CreateTimer(4.0, ResetMatchTimer);
4413 }
4414 else
4415 {
4416 if (GetConVarBool(wm_stats_enabled))
4417 {
4418 LogEvent("{\"event\": \"full_time_playing_out\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4419 }
4420 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Playing Out Notice", (GetConVarInt(mp_maxrounds)/2));
4421 }
4422 }
4423 else
4424 {
4425 DisplayScore(0, 0, false);
4426 }
4427 }
4428 else
4429 {
4430 if (GetOTScore() == (GetConVarInt(mp_overtime_maxrounds)/2)) // half time
4431 {
4432 if (!g_first_half)
4433 {
4434 return;
4435 }
4436
4437 Call_StartForward(g_f_on_half_time);
4438 Call_PushString(g_ct_name);
4439 Call_PushCell(GetCTTotalScore());
4440 Call_PushCell(GetTTotalScore());
4441 Call_PushString(g_t_name);
4442 Call_Finish();
4443
4444 if (GetConVarBool(wm_stats_enabled))
4445 {
4446 LogEvent("{\"event\": \"over_half_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4447 }
4448 if (team_switch) {
4449 team_switch = false;
4450 } else {
4451 team_switch = true;
4452 }
4453 DisplayScore(0, 1, false);
4454
4455 g_t_money = false;
4456 g_first_half = false;
4457 g_tag_set = false;
4458 SwitchScores();
4459
4460 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4461 {
4462 SwitchTeamNames();
4463 }
4464 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4465 {
4466 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
4467 SwitchTeamNames();
4468 }
4469 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
4470 {
4471 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
4472 SwitchTeamNames();
4473 }
4474
4475 if (GetConVarBool(wm_half_time_break))
4476 {
4477 g_half_swap = false;
4478 g_live = false;
4479 SetAllCancelled(false);
4480 ReadyChangeAll(0, false, true);
4481 ReadySystem(true);
4482 ShowInfo(0, true, false, 0);
4483 ServerCommand("mp_overtime_halftime_pausetimer 1");
4484 }
4485 }
4486 else if (GetTOTScore() == (GetConVarInt(mp_overtime_maxrounds)/2) && GetCTOTScore() == (GetConVarInt(mp_overtime_maxrounds)/2)) // complete draw
4487 {
4488 if (g_overtime_mode == 1)
4489 { // max rounds overtime
4490 if (GetConVarBool(wm_stats_enabled))
4491 {
4492 LogEvent("{\"event\": \"over_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4493 }
4494 DisplayScore(0, 1, false);
4495 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Over Time", (GetConVarInt(mp_overtime_maxrounds)/2));
4496 g_overtime_count++;
4497 g_first_half = true;
4498 g_tag_set = false;
4499
4500 if (GetConVarBool(wm_half_time_break) || GetConVarBool(wm_over_time_break))
4501 {
4502 g_half_swap = false;
4503 g_live = false;
4504 SetAllCancelled(false);
4505 ReadyChangeAll(0, false, true);
4506 ReadySystem(true);
4507 ShowInfo(0, true, false, 0);
4508 ServerCommand("mp_overtime_halftime_pausetimer 1");
4509 }
4510
4511 return;
4512 }
4513 }
4514 else if (GetTOTScore() == (GetConVarInt(mp_overtime_maxrounds)/2) + 1 || GetCTOTScore() == (GetConVarInt(mp_overtime_maxrounds)/2) + 1) // full time
4515 {
4516 Call_StartForward(g_f_on_end_match);
4517 Call_PushString(g_ct_name);
4518 Call_PushCell(GetCTTotalScore());
4519 Call_PushCell(GetTTotalScore());
4520 Call_PushString(g_t_name);
4521 Call_Finish();
4522
4523 if (GetConVarBool(wm_stats_enabled))
4524 {
4525 LogEvent("{\"event\": \"over_full_time\", \"teams\": [{\"name\": \"%s\", \"team\": %d, \"score\": %d}, {\"name\": \"%s\", \"team\": %d, \"score\": %d}]}", g_t_name_escaped, CS_TEAM_T, GetTTotalScore(), g_ct_name_escaped, CS_TEAM_CT, GetCTTotalScore());
4526 g_round = GetTTotalScore() + GetCTTotalScore();
4527 }
4528 if (GetConVarBool(wm_prefix_logs))
4529 {
4530 CreateTimer(5.0, RenameLogs);
4531 }
4532 DisplayScore(0, 2, false);
4533 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Full Time");
4534/*
4535 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4536 {
4537 SwitchTeamNames();
4538 }
4539 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
4540 {
4541 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
4542 SwitchTeamNames();
4543 }
4544 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
4545 {
4546 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
4547 SwitchTeamNames();
4548 }
4549 SwitchScores();
4550*/
4551 SetLastMatchScores();
4552
4553 if (GetConVarBool(wm_upload_results)) {
4554 if (hDatabase == INVALID_HANDLE) {
4555 StartSQL(1);
4556 } else {
4557 MySQL_UploadResults();
4558 }
4559 }
4560
4561 if (GetConVarBool(mp_match_end_restart) && ((g_veto_bo3_active && g_veto_map_number < 3) || (g_veto_bo5_active && g_veto_map_number < 5) || (g_veto_bo2_active && g_veto_map_number < 2)))
4562 {
4563 VetoMapChange();
4564 }
4565
4566 CreateTimer(4.0, ResetMatchTimer);
4567 return;
4568 }
4569 else
4570 {
4571 DisplayScore(0, 1, false);
4572 }
4573 }
4574}
4575
4576int GetScore()
4577{
4578 return GetTScore() + GetCTScore();
4579}
4580
4581int GetTScore()
4582{
4583 return g_scores[SCORE_T][SCORE_FIRST_HALF] + g_scores[SCORE_T][SCORE_SECOND_HALF];
4584}
4585
4586int GetCTScore()
4587{
4588 return g_scores[SCORE_CT][SCORE_FIRST_HALF] + g_scores[SCORE_CT][SCORE_SECOND_HALF];
4589}
4590
4591int GetOTScore()
4592{
4593 return GetTOTScore() + GetCTOTScore();
4594}
4595
4596int GetTOTScore()
4597{
4598 return g_scores_overtime[SCORE_T][g_overtime_count][SCORE_FIRST_HALF] + g_scores_overtime[SCORE_T][g_overtime_count][SCORE_SECOND_HALF];
4599}
4600
4601int GetCTOTScore()
4602{
4603 return g_scores_overtime[SCORE_CT][g_overtime_count][SCORE_FIRST_HALF] + g_scores_overtime[SCORE_CT][g_overtime_count][SCORE_SECOND_HALF];
4604}
4605
4606int GetTOTTotalScore()
4607{
4608 int result;
4609 for (int i = 0; i <= g_overtime_count; i++)
4610 {
4611 result += g_scores_overtime[SCORE_T][i][SCORE_FIRST_HALF] + g_scores_overtime[SCORE_T][i][SCORE_SECOND_HALF];
4612 }
4613 return result;
4614}
4615
4616int GetCTOTTotalScore()
4617{
4618 int result;
4619 for (int i = 0; i <= g_overtime_count; i++)
4620 {
4621 result += g_scores_overtime[SCORE_CT][i][SCORE_FIRST_HALF] + g_scores_overtime[SCORE_CT][i][SCORE_SECOND_HALF];
4622 }
4623 return result;
4624}
4625
4626int GetTTotalScore()
4627{
4628 int result;
4629 result = GetTScore();
4630 for (int i = 0; i <= g_overtime_count; i++)
4631 {
4632 result += g_scores_overtime[SCORE_T][i][SCORE_FIRST_HALF] + g_scores_overtime[SCORE_T][i][SCORE_SECOND_HALF];
4633 }
4634 return result;
4635}
4636
4637int GetCTTotalScore()
4638{
4639 int result;
4640 result = GetCTScore();
4641 for (int i = 0; i <= g_overtime_count; i++)
4642 {
4643 result += g_scores_overtime[SCORE_CT][i][SCORE_FIRST_HALF] + g_scores_overtime[SCORE_CT][i][SCORE_SECOND_HALF];
4644 }
4645 return result;
4646}
4647
4648public int SortMoney(int elem1, int elem2, const int[] array, Handle hndl)
4649{
4650 int money1 = GetEntData(elem1, g_iAccount);
4651 int money2 = GetEntData(elem2, g_iAccount);
4652
4653 if (money1 > money2)
4654 {
4655 return -1;
4656 }
4657 else if (money1 == money2)
4658 {
4659 return 0;
4660 }
4661 else
4662 {
4663 return 1;
4664 }
4665}
4666
4667void ReadyServ(int client, bool ready, bool silent, bool show, bool priv)
4668{
4669 char log_string[384];
4670 CS_GetLogString(client, log_string, sizeof(log_string));
4671
4672 if (ready)
4673 {
4674 if (GetConVarBool(wm_stats_enabled) && g_player_list[client] == PLAYER_UNREADY)
4675 {
4676 LogEvent("{\"event\": \"player_ready\", \"player\": %s}", log_string);
4677 }
4678
4679 g_player_list[client] = PLAYER_READY;
4680 SetTagReady(client);
4681
4682 if (!silent)
4683 {
4684 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Ready");
4685 }
4686 }
4687 else
4688 {
4689 if (GetConVarBool(wm_stats_enabled) && g_player_list[client] == PLAYER_READY)
4690 {
4691 LogEvent("{\"event\": \"player_unready\", \"player\": %s}", log_string);
4692 }
4693
4694 g_player_list[client] = PLAYER_UNREADY;
4695 SetTagNotReady(client);
4696
4697 if (!silent)
4698 {
4699 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Not Ready");
4700 }
4701 }
4702
4703 if (show)
4704 {
4705 ShowInfo(client, true, priv, 0);
4706 }
4707
4708 CheckReady();
4709}
4710
4711void GetCaptainFromFileCR(int team)
4712{
4713 char authid[32];
4714 char teamflag[4];
4715 char teamlogo[8];
4716 char teamname[64];
4717 Handle kv = CreateKeyValues("Captains");
4718 FileToKeyValues(kv, "cfg/warmod/team_captains.txt");
4719 for (int i = 1; i <= MaxClients; i++)
4720 {
4721 if (IsValidClient(i) && GetClientTeam(i) == team)
4722 {
4723 GetClientAuthId(i, AuthId_Steam2, authid, sizeof(authid));
4724
4725 if (KvJumpToKey(kv, authid))
4726 {
4727 KvGetString(kv, "teamname", teamname, sizeof(teamname));
4728 KvGetString(kv, "teamlogo", teamlogo, sizeof(teamlogo));
4729 KvGetString(kv, "teamflag", teamflag, sizeof(teamflag));
4730 if (team == CS_TEAM_T) {
4731 ServerCommand("mp_teamname_2 %s", teamname);
4732 ServerCommand("mp_teamflag_2 %s", teamflag);
4733 ServerCommand("mp_teamlogo_2 %s", teamlogo);
4734 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x09%s", CHAT_PREFIX, teamname);
4735 captain_file_checked_t = true;
4736 } else if (team == CS_TEAM_CT) {
4737 ServerCommand("mp_teamname_1 %s", teamname);
4738 ServerCommand("mp_teamflag_1 %s", teamflag);
4739 ServerCommand("mp_teamlogo_1 %s", teamlogo);
4740 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x09%s", CHAT_PREFIX, teamname);
4741 captain_file_checked_ct = true;
4742 }
4743
4744 CloseHandle(kv);
4745 return;
4746 }
4747 }
4748 }
4749
4750 if (team == CS_TEAM_T) {
4751 captain_file_checked_t = true;
4752 } else if (team == CS_TEAM_CT) {
4753 captain_file_checked_ct = true;
4754 }
4755
4756 CloseHandle(kv);
4757 return;
4758}
4759
4760void CheckReady()
4761{
4762 if (g_live)
4763 {
4764 return;
4765 }
4766
4767 if (g_ready_enabled && !GetConVarBool(wm_warmod_safemode))
4768 {
4769 for (int i = 1; i <= MaxClients; i++)
4770 {
4771 if (IsValidClient(i))
4772 {
4773 if (g_player_list[i] == PLAYER_READY)
4774 {
4775 SetTagReady(i);
4776 }
4777 else if (g_player_list[i] == PLAYER_UNREADY)
4778 {
4779 SetTagNotReady(i);
4780 }
4781 }
4782 }
4783 }
4784
4785 char t_name[64];
4786 char ct_name[64];
4787 Format(t_name, sizeof(t_name), g_t_name);
4788 Format(ct_name, sizeof(ct_name), g_ct_name);
4789
4790 StripFilename(t_name, sizeof(t_name));
4791 StripFilename(ct_name, sizeof(ct_name));
4792 ReplaceString(t_name, sizeof(t_name), ".", "");
4793 ReplaceString(ct_name, sizeof(ct_name), ".", "");
4794
4795 if (((GetConVarBool(wm_require_names) || GetConVarBool(wm_require_logos)) && GetTeamClientCount(CS_TEAM_CT) >= (GetConVarInt(wm_min_ready)/2) && GetTeamClientCount(CS_TEAM_T) >= (GetConVarInt(wm_min_ready)/2) && ((StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) || (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)))))
4796 {
4797 if (!GetConVarBool(wm_warmod_safemode) && !GetConVarBool(wm_require_logos))
4798 {
4799 if (StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false))
4800 {
4801 getTerroristTeamName();
4802 }
4803
4804 if (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false))
4805 {
4806 getCounterTerroristTeamName();
4807 }
4808 }
4809
4810 if (GetConVarBool(wm_require_logos))
4811 {
4812 char t_logo[8];
4813 char ct_logo[8];
4814 GetConVarString(mp_teamlogo_1, ct_logo, sizeof(ct_logo));
4815 GetConVarString(mp_teamlogo_2, t_logo, sizeof(t_logo));
4816
4817 if (StrEqual(t_logo, "", false) && !captain_file_checked_t) {
4818 GetCaptainFromFileCR(CS_TEAM_T);
4819 }
4820
4821 if (StrEqual(ct_logo, "", false) && !captain_file_checked_ct) {
4822 GetCaptainFromFileCR(CS_TEAM_CT);
4823 }
4824
4825 if (StrEqual(t_logo, "", false) && StrEqual(ct_logo, "", false))
4826 {
4827 g_p_ct_name = true;
4828 g_p_t_name = true;
4829 if (g_setNameLimiter)
4830 {
4831 g_setNameLimiter = false;
4832 CreateTimer(20.0, setNameLimiterTrue);
4833 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Logos Required");
4834 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Logo Both");
4835 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Logo CMD");
4836 }
4837 }
4838 else if (!StrEqual(t_logo, "", false) && StrEqual(ct_logo, "", false))
4839 {
4840 g_p_ct_name = true;
4841 if (g_setNameLimiter)
4842 {
4843 g_setNameLimiter = false;
4844 CreateTimer(20.0, setNameLimiterTrue);
4845 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Logos Required");
4846 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Logo CT");
4847 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Logo CMD");
4848 }
4849 }
4850 else if (StrEqual(t_logo, "", false) && !StrEqual(ct_logo, "", false))
4851 {
4852 g_p_t_name = true;
4853 if (g_setNameLimiter)
4854 {
4855 g_setNameLimiter = false;
4856 CreateTimer(20.0, setNameLimiterTrue);
4857 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Logos Required");
4858 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Logo T");
4859 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Logo CMD");
4860 }
4861
4862 }
4863 else if ((StrEqual(t_logo, "none", false) && StrEqual(ct_logo, "none", false)) && (StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) && (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)))
4864 {
4865 g_p_ct_name = true;
4866 g_p_t_name = true;
4867 if (g_setNameLimiter)
4868 {
4869 g_setNameLimiter = false;
4870 CreateTimer(20.0, setNameLimiterTrue);
4871 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Names Required");
4872 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Name Both");
4873 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Name CMD");
4874 }
4875 }
4876 else if (StrEqual(ct_logo, "none", false) && (!StrEqual(t_name, DEFAULT_T_NAME, false) || !StrEqual(t_name, "", false) || !StrEqual(t_name, "_", false)) && (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)))
4877 {
4878 g_p_ct_name = true;
4879 if (g_setNameLimiter)
4880 {
4881 g_setNameLimiter = false;
4882 CreateTimer(20.0, setNameLimiterTrue);
4883 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Names Required");
4884 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Name CT");
4885 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Name CMD");
4886 }
4887 }
4888 else if (StrEqual(t_logo, "none", false) && (StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) && (!StrEqual(ct_name, DEFAULT_CT_NAME, false) || !StrEqual(ct_name, "", false) || !StrEqual(ct_name, "_", false)))
4889 {
4890 g_p_t_name = true;
4891 if (g_setNameLimiter)
4892 {
4893 g_setNameLimiter = false;
4894 CreateTimer(20.0, setNameLimiterTrue);
4895 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Names Required");
4896 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Name T");
4897 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Name CMD");
4898 }
4899 }
4900 else if ((!StrEqual(t_name, DEFAULT_T_NAME, false) || !StrEqual(t_name, "", false) || !StrEqual(t_name, "_", false)) && (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)))
4901 {
4902 g_p_ct_name = true;
4903 if (g_setNameLimiter)
4904 {
4905 g_setNameLimiter = false;
4906 CreateTimer(20.0, setNameLimiterTrue);
4907 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Names Required");
4908 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Name CT");
4909 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Name CMD");
4910 }
4911 }
4912 else if ((StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) && (!StrEqual(ct_name, DEFAULT_CT_NAME, false) || !StrEqual(ct_name, "", false) || !StrEqual(ct_name, "_", false)))
4913 {
4914 g_p_t_name = true;
4915 if (g_setNameLimiter)
4916 {
4917 g_setNameLimiter = false;
4918 CreateTimer(20.0, setNameLimiterTrue);
4919 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Names Required");
4920 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Name T");
4921 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Name CMD");
4922 }
4923 }
4924
4925 if (StrEqual(t_logo, "", false) || StrEqual(ct_logo, "", false) || StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false) || StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false))
4926 {
4927 return;
4928 }
4929 }
4930 else
4931 {
4932 if ((StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) && !captain_file_checked_t) {
4933 GetCaptainFromFileCR(CS_TEAM_T);
4934 }
4935
4936 if ((StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)) && !captain_file_checked_ct) {
4937 GetCaptainFromFileCR(CS_TEAM_CT);
4938 }
4939
4940 if ((StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) && (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)))
4941 {
4942 g_p_ct_name = true;
4943 g_p_t_name = true;
4944 if (g_setNameLimiter)
4945 {
4946 g_setNameLimiter = false;
4947 CreateTimer(20.0, setNameLimiterTrue);
4948 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Names Required");
4949 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Name Both");
4950 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Set Name CMD");
4951 }
4952 return;
4953 }
4954 else if ((!StrEqual(t_name, DEFAULT_T_NAME, false) || !StrEqual(t_name, "", false) || !StrEqual(t_name, "_", false)) && (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false)))
4955 {
4956 g_p_ct_name = true;
4957 if (g_setNameLimiter)
4958 {
4959 g_setNameLimiter = false;
4960 CreateTimer(20.0, setNameLimiterTrue);
4961 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Names Required");
4962 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Name CT");
4963 PrintToChatAll("\x01 \x09[\x04%s\x09]\x0C %t", CHAT_PREFIX, "Set Name CMD");
4964 }
4965 return;
4966 }
4967 else if ((StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false)) && (!StrEqual(ct_name, DEFAULT_CT_NAME, false) || !StrEqual(ct_name, "", false) || !StrEqual(ct_name, "_", false)))
4968 {
4969 g_p_t_name = true;
4970 if (g_setNameLimiter)
4971 {
4972 g_setNameLimiter = false;
4973 CreateTimer(20.0, setNameLimiterTrue);
4974 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Names Required");
4975 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Name T");
4976 PrintToChatAll("\x01 \x09[\x04%s\x09]\x02 %t", CHAT_PREFIX, "Set Name CMD");
4977 }
4978 return;
4979 }
4980 }
4981 }
4982
4983
4984
4985 int ready_num;
4986 for (int i = 1; i <= MaxClients; i++)
4987 {
4988 if (g_player_list[i] == PLAYER_READY && IsClientInGame(i) && !IsFakeClient(i))
4989 {
4990 ready_num++;
4991 }
4992 }
4993
4994 if (g_ready_enabled && !g_live && (ready_num >= GetConVarInt(wm_min_ready) || GetConVarInt(wm_min_ready) == 0))
4995 {
4996 if (!g_t_had_knife && !g_match && GetConVarBool(wm_auto_knife))
4997 {
4998 ShowInfo(0, false, false, 1);
4999 SetAllCancelled(false);
5000 ReadySystem(false);
5001 KnifeOn3(0, 0);
5002 return;
5003 }
5004 ShowInfo(0, false, false, 1);
5005 SetAllCancelled(false);
5006 ReadySystem(false);
5007 ServerCommand("mp_warmup_end");
5008 LiveOn3(true);
5009 }
5010}
5011
5012void ReadyChecked()
5013{
5014 if (!g_start)
5015 {
5016 g_match_start = GetEngineTime();
5017 FormatTime(date, sizeof(date), "%Y-%m-%d");
5018 FormatTime(startHour, sizeof(startHour), "%H");
5019 FormatTime(startMin, sizeof(startMin), "%M");
5020
5021 if (GetConVarBool(wm_random_team_names))
5022 {
5023 g_teamNumber_ct = GetRandomInt(0, 33);
5024 g_teamNumber_t = GetRandomInt(0, 33);
5025
5026 while (g_teamNumber_ct == g_teamNumber_t)
5027 {
5028 g_teamNumber_ct = GetRandomInt(0, 33);
5029 g_teamNumber_t = GetRandomInt(0, 33);
5030 }
5031
5032 Format(g_t_name, sizeof(g_t_name), g_teamName[g_teamNumber_t]);
5033 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_teamName[g_teamNumber_t]);
5034 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
5035 ServerCommand("mp_teamname_2 %s", g_t_name);
5036 ServerCommand("mp_teamlogo_2 %s", g_teamLogo[g_teamNumber_t]);
5037 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x02%s", CHAT_PREFIX, g_t_name);
5038
5039 Format(g_ct_name, sizeof(g_ct_name), g_teamName[g_teamNumber_ct]);
5040 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_teamName[g_teamNumber_ct]);
5041 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
5042 ServerCommand("mp_teamname_1 %s", g_ct_name);
5043 ServerCommand("mp_teamlogo_1 %s", g_teamLogo[g_teamNumber_ct]);
5044 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x0C%s", CHAT_PREFIX, g_ct_name);
5045
5046 if (!GetConVarBool(wm_warmod_safemode))
5047 {
5048 for (int i = 1; i <= MaxClients; i++)
5049 {
5050 if (IsValidClient(i) && GetClientTeam(i) == 3)
5051 {
5052 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_ct]);
5053 }
5054 else if (IsValidClient(i) && GetClientTeam(i) == 2)
5055 {
5056 CS_SetClientClanTag(i, g_teamTag[g_teamNumber_t]);
5057 }
5058 }
5059 g_tag_set = true;
5060 }
5061 }
5062
5063 char t_name[64];
5064 char ct_name[64];
5065 Format(t_name, sizeof(t_name), g_t_name);
5066 Format(ct_name, sizeof(ct_name), g_ct_name);
5067
5068 StripFilename(t_name, sizeof(t_name));
5069 StripFilename(ct_name, sizeof(ct_name));
5070 ReplaceString(t_name, sizeof(t_name), ".", "");
5071 ReplaceString(ct_name, sizeof(ct_name), ".", "");
5072 StringToLower(t_name, sizeof(t_name));
5073 StringToLower(ct_name, sizeof(ct_name));
5074
5075 if (!GetConVarBool(wm_warmod_safemode))
5076 {
5077 if (StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false))
5078 {
5079 getTerroristTeamName();
5080 }
5081
5082 if (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "CounterTerrorists", false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false))
5083 {
5084 getCounterTerroristTeamName();
5085 }
5086 }
5087
5088 Format(t_name, sizeof(t_name), g_t_name);
5089 Format(ct_name, sizeof(ct_name), g_ct_name);
5090
5091 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) || !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
5092 {
5093 StripFilename(t_name, sizeof(t_name));
5094 StripFilename(ct_name, sizeof(ct_name));
5095 ReplaceString(t_name, sizeof(t_name), ".", "");
5096 ReplaceString(ct_name, sizeof(ct_name), ".", "");
5097 StringToLower(t_name, sizeof(t_name));
5098 StringToLower(ct_name, sizeof(ct_name));
5099 if (StrEqual(t_name, "rrorists", false)) {
5100 Format(t_name, sizeof(t_name), "terroists");
5101 }
5102 if (StrEqual(ct_name, "unterterrorists", false)) {
5103 Format(ct_name, sizeof(ct_name), "counterterroists");
5104 }
5105 Format(g_log_filename, sizeof(g_log_filename), "%s-%s%s-%04x-%s-%s-vs-%s", date, startHour, startMin, GetConVarInt(FindConVar("hostport")), g_map, t_name, ct_name);
5106 }
5107 else
5108 {
5109 Format(g_log_filename, sizeof(g_log_filename), "%s-%s%s-%04x-%s", date, startHour, startMin, GetConVarInt(FindConVar("hostport")), g_map);
5110 }
5111
5112 char save_dir[128];
5113 GetConVarString(wm_save_dir, save_dir, sizeof(save_dir));
5114 char file_prefix[1];
5115 if (GetConVarBool(wm_prefix_logs))
5116 {
5117 file_prefix = "_";
5118 }
5119 if (!StrEqual(save_dir, ""))
5120 {
5121 if (!DirExists(save_dir))
5122 {
5123 CreateDirectory(save_dir, 511);
5124 }
5125 }
5126 if (GetConVarBool(wm_auto_record))
5127 {
5128 ServerCommand("tv_stoprecord");
5129 if (!GetConVarBool(tv_enable))
5130 {
5131 LogError("[WarMod] GOTV is not enabled - Please enable to record demos or disable wm_auto_record");
5132 }
5133 else if (!StrEqual(save_dir, ""))
5134 {
5135 if (DirExists(save_dir))
5136 {
5137 ServerCommand("tv_record \"%s/%s%s.dem\"", save_dir, file_prefix, g_log_filename);
5138 g_log_warmod_dir = true;
5139 Format(g_sDemoPath, sizeof(g_sDemoPath), "%s/%s%s.dem", save_dir, file_prefix, g_log_filename);
5140 Format(g_sDemoName, sizeof(g_sDemoName), "%s%s.dem", file_prefix, g_log_filename);
5141 g_bRecording = true;
5142 }
5143 else
5144 {
5145 ServerCommand("tv_record \"%s%s.dem\"", file_prefix, g_log_filename);
5146 g_log_warmod_dir = false;
5147 Format(g_sDemoPath, sizeof(g_sDemoPath), "%s%s.dem", file_prefix, g_log_filename);
5148 Format(g_sDemoName, sizeof(g_sDemoName), "%s%s.dem", file_prefix, g_log_filename);
5149 g_bRecording = true;
5150 }
5151 }
5152 else
5153 {
5154 ServerCommand("tv_record \"%s%s.dem\"", file_prefix, g_log_filename);
5155 g_log_warmod_dir = false;
5156 Format(g_sDemoPath, sizeof(g_sDemoPath), "%s%s.dem", file_prefix, g_log_filename);
5157 Format(g_sDemoName, sizeof(g_sDemoName), "%s%s.dem", file_prefix, g_log_filename);
5158 g_bRecording = true;
5159 }
5160 }
5161
5162 if (GetConVarBool(wm_stats_enabled))
5163 {
5164 char filepath[128];
5165 if (!StrEqual(save_dir, ""))
5166 {
5167 if (DirExists(save_dir))
5168 {
5169 Format(filepath, sizeof(filepath), "%s/%s%s.log", save_dir, file_prefix, g_log_filename);
5170 Format(g_sLogPath, sizeof(g_sLogPath), "%s/%s%s.log", save_dir, file_prefix, g_log_filename);
5171 g_log_file = OpenFile(filepath, "w");
5172 g_log_warmod_dir = true;
5173 }
5174 else if (DirExists("logs"))
5175 {
5176 Format(filepath, sizeof(filepath), "logs/%s%s.log", file_prefix, g_log_filename);
5177 Format(g_sLogPath, sizeof(g_sLogPath), "logs/%s%s.log", file_prefix, g_log_filename);
5178 g_log_file = OpenFile(filepath, "w");
5179 g_log_warmod_dir = false;
5180 }
5181 else
5182 {
5183 Format(filepath, sizeof(filepath), "%s%s.log", file_prefix, g_log_filename);
5184 Format(g_sLogPath, sizeof(g_sLogPath), "%s%s.log", file_prefix, g_log_filename);
5185 g_log_file = OpenFile(filepath, "w");
5186 g_log_warmod_dir = false;
5187 }
5188 }
5189 else if (DirExists("logs"))
5190 {
5191 Format(filepath, sizeof(filepath), "logs/%s%s.log", file_prefix, g_log_filename);
5192 Format(g_sLogPath, sizeof(g_sLogPath), "logs/%s%s.log", file_prefix, g_log_filename);
5193 g_log_file = OpenFile(filepath, "w");
5194 g_log_warmod_dir = false;
5195 }
5196 else
5197 {
5198 Format(filepath, sizeof(filepath), "%s%s.log", file_prefix, g_log_filename);
5199 Format(g_sLogPath, sizeof(g_sLogPath), "%s%s.log", file_prefix, g_log_filename);
5200 g_log_file = OpenFile(filepath, "w");
5201 g_log_warmod_dir = false;
5202 }
5203 g_log_live = true;
5204 LogEvent("{\"event\": \"log_start\", \"unixTime\": %d}", GetTime());
5205 }
5206 g_log_live = true;
5207 LogPlayers();
5208 }
5209}
5210
5211void LiveOn3(bool e_war)
5212{
5213 ServerCommand("mp_warmup_end");
5214 Call_StartForward(g_f_on_lo3);
5215 Call_Finish();
5216
5217 g_t_score = false;
5218
5219 char match_config[64];
5220 GetConVarString(wm_match_config, match_config, sizeof(match_config));
5221
5222 if (e_war && !StrEqual(match_config, ""))
5223 {
5224 ServerCommand("exec %s", match_config);
5225 }
5226
5227 ReadyChecked();
5228 g_start = true;
5229 g_max_lock = true;
5230 g_match = true;
5231 g_live = true;
5232 g_MatchComplete = true;
5233 LiveOn3Override();
5234}
5235
5236stock bool LiveOn3Override()
5237{
5238
5239 if (!g_half_swap)
5240 {
5241 ServerCommand("mp_halftime_pausetimer 0");
5242 ServerCommand("mp_overtime_halftime_pausetimer 0");
5243 LiveOn3Text = true;
5244 g_half_swap = true;
5245 LiveText();
5246 return true;
5247 }
5248
5249// SQL_Player_Info();
5250 if (hDatabase == INVALID_HANDLE) {
5251 StartSQL(2);
5252 } else {
5253 MySQL_CreateResultKey();
5254 }
5255
5256
5257 if (g_restore)
5258 {
5259 LiveOn3Text = true;
5260 Event_Round_Start_CMD();
5261 ServerCommand("mp_backup_restore_load_autopause 0");
5262 ServerCommand("mp_backup_restore_load_file %s", g_c_backup);
5263 g_restore = false;
5264 char id_match[16];
5265 if(SplitString(g_c_backup, "_", id_match, sizeof(id_match)) != -1) {
5266 match_id = StringToInt(id_match);
5267 }
5268
5269 if (GetConVarBool(wm_stats_enabled))
5270 {
5271 char serverstring[384];
5272 GetServerString(serverstring, sizeof(serverstring));
5273 LogEvent("{\"event\": \"live_on_3_restored\", \"map\": \"%s\", \"teams\": [{\"name\": \"%s\", \"team\": %d}, {\"name\": \"%s\", \"team\": %d}], \"status\": %d, \"settings\": {\"max_rounds\": %d, \"overtime_enabled\": %d, \"overtime_max_rounds\": %d}, \"server\": %s, \"competition\": \"%s\", \"event_name\": \"%s\", \"version\": \"%s\"}", g_map, g_t_name_escaped, CS_TEAM_T, g_ct_name_escaped, CS_TEAM_CT, UpdateStatus(), GetConVarInt(mp_maxrounds), GetConVarInt(mp_overtime_enable), GetConVarInt(mp_overtime_maxrounds), serverstring, g_competition, g_event, WM_VERSION);
5274 }
5275 return true;
5276 }
5277
5278 team_switch = false;
5279 if (!InWarmup())
5280 {
5281 ServerCommand("mp_unpause_match 1");
5282 ServerCommand("mp_restartgame 1");
5283 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Live on 3");
5284 LiveOn2 = true;
5285 ServerCommand("mp_teamname_1 %s", g_ct_name);
5286 ServerCommand("mp_teamname_2 %s", g_t_name);
5287 g_t_pause_count = 0;
5288 g_ct_pause_count = 0;
5289
5290 if (GetConVarBool(wm_stats_enabled))
5291 {
5292 char serverstring[384];
5293 GetServerString(serverstring, sizeof(serverstring));
5294 LogEvent("{\"event\": \"live_on_3\", \"map\": \"%s\", \"teams\": [{\"name\": \"%s\", \"team\": %d}, {\"name\": \"%s\", \"team\": %d}], \"status\": %d, \"settings\": {\"max_rounds\": %d, \"overtime_enabled\": %d, \"overtime_max_rounds\": %d}, \"server\": %s, \"competition\": \"%s\", \"event_name\": \"%s\", \"version\": \"%s\"}", g_map, g_t_name_escaped, CS_TEAM_T, g_ct_name_escaped, CS_TEAM_CT, UpdateStatus(), GetConVarInt(mp_maxrounds), GetConVarInt(mp_overtime_enable), GetConVarInt(mp_overtime_maxrounds), serverstring, g_competition, g_event, WM_VERSION);
5295 }
5296 return true;
5297 }
5298 else
5299 {
5300 ServerCommand("mp_warmup_end");
5301 CreateTimer(1.0, Lo3Timer);
5302 return true;
5303 }
5304}
5305
5306public Action Lo3Timer(Handle timer)
5307{
5308 ServerCommand("mp_unpause_match 1");
5309 ServerCommand("mp_restartgame 1");
5310 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Live on 3");
5311 LiveOn2 = true;
5312 ServerCommand("mp_teamname_1 %s", g_ct_name);
5313 ServerCommand("mp_teamname_2 %s", g_t_name);
5314 g_t_pause_count = 0;
5315 g_ct_pause_count = 0;
5316
5317 if (GetConVarBool(wm_stats_enabled))
5318 {
5319 char serverstring[384];
5320 GetServerString(serverstring, sizeof(serverstring));
5321 LogEvent("{\"event\": \"live_on_3\", \"map\": \"%s\", \"teams\": [{\"name\": \"%s\", \"team\": %d}, {\"name\": \"%s\", \"team\": %d}], \"status\": %d, \"settings\": {\"max_rounds\": %d, \"overtime_enabled\": %d, \"overtime_max_rounds\": %d}, \"server\": %s, \"competition\": \"%s\", \"event_name\": \"%s\", \"version\": \"%s\"}", g_map, g_t_name_escaped, CS_TEAM_T, g_ct_name_escaped, CS_TEAM_CT, UpdateStatus(), GetConVarInt(mp_maxrounds), GetConVarInt(mp_overtime_enable), GetConVarInt(mp_overtime_maxrounds), serverstring, g_competition, g_event, WM_VERSION);
5322 }
5323}
5324
5325static void LiveText() {
5326 if (LiveOn2) {
5327 LiveOn2 = false;
5328 LiveOn1 = true;
5329 ServerCommand("mp_restartgame 1");
5330 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Live on 2");
5331 } else if (LiveOn1) {
5332 LiveOn1 = false;
5333 LiveOn3Text = true;
5334 ServerCommand("mp_restartgame 3");
5335 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Live on 1");
5336 } else if(LiveOn3Text) {
5337 LiveOn3Text = false;
5338 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Live");
5339 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Good Luck");
5340 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t \x03WarMod [BFG]", CHAT_PREFIX, "Powered By");
5341
5342 if (!GetConVarBool(wm_random_team_names)) {
5343 CreateTimer(1.0, SetTagClientDefault);
5344 }
5345 ClearForceTeamList(4);
5346 } else if(KnifeOn2) {
5347 KnifeOn2 = false;
5348 KnifeOn1 = true;
5349 ServerCommand("mp_restartgame 1");
5350 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife on 2");
5351 } else if(KnifeOn1) {
5352 KnifeOn1 = false;
5353 KnifeOn3Text = true;
5354 ServerCommand("mp_restartgame 3");
5355 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife on 1");
5356 } else if(KnifeOn3Text) {
5357 KnifeOn3Text = false;
5358 if (GetConVarBool(wm_knife_zeus)) {
5359 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 \x02%t", CHAT_PREFIX, "Zeus");
5360 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 \x02%t", CHAT_PREFIX, "Knife");
5361 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Good Luck");
5362 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t \x03WarMod [BFG]", CHAT_PREFIX, "Powered By");
5363 } else {
5364 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 \x02%t", CHAT_PREFIX, "Knife");
5365 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 \x02%t", CHAT_PREFIX, "Knife");
5366 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Good Luck");
5367 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t \x03WarMod [BFG]", CHAT_PREFIX, "Powered By");
5368 }
5369
5370 if (!GetConVarBool(wm_random_team_names)) {
5371 CreateTimer(1.0, SetTagClientDefault);
5372 }
5373 ClearForceTeamList(4);
5374 }
5375}
5376
5377public Action KnifeOn3(int client, int args)
5378{
5379 if (!IsActive(client, false))
5380 {
5381 // warmod is disabled
5382 return Plugin_Handled;
5383 }
5384
5385 if (!IsAdminCmd(client, false))
5386 {
5387 // not allowed, rcon only
5388 return Plugin_Handled;
5389 }
5390
5391 ShowInfo(0, false, false, 1);
5392 SetAllCancelled(false);
5393 ReadySystem(false);
5394 ReadyChecked();
5395 g_t_knife = true;
5396 g_max_lock = true;
5397 g_t_score = false;
5398
5399 if (GetConVarBool(wm_stats_enabled))
5400 {
5401 char serverstring[384];
5402 GetServerString(serverstring, sizeof(serverstring));
5403 LogEvent("{\"event\": \"knife_on_3\", \"map\": \"%s\", \"teams\": [{\"name\": \"%s\", \"team\": %d}, {\"name\": \"%s\", \"team\": %d}], \"server\": %s}", g_map, g_t_name_escaped, CS_TEAM_T, g_ct_name_escaped, CS_TEAM_CT, serverstring);
5404 }
5405
5406 char match_config[64];
5407 GetConVarString(wm_knife_config, match_config, sizeof(match_config));
5408
5409 if (!StrEqual(match_config, ""))
5410 {
5411 ServerCommand("exec %s", match_config);
5412 }
5413 g_start = true;
5414 KnifeOn3Override();
5415 UpdateStatus();
5416 LogAction(client, -1, "\"knife_on_3\" (player \"%L\")", client);
5417 return Plugin_Handled;
5418}
5419
5420stock bool KnifeOn3Override()
5421{
5422 if (!InWarmup())
5423 {
5424 ServerCommand("mp_restartgame 1");
5425 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife On 3");
5426 KnifeOn2 = true;
5427
5428 return true;
5429 }
5430 else
5431 {
5432 ServerCommand("mp_warmup_end");
5433 CreateTimer(1.0, Ko3Timer);
5434 return true;
5435 }
5436}
5437
5438public Action Ko3Timer(Handle timer)
5439{
5440 ServerCommand("mp_restartgame 1");
5441 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife On 3");
5442 KnifeOn2 = true;
5443}
5444
5445public Action Command_JoinTeam(int client, const char[]command, int args)
5446{
5447 if (!IsActive(client, true))
5448 {
5449 return Plugin_Continue;
5450 }
5451
5452 if (client == 0 || IsFakeClient(client))
5453 {
5454 return Plugin_Continue;
5455 }
5456
5457 if ((g_match || g_t_knife) && GetClientTeam(client) > 1 && GetConVarBool(wm_lock_teams))
5458 {
5459 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Change Teams Midgame");
5460 return Plugin_Stop;
5461 }
5462
5463 //char m_szTeam[8];
5464 //GetCmdArg(1, m_szTeam, sizeof(m_szTeam));
5465 //int m_iTeam = StringToInt(m_szTeam);
5466
5467 int max_players = GetConVarInt(wm_max_players);
5468 if ((g_ready_enabled || g_match || g_t_knife || g_max_lock) && max_players != 0 && GetClientTeam(client) <= 1 && CS_GetPlayingCount() >= max_players) {
5469 //((GetTeamClientCount(CS_TEAM_T) > (max_players/2) && m_iTeam == CS_TEAM_T) || (GetTeamClientCount(CS_TEAM_CT) > (max_players/2) && m_iTeam == CS_TEAM_CT))) {
5470 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Maximum Players");
5471 ChangeClientTeam(client, CS_TEAM_SPECTATOR);
5472 return Plugin_Stop;
5473 }
5474
5475 char CommunityID[18];
5476 GetClientAuthId(client, AuthId_SteamID64, CommunityID, sizeof(CommunityID));
5477 for (int i = 0; i < 10; i++) {
5478 if (strcmp(force_team_t[i], CommunityID, false) == 0) {
5479 ChangeClientTeam(client, CS_TEAM_T);
5480 return Plugin_Stop;
5481 } else if (strcmp(force_team_ct[i], CommunityID, false) == 0) {
5482 ChangeClientTeam(client, CS_TEAM_CT);
5483 return Plugin_Stop;
5484 }
5485 }
5486
5487 return Plugin_Continue;
5488}
5489
5490public Action ChooseTeam(int client, int args)
5491{
5492 if (!IsActive(client, true))
5493 {
5494 return Plugin_Continue;
5495 }
5496
5497 if (client == 0 || IsFakeClient(client))
5498 {
5499 return Plugin_Continue;
5500 }
5501
5502 if ((g_match || g_t_knife) && GetClientTeam(client) > 1 && GetConVarBool(wm_lock_teams))
5503 {
5504 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Change Teams Midgame");
5505 return Plugin_Stop;
5506 }
5507
5508 //char m_szTeam[8];
5509 //GetCmdArg(1, m_szTeam, sizeof(m_szTeam));
5510 //int m_iTeam = StringToInt(m_szTeam);
5511
5512 int max_players = GetConVarInt(wm_max_players);
5513 if ((g_ready_enabled || g_match || g_t_knife || g_max_lock) && max_players != 0 && GetClientTeam(client) <= 1 && CS_GetPlayingCount() >= max_players) {
5514 //((GetTeamClientCount(CS_TEAM_T) > (max_players/2) && m_iTeam == CS_TEAM_T) || (GetTeamClientCount(CS_TEAM_CT) > (max_players/2) && m_iTeam == CS_TEAM_CT))) {
5515 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Maximum Players");
5516 ChangeClientTeam(client, CS_TEAM_SPECTATOR);
5517 return Plugin_Stop;
5518 }
5519
5520 char CommunityID[18];
5521 GetClientAuthId(client, AuthId_SteamID64, CommunityID, sizeof(CommunityID));
5522 for (int i = 0; i < 10; i++) {
5523 if (strcmp(force_team_t[i], CommunityID, false) == 0) {
5524 ChangeClientTeam(client, CS_TEAM_T);
5525 return Plugin_Stop;
5526 } else if (strcmp(force_team_ct[i], CommunityID, false) == 0) {
5527 ChangeClientTeam(client, CS_TEAM_CT);
5528 return Plugin_Stop;
5529 }
5530 }
5531
5532 return Plugin_Continue;
5533}
5534
5535public Action RestrictBuy(int client, int args)
5536{
5537 if (!IsActive(client, true))
5538 {
5539 return Plugin_Continue;
5540 }
5541
5542 if (client == 0)
5543 {
5544 return Plugin_Continue;
5545 }
5546
5547 char arg[128];
5548 GetCmdArgString(arg, 128);
5549 if (!g_live && GetConVarBool(wm_block_warm_up_grenades))
5550 {
5551 char the_weapon[32];
5552 Format(the_weapon, sizeof(the_weapon), "%s", arg);
5553 ReplaceString(the_weapon, sizeof(the_weapon), "weapon_", "");
5554 ReplaceString(the_weapon, sizeof(the_weapon), "item_", "");
5555
5556 if (StrContains(the_weapon, "hegren", false) != -1 || StrContains(the_weapon, "flash", false) != -1 || StrContains(the_weapon, "smokegrenade", false) != -1 || StrContains(the_weapon, "molotov", false) != -1 || StrContains(the_weapon, "incgrenade", false) != -1 || StrContains(the_weapon, "decoy", false) != -1)
5557 {
5558 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Grenades Blocked");
5559 return Plugin_Handled;
5560 }
5561 }
5562
5563 return Plugin_Continue;
5564}
5565
5566public Action ReadyList(int client, int args)
5567{
5568 if (!IsActive(client, false))
5569 {
5570 // warmod is disabled
5571 return Plugin_Handled;
5572 }
5573
5574 char player_name[64];
5575 int player_count;
5576
5577 ReplyToCommand(client, "\x01 \x09[\x04%s\x09]\x01 %T:", CHAT_PREFIX, "Ready System", LANG_SERVER);
5578 for (int i = 1; i <= MaxClients; i++)
5579 {
5580 if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1)
5581 {
5582 GetClientName(i, player_name, sizeof(player_name));
5583 if (g_player_list[i] == PLAYER_UNREADY) {
5584 ReplyToCommand(client, "unready > %s", player_name);
5585 player_count++;
5586 }
5587 }
5588 }
5589 for (int i = 1; i <= MaxClients; i++)
5590 {
5591 if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1)
5592 {
5593 GetClientName(i, player_name, sizeof(player_name));
5594 if (g_player_list[i] == PLAYER_READY)
5595 {
5596 ReplyToCommand(client, "ready > %s", player_name);
5597 player_count++;
5598 }
5599 }
5600 }
5601 if (player_count == 0)
5602 {
5603 ReplyToCommand(client, "%T", "No Players Found", LANG_SERVER);
5604 }
5605
5606 return Plugin_Handled;
5607}
5608
5609public Action NotLive(int client, int args)
5610{
5611 if (!IsActive(client, false))
5612 {
5613 // warmod is disabled
5614 return Plugin_Handled;
5615 }
5616
5617 if (!IsAdminCmd(client, false))
5618 {
5619 // not allowed, rcon only
5620 return Plugin_Handled;
5621 }
5622
5623 ResetHalf(false);
5624
5625 if (client == 0)
5626 {
5627 PrintToServer("[%s] %t", CHAT_PREFIX, "Half Reset", LANG_SERVER);
5628 }
5629
5630 LogAction(client, -1, "\"half_reset\" (player \"%L\")", client);
5631
5632 return Plugin_Handled;
5633}
5634
5635public Action WarmUp(int client, int args)
5636{
5637 if (g_live)
5638 {
5639 if (client == 0)
5640 {
5641 PrintToServer("[%s] %T", CHAT_PREFIX, "Match Is Live", LANG_SERVER);
5642 }
5643 else
5644 {
5645 PrintToChat(client,"\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Match Is Live", LANG_SERVER);
5646 }
5647 return Plugin_Handled;
5648 }
5649
5650 if (!IsAdminCmd(client, false))
5651 {
5652 // not allowed, rcon only
5653 return Plugin_Handled;
5654 }
5655
5656 char warmup_config[128];
5657 GetConVarString(wm_warmup_config, warmup_config, sizeof(warmup_config));
5658 ServerCommand("exec %s", warmup_config);
5659 ServerCommand("mp_warmup_start");
5660
5661 if (client == 0)
5662 {
5663 PrintToServer("[%s] %T", CHAT_PREFIX, "Warm Up Active", LANG_SERVER);
5664 }
5665
5666 return Plugin_Handled;
5667}
5668
5669public Action Practice(int client, int args)
5670{
5671 if (g_live)
5672 {
5673 if (client == 0)
5674 {
5675 PrintToServer("[%s] %T", CHAT_PREFIX, "Match Is Live", LANG_SERVER);
5676 }
5677 else
5678 {
5679 PrintToChat(client,"\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Match Is Live", LANG_SERVER);
5680 }
5681 return Plugin_Handled;
5682 }
5683
5684 if (!IsAdminCmd(client, false))
5685 {
5686 // not allowed, rcon only
5687 return Plugin_Handled;
5688 }
5689
5690 char prac_config[128];
5691 GetConVarString(wm_prac_config, prac_config, sizeof(prac_config));
5692 ServerCommand("exec %s", prac_config);
5693
5694 if (client == 0)
5695 {
5696 PrintToServer("[%s] %T", CHAT_PREFIX, "Practice Mode Active", LANG_SERVER);
5697 }
5698
5699 return Plugin_Handled;
5700}
5701
5702public Action CancelMatch(int client, int args)
5703{
5704 if (!IsActive(client, false))
5705 {
5706 // warmod is disabled
5707 return Plugin_Handled;
5708 }
5709
5710 if (!IsAdminCmd(client, false))
5711 {
5712 // not allowed, rcon only
5713 return Plugin_Handled;
5714 }
5715
5716 ResetMatch(false, false);
5717
5718 if (client == 0)
5719 {
5720 PrintToServer("[%s] %T", CHAT_PREFIX, "Match Reset", LANG_SERVER);
5721 }
5722
5723 LogAction(client, -1, "\"match_reset\" (player \"%L\")", client);
5724
5725 return Plugin_Handled;
5726}
5727
5728public Action CancelKnife(int client, int args)
5729{
5730 if (!IsActive(client, false))
5731 {
5732 // warmod is disabled
5733 return Plugin_Handled;
5734 }
5735
5736 if (!IsAdminCmd(client, false))
5737 {
5738 // not allowed, rcon only
5739 return Plugin_Handled;
5740 }
5741
5742 if (g_t_knife)
5743 {
5744 if (GetConVarBool(wm_stats_enabled))
5745 {
5746 char event_name[] = "knife_reset";
5747 LogSimpleEvent(event_name, sizeof(event_name));
5748 }
5749
5750 g_t_knife = false;
5751 g_t_had_knife = false;
5752 ServerCommand("mp_restartgame 1");
5753 for (int x = 1; x <= 3; x++)
5754 {
5755 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife Round Cancelled");
5756 }
5757 if (client == 0)
5758 {
5759 PrintToServer("[%s] %T", CHAT_PREFIX, "Knife Round Cancelled", LANG_SERVER);
5760 }
5761 }
5762 else
5763 {
5764 if (client != 0)
5765 {
5766 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Knife Round Inactive");
5767 }
5768 else
5769 {
5770 PrintToServer("[%s] %t", CHAT_PREFIX, "Knife Round Inactive", LANG_SERVER);
5771 }
5772 }
5773
5774 UpdateStatus();
5775
5776 LogAction(client, -1, "\"knife_reset\" (player \"%L\")", client);
5777
5778 return Plugin_Handled;
5779}
5780
5781void ReadySystem(bool enable)
5782{
5783 if (enable)
5784 {
5785 if (GetConVarBool(wm_stats_enabled))
5786 {
5787 if (g_t_knife)
5788 {
5789 LogEvent("{\"event\": \"knife_ready_system\", \"enabled\": true}");
5790 }
5791 else
5792 {
5793 LogEvent("{\"event\": \"ready_system\", \"enabled\": true}");
5794 }
5795 }
5796 g_ready_enabled = true;
5797 }
5798 else
5799 {
5800 if (GetConVarBool(wm_stats_enabled))
5801 {
5802 if (g_t_knife)
5803 {
5804 LogEvent("{\"event\": \"knife_ready_system\", \"enabled\": false}");
5805 }
5806 else
5807 {
5808 LogEvent("{\"event\": \"ready_system\", \"enabled\": false}");
5809 }
5810 }
5811 g_ready_enabled = false;
5812 }
5813}
5814
5815void ShowInfo(int client, bool enable, bool priv, int time)
5816{
5817 if (!IsActive(client, true))
5818 {
5819 return;
5820 }
5821
5822 if (priv && g_cancel_list[client])
5823 {
5824 return;
5825 }
5826
5827 if (!GetConVarBool(wm_show_info))
5828 {
5829 return;
5830 }
5831
5832 if (!enable)
5833 {
5834 if (GetConVarBool(wm_ready_panel)) {
5835 g_m_ready_up = CreatePanel();
5836 char panel_title[128];
5837 Format(panel_title, sizeof(panel_title), "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Ready System Disabled", client);
5838 SetPanelTitle(g_m_ready_up, panel_title);
5839
5840 for (int i = 1; i <= MaxClients; i++)
5841 {
5842 if (IsClientInGame(i) && !IsFakeClient(i))
5843 {
5844 SendPanelToClient(g_m_ready_up, i, Handler_DoNothing, time);
5845 }
5846 }
5847
5848 CloseHandle(g_m_ready_up);
5849
5850 UpdateStatus();
5851 } else {
5852 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Ready System Disabled");
5853 }
5854
5855 return;
5856 }
5857
5858 char players_unready[192];
5859 char player_name[64];
5860 char player_temp[192];
5861
5862 for (int i = 1; i <= MaxClients; i++)
5863 {
5864 if (g_player_list[i] == PLAYER_UNREADY && IsClientInGame(i) && !IsFakeClient(i))
5865 {
5866 GetClientName(i, player_name, sizeof(player_name));
5867 if (GetConVarBool(wm_ready_panel)) {
5868 Format(player_temp, sizeof(player_temp), " %s\n", player_name);
5869 } else {
5870 Format(player_temp, sizeof(player_temp), " %s,", player_name);
5871 }
5872 StrCat(players_unready, sizeof(players_unready), player_temp);
5873 SetTagNotReady(i);
5874 }
5875 }
5876
5877 if (priv)
5878 {
5879 DispInfo(client, players_unready, time);
5880 }
5881 else
5882 {
5883 for (int i = 1; i <= MaxClients; i++)
5884 {
5885 if (IsClientInGame(i) && !IsFakeClient(i) && !g_cancel_list[i])
5886 {
5887 if (GetConVarBool(wm_ready_panel)) {
5888 DispInfo(i, players_unready, time);
5889 } else if (!(GetConVarBool(wm_ready_panel)) && g_DispInfoLimiter) {
5890 g_DispInfoLimiter = false;
5891 DispInfo(i, players_unready, time);
5892 CreateTimer(30.0, DispInfoLimiterTrue);
5893 }
5894 }
5895 }
5896 }
5897 UpdateStatus();
5898}
5899
5900void DispInfo(int client, char[] players_unready, int time)
5901{
5902 if (GetConVarBool(wm_ready_panel)) {
5903 char Temp[128];
5904 SetGlobalTransTarget(client);
5905 g_m_ready_up = CreatePanel();
5906 Format(Temp, sizeof(Temp), "WarMod [BFG]- %t", "Ready System");
5907 SetPanelTitle(g_m_ready_up, Temp);
5908 DrawPanelText(g_m_ready_up, "\n \n");
5909 Format(Temp, sizeof(Temp), "%t", "Match Begin Msg", GetConVarInt(wm_min_ready));
5910 DrawPanelItem(g_m_ready_up, Temp);
5911 DrawPanelText(g_m_ready_up, "\n \n");
5912 Format(Temp, sizeof(Temp), "%t", "Info Not Ready");
5913 DrawPanelItem(g_m_ready_up, Temp);
5914 DrawPanelText(g_m_ready_up, players_unready);
5915 DrawPanelText(g_m_ready_up, " \n");
5916 Format(Temp, sizeof(Temp), "%t", "Info Exit");
5917 DrawPanelItem(g_m_ready_up, Temp);
5918 SendPanelToClient(g_m_ready_up, client, Handler_ReadySystem, time);
5919 CloseHandle(g_m_ready_up);
5920 } else if (!g_live) {
5921 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x04 %t", CHAT_PREFIX, "Ready System");
5922 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x04 %t", CHAT_PREFIX, "Match Begin Msg", GetConVarInt(wm_min_ready));
5923 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x02 %t\x01%s", CHAT_PREFIX, "Info Not Ready", players_unready);
5924 }
5925}
5926
5927void ReadyChangeAll(int client, bool up, bool silent)
5928{
5929 if (up)
5930 {
5931 if (GetConVarBool(wm_stats_enabled))
5932 {
5933 char event_name[] = "ready_all";
5934 LogSimpleEvent(event_name, sizeof(event_name));
5935 }
5936 for (int i = 1; i <= MaxClients; i++)
5937 {
5938 if (IsValidClient(i) && GetClientTeam(i) > 1)
5939 {
5940 g_player_list[i] = PLAYER_READY;
5941 SetTagReady(i);
5942 }
5943 }
5944 }
5945 else
5946 {
5947 if (GetConVarBool(wm_stats_enabled))
5948 {
5949 char event_name[] = "unready_all";
5950 LogSimpleEvent(event_name, sizeof(event_name));
5951
5952 }
5953 for (int i = 1; i <= MaxClients; i++)
5954 {
5955 if (IsValidClient(i) && GetClientTeam(i) > 1)
5956 {
5957 g_player_list[i] = PLAYER_UNREADY;
5958 SetTagNotReady(i);
5959 }
5960 }
5961 }
5962 if (!silent)
5963 {
5964 ShowInfo(client, true, true, 0);
5965 }
5966}
5967
5968bool IsReadyEnabled(int client, bool silent)
5969{
5970 if (g_ready_enabled)
5971 {
5972 return true;
5973 }
5974 else
5975 {
5976 if (!silent)
5977 {
5978 if (client != 0)
5979 {
5980 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Ready System Disabled2");
5981 }
5982 else
5983 {
5984 PrintToServer("[%s] %t", CHAT_PREFIX, "Ready System Disabled2", LANG_SERVER);
5985 }
5986 }
5987 }
5988 return false;
5989}
5990
5991bool IsLive(int client, bool silent)
5992{
5993 if (!g_live)
5994 {
5995 return false;
5996 }
5997 else
5998 {
5999 if (!silent)
6000 {
6001 if (client != 0)
6002 {
6003 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Match Is Live");
6004 }
6005 else
6006 {
6007 PrintToServer("[%s] %t", CHAT_PREFIX, "Match Is Live", LANG_SERVER);
6008 }
6009 }
6010 }
6011 return true;
6012}
6013
6014bool IsActive(int client, bool silent)
6015{
6016 if (g_active)
6017 {
6018 return true;
6019 }
6020 else
6021 {
6022 if (!silent)
6023 {
6024 if (client != 0)
6025 {
6026 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "WarMod Inactive");
6027 }
6028 else
6029 {
6030 PrintToServer("[%s] %t", CHAT_PREFIX, "WarMod Inactive", LANG_SERVER);
6031 }
6032 }
6033 }
6034 return false;
6035}
6036
6037bool IsAdminCmd(int client, bool silent)
6038{
6039 if (client == 0 || !GetConVarBool(wm_rcon_only))
6040 {
6041 return true;
6042 }
6043 else
6044 {
6045 if (!silent)
6046 {
6047 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "WarMod Rcon Only");
6048 }
6049 }
6050 return false;
6051}
6052
6053public void OnActiveChange(Handle cvar, const char[]oldVal, const char[]newVal)
6054{
6055 if (StringToInt(newVal) != 0)
6056 {
6057 g_active = true;
6058 }
6059 else
6060 {
6061 g_active = false;
6062 }
6063}
6064
6065/*public OnReqNameChange(Handle cvar, const char[]oldVal, const char[]newVal)
6066{
6067 CheckReady();
6068}*/
6069
6070public void OnMinReadyChange(Handle cvar, const char[]oldVal, const char[]newVal)
6071{
6072 if (!IsActive(0, true))
6073 {
6074 return;
6075 }
6076
6077 if (!g_live && g_ready_enabled)
6078 {
6079 ShowInfo(0, true, false, 0);
6080 }
6081
6082 if (!g_match && g_ready_enabled)
6083 {
6084 CheckReady();
6085 }
6086}
6087
6088public void OnStatsTraceChange(Handle cvar, const char[]oldVal, const char[]newVal)
6089{
6090 if (g_stats_trace_timer != INVALID_HANDLE)
6091 {
6092 KillTimer(g_stats_trace_timer);
6093 g_stats_trace_timer = INVALID_HANDLE;
6094 }
6095 if (!StrEqual(newVal, "0", false))
6096 {
6097 g_stats_trace_timer = CreateTimer(GetConVarFloat(wm_stats_trace_delay), Stats_Trace, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
6098 }
6099}
6100
6101public void OnStatsTraceDelayChange(Handle cvar, const char[]oldVal, const char[]newVal)
6102{
6103 if (g_stats_trace_timer != INVALID_HANDLE)
6104 {
6105 KillTimer(g_stats_trace_timer);
6106 g_stats_trace_timer = INVALID_HANDLE;
6107 }
6108 if (GetConVarBool(wm_stats_trace))
6109 {
6110 g_stats_trace_timer = CreateTimer(GetConVarFloat(wm_stats_trace_delay), Stats_Trace, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
6111 }
6112}
6113
6114public void OnAutoReadyChange(Handle cvar, const char[]oldVal, const char[]newVal)
6115{
6116 if (!IsActive(0, true))
6117 {
6118 return;
6119 }
6120
6121 if (!g_match && !g_ready_enabled && StrEqual(newVal, "1", false))
6122 {
6123 ReadySystem(true);
6124 ReadyChangeAll(0, false, true);
6125 SetAllCancelled(false);
6126 ShowInfo(0, true, false, 0);
6127 }
6128}
6129
6130public void OnTChange(Handle cvar, const char[]oldVal, const char[]newVal)
6131{
6132 if (!StrEqual(newVal, ""))
6133 {
6134 Format(g_t_name, sizeof(g_t_name), "%s", newVal);
6135 }
6136// else
6137// {
6138// Format(g_t_name, sizeof(g_t_name), "%s", DEFAULT_T_NAME);
6139// }
6140 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_t_name);
6141 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
6142// ServerCommand("mp_teamname_2 %s", g_t_name);
6143
6144 CheckReady();
6145}
6146
6147public void OnCTChange(Handle cvar, const char[]oldVal, const char[]newVal)
6148{
6149 if (!StrEqual(newVal, ""))
6150 {
6151 Format(g_ct_name, sizeof(g_ct_name), "%s", newVal);
6152 }
6153// else
6154// {
6155// Format(g_ct_name, sizeof(g_ct_name), "%s", DEFAULT_CT_NAME);
6156// }
6157 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_ct_name);
6158 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
6159// ServerCommand("mp_teamname_1 %s", g_ct_name);
6160
6161 CheckReady();
6162}
6163
6164public int Handler_ReadySystem(Handle menu, MenuAction action, int param1, int param2)
6165{
6166 if (action == MenuAction_Select)
6167 {
6168 if (param2 == 3)
6169 {
6170 g_cancel_list[param1] = true;
6171 }
6172 }
6173}
6174
6175//Knife vote stay
6176public Action Stay(int client, int args)
6177{
6178 if ((g_knife_vote) && GetClientTeam(client) == g_knife_winner)
6179 {
6180 if (g_knife_winner == 2)
6181 {
6182 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_t_name, "Knife Stay", LANG_SERVER);
6183 }
6184 else
6185 {
6186 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_ct_name, "Knife Stay", LANG_SERVER);
6187 }
6188
6189 if (GetConVarBool(wm_knife_auto_start))
6190 {
6191 g_knife_winner = 0;
6192 g_knife_vote = false;
6193 ShowInfo(0, false, false, 1);
6194 SetAllCancelled(false);
6195 ReadySystem(false);
6196 LiveOn3(true);
6197 }
6198 else
6199 {
6200 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Match Begin Msg", GetConVarInt(wm_min_ready));
6201 ReadyChangeAll(0, false, true);
6202 SetAllCancelled(false);
6203 ReadySystem(true);
6204 ShowInfo(0, true, false, 0);
6205 g_knife_winner = 0;
6206 g_knife_vote = false;
6207 UpdateStatus();
6208 }
6209 }
6210 return Plugin_Handled;
6211}
6212
6213//Knife vote switch
6214public Action Switch(int client, int args)
6215{
6216 if ((g_knife_vote) && GetClientTeam(client) == g_knife_winner)
6217 {
6218 if (g_knife_winner == 2)
6219 {
6220 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_t_name, "Knife Switch", LANG_SERVER);
6221 }
6222 else
6223 {
6224 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %s %T", CHAT_PREFIX, g_ct_name, "Knife Switch", LANG_SERVER);
6225 }
6226 ServerCommand("mp_swapteams");
6227 int temp = g_teamNumber_t;
6228 g_teamNumber_t = g_teamNumber_ct;
6229 g_teamNumber_ct = temp;
6230 g_tag_set = false;
6231
6232 char teamflag1[4];
6233 char teamlogo1[8];
6234 char teamname1[64];
6235 char teamflag2[4];
6236 char teamlogo2[8];
6237 char teamname2[64];
6238
6239 GetConVarString(mp_teamname_1, teamname1, sizeof(teamname1));
6240 GetConVarString(mp_teamlogo_1, teamlogo1, sizeof(teamlogo1));
6241 GetConVarString(mp_teamflag_1, teamflag1, sizeof(teamflag1));
6242 GetConVarString(mp_teamname_2, teamname2, sizeof(teamname2));
6243 GetConVarString(mp_teamlogo_2, teamlogo2, sizeof(teamlogo2));
6244 GetConVarString(mp_teamflag_2, teamflag2, sizeof(teamflag2));
6245
6246 if (GetConVarBool(wm_name_fix)) {
6247 if (!StrEqual(teamname1, DEFAULT_T_NAME, false) && !StrEqual(teamname1, DEFAULT_CT_NAME, false)) {
6248 ServerCommand("mp_teamname_2 %s", teamname1);
6249 } else {
6250 ServerCommand("mp_teamname_2 \"\"");
6251 }
6252 if (!StrEqual(teamflag1, "", false)) {
6253 ServerCommand("mp_teamflag_2 %s", teamflag1);
6254 } else {
6255 ServerCommand("mp_teamflag_2 \"\"");
6256 }
6257 if (!StrEqual(teamlogo1, "", false)) {
6258 ServerCommand("mp_teamlogo_2 %s", teamlogo1);
6259 } else {
6260 ServerCommand("mp_teamlogo_2 \"\"");
6261 }
6262
6263 if (!StrEqual(teamname2, DEFAULT_T_NAME, false) && !StrEqual(teamname2, DEFAULT_CT_NAME, false)) {
6264 ServerCommand("mp_teamname_1 %s", teamname2);
6265 } else {
6266 ServerCommand("mp_teamname_1 \"\"");
6267 }
6268 if (!StrEqual(teamflag2, "", false)) {
6269 ServerCommand("mp_teamflag_1 %s", teamflag2);
6270 } else {
6271 ServerCommand("mp_teamflag_1 \"\"");
6272 }
6273 if (!StrEqual(teamlogo2, "", false)) {
6274 ServerCommand("mp_teamlogo_1 %s", teamlogo2);
6275 } else {
6276 ServerCommand("mp_teamlogo_1 \"\"");
6277 }
6278 }
6279
6280 if (GetConVarBool(wm_knife_auto_start))
6281 {
6282 g_knife_winner = 0;
6283 g_knife_vote = false;
6284 ShowInfo(0, false, false, 1);
6285 ReadySystem(false);
6286 LiveOn3(true);
6287 }
6288 else
6289 {
6290 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Match Begin Msg", GetConVarInt(wm_min_ready));
6291 ReadyChangeAll(0, false, true);
6292 SetAllCancelled(false);
6293 ReadySystem(true);
6294 ShowInfo(0, true, false, 0);
6295 g_knife_winner = 0;
6296 g_knife_vote = false;
6297 UpdateStatus();
6298 }
6299 }
6300 return Plugin_Handled;
6301}
6302
6303public int Handler_DoNothing(Handle menu, MenuAction action, int param1, int param2)
6304{
6305 /* Do nothing */
6306}
6307
6308public void SetAllCancelled(bool cancelled)
6309{
6310 for (int i = 1; i <= MaxClients; i++)
6311 {
6312 if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) > 1)
6313 {
6314 g_cancel_list[i] = cancelled;
6315 }
6316 }
6317}
6318
6319//Eddylad created this part for me. There was no way I could of come up with this. Thanks Eddy =D
6320public void getTerroristTeamName()
6321{
6322 char clanTags[MAXPLAYERS+1][MAX_NAME_LENGTH];
6323 int j = 0;
6324
6325 for (int i = 1; i <= MaxClients; i++)
6326 {
6327 if (IsValidClient(i) && GetClientTeam(i) == 2)
6328 {
6329 Format(clanTags[j], sizeof(clanTags[]), g_clanTags[i]);
6330 // CS_GetClientClanTag(i, clanTags[j], sizeof(clanTags[]));
6331 j++;
6332 }
6333 //j++;
6334 }
6335
6336 char finalTag[MAX_NAME_LENGTH];
6337
6338 if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6339 {
6340 Format(finalTag, sizeof(finalTag), clanTags[0]);
6341 }
6342 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]))
6343 {
6344 Format(finalTag, sizeof(finalTag), clanTags[0]);
6345 }
6346 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[4]))
6347 {
6348 Format(finalTag, sizeof(finalTag), clanTags[0]);
6349 }
6350 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6351 {
6352 Format(finalTag, sizeof(finalTag), clanTags[0]);
6353 }
6354 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6355 {
6356 Format(finalTag, sizeof(finalTag), clanTags[0]);
6357 }
6358 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6359 {
6360 Format(finalTag, sizeof(finalTag), clanTags[1]);
6361 }
6362 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]))
6363 {
6364 Format(finalTag, sizeof(finalTag), clanTags[0]);
6365 }
6366 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[3]))
6367 {
6368 Format(finalTag, sizeof(finalTag), clanTags[0]);
6369 }
6370 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[4]))
6371 {
6372 Format(finalTag, sizeof(finalTag), clanTags[0]);
6373 }
6374 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]))
6375 {
6376 Format(finalTag, sizeof(finalTag), clanTags[0]);
6377 }
6378 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]) && StrEqual(clanTags[2], clanTags[4]))
6379 {
6380 Format(finalTag, sizeof(finalTag), clanTags[0]);
6381 }
6382 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6383 {
6384 Format(finalTag, sizeof(finalTag), clanTags[0]);
6385 }
6386 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]))
6387 {
6388 Format(finalTag, sizeof(finalTag), clanTags[1]);
6389 }
6390 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[4]))
6391 {
6392 Format(finalTag, sizeof(finalTag), clanTags[1]);
6393 }
6394 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6395 {
6396 Format(finalTag, sizeof(finalTag), clanTags[1]);
6397 }
6398 else if (strlen(clanTags[2]) > 0 && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6399 {
6400 Format(finalTag, sizeof(finalTag), clanTags[2]);
6401 }
6402 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]))
6403 {
6404 Format(finalTag, sizeof(finalTag), clanTags[0]);
6405 }
6406 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]))
6407 {
6408 Format(finalTag, sizeof(finalTag), clanTags[0]);
6409 }
6410 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[3]))
6411 {
6412 Format(finalTag, sizeof(finalTag), clanTags[0]);
6413 }
6414 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[4]))
6415 {
6416 Format(finalTag, sizeof(finalTag), clanTags[0]);
6417 }
6418 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]))
6419 {
6420 Format(finalTag, sizeof(finalTag), clanTags[1]);
6421 }
6422 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[3]))
6423 {
6424 Format(finalTag, sizeof(finalTag), clanTags[1]);
6425 }
6426 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[4]))
6427 {
6428 Format(finalTag, sizeof(finalTag), clanTags[1]);
6429 }
6430 else if (strlen(clanTags[2]) > 0 && StrEqual(clanTags[2], clanTags[3]))
6431 {
6432 Format(finalTag, sizeof(finalTag), clanTags[2]);
6433 }
6434 else if (strlen(clanTags[2]) > 0 && StrEqual(clanTags[2], clanTags[4]))
6435 {
6436 Format(finalTag, sizeof(finalTag), clanTags[2]);
6437 }
6438 else if (strlen(clanTags[3]) > 0 && StrEqual(clanTags[3], clanTags[4]))
6439 {
6440 Format(finalTag, sizeof(finalTag), clanTags[3]);
6441 }
6442 else
6443 {
6444 finalTag = DEFAULT_T_NAME;
6445 Format(g_t_name, sizeof(g_t_name), finalTag);
6446 ServerCommand("mp_teamname_2 \"\"");
6447 }
6448
6449 if (!StrEqual(finalTag, DEFAULT_T_NAME))
6450 {
6451 char name_old[64];
6452 Format(name_old, sizeof(name_old), "%s", g_t_name);
6453 Format(g_t_name, sizeof(g_t_name), finalTag);
6454 Format(g_t_name_escaped, sizeof(g_t_name_escaped), finalTag);
6455 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
6456 ServerCommand("mp_teamname_2 %s", g_t_name);
6457 LogEvent("{\"event\": \"name_change\", \"team\": 2, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_t_name);
6458 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x02%s", CHAT_PREFIX, g_t_name);
6459 }
6460}
6461
6462//Eddylad created this part for me. There was no way I could of come up with this. Thanks Eddy =D
6463public void getCounterTerroristTeamName()
6464{
6465 char clanTags[MAXPLAYERS+1][MAX_NAME_LENGTH];
6466 int j = 0;
6467
6468 for (int i = 1; i <= MaxClients; i++)
6469 {
6470 if (IsValidClient(i) && GetClientTeam(i) == 3)
6471 {
6472 Format(clanTags[j], sizeof(clanTags[]), g_clanTags[i]);
6473 // CS_GetClientClanTag(i, clanTags[j], sizeof(clanTags[]));
6474 j++;
6475 }
6476 //j++;
6477 }
6478
6479 char finalTag[MAX_NAME_LENGTH];
6480
6481 if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6482 {
6483 Format(finalTag, sizeof(finalTag), clanTags[0]);
6484 }
6485 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]))
6486 {
6487 Format(finalTag, sizeof(finalTag), clanTags[0]);
6488 }
6489 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[4]))
6490 {
6491 Format(finalTag, sizeof(finalTag), clanTags[0]);
6492 }
6493 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6494 {
6495 Format(finalTag, sizeof(finalTag), clanTags[0]);
6496 }
6497 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6498 {
6499 Format(finalTag, sizeof(finalTag), clanTags[0]);
6500 }
6501 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6502 {
6503 Format(finalTag, sizeof(finalTag), clanTags[1]);
6504 }
6505 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[2]))
6506 {
6507 Format(finalTag, sizeof(finalTag), clanTags[0]);
6508 }
6509 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[3]))
6510 {
6511 Format(finalTag, sizeof(finalTag), clanTags[0]);
6512 }
6513 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]) && StrEqual(clanTags[1], clanTags[4]))
6514 {
6515 Format(finalTag, sizeof(finalTag), clanTags[0]);
6516 }
6517 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]))
6518 {
6519 Format(finalTag, sizeof(finalTag), clanTags[0]);
6520 }
6521 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]) && StrEqual(clanTags[2], clanTags[4]))
6522 {
6523 Format(finalTag, sizeof(finalTag), clanTags[0]);
6524 }
6525 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6526 {
6527 Format(finalTag, sizeof(finalTag), clanTags[0]);
6528 }
6529 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[3]))
6530 {
6531 Format(finalTag, sizeof(finalTag), clanTags[1]);
6532 }
6533 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]) && StrEqual(clanTags[2], clanTags[4]))
6534 {
6535 Format(finalTag, sizeof(finalTag), clanTags[1]);
6536 }
6537 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6538 {
6539 Format(finalTag, sizeof(finalTag), clanTags[1]);
6540 }
6541 else if (strlen(clanTags[2]) > 0 && StrEqual(clanTags[2], clanTags[3]) && StrEqual(clanTags[3], clanTags[4]))
6542 {
6543 Format(finalTag, sizeof(finalTag), clanTags[2]);
6544 }
6545 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[1]))
6546 {
6547 Format(finalTag, sizeof(finalTag), clanTags[0]);
6548 }
6549 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[2]))
6550 {
6551 Format(finalTag, sizeof(finalTag), clanTags[0]);
6552 }
6553 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[3]))
6554 {
6555 Format(finalTag, sizeof(finalTag), clanTags[0]);
6556 }
6557 else if (strlen(clanTags[0]) > 0 && StrEqual(clanTags[0], clanTags[4]))
6558 {
6559 Format(finalTag, sizeof(finalTag), clanTags[0]);
6560 }
6561 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[2]))
6562 {
6563 Format(finalTag, sizeof(finalTag), clanTags[1]);
6564 }
6565 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[3]))
6566 {
6567 Format(finalTag, sizeof(finalTag), clanTags[1]);
6568 }
6569 else if (strlen(clanTags[1]) > 0 && StrEqual(clanTags[1], clanTags[4]))
6570 {
6571 Format(finalTag, sizeof(finalTag), clanTags[1]);
6572 }
6573 else if (strlen(clanTags[2]) > 0 && StrEqual(clanTags[2], clanTags[3]))
6574 {
6575 Format(finalTag, sizeof(finalTag), clanTags[2]);
6576 }
6577 else if (strlen(clanTags[2]) > 0 && StrEqual(clanTags[2], clanTags[4]))
6578 {
6579 Format(finalTag, sizeof(finalTag), clanTags[2]);
6580 }
6581 else if (strlen(clanTags[3]) > 0 && StrEqual(clanTags[3], clanTags[4]))
6582 {
6583 Format(finalTag, sizeof(finalTag), clanTags[3]);
6584 }
6585 else
6586 {
6587 finalTag = DEFAULT_CT_NAME;
6588 Format(g_ct_name, sizeof(g_ct_name), finalTag);
6589 ServerCommand("mp_teamname_1 \"\"");
6590 }
6591
6592 if (!StrEqual(finalTag, DEFAULT_CT_NAME))
6593 {
6594 char name_old[64];
6595 Format(name_old, sizeof(name_old), "%s", g_ct_name);
6596 Format(g_ct_name, sizeof(g_ct_name), finalTag);
6597 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), finalTag);
6598 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
6599 ServerCommand("mp_teamname_1 %s", g_ct_name);
6600 LogEvent("{\"event\": \"name_change\", \"team\": 3, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_ct_name);
6601 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x09%s", CHAT_PREFIX, g_ct_name);
6602 }
6603}
6604
6605public Action ChangeT(int client, int args)
6606{
6607 if (!IsActive(client, false))
6608 {
6609 // warmod is disabled
6610 return Plugin_Handled;
6611 }
6612
6613 if (!IsAdminCmd(client, false))
6614 {
6615 // not allowed, rcon only
6616 return Plugin_Handled;
6617 }
6618
6619 char name[64];
6620
6621 if (GetCmdArgs() > 0)
6622 {
6623 GetCmdArgString(name, sizeof(name));
6624 char name_old[64];
6625 Format(name_old, sizeof(name_old), "%s", g_t_name);
6626 Format(g_t_name, sizeof(g_t_name), "%s", name);
6627 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_t_name);
6628 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
6629 LogEvent("{\"event\": \"name_change\", \"team\": 2, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_t_name);
6630 ServerCommand("mp_teamname_2 %s", name);
6631 if (client != 0)
6632 {
6633 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Change T Name", name);
6634 }
6635 else
6636 {
6637 PrintToServer("[%s] %T", CHAT_PREFIX, "Change T Name", LANG_SERVER, name);
6638 }
6639 CheckReady();
6640 LogAction(client, -1, "\"set_t_name\" (player \"%L\") (name \"%s\")", client, name);
6641 }
6642
6643 return Plugin_Handled;
6644}
6645
6646public Action ChangeCT(int client, int args)
6647{
6648 if (!IsActive(client, false))
6649 {
6650 // warmod is disabled
6651 return Plugin_Handled;
6652 }
6653
6654 if (!IsAdminCmd(client, false))
6655 {
6656 // not allowed, rcon only
6657 return Plugin_Handled;
6658 }
6659
6660 char name[64];
6661
6662 if (GetCmdArgs() > 0)
6663 {
6664 GetCmdArgString(name, sizeof(name));
6665 char name_old[64];
6666 Format(name_old, sizeof(name_old), "%s", g_ct_name);
6667 Format(g_ct_name, sizeof(g_ct_name), "%s", name);
6668 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_ct_name);
6669 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
6670 LogEvent("{\"event\": \"name_change\", \"team\": 3, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_ct_name);
6671 ServerCommand("mp_teamname_1 %s", name);
6672 if (client != 0)
6673 {
6674 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Change CT Name", name);
6675 }
6676 else
6677 {
6678 PrintToServer("[%s] %T", CHAT_PREFIX, "Change CT Name", LANG_SERVER, name);
6679 }
6680 CheckReady();
6681 LogAction(client, -1, "\"set_ct_name\" (player \"%L\") (name \"%s\")", client, name);
6682 }
6683
6684 return Plugin_Handled;
6685}
6686
6687/* Chat Commands */
6688
6689#define ChatAlias(%1,%2) \
6690if (StrEqual(sArgs[0], %1, false)) { \
6691 %2 (client, 0); \
6692}
6693public Action OnClientSayCommand(int client, const char[]command, const char[]sArgs)
6694{
6695 ChatAlias(".ready", ReadyUp)
6696 ChatAlias(".r", ReadyUp)
6697 ChatAlias(".rdy", ReadyUp)
6698 ChatAlias(".unready", ReadyDown)
6699 ChatAlias(".ur", ReadyDown)
6700 ChatAlias(".urdy", ReadyDown)
6701 ChatAlias(".info", ReadyInfoPriv)
6702 ChatAlias(".i", ReadyInfoPriv)
6703 ChatAlias(".score", ShowScore)
6704 ChatAlias(".s", ShowScore)
6705 ChatAlias(".stay", Stay)
6706 ChatAlias(".switch", Switch)
6707 ChatAlias(".swap", Switch)
6708 ChatAlias(".pause", Pause)
6709 ChatAlias(".unpause", Unpause)
6710 ChatAlias(".help", DisplayHelp)
6711 ChatAlias(".veto", Veto_Setup)
6712 ChatAlias(".vetoBo1", Veto_Bo1)
6713 ChatAlias(".vetoBo2", Veto_Bo2)
6714 ChatAlias(".vetoBo3", Veto_Bo3)
6715 ChatAlias(".vetoBo5", Veto_Bo5)
6716 ChatAlias(".veto1", Veto_Bo1)
6717 ChatAlias(".veto2", Veto_Bo2)
6718 ChatAlias(".veto3", Veto_Bo3)
6719 ChatAlias(".veto5", Veto_Bo5)
6720 ChatAlias(".vetomaps", Veto_Bo3_Maps)
6721 ChatAlias(".playout", PlayOut_Offer)
6722 ChatAlias(".pl", PlayOut_Offer)
6723 ChatAlias(".hardprac", PlayOut_Offer)
6724 ChatAlias(".hp", PlayOut_Offer)
6725 ChatAlias(".overtime", OverTime_Offer)
6726 ChatAlias(".ot", OverTime_Offer)
6727 ChatAlias(".normal", Default_Offer)
6728 ChatAlias(".norm", Default_Offer)
6729 ChatAlias(".default", Default_Offer)
6730 ChatAlias(".def", Default_Offer)
6731
6732 if (client == 0)
6733 {
6734 return Plugin_Continue;
6735 }
6736
6737 bool teamOnly = false;
6738 if (StrEqual(command, "say_team", false))
6739 {
6740 teamOnly = true;
6741 }
6742
6743 char message[192];
6744 strcopy(message, sizeof(message), sArgs);
6745 StripQuotes(message);
6746
6747 if (StrEqual(message, ""))
6748 {
6749 // no message
6750 return Plugin_Continue;
6751 }
6752
6753 char log_string[192];
6754 CS_GetLogString(client, log_string, sizeof(log_string));
6755
6756 EscapeString(message, sizeof(message));
6757 if (g_t_knife)
6758 {
6759 LogEvent("{\"event\": \"knife_player_say\", \"round\": %i, \"player\": %s, \"message\": \"%s\", \"teamOnly\": %d}", g_round, log_string, message, teamOnly);
6760 }
6761 else
6762 {
6763 LogEvent("{\"event\": \"player_say\", \"round\": %i, \"player\": %s, \"message\": \"%s\", \"teamOnly\": %d}", g_round, log_string, message, teamOnly);
6764 }
6765
6766 // continue normally
6767 return Plugin_Continue;
6768}
6769
6770void SwitchScores()
6771{
6772 int temp;
6773
6774 temp = g_scores[SCORE_T][SCORE_FIRST_HALF];
6775 g_scores[SCORE_T][SCORE_FIRST_HALF] = g_scores[SCORE_CT][SCORE_FIRST_HALF];
6776 g_scores[SCORE_CT][SCORE_FIRST_HALF] = temp;
6777
6778 temp = g_scores[SCORE_T][SCORE_SECOND_HALF];
6779 g_scores[SCORE_T][SCORE_SECOND_HALF] = g_scores[SCORE_CT][SCORE_SECOND_HALF];
6780 g_scores[SCORE_CT][SCORE_SECOND_HALF] = temp;
6781
6782 for (int i = 0; i <= g_overtime_count; i++)
6783 {
6784 temp = g_scores_overtime[SCORE_T][i][SCORE_FIRST_HALF];
6785 g_scores_overtime[SCORE_T][i][SCORE_FIRST_HALF] = g_scores_overtime[SCORE_CT][i][SCORE_FIRST_HALF];
6786 g_scores_overtime[SCORE_CT][i][SCORE_FIRST_HALF] = temp;
6787
6788 temp = g_scores_overtime[SCORE_T][i][SCORE_SECOND_HALF];
6789 g_scores_overtime[SCORE_T][i][SCORE_SECOND_HALF] = g_scores_overtime[SCORE_CT][i][SCORE_SECOND_HALF];
6790 g_scores_overtime[SCORE_CT][i][SCORE_SECOND_HALF] = temp;
6791 }
6792}
6793
6794void SwitchTeamNames()
6795{
6796 char temp[64];
6797 Format(temp, sizeof(temp), "%s", g_t_name);
6798 Format(g_t_name, sizeof(g_t_name), "%s", g_ct_name);
6799 Format(g_ct_name, sizeof(g_ct_name), "%s", temp);
6800
6801 Format(g_t_name_escaped, sizeof(g_t_name_escaped), "%s", g_t_name);
6802 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
6803 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), "%s", g_ct_name);
6804 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
6805}
6806
6807public Action SwapAll(int client, int args)
6808{
6809 if (!IsActive(client, false))
6810 {
6811 // warmod is disabled
6812 return Plugin_Handled;
6813 }
6814
6815 if (!IsAdminCmd(client, false))
6816 {
6817 // not allowed, rcon only
6818 return Plugin_Handled;
6819 }
6820
6821 CS_SwapTeams();
6822 SwitchScores();
6823
6824 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) && !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
6825 {
6826 SwitchTeamNames();
6827 }
6828 else if (!StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
6829 {
6830 Format(g_t_name, sizeof(g_t_name), DEFAULT_T_NAME);
6831 SwitchTeamNames();
6832 }
6833 else if (!StrEqual(g_t_name, DEFAULT_T_NAME, false))
6834 {
6835 Format(g_ct_name, sizeof(g_ct_name), DEFAULT_CT_NAME);
6836 SwitchTeamNames();
6837 }
6838
6839 LogAction(client, -1, "\"team_swap\" (player \"%L\")", client);
6840
6841 return Plugin_Handled;
6842}
6843
6844public Action Timer_DelayedResetConfig(Handle timer) {
6845 char end_config[128];
6846 GetConVarString(wm_reset_config, end_config, sizeof(end_config));
6847 ServerCommand("exec %s", end_config);
6848}
6849
6850public Action Swap(Handle timer)
6851{
6852 if (!IsActive(0, true))
6853 {
6854 return;
6855 }
6856
6857 if (!g_live)
6858 {
6859 CS_SwapTeams();
6860 }
6861}
6862
6863public Action DispInfoLimiterTrue(Handle timer)
6864{
6865 g_DispInfoLimiter = true;
6866 ShowInfo(0, true, false, 0);
6867}
6868
6869public Action setNameLimiterTrue(Handle timer)
6870{
6871 g_setNameLimiter = true;
6872 CheckReady();
6873}
6874
6875public Action UpdateInfo(Handle timer)
6876{
6877 if (!IsActive(0, true))
6878 {
6879 return;
6880 }
6881
6882 if (!g_live)
6883 {
6884 ShowInfo(0, true, false, 0);
6885 }
6886}
6887
6888public Action StopRecord(Handle timer)
6889{
6890 if (!g_match)
6891 {
6892 // only stop if another match hasn't started
6893 ServerCommand("tv_stoprecord");
6894 if (GetConVarBool(wm_autodemoupload_enable) && g_bRecording && LibraryExists("teftp"))
6895 {
6896 if (GetConVarBool(wm_autodemoupload_completed))
6897 {
6898 if (g_MatchComplete)
6899 {
6900 Handle hDataPack = CreateDataPack();
6901 CreateDataTimer(1.0, Timer_UploadDemo, hDataPack);
6902 WritePackString(hDataPack, g_sDemoPath);
6903 Format(g_sDemoPath, sizeof(g_sDemoPath), "");
6904 }
6905 }
6906 else
6907 {
6908 Handle hDataPack = CreateDataPack();
6909 CreateDataTimer(1.0, Timer_UploadDemo, hDataPack);
6910 WritePackString(hDataPack, g_sDemoPath);
6911 Format(g_sDemoPath, sizeof(g_sDemoPath), "");
6912 }
6913 }
6914 else if (GetConVarBool(wm_autodemoupload_enable) && g_bRecording && !LibraryExists("teftp"))
6915 {
6916 LogError("Plug-in tEasyFTP.smx required to auto upload demos");
6917 }
6918 CreateTimer(2.0, RecordingFalse);
6919 }
6920}
6921
6922public Action RecordingFalse(Handle timer)
6923{
6924 g_bRecording = false;
6925}
6926
6927public Action LogFileUpload(Handle timer)
6928{
6929 if (!g_match)
6930 {
6931 if (GetConVarBool(wm_autodemoupload_enable) && g_bRecording && LibraryExists("teftp"))
6932 {
6933 if (GetConVarBool(wm_autodemoupload_completed))
6934 {
6935 if (g_MatchComplete)
6936 {
6937 Handle hDataPackLog = CreateDataPack();
6938 CreateDataTimer(1.0, Timer_UploadLog, hDataPackLog);
6939 WritePackString(hDataPackLog, g_sLogPath);
6940 Format(g_sLogPath, sizeof(g_sLogPath), "");
6941 }
6942 }
6943 else
6944 {
6945 Handle hDataPackLog = CreateDataPack();
6946 CreateDataTimer(1.0, Timer_UploadLog, hDataPackLog);
6947 WritePackString(hDataPackLog, g_sLogPath);
6948 Format(g_sLogPath, sizeof(g_sLogPath), "");
6949 }
6950 }
6951 }
6952}
6953
6954//Coded by Thrawn2 from tAutoDemoUpload plugin [Built in for better execution]
6955public Action Timer_UploadDemo(Handle timer, Handle hDataPack)
6956{
6957 if (LibraryExists("teftp"))
6958 {
6959 ResetPack(hDataPack);
6960 char sDemoPath[PLATFORM_MAX_PATH];
6961 ReadPackString(hDataPack, sDemoPath, sizeof(sDemoPath));
6962 if (LibraryExists("zip"))
6963 {
6964 CompressionZip(sDemoPath);
6965 }
6966 else if (GetConVarInt(wm_autodemoupload_bzip2) > 0 && GetConVarInt(wm_autodemoupload_bzip2) < 10 && LibraryExists("bzip2"))
6967 {
6968 Compressionbzip2(sDemoPath);
6969 }
6970 else
6971 {
6972 EasyFTP_UploadFile(g_sFtpTargetDemo, sDemoPath, "/", UploadComplete);
6973 }
6974 }
6975}
6976
6977public void CompressionZip(char[] sDemoPath)
6978{
6979 char sZipPath[PLATFORM_MAX_PATH];
6980 Format(sZipPath, sizeof(sZipPath), "%s.zip", sDemoPath);
6981 ReplaceString(sZipPath, sizeof(sZipPath), ".dem.", ".", false);
6982 Handle hZip = Zip_Open(sZipPath, ZIP_APPEND_STATUS_CREATE);
6983 if (INVALID_HANDLE != hZip)
6984 {
6985 if (!Zip_AddFile(hZip, sDemoPath))
6986 {
6987 LogError("Could not compress demo file %s", sDemoPath, sZipPath);
6988 CloseHandle(hZip);
6989 DeleteFile(sZipPath);
6990 //try upload demo with something different
6991 if (GetConVarInt(wm_autodemoupload_bzip2) > 0 && GetConVarInt(wm_autodemoupload_bzip2) < 10 && LibraryExists("bzip2"))
6992 {
6993 Compressionbzip2(sDemoPath);
6994 }
6995 else
6996 {
6997 EasyFTP_UploadFile(g_sFtpTargetDemo, sDemoPath, "/", UploadComplete);
6998 }
6999 }
7000 else
7001 {
7002 CloseHandle(hZip);
7003 LogToGame("Wrote compressed demo %s", sZipPath);
7004 EasyFTP_UploadFile(g_sFtpTargetDemo, sZipPath, "/", UploadComplete);
7005 }
7006 }
7007 else
7008 {
7009 LogError("Could not open %s for writing", sZipPath);
7010 //try upload demo with something different
7011 if (GetConVarInt(wm_autodemoupload_bzip2) > 0 && GetConVarInt(wm_autodemoupload_bzip2) < 10 && LibraryExists("bzip2"))
7012 {
7013 Compressionbzip2(sDemoPath);
7014 }
7015 else
7016 {
7017 EasyFTP_UploadFile(g_sFtpTargetDemo, sDemoPath, "/", UploadComplete);
7018 }
7019 }
7020}
7021
7022public void Compressionbzip2(char[] sDemoPath)
7023{
7024 char sBzipPath[PLATFORM_MAX_PATH];
7025 Format(sBzipPath, sizeof(sBzipPath), "%s.bz2", sDemoPath);
7026 BZ2_CompressFile(sDemoPath, sBzipPath, GetConVarInt(wm_autodemoupload_bzip2), CompressionComplete);
7027}
7028
7029public Action Timer_UploadLog(Handle timer, Handle hDataPackLog)
7030{
7031 if (LibraryExists("teftp"))
7032 {
7033 ResetPack(hDataPackLog);
7034 char sLogPath[PLATFORM_MAX_PATH];
7035 ReadPackString(hDataPackLog, sLogPath, sizeof(sLogPath));
7036 EasyFTP_UploadFile(g_sFtpTargetLog, sLogPath, "/", UploadComplete);
7037 }
7038}
7039
7040public int CompressionComplete(BZ_Error iError, char[] inFile, char[] outFile, any data)
7041{
7042 if (LibraryExists("teftp"))
7043 {
7044 if (iError == BZ_OK)
7045 {
7046 LogMessage("%s compressed to %s", inFile, outFile);
7047 EasyFTP_UploadFile(g_sFtpTargetDemo, outFile, "/", UploadComplete);
7048 }
7049 else
7050 {
7051 LogBZ2Error(iError);
7052 EasyFTP_UploadFile(g_sFtpTargetDemo, inFile, "/", UploadComplete);
7053 }
7054 }
7055}
7056
7057public int UploadComplete(const char[]sTarget, const char[]sLocalFile, const char[]sRemoteFile, int iErrorCode, any data) {
7058 if (iErrorCode == 0 && GetConVarBool(wm_autodemoupload_delete))
7059 {
7060 DeleteFile(sLocalFile);
7061 if (StrEqual(sLocalFile[strlen(sLocalFile)-4], ".bz2") || StrEqual(sLocalFile[strlen(sLocalFile)-4], ".zip"))
7062 {
7063 char sLocalNoCompressFile[PLATFORM_MAX_PATH];
7064 strcopy(sLocalNoCompressFile, strlen(sLocalFile)-3, sLocalFile);
7065 DeleteFile(sLocalNoCompressFile);
7066 }
7067 }
7068
7069 if (iErrorCode == 0)
7070 {
7071 if (StrEqual(sLocalFile[strlen(sLocalFile)-4], ".log"))
7072 {
7073 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "FTP Log Upload Successful");
7074 }
7075 else
7076 {
7077 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "FTP Demo Upload Successful");
7078 }
7079 }
7080 else
7081 {
7082 for(int client = 1; client <= MaxClients; client++)
7083 {
7084 if (IsClientInGame(client) && GetAdminFlag(GetUserAdmin(client), Admin_Reservation))
7085 {
7086 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "FTP Upload Failed");
7087 }
7088 }
7089 }
7090}
7091
7092public void Cvar_Changed(Handle convar, const char[]oldValue, const char[]newValue)
7093{
7094 OnConfigsExecuted();
7095}
7096
7097public int GetConVarValueInt(const char[]sConVar)
7098{
7099 Handle hConVar = FindConVar(sConVar);
7100 int iResult = GetConVarInt(hConVar);
7101 CloseHandle(hConVar);
7102 return iResult;
7103}
7104
7105public Action HalfTime(Handle timer)
7106{
7107 // starts warmup for second half
7108 ServerCommand("mp_warmuptime 5000");
7109 ServerCommand("mp_warmup_start");
7110 ReadySystem(true);
7111 ShowInfo(0, true, false, 0);
7112}
7113
7114stock void LogSimpleEvent(char[] event_name, int size)
7115{
7116 char json[384];
7117 EscapeString(event_name, size);
7118
7119 Format(json, sizeof(json), "{\"event\": \"%s\"}", event_name);
7120 LogEvent("%s", json);
7121}
7122
7123stock void LogEvent(const char[]format, any:...)
7124{
7125 char event[1024];
7126 VFormat(event, sizeof(event), format, 2);
7127 int stats_method = GetConVarInt(wm_stats_method);
7128
7129 // inject timestamp into JSON object, hacky but quite simple
7130 char timestamp[64];
7131 FormatTime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S");
7132
7133 // remove leading '{' from the event and add the timestamp in, including new '{'
7134 Format(event, sizeof(event), "{\"timestamp\": \"%s\", %s", timestamp, event[1]);
7135
7136 if (g_log_live && (stats_method == 0 || stats_method == 2))
7137 {
7138 // standard server log files + udp stream
7139 LogToGame("[WarMod_BFG] %s", event);
7140 }
7141
7142 if ((stats_method == 1 || stats_method == 2) && g_log_file != INVALID_HANDLE)
7143 {
7144 WriteFileLine(g_log_file, event);
7145 }
7146
7147 if (LibraryExists("livewire"))
7148 {
7149 Call_StartForward(g_f_livewire_log_event);
7150 Call_PushString(event);
7151 Call_Finish();
7152 }
7153}
7154
7155void LogPlayers()
7156{
7157 char ip_address[32];
7158 char country[2];
7159 char log_string[384];
7160 for (int i = 1; i <= MaxClients; i++)
7161 {
7162 if (IsClientInGame(i))
7163 {
7164 GetClientIP(i, ip_address, sizeof(ip_address));
7165 GeoipCode2(ip_address, country);
7166 CS_GetLogString(i, log_string, sizeof(log_string));
7167
7168 EscapeString(ip_address, sizeof(ip_address));
7169 EscapeString(country, sizeof(country));
7170
7171 LogEvent("{\"event\": \"player_status\", \"player\": %s, \"address\": \"%s\", \"country\": \"%s\"}", log_string, ip_address, country);
7172 }
7173 }
7174}
7175
7176public Action Stats_Trace(Handle timer)
7177{
7178 if (GetConVarBool(wm_stats_enabled))
7179 {
7180 char log_string[384];
7181 char weapon[64];
7182 for (int i = 1; i <= MaxClients; i++)
7183 {
7184 if (IsClientInGame(i) && GetClientTeam(i) > 1 && IsPlayerAlive(i))
7185 {
7186 CS_GetAdvLogString(i, log_string, sizeof(log_string));
7187 GetClientWeapon(i, weapon, 64);
7188 ReplaceString(weapon, 64, "weapon_", "");
7189 if (StrEqual(weapon, "m4a1"))
7190 {
7191 int iWeapon = GetPlayerWeaponSlot(i, CS_SLOT_PRIMARY);
7192 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
7193 if (pWeapon == 60)
7194 {
7195 weapon = "m4a1_silencer";
7196 }
7197 }
7198 else if (StrEqual(weapon, "hkp2000") || StrEqual(weapon, "p250") || StrEqual(weapon, "fiveseven") || StrEqual(weapon, "tec9") || StrEqual(weapon, "deagle"))
7199 {
7200 int iWeapon = GetPlayerWeaponSlot(i, CS_SLOT_SECONDARY);
7201 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
7202 if (pWeapon == 61)
7203 {
7204 weapon = "usp_silencer";
7205 }
7206 else if (pWeapon == 63)
7207 {
7208 weapon = "cz75a";
7209 }
7210 else if (pWeapon == 64)
7211 {
7212 weapon = "revolver";
7213 }
7214 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
7215 int iWeapon = GetPlayerWeaponSlot(i, CS_SLOT_KNIFE);
7216 int pWeapon = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
7217 if (pWeapon == 500 || pWeapon == 505 || pWeapon == 506 || pWeapon == 507 || pWeapon == 508 || pWeapon == 509 || pWeapon == 512 || pWeapon == 515 || pWeapon == 516 || pWeapon == 59 || pWeapon == 42)
7218 {
7219 weapon = "knife";
7220 }
7221 }
7222
7223 if (StrEqual(weapon, "m4a1_silencer_off")) {
7224 weapon = "m4a1_silencer";
7225 } else if (StrEqual(weapon, "usp_silencer_off")) {
7226 weapon = "usp_silencer";
7227 } else if (StrEqual(weapon, "knife_t") || StrEqual(weapon, "knife_default_ct") || StrEqual(weapon, "knife_flip") || StrEqual(weapon, "knife_gut") || StrEqual(weapon, "knife_karambit") || StrEqual(weapon, "knife_m9_bayonet") || StrEqual(weapon, "knife_tactical") || StrEqual(weapon, "knife_falchion") || StrEqual(weapon, "knife_butterfly") || StrEqual(weapon, "knife_push") || StrEqual(weapon, "bayonet") || StrEqual(weapon, "knifegg")) {
7228 weapon = "knife";
7229 }
7230
7231 if (g_t_knife)
7232 {
7233 LogEvent("{\"event\": \"knife_player_trace\", \"round\": %i, \"player\": %s, \"weapon\": \"%s\"}", g_round, log_string, weapon);
7234 }
7235 else
7236 {
7237 LogEvent("{\"event\": \"player_trace\", \"round\": %i, \"player\": %s, \"weapon\": \"%s\"}", g_round, log_string, weapon);
7238 }
7239 }
7240 }
7241 }
7242}
7243
7244public Action RenameLogs(Handle timer)
7245{
7246 char save_dir[128];
7247 GetConVarString(wm_save_dir, save_dir, sizeof(save_dir));
7248 if (g_log_file != INVALID_HANDLE)
7249 {
7250 FlushFile(g_log_file);
7251 CloseHandle(g_log_file);
7252 g_log_file = INVALID_HANDLE;
7253 char old_log_filename[128];
7254 char new_log_filename[128];
7255 if (g_log_warmod_dir)
7256 {
7257 Format(old_log_filename, sizeof(old_log_filename), "%s/_%s.log", save_dir, g_log_filename);
7258 Format(new_log_filename, sizeof(new_log_filename), "%s/%s.log", save_dir, g_log_filename);
7259 }
7260 else if (DirExists("logs"))
7261 {
7262 Format(old_log_filename, sizeof(old_log_filename), "logs/_%s.log", g_log_filename);
7263 Format(new_log_filename, sizeof(new_log_filename), "logs/%s.log", g_log_filename);
7264 }
7265 else
7266 {
7267 Format(old_log_filename, sizeof(old_log_filename), "_%s.log", g_log_filename);
7268 Format(new_log_filename, sizeof(new_log_filename), "%s.log", g_log_filename);
7269 }
7270
7271 RenameFile(new_log_filename, old_log_filename);
7272 Format(g_sLogPath, sizeof(g_sLogPath), new_log_filename);
7273 }
7274 CreateTimer(15.0, RenameDemos);
7275}
7276
7277public Action RenameDemos(Handle timer)
7278{
7279 char save_dir[128];
7280 GetConVarString(wm_save_dir, save_dir, sizeof(save_dir));
7281 char old_demo_filename[128];
7282 char new_demo_filename[128];
7283 if (g_log_warmod_dir)
7284 {
7285 Format(old_demo_filename, sizeof(old_demo_filename), "%s/_%s.dem", save_dir, g_log_filename);
7286 Format(new_demo_filename, sizeof(new_demo_filename), "%s/%s.dem", save_dir, g_log_filename);
7287 }
7288 else
7289 {
7290 Format(old_demo_filename, sizeof(old_demo_filename), "_%s.dem", g_log_filename);
7291 Format(new_demo_filename, sizeof(new_demo_filename), "%s.dem", g_log_filename);
7292 }
7293 RenameFile(new_demo_filename, old_demo_filename);
7294 Format(g_sDemoPath, sizeof(g_sDemoPath), new_demo_filename);
7295}
7296
7297void ResetPlayerStats(int client)
7298{
7299 for (int i = 0; i < NUM_WEAPONS; i++)
7300 {
7301 for (int x = 0; x < LOG_HIT_NUM; x++)
7302 {
7303 weapon_stats[client][i][x] = 0;
7304 }
7305 }
7306 for (int z = 0; z < ASSIST_NUM; z++)
7307 {
7308 assist_stats[client][z] = 0;
7309 }
7310 clutch_stats[client][CLUTCH_LAST] = 0;
7311 clutch_stats[client][CLUTCH_VERSUS] = 0;
7312 clutch_stats[client][CLUTCH_FRAGS] = 0;
7313 clutch_stats[client][CLUTCH_WON] = 0;
7314}
7315
7316void ResetClutchStats()
7317{
7318 for (int i = 1; i <= MaxClients; i++)
7319 {
7320 clutch_stats[i][CLUTCH_LAST] = 0;
7321 clutch_stats[i][CLUTCH_VERSUS] = 0;
7322 clutch_stats[i][CLUTCH_FRAGS] = 0;
7323 clutch_stats[i][CLUTCH_WON] = 0;
7324 round_health[i] = 100;
7325
7326 for (int j = 1; j <= MaxClients; j++) {
7327 g_DamageDone[i][j] = 0;
7328 g_DamageDoneHits[i][j] = 0;
7329 g_GotKill[i][j] = false;
7330 }
7331 }
7332}
7333
7334void LogPlayerStats(int client)
7335{
7336 if (IsClientInGame(client) && GetClientTeam(client) > 1)
7337 {
7338 char log_string[384];
7339 CS_GetLogString(client, log_string, sizeof(log_string));
7340
7341 char player_name[64];
7342 char authid[20];
7343 int team = GetClientTeam(client);
7344 int clutch_won;
7345 GetClientName(client, player_name, sizeof(player_name));
7346 GetClientAuthId(client, AuthId_SteamID64, authid, sizeof(authid));
7347 for (int i = 0; i < NUM_WEAPONS; i++)
7348 {
7349 if (weapon_stats[client][i][LOG_HIT_SHOTS] > 0 || weapon_stats[client][i][LOG_HIT_DEATHS] > 0)
7350 {
7351 if (g_t_knife)
7352 {
7353 LogEvent("{\"event\": \"knife_weapon_stats\", \"round\": %i, \"player\": %s, \"weapon\": \"%s\", \"shots\": %d, \"hits\": %d, \"kills\": %d, \"headshots\": %d, \"tks\": %d, \"damage\": %d, \"deaths\": %d, \"head\": %d, \"chest\": %d, \"stomach\": %d, \"leftArm\": %d, \"rightArm\": %d, \"leftLeg\": %d, \"rightLeg\": %d, \"generic\": %d}", g_round, log_string, weapon_list[i], weapon_stats[client][i][LOG_HIT_SHOTS], weapon_stats[client][i][LOG_HIT_HITS], weapon_stats[client][i][LOG_HIT_KILLS], weapon_stats[client][i][LOG_HIT_HEADSHOTS], weapon_stats[client][i][LOG_HIT_TEAMKILLS], weapon_stats[client][i][LOG_HIT_DAMAGE], weapon_stats[client][i][LOG_HIT_DEATHS], weapon_stats[client][i][LOG_HIT_HEAD], weapon_stats[client][i][LOG_HIT_CHEST], weapon_stats[client][i][LOG_HIT_STOMACH], weapon_stats[client][i][LOG_HIT_LEFTARM], weapon_stats[client][i][LOG_HIT_RIGHTARM], weapon_stats[client][i][LOG_HIT_LEFTLEG], weapon_stats[client][i][LOG_HIT_RIGHTLEG], weapon_stats[client][i][LOG_HIT_GENERIC]);
7354 }
7355 else
7356 {
7357 LogEvent("{\"event\": \"weapon_stats\", \"round\": %i, \"player\": %s, \"weapon\": \"%s\", \"shots\": %d, \"hits\": %d, \"kills\": %d, \"headshots\": %d, \"tks\": %d, \"damage\": %d, \"deaths\": %d, \"head\": %d, \"chest\": %d, \"stomach\": %d, \"leftArm\": %d, \"rightArm\": %d, \"leftLeg\": %d, \"rightLeg\": %d, \"generic\": %d}", g_round, log_string, weapon_list[i], weapon_stats[client][i][LOG_HIT_SHOTS], weapon_stats[client][i][LOG_HIT_HITS], weapon_stats[client][i][LOG_HIT_KILLS], weapon_stats[client][i][LOG_HIT_HEADSHOTS], weapon_stats[client][i][LOG_HIT_TEAMKILLS], weapon_stats[client][i][LOG_HIT_DAMAGE], weapon_stats[client][i][LOG_HIT_DEATHS], weapon_stats[client][i][LOG_HIT_HEAD], weapon_stats[client][i][LOG_HIT_CHEST], weapon_stats[client][i][LOG_HIT_STOMACH], weapon_stats[client][i][LOG_HIT_LEFTARM], weapon_stats[client][i][LOG_HIT_RIGHTARM], weapon_stats[client][i][LOG_HIT_LEFTLEG], weapon_stats[client][i][LOG_HIT_RIGHTLEG], weapon_stats[client][i][LOG_HIT_GENERIC]);
7358 }
7359 }
7360 }
7361 int round_stats[LOG_HIT_NUM];
7362 for (int i = 0; i < NUM_WEAPONS; i++)
7363 {
7364 for (int x = 0; x < LOG_HIT_NUM; x++)
7365 {
7366 round_stats[x] += weapon_stats[client][i][x];
7367 }
7368 }
7369 if (g_t_knife)
7370 {
7371 LogEvent("{\"event\": \"knife_round_stats\", \"round\": %i, \"player\": %s, \"shots\": %d, \"hits\": %d, \"kills\": %d, \"headshots\": %d, \"tks\": %d, \"damage\": %d, \"assists\": %d, \"assists_tk\": %d, \"deaths\": %d, \"head\": %d, \"chest\": %d, \"stomach\": %d, \"leftArm\": %d, \"rightArm\": %d, \"leftLeg\": %d, \"rightLeg\": %d, \"generic\": %d}", g_round, log_string, round_stats[LOG_HIT_SHOTS], round_stats[LOG_HIT_HITS], round_stats[LOG_HIT_KILLS], round_stats[LOG_HIT_HEADSHOTS], round_stats[LOG_HIT_TEAMKILLS], round_stats[LOG_HIT_DAMAGE], assist_stats[client][ASSIST_COUNT], assist_stats[client][ASSIST_COUNT_TK], round_stats[LOG_HIT_DEATHS], round_stats[LOG_HIT_HEAD], round_stats[LOG_HIT_CHEST], round_stats[LOG_HIT_STOMACH], round_stats[LOG_HIT_LEFTARM], round_stats[LOG_HIT_RIGHTARM], round_stats[LOG_HIT_LEFTLEG], round_stats[LOG_HIT_RIGHTLEG], round_stats[LOG_HIT_GENERIC]);
7372 }
7373 else
7374 {
7375 LogEvent("{\"event\": \"round_stats\", \"round\": %i, \"player\": %s, \"shots\": %d, \"hits\": %d, \"kills\": %d, \"headshots\": %d, \"tks\": %d, \"damage\": %d, \"assists\": %d, \"assists_tk\": %d, \"deaths\": %d, \"head\": %d, \"chest\": %d, \"stomach\": %d, \"leftArm\": %d, \"rightArm\": %d, \"leftLeg\": %d, \"rightLeg\": %d, \"generic\": %d}", g_round, log_string, round_stats[LOG_HIT_SHOTS], round_stats[LOG_HIT_HITS], round_stats[LOG_HIT_KILLS], round_stats[LOG_HIT_HEADSHOTS], round_stats[LOG_HIT_TEAMKILLS], round_stats[LOG_HIT_DAMAGE], assist_stats[client][ASSIST_COUNT], assist_stats[client][ASSIST_COUNT_TK], round_stats[LOG_HIT_DEATHS], round_stats[LOG_HIT_HEAD], round_stats[LOG_HIT_CHEST], round_stats[LOG_HIT_STOMACH], round_stats[LOG_HIT_LEFTARM], round_stats[LOG_HIT_RIGHTARM], round_stats[LOG_HIT_LEFTLEG], round_stats[LOG_HIT_RIGHTLEG], round_stats[LOG_HIT_GENERIC]);
7376 }
7377 if (clutch_stats[client][CLUTCH_LAST] == 1)
7378 {
7379 if (g_t_knife)
7380 {
7381 LogEvent("{\"event\": \"knife_player_clutch\", \"round\": %i, \"player\": %s, \"versus\": %d, \"frags\": %d, \"bombPlanted\": %d, \"won\": %d}", g_round, log_string, clutch_stats[client][CLUTCH_VERSUS], clutch_stats[client][CLUTCH_FRAGS], g_planted, clutch_stats[client][CLUTCH_WON]);
7382 }
7383 else
7384 {
7385 LogEvent("{\"event\": \"player_clutch\", \"round\": %i, \"player\": %s, \"versus\": %d, \"frags\": %d, \"bombPlanted\": %d, \"won\": %d}", g_round, log_string, clutch_stats[client][CLUTCH_VERSUS], clutch_stats[client][CLUTCH_FRAGS], g_planted, clutch_stats[client][CLUTCH_WON]);
7386 }
7387 clutch_won = clutch_stats[client][CLUTCH_WON];
7388
7389 }
7390
7391 if (GetConVarBool(wm_upload_results) && match_id != 0) {
7392 char query[1024];
7393 char insertquery[1024];
7394 char table_name[128];
7395 StripFilename(player_name, sizeof(player_name));
7396 if (StrEqual("", authid, false)) {
7397 Format(authid, sizeof(authid), "BOT_%s", player_name);
7398 }
7399 if (team_switch) {
7400 if (team == 2) {
7401 team = 1;
7402 } else if (team == 3) {
7403 team = 2;
7404 }
7405 } else {
7406 if (team == 2) {
7407 team = 2;
7408 } else if (team == 3) {
7409 team = 1;
7410 }
7411 }
7412 int k1; int k2; int k3; int k4; int k5;
7413 if (round_stats[LOG_HIT_KILLS] == 1) {
7414 k1 = 1;
7415 } else if (round_stats[LOG_HIT_KILLS] == 2) {
7416 k2 = 1;
7417 } else if (round_stats[LOG_HIT_KILLS] == 3) {
7418 k3 = 1;
7419 } else if (round_stats[LOG_HIT_KILLS] == 4) {
7420 k4 = 1;
7421 } else if (round_stats[LOG_HIT_KILLS] == 5) {
7422 k5 = 1;
7423 }
7424
7425 GetConVarString(wm_table_round_stats, table_name, sizeof(table_name));
7426 Format(query, sizeof(query), "UPDATE `%s` SET `rounds_played` = `rounds_played` + 1, `player_name` = '%s', `kills` = `kills` + %i, `deaths` = `deaths` + %i, `assists` = `assists` + %i, `head_shots` = `head_shots` + %i, `team_kills` = `team_kills` + %i, `assists_team_attack` = `assists_team_attack` + %i, `damage` = `damage` + %i, `hits` = `hits` + %i, `shots` = `shots` + %i, `last_alive` = `last_alive` + %i, `clutch_won` = `clutch_won` + %i, `1k` = `1k` + %i, `2k` = `2k` + %i, `3k` = `3k` + %i, `4k` = `4k` + %i, `5k` = `5k` + %i WHERE `match_id` = %i AND `steam_id_64` = '%s';", table_name, player_name, round_stats[LOG_HIT_KILLS], round_stats[LOG_HIT_DEATHS], assist_stats[client][ASSIST_COUNT], round_stats[LOG_HIT_HEADSHOTS], round_stats[LOG_HIT_TEAMKILLS], assist_stats[client][ASSIST_COUNT_TK], round_stats[LOG_HIT_DAMAGE], round_stats[LOG_HIT_HITS], round_stats[LOG_HIT_SHOTS], clutch_stats[client][CLUTCH_LAST], clutch_won, k1, k2, k3, k4, k5, match_id, authid);
7427 if ((GetTTotalScore() + GetCTTotalScore()) == 1) {
7428 Format(insertquery, sizeof(insertquery), "INSERT INTO `%s` (`key_id`, `match_id`, `rounds_played`, `player_name`, `steam_id_64`, `team`, `kills`, `deaths`, `assists`, `head_shots`, `team_kills`, `assists_team_attack`, `damage`, `hits`, `shots`, `last_alive`, `clutch_won`, `1k`, `2k`, `3k`, `4k`, `5k`) VALUES (NULL, %i, 2, '%s', '%s', %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i);", table_name, match_id, player_name, authid, team, round_stats[LOG_HIT_KILLS], round_stats[LOG_HIT_DEATHS], assist_stats[client][ASSIST_COUNT], round_stats[LOG_HIT_HEADSHOTS], round_stats[LOG_HIT_TEAMKILLS], assist_stats[client][ASSIST_COUNT_TK], round_stats[LOG_HIT_DAMAGE], round_stats[LOG_HIT_HITS], round_stats[LOG_HIT_SHOTS], clutch_stats[client][CLUTCH_LAST], clutch_won, k1, k2, k3, k4, k5);
7429 } else {
7430 Format(insertquery, sizeof(insertquery), "INSERT INTO `%s` (`key_id`, `match_id`, `rounds_played`, `player_name`, `steam_id_64`, `team`, `kills`, `deaths`, `assists`, `head_shots`, `team_kills`, `assists_team_attack`, `damage`, `hits`, `shots`, `last_alive`, `clutch_won`, `1k`, `2k`, `3k`, `4k`, `5k`) VALUES (NULL, %i, 1, '%s', '%s', %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i);", table_name, match_id, player_name, authid, team, round_stats[LOG_HIT_KILLS], round_stats[LOG_HIT_DEATHS], assist_stats[client][ASSIST_COUNT], round_stats[LOG_HIT_HEADSHOTS], round_stats[LOG_HIT_TEAMKILLS], assist_stats[client][ASSIST_COUNT_TK], round_stats[LOG_HIT_DAMAGE], round_stats[LOG_HIT_HITS], round_stats[LOG_HIT_SHOTS], clutch_stats[client][CLUTCH_LAST], clutch_won, k1, k2, k3, k4, k5);
7431 }
7432 Handle hPack = CreateDataPack();
7433 WritePackString(hPack, insertquery);
7434 if (SQL_DEBUG) {
7435 LogError(query);
7436 }
7437 SQL_TQuery(hDatabase, MySQL_UploadRoundStatsReturn, query, hPack);
7438 }
7439 ResetPlayerStats(client);
7440 }
7441}
7442
7443public void MySQL_UploadRoundStatsReturn(Handle owner, Handle hndl, const char[] error, any data) {
7444 if (hndl == INVALID_HANDLE) {
7445 LogError("Query failed! %s", error);
7446 } else if (SQL_GetAffectedRows(hndl) == 0) {
7447 char query[1024];
7448 ResetPack(data);
7449 ReadPackString(data, query, sizeof(query));
7450 if (SQL_DEBUG) {
7451 LogError(query);
7452 }
7453 SQL_TQuery(hDatabase, MySQL_UploadRoundStatsInsertReturn, query);
7454 }
7455 CloseHandle(data);
7456}
7457
7458public void MySQL_UploadRoundStatsInsertReturn(Handle owner, Handle hndl, const char[] error, any data) {
7459 if (hndl == INVALID_HANDLE) {
7460 LogError("Query failed! %s", error);
7461 }
7462}
7463
7464int GetWeaponIndex(const char[]weapon)
7465{
7466 for (int i = 0; i < NUM_WEAPONS; i++)
7467 {
7468 if (StrEqual(weapon, weapon_list[i], false))
7469 {
7470 return i;
7471 }
7472 }
7473 return -1;
7474}
7475
7476public int MenuHandler(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
7477{
7478 char menu_name[256];
7479 GetTopMenuObjName(topmenu, object_id, menu_name, sizeof(menu_name));
7480 SetGlobalTransTarget(param);
7481
7482 if (StrEqual(menu_name, "WarModCommands"))
7483 {
7484 if (action == TopMenuAction_DisplayTitle)
7485 {
7486 Format(buffer, maxlength, "%t:", "Admin_Menu WarMod Commands");
7487 }
7488 else if (action == TopMenuAction_DisplayOption)
7489 {
7490 Format(buffer, maxlength, "%t", "Admin_Menu WarMod Commands");
7491 }
7492 }
7493 else if (StrEqual(menu_name, "forcestart"))
7494 {
7495 if (action == TopMenuAction_DisplayOption)
7496 {
7497 Format(buffer, maxlength, "%t", "Admin_Menu Force Start");
7498 }
7499 else if (action == TopMenuAction_SelectOption)
7500 {
7501 ForceStart(param, 0);
7502 }
7503 }
7504 else if (StrEqual(menu_name, "readyup"))
7505 {
7506 if (action == TopMenuAction_DisplayOption)
7507 {
7508 if (g_ready_enabled)
7509 {
7510 Format(buffer, maxlength, "%t", "Admin_Menu Disable ReadyUp");
7511 }
7512 else
7513 {
7514 Format(buffer, maxlength, "%t", "Admin_Menu Enable ReadyUp");
7515 }
7516 }
7517 else if (action == TopMenuAction_SelectOption)
7518 {
7519 ReadyToggle(param, 0);
7520 }
7521 }
7522 else if (StrEqual(menu_name, "knife"))
7523 {
7524 if (action == TopMenuAction_DisplayOption)
7525 {
7526 Format(buffer, maxlength, "%t", "Admin_Menu Knife");
7527 }
7528 else if (action == TopMenuAction_SelectOption)
7529 {
7530 KnifeOn3(param, 0);
7531 }
7532 }
7533 else if (StrEqual(menu_name, "cancelhalf"))
7534 {
7535 if (action == TopMenuAction_DisplayOption)
7536 {
7537 Format(buffer, maxlength, "%t", "Admin_Menu Cancel Half");
7538 }
7539 else if (action == TopMenuAction_SelectOption)
7540 {
7541 NotLive(param, 0);
7542 }
7543 }
7544 else if (StrEqual(menu_name, "cancelmatch"))
7545 {
7546 if (action == TopMenuAction_DisplayOption)
7547 {
7548 Format(buffer, maxlength, "%t", "Admin_Menu Cancel Match");
7549 }
7550 else if (action == TopMenuAction_SelectOption)
7551 {
7552 CancelMatch(param, 0);
7553 }
7554 }
7555 else if (StrEqual(menu_name, "forceallready"))
7556 {
7557 if (action == TopMenuAction_DisplayOption)
7558 {
7559 Format(buffer, maxlength, "%t", "Admin_Menu ForceAllReady");
7560 }
7561 else if (action == TopMenuAction_SelectOption)
7562 {
7563 ForceAllReady(param, 0);
7564 }
7565 }
7566 else if (StrEqual(menu_name, "forceallunready"))
7567 {
7568 if (action == TopMenuAction_DisplayOption)
7569 {
7570 Format(buffer, maxlength, "%t", "Admin_Menu ForceAllUnready");
7571 }
7572 else if (action == TopMenuAction_SelectOption)
7573 {
7574 ForceAllUnready(param, 0);
7575 }
7576 }
7577 else if (StrEqual(menu_name, "forceallspectate"))
7578 {
7579 if (action == TopMenuAction_DisplayOption)
7580 {
7581 Format(buffer, maxlength, "%t", "Admin_Menu ForceAllSpectate");
7582 }
7583 else if (action == TopMenuAction_SelectOption)
7584 {
7585 ForceAllSpectate(param, 0);
7586 }
7587 }
7588 else if (StrEqual(menu_name, "toggleactive"))
7589 {
7590 if (action == TopMenuAction_DisplayOption)
7591 {
7592 if (GetConVarBool(wm_active))
7593 {
7594 Format(buffer, maxlength, "%t", "Admin_Menu Deactivate WarMod");
7595 }
7596 else
7597 {
7598 Format(buffer, maxlength, "%t", "Admin_Menu Activate WarMod");
7599 }
7600 }
7601 else if (action == TopMenuAction_SelectOption)
7602 {
7603 ActiveToggle(param, 0);
7604 }
7605 }
7606}
7607
7608public Action RestartRound(Handle timer, any delay)
7609{
7610 ServerCommand("mp_restartgame %d", delay);
7611}
7612
7613public Action PrintToChatDelayed(Handle timer, Handle datapack)
7614{
7615 char text[128];
7616 ResetPack(datapack);
7617 ReadPackString(datapack, text, sizeof(text));
7618 ServerCommand("say %s", text);
7619}
7620
7621public Action CheckNames(Handle timer, any client)
7622{
7623 if (((GetConVarBool(wm_require_names) || GetConVarBool(wm_require_logos))&& g_ready_enabled && !g_live && (StrEqual(g_t_name, DEFAULT_T_NAME, false) || StrEqual(g_ct_name, DEFAULT_CT_NAME, false))) && (!GetConVarBool(wm_auto_knife) || g_t_had_knife))
7624 {
7625 int num_ready;
7626 for (int i = 1; i <= MaxClients; i++)
7627 {
7628 if (g_player_list[i] == PLAYER_READY && IsClientInGame(i) && !IsFakeClient(i))
7629 {
7630 num_ready++;
7631 }
7632 }
7633 if (num_ready >= GetConVarInt(wm_min_ready))
7634 {
7635 for (int i = 1; i <= MaxClients; i++)
7636 {
7637 if (IsClientInGame(i) && !IsFakeClient(i))
7638 {
7639 if (GetConVarBool(wm_require_logos))
7640 {
7641 PrintToChat(i, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Logos Required");
7642 }
7643 else
7644 {
7645 PrintToChat(i, "\x01 \x09[\x04%s\x09]\x01 %t", CHAT_PREFIX, "Names Required");
7646 }
7647 }
7648 }
7649 }
7650 }
7651}
7652
7653public Action RespawnPlayer(Handle timer, int client)
7654{
7655 if (IsClientInGame(client))
7656 {
7657 int team = GetClientTeam(client);
7658 if (IsClientInGame(client) && (team == CS_TEAM_CT || team == CS_TEAM_T))
7659 {
7660 CS_RespawnPlayer(client);
7661 SetEntData(client, g_iAccount, GetConVarInt(mp_startmoney));
7662 }
7663 }
7664}
7665
7666public Action HelpText(Handle timer, int client)
7667{
7668 if (!IsActive(0, true))
7669 {
7670 return Plugin_Handled;
7671 }
7672
7673 if (!g_live && g_ready_enabled)
7674 {
7675 DisplayHelp(client, 0);
7676 }
7677
7678 return Plugin_Handled;
7679}
7680
7681public Action DisplayHelp(int client, int args)
7682{
7683 if (client == 0)
7684 {
7685 PrintHintTextToAll("%t: /ready /unready /info /score", "Available Commands");
7686 }
7687 else
7688 {
7689 if (IsClientConnected(client) && IsClientInGame(client))
7690 {
7691 PrintHintText(client, "%t: /ready /unready /info /score", "Available Commands");
7692 }
7693 }
7694 return Plugin_Handled;
7695}
7696
7697public Action ShowPluginInfo(Handle timer, int client)
7698{
7699 if (client != 0 && IsClientConnected(client) && IsClientInGame(client))
7700 {
7701 char max_rounds[64];
7702 GetConVarName(mp_maxrounds, max_rounds, sizeof(max_rounds));
7703 char min_ready[64];
7704 GetConVarName(wm_min_ready, min_ready, sizeof(min_ready));
7705 PrintToConsole(client, "===============================================================================");
7706 PrintToConsole(client, "This server is running WarMod [BFG] %s Server Plugin", WM_VERSION);
7707 PrintToConsole(client, "");
7708 PrintToConsole(client, "Created by Versatile [BFG]");
7709 PrintToConsole(client, "");
7710 PrintToConsole(client, "Messagemode commands: Aliases:");
7711 PrintToConsole(client, " /ready - Mark yourself as ready /rdy /r");
7712 PrintToConsole(client, " /unready - Mark yourself as not ready /unrdy /ur");
7713 PrintToConsole(client, " /info - Display the Ready System if enabled /i");
7714 PrintToConsole(client, " /scores - Display the match score if live /score /s");
7715 PrintToConsole(client, "");
7716 PrintToConsole(client, "Current settings: %s: %d / %s: %d / mp_match_can_clinch: %d", max_rounds, GetConVarInt(mp_maxrounds), min_ready, GetConVarInt(wm_min_ready), GetConVarInt(mp_match_can_clinch));
7717 PrintToConsole(client, "===============================================================================");
7718 }
7719}
7720
7721public Action WMVersion(int client, int args)
7722{
7723 if (client == 0)
7724 {
7725 PrintToServer("\"wm_version\" = \"%s\"\n - [WarMod_BFG] %s", WM_VERSION, WM_DESCRIPTION);
7726 }
7727 else
7728 {
7729 PrintToConsole(client, "\"wm_version\" = \"%s\"\n - [WarMod_BFG] %s", WM_VERSION, WM_DESCRIPTION);
7730 }
7731
7732 return Plugin_Handled;
7733}
7734
7735int UpdateStatus()
7736{
7737 int value;
7738 if (!g_match)
7739 {
7740 if (!g_t_knife)
7741 {
7742 if (!g_ready_enabled)
7743 {
7744 if (!g_t_had_knife)
7745 {
7746 value = 0;
7747 }
7748 else
7749 {
7750 value = 3;
7751 }
7752 }
7753 else
7754 {
7755 if (!g_t_had_knife && GetConVarBool(wm_auto_knife))
7756 {
7757 value = 1;
7758 }
7759 else
7760 {
7761 value = 4;
7762 }
7763 }
7764 }
7765 else
7766 {
7767 value = 2;
7768 }
7769 }
7770 else
7771 {
7772 if (!g_overtime)
7773 {
7774 if (!g_live)
7775 {
7776 if (!g_ready_enabled)
7777 {
7778 if (g_first_half)
7779 {
7780 value = 3;
7781 }
7782 else
7783 {
7784 value = 6;
7785 }
7786 }
7787 else
7788 {
7789 if (g_first_half)
7790 {
7791 value = 4;
7792 }
7793 else
7794 {
7795 value = 7;
7796 }
7797 }
7798 }
7799 else
7800 {
7801 if (g_first_half)
7802 {
7803 value = 5;
7804 }
7805 else
7806 {
7807 value = 8;
7808 }
7809 }
7810 }
7811 else
7812 {
7813 if (!g_live)
7814 {
7815 if (!g_ready_enabled)
7816 {
7817 value = 9;
7818 }
7819 else
7820 {
7821 value = 10;
7822 }
7823 }
7824 else
7825 {
7826 if (g_first_half)
7827 {
7828 value = 11 + (g_overtime_count * 2);
7829 }
7830 else
7831 {
7832 value = 12 + (g_overtime_count * 2);
7833 }
7834 }
7835 }
7836 }
7837 // SetConVarIntHidden(g_h_status, value);
7838 return value;
7839}
7840
7841bool isNumeric(char[] argstring)
7842{
7843 int argeLength = strlen(argstring);
7844 for (int i = 0; i < argeLength; i++)
7845 {
7846 if (!IsCharNumeric(argstring[i]))
7847 {
7848 return false;
7849 }
7850 }
7851 return true;
7852}
7853
7854/* Veto Code */
7855public Action Veto_Bo3_Maps(int client, int args)
7856{
7857 if (g_veto_bo3_active) // Bo3
7858 {
7859 if (g_ChosenMapBo3[0] == -1)
7860 {
7861 int bo = 3;
7862 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto No Maps", bo, LANG_SERVER);
7863 g_veto_bo3_active = false;
7864 return Plugin_Handled;
7865 }
7866 char map[3][PLATFORM_MAX_PATH];
7867 for (int i = 0; i <= 2; i++)
7868 {
7869 GetArrayString(g_MapNames, g_ChosenMapBo3[i], map[i], PLATFORM_MAX_PATH);
7870 }
7871 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Bo3 Map List", LANG_SERVER, map[0], map[1], map[2]);
7872 }
7873 else if (g_veto_bo2_active) // Bo2
7874 {
7875 if (g_ChosenMapBo2[0] == -1)
7876 {
7877 int bo = 2;
7878 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto No Maps", bo, LANG_SERVER);
7879 g_veto_bo2_active = false;
7880 return Plugin_Handled;
7881 }
7882 char map[2][PLATFORM_MAX_PATH];
7883 for (int i = 0; i <= 1; i++)
7884 {
7885 GetArrayString(g_MapNames, g_ChosenMapBo2[i], map[i], PLATFORM_MAX_PATH);
7886 }
7887 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Bo2 Map List", LANG_SERVER, map[0], map[1]);
7888 }
7889 else if (g_veto_bo5_active) // Bo5
7890 {
7891 if (g_ChosenMapBo5[0] == -1)
7892 {
7893 int bo = 5;
7894 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto No Maps", bo, LANG_SERVER);
7895 g_veto_bo5_active = false;
7896 return Plugin_Handled;
7897 }
7898 char map[5][PLATFORM_MAX_PATH];
7899 for (int i = 0; i <= 4; i++)
7900 {
7901 GetArrayString(g_MapNames, g_ChosenMapBo5[i], map[i], PLATFORM_MAX_PATH);
7902 }
7903 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Bo5 Map List", LANG_SERVER, map[0], map[1], map[2], map[3], map[4]);
7904 }
7905 return Plugin_Handled;
7906}
7907
7908public Action VetoTimeout(Handle timer)
7909{
7910 g_h_stored_timer_v = INVALID_HANDLE;
7911 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Offer Not Confirmed", LANG_SERVER);
7912 veto_offer_t = false;
7913 veto_offer_ct = false;
7914}
7915
7916public Action Veto_Bo1(int client, int args)
7917{
7918 if (client == 0)
7919 {
7920 SetConVarInt(wm_veto, 1);
7921 Veto_Admin_Setup(client, args);
7922 return Plugin_Handled;
7923 }
7924
7925 if (GetConVarInt(wm_veto) == 0)
7926 {
7927 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Disabled", LANG_SERVER);
7928 return Plugin_Handled;
7929 }
7930
7931 if (g_veto_active)
7932 {
7933 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Veto Active Already", CHAT_PREFIX);
7934 return Plugin_Handled;
7935 }
7936
7937 SetConVarInt(wm_veto, 1);
7938 Veto_Setup(client, args);
7939 return Plugin_Handled;
7940}
7941
7942public Action Veto_Bo2(int client, int args)
7943{
7944 if (client == 0)
7945 {
7946 SetConVarInt(wm_veto, 2);
7947 Veto_Admin_Setup(client, args);
7948 return Plugin_Handled;
7949 }
7950
7951 if (GetConVarInt(wm_veto) == 0)
7952 {
7953 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Disabled", LANG_SERVER);
7954 return Plugin_Handled;
7955 }
7956
7957 if (g_veto_active)
7958 {
7959 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Veto Active Already", CHAT_PREFIX);
7960 return Plugin_Handled;
7961 }
7962
7963 SetConVarInt(wm_veto, 2);
7964 Veto_Setup(client, args);
7965 return Plugin_Handled;
7966}
7967
7968public Action Veto_Bo3(int client, int args)
7969{
7970 if (client == 0)
7971 {
7972 SetConVarInt(wm_veto, 3);
7973 Veto_Admin_Setup(client, args);
7974 return Plugin_Handled;
7975 }
7976
7977 if (GetConVarInt(wm_veto) == 0)
7978 {
7979 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Disabled", LANG_SERVER);
7980 return Plugin_Handled;
7981 }
7982
7983 if (g_veto_active)
7984 {
7985 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Veto Active Already", CHAT_PREFIX);
7986 return Plugin_Handled;
7987 }
7988 SetConVarInt(wm_veto, 3);
7989 Veto_Setup(client, args);
7990 return Plugin_Handled;
7991}
7992
7993public Action Veto_Bo5(int client, int args)
7994{
7995 if (client == 0)
7996 {
7997 SetConVarInt(wm_veto, 5);
7998 Veto_Admin_Setup(client, args);
7999 return Plugin_Handled;
8000 }
8001
8002 if (GetConVarInt(wm_veto) == 0)
8003 {
8004 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Disabled", LANG_SERVER);
8005 return Plugin_Handled;
8006 }
8007
8008 if (g_veto_active)
8009 {
8010 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Veto Active Already", CHAT_PREFIX);
8011 return Plugin_Handled;
8012 }
8013 SetConVarInt(wm_veto, 5);
8014 Veto_Setup(client, args);
8015 return Plugin_Handled;
8016}
8017
8018public Action Veto_Setup(int client, int args)
8019{
8020 if (client == 0)
8021 {
8022 Veto_Admin_Setup(client, args);
8023 return Plugin_Handled;
8024 }
8025
8026 if (GetConVarInt(wm_veto) == 0)
8027 {
8028 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Disabled", LANG_SERVER);
8029 return Plugin_Handled;
8030 }
8031
8032 if (g_veto_active)
8033 {
8034 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Veto Active Already", CHAT_PREFIX);
8035 return Plugin_Handled;
8036 }
8037
8038 if (GetClientTeam(client) == 2)
8039 {
8040 if (veto_offer_t)
8041 {
8042 return Plugin_Handled;
8043 }
8044 veto_offer_t = true;
8045 }
8046 else if (GetClientTeam(client) == 3)
8047 {
8048 if (veto_offer_ct)
8049 {
8050 return Plugin_Handled;
8051 }
8052 veto_offer_ct = true;
8053 }
8054 else
8055 {
8056 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 %T", CHAT_PREFIX, "Veto Non-player", LANG_SERVER);
8057 return Plugin_Handled;
8058 }
8059
8060 int vetonum = GetConVarInt(wm_veto);
8061
8062 if (veto_offer_ct && veto_offer_t)
8063 {
8064 if (g_h_stored_timer_v != INVALID_HANDLE)
8065 {
8066 KillTimer(g_h_stored_timer_v);
8067 g_h_stored_timer_v = INVALID_HANDLE;
8068 }
8069 g_veto_bo2_active = false;
8070 g_veto_bo3_active = false;
8071 g_veto_bo5_active = false;
8072 g_bo3_count = -1;
8073 g_bo5_count = -1;
8074 g_ChosenMapBo5[0] = -1;
8075 g_ChosenMapBo3[0] = -1;
8076 g_ChosenMapBo2[0] = -1;
8077 g_veto_map_number = 0;
8078 veto_offer_ct = false;
8079 veto_offer_t = false;
8080 g_veto_active = true;
8081
8082 if (GetConVarBool(wm_veto_knife))
8083 {
8084 ServerCommand("exec gamemode_competitive_server.cfg");
8085 g_t_knife = true;
8086 g_t_veto = true;
8087 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Veto Knife!", CHAT_PREFIX);
8088 KnifeOn3Override();
8089 }
8090 else
8091 {
8092 SetCaptains();
8093 CreateMapVeto(3);
8094 }
8095 }
8096 else if (veto_offer_ct && !veto_offer_t)
8097 {
8098 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorist %T", CHAT_PREFIX, "Veto Offer", LANG_SERVER, vetonum);
8099 DisplayVetoOffer(CS_TEAM_CT);
8100 g_h_stored_timer_v = CreateTimer(30.0, VetoTimeout);
8101 return Plugin_Handled;
8102 }
8103 else if (!veto_offer_ct && veto_offer_t)
8104 {
8105 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorist %T", CHAT_PREFIX, "Veto Offer", LANG_SERVER, vetonum);
8106 DisplayVetoOffer(CS_TEAM_T);
8107 g_h_stored_timer_v = CreateTimer(30.0, VetoTimeout);
8108 return Plugin_Handled;
8109 }
8110 return Plugin_Handled;
8111}
8112
8113public void DisplayVetoOffer(int team)
8114{
8115 int vetonum = GetConVarInt(wm_veto);
8116 if (team == CS_TEAM_T)
8117 {
8118 PrintHintTextToAll("Terrorist %T", "Veto Offer", LANG_SERVER, vetonum);
8119 }
8120 else if (team == CS_TEAM_CT)
8121 {
8122 PrintHintTextToAll("Counter Terrorist %T", "Veto Offer", LANG_SERVER, vetonum);
8123 }
8124}
8125
8126public Action Veto_Admin_Setup(int client, int args)
8127{
8128 if (g_veto_active)
8129 {
8130 PrintToServer("[%s] Veto Active Already", CHAT_PREFIX);
8131 return Plugin_Handled;
8132 }
8133
8134 if (g_h_stored_timer_v != INVALID_HANDLE)
8135 {
8136 KillTimer(g_h_stored_timer_v);
8137 g_h_stored_timer_v = INVALID_HANDLE;
8138 }
8139 g_veto_bo2_active = false;
8140 g_veto_bo3_active = false;
8141 g_veto_bo5_active = false;
8142 g_bo3_count = -1;
8143 g_bo5_count = -1;
8144 g_ChosenMapBo5[0] = -1;
8145 g_ChosenMapBo3[0] = -1;
8146 g_ChosenMapBo2[0] = -1;
8147 g_veto_map_number = 0;
8148 veto_offer_ct = false;
8149 veto_offer_t = false;
8150 g_veto_active = true;
8151
8152 if (GetConVarBool(wm_veto_knife))
8153 {
8154 ServerCommand("exec gamemode_competitive_server.cfg");
8155 g_t_knife = true;
8156 g_t_veto = true;
8157 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Veto Knife!", CHAT_PREFIX);
8158 KnifeOn3Override();
8159 }
8160 else
8161 {
8162 SetCaptains();
8163 CreateMapVeto(3);
8164 }
8165 return Plugin_Handled;
8166}
8167
8168public int OtherCaptain(int captain)
8169{
8170 if (captain == g_capt1)
8171 return g_capt2;
8172 else
8173 return g_capt1;
8174}
8175
8176public void SetCaptains()
8177{
8178 if (GetConVarBool(wm_captain_from_file))
8179 {
8180 SetCaptainsViaFile();
8181 }
8182 else
8183 {
8184 SetRandomCaptains();
8185 }
8186}
8187
8188public void SetCaptainsViaFile()
8189{
8190 int c1 = GetCaptainFromFile(CS_TEAM_T);
8191 int c2 = GetCaptainFromFile(CS_TEAM_CT);
8192 SetCapt1(c1);
8193 SetCapt2(c2);
8194}
8195
8196int GetCaptainFromFile(int team)
8197{
8198 char authid[32];
8199 char teamflag[4];
8200 char teamlogo[8];
8201 char teamname[64];
8202 Handle kv = CreateKeyValues("Captains");
8203 FileToKeyValues(kv, "cfg/warmod/team_captains.txt");
8204 for (int i = 1; i <= MaxClients; i++)
8205 {
8206 if (IsValidClient(i) && GetClientTeam(i) == team)
8207 {
8208 GetClientAuthId(i, AuthId_Steam2, authid, sizeof(authid));
8209
8210 if (KvJumpToKey(kv, authid))
8211 {
8212 KvGetString(kv, "teamname", teamname, sizeof(teamname));
8213 KvGetString(kv, "teamlogo", teamlogo, sizeof(teamlogo));
8214 KvGetString(kv, "teamflag", teamflag, sizeof(teamflag));
8215 if (team == CS_TEAM_T) {
8216 ServerCommand("mp_teamname_2 %s", teamname);
8217 ServerCommand("mp_teamflag_2 %s", teamflag);
8218 ServerCommand("mp_teamlogo_2 %s", teamlogo);
8219 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x09%s", CHAT_PREFIX, teamname);
8220 } else if (team == CS_TEAM_CT) {
8221 ServerCommand("mp_teamname_1 %s", teamname);
8222 ServerCommand("mp_teamflag_1 %s", teamflag);
8223 ServerCommand("mp_teamlogo_1 %s", teamlogo);
8224 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x09%s", CHAT_PREFIX, teamname);
8225 }
8226 CloseHandle(kv);
8227 return i;
8228 }
8229 }
8230 }
8231 CloseHandle(kv);
8232 return -1;
8233}
8234
8235public void SetRandomCaptains()
8236{
8237 int c1 = -1;
8238 int c2 = -1;
8239 c1 = Client_GetRandom(CS_TEAM_T);
8240 c2 = Client_GetRandom(CS_TEAM_CT);
8241
8242 SetCapt1(c1);
8243 SetCapt2(c2);
8244}
8245
8246public void SetCapt1(int client)
8247{
8248 if (IsValidClient(client))
8249 {
8250 g_capt1 = client;
8251 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists %T %N", CHAT_PREFIX, "Veto Captain", LANG_SERVER, g_capt1);
8252 }
8253 else
8254 {
8255 int number = 0;
8256 for (int i = 1; i <= MaxClients; i++)
8257 {
8258 if (IsValidClient(i) && GetClientTeam(i) == 2)
8259 {
8260 number++;
8261 }
8262 }
8263 if (number > 0)
8264 {
8265 int c1 = -1;
8266 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Getting a random Terrorists Captain", CHAT_PREFIX);
8267 c1 = Client_GetRandom(CS_TEAM_T);
8268 SetCapt1(c1);
8269 }
8270 else
8271 {
8272 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Could not find a Terrorists Captain", CHAT_PREFIX);
8273 }
8274 }
8275}
8276
8277public void SetCapt2(int client)
8278{
8279 if (IsValidClient(client))
8280 {
8281 g_capt2 = client;
8282 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter-Terrorists %T %N", CHAT_PREFIX, "Veto Captain", LANG_SERVER, g_capt2);
8283 }
8284 else
8285 {
8286 int number = 0;
8287 for (int i = 1; i <= MaxClients; i++)
8288 {
8289 if (IsValidClient(i) && GetClientTeam(i) == 3)
8290 {
8291 number++;
8292 }
8293 }
8294 if (number > 0)
8295 {
8296 int c2 = -1;
8297 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Getting a random Counter-Terrorists Captain", CHAT_PREFIX);
8298 c2 = Client_GetRandom(CS_TEAM_CT);
8299 SetCapt2(c2);
8300 }
8301 else
8302 {
8303 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Could not find a Counter-Terrorists Captain", CHAT_PREFIX);
8304 }
8305 }
8306}
8307
8308stock void LogVetoEvent(const char[]format, any:...)
8309{
8310 char event[1024];
8311 VFormat(event, sizeof(event), format, 2);
8312 int stats_method = GetConVarInt(wm_stats_method);
8313
8314 // inject timestamp into JSON object, hacky but quite simple
8315 char timestamp[64];
8316 FormatTime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S");
8317
8318 // remove leading '{' from the event and add the timestamp in, including new '{'
8319 Format(event, sizeof(event), "{\"timestamp\": \"%s\", %s", timestamp, event[1]);
8320
8321 if (stats_method == 0 || stats_method == 2)
8322 {
8323 // standard server log files + udp stream
8324 LogToGame("[WarMod_BFG] %s", event);
8325 }
8326
8327 if ((stats_method == 1 || stats_method == 2) && g_log_veto_file != INVALID_HANDLE)
8328 {
8329 WriteFileLine(g_log_veto_file, event);
8330 }
8331
8332 if (LibraryExists("livewire"))
8333 {
8334 Call_StartForward(g_f_livewire_log_event);
8335 Call_PushString(event);
8336 Call_Finish();
8337 }
8338}
8339
8340void VetoLogFileCreate()
8341{
8342 FormatTime(date, sizeof(date), "%Y-%m-%d");
8343 FormatTime(startHour, sizeof(startHour), "%H");
8344 FormatTime(startMin, sizeof(startMin), "%M");
8345
8346 char t_name[64];
8347 char ct_name[64];
8348 Format(t_name, sizeof(t_name), g_t_name);
8349 Format(ct_name, sizeof(ct_name), g_ct_name);
8350
8351 StripFilename(t_name, sizeof(t_name));
8352 StripFilename(ct_name, sizeof(ct_name));
8353 ReplaceString(t_name, sizeof(t_name), ".", "");
8354 ReplaceString(ct_name, sizeof(ct_name), ".", "");
8355 StringToLower(t_name, sizeof(t_name));
8356 StringToLower(ct_name, sizeof(ct_name));
8357
8358 if (!GetConVarBool(wm_warmod_safemode))
8359 {
8360 if (StrEqual(t_name, DEFAULT_T_NAME, false) || StrEqual(t_name, "", false) || StrEqual(t_name, "_", false))
8361 {
8362 getTerroristTeamName();
8363 }
8364
8365 if (StrEqual(ct_name, DEFAULT_CT_NAME, false) || StrEqual(ct_name, "", false) || StrEqual(ct_name, "_", false))
8366 {
8367 getCounterTerroristTeamName();
8368 }
8369 }
8370
8371 Format(t_name, sizeof(t_name), g_t_name);
8372 Format(ct_name, sizeof(ct_name), g_ct_name);
8373 int num = GetConVarInt(wm_veto);
8374 if (!StrEqual(g_t_name, DEFAULT_T_NAME, false) || !StrEqual(g_ct_name, DEFAULT_CT_NAME, false))
8375 {
8376 StripFilename(t_name, sizeof(t_name));
8377 StripFilename(ct_name, sizeof(ct_name));
8378 ReplaceString(t_name, sizeof(t_name), ".", "");
8379 ReplaceString(ct_name, sizeof(ct_name), ".", "");
8380 StringToLower(t_name, sizeof(t_name));
8381 StringToLower(ct_name, sizeof(ct_name));
8382 if (StrEqual(t_name, "rrorists", false)) {
8383 Format(t_name, sizeof(t_name), "terroists");
8384 }
8385 if (StrEqual(ct_name, "unterterrorists", false)) {
8386 Format(ct_name, sizeof(ct_name), "counterterroists");
8387 }
8388 Format(g_log_veto_filename, sizeof(g_log_veto_filename), "%s-%s%s-%04x-veto_Bo%i-%s-vs-%s", date, startHour, startMin, GetConVarInt(FindConVar("hostport")), num, t_name, ct_name);
8389 }
8390 else
8391 {
8392 Format(g_log_veto_filename, sizeof(g_log_veto_filename), "%s-%s%s-%04x-veto_Bo%i", date, startHour, startMin, GetConVarInt(FindConVar("hostport")), num);
8393 }
8394
8395 char save_dir[128];
8396 GetConVarString(wm_save_dir, save_dir, sizeof(save_dir));
8397 if (!StrEqual(save_dir, ""))
8398 {
8399 if (!DirExists(save_dir))
8400 {
8401 CreateDirectory(save_dir, 511);
8402 }
8403 }
8404 if (GetConVarBool(wm_stats_enabled))
8405 {
8406 char filepath[128];
8407 if (!StrEqual(save_dir, ""))
8408 {
8409 if (DirExists(save_dir))
8410 {
8411 Format(filepath, sizeof(filepath), "%s/%s.log", save_dir, g_log_veto_filename);
8412 Format(g_sLogPath, sizeof(g_sLogPath), "%s/%s.log", save_dir, g_log_veto_filename);
8413 g_log_veto_file = OpenFile(filepath, "w");
8414 g_log_warmod_dir = true;
8415 }
8416 else if (DirExists("logs"))
8417 {
8418 Format(filepath, sizeof(filepath), "logs/%s.log", g_log_veto_filename);
8419 Format(g_sLogPath, sizeof(g_sLogPath), "logs/%s.log", g_log_veto_filename);
8420 g_log_veto_file = OpenFile(filepath, "w");
8421 g_log_warmod_dir = false;
8422 }
8423 else
8424 {
8425 Format(filepath, sizeof(filepath), "%s.log", g_log_veto_filename);
8426 Format(g_sLogPath, sizeof(g_sLogPath), "%s.log", g_log_veto_filename);
8427 g_log_veto_file = OpenFile(filepath, "w");
8428 g_log_warmod_dir = false;
8429 }
8430 }
8431 else if (DirExists("logs"))
8432 {
8433 Format(filepath, sizeof(filepath), "logs/%s.log", g_log_veto_filename);
8434 Format(g_sLogPath, sizeof(g_sLogPath), "logs/%s.log", g_log_veto_filename);
8435 g_log_veto_file = OpenFile(filepath, "w");
8436 g_log_warmod_dir = false;
8437 }
8438 else
8439 {
8440 Format(filepath, sizeof(filepath), "%s.log", g_log_veto_filename);
8441 Format(g_sLogPath, sizeof(g_sLogPath), "%s.log", g_log_veto_filename);
8442 g_log_veto_file = OpenFile(filepath, "w");
8443 g_log_warmod_dir = false;
8444 }
8445 LogEvent("{\"event\": \"log_start\", \"unixTime\": %d}", GetTime());
8446 }
8447 LogPlayers();
8448}
8449
8450/**
8451 * Map vetoing functions
8452*/
8453public void CreateMapVeto(int team)
8454{
8455 if (g_capt1 == -1 || g_capt2 == -1)
8456 {
8457 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Veto Cancelled", CHAT_PREFIX);
8458 g_veto_active = false;
8459 return;
8460 }
8461
8462 if (team == 2)
8463 {
8464 GiveVetoPickMenu(g_capt1);
8465 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %N %T", CHAT_PREFIX, g_capt1, "Veto First Second", LANG_SERVER);
8466 }
8467 else
8468 {
8469 GiveVetoPickMenu(g_capt2);
8470 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 %N %T", CHAT_PREFIX, g_capt2, "Veto First Second", LANG_SERVER);
8471 }
8472}
8473
8474public Action GiveVetoPickMenu(int client) {
8475 VetoLogFileCreate();
8476 Menu menu = new Menu(VetoPickHandler);
8477 SetMenuExitButton(menu, false);
8478 SetMenuTitle(menu, "Select to Vote first or second");
8479 AddMenuItem(menu, "First", "First");
8480 AddMenuItem(menu, "Second", "Second");
8481 DisplayMenu(menu, client, MENU_TIME_FOREVER);
8482}
8483
8484public int VetoPickHandler(Menu menu, MenuAction action, int param1, int param2)
8485{
8486 if (action == MenuAction_Select)
8487 {
8488 GetMapList();
8489 int client = param1;
8490 char info[32];
8491 GetMenuItem(menu, param2, info, sizeof(info));
8492
8493 LogVetoEvent("{\"event\": \"veto_first_second\", \"player\": \"%N\", \"team\": %d, \"selection\": \"%s\"}", client, GetClientTeam(client), info);
8494 if (StrEqual(info, "Second"))
8495 {
8496 client = OtherCaptain(client);
8497 }
8498
8499 GiveVetoMenu(client);
8500 for (int i = 1; i <= MaxClients; i++)
8501 {
8502 if (IsValidClient(i) && i != client)
8503 {
8504 VetoStatusDisplay(i);
8505 }
8506 }
8507
8508 }
8509 else if (action == MenuAction_End)
8510 {
8511 CloseHandle(menu);
8512 }
8513}
8514
8515public void GiveVetoMenu(int client) {
8516 Menu menu = new Menu(VetoHandler);
8517 SetMenuExitButton(menu, false);
8518 SetMenuTitle(menu, "Select a map to veto");
8519 for (int i = 0; i < GetArraySize(g_MapNames); i++) {
8520 if (!GetArrayCell(g_MapVetoed, i)) {
8521 char map[PLATFORM_MAX_PATH];
8522 GetArrayString(g_MapNames, i, map, sizeof(map));
8523 AddMenuInt(menu, i, map);
8524 }
8525 }
8526 DisplayMenu(menu, client, MENU_TIME_FOREVER);
8527}
8528
8529public int GiveVetoMenuSelect(int client) {
8530 g_veto_s = true;
8531
8532 Menu menu = new Menu(VetoHandler);
8533 SetMenuExitButton(menu, false);
8534 SetMenuTitle(menu, "Select a map to play");
8535 for (int i = 0; i < GetArraySize(g_MapNames); i++) {
8536 if (!GetArrayCell(g_MapVetoed, i)) {
8537 char map[PLATFORM_MAX_PATH];
8538 GetArrayString(g_MapNames, i, map, sizeof(map));
8539 AddMenuInt(menu, i, map);
8540 }
8541 }
8542 DisplayMenu(menu, client, MENU_TIME_FOREVER);
8543}
8544
8545static int GetNumMapsLeft() {
8546 int count = 0;
8547 for (int i = 0; i < GetArraySize(g_MapNames); i++) {
8548 if (!GetArrayCell(g_MapVetoed, i))
8549 count++;
8550 }
8551 return count;
8552}
8553
8554static int GetFirstMapLeft() {
8555 for (int i = 0; i < GetArraySize(g_MapNames); i++) {
8556 if (!GetArrayCell(g_MapVetoed, i))
8557 return i;
8558 }
8559 return -1;
8560}
8561
8562static int GetRandomMapLeft() {
8563 int max = GetNumMapsLeft();
8564 int random = Math_GetRandomInt(0, max);
8565 int count = -1;
8566 for (int i = 0; i < GetArraySize(g_MapNames); i++) {
8567 if (!GetArrayCell(g_MapVetoed, i))
8568 {
8569 count++;
8570 if (count == random)
8571 {
8572 return i;
8573 }
8574 }
8575
8576 }
8577 return -1;
8578}
8579
8580public int VetoHandler(Handle menu, MenuAction action, int param1, int param2)
8581{
8582 if (action == MenuAction_Select)
8583 {
8584 int client = param1;
8585 int index = GetMenuInt(menu, param2);
8586 char map[PLATFORM_MAX_PATH];
8587 GetArrayString(g_MapNames, index, map, PLATFORM_MAX_PATH);
8588 g_veto_number = g_veto_number + 1;
8589 SetArrayCell(g_MapVetoed, index, true);
8590
8591 if (!g_veto_s)
8592 {
8593 LogVetoEvent("{\"event\": \"veto_remove\", \"player\": \"%N\", \"team\": %d, \"selection\": \"%s\"}", client, GetClientTeam(client), map);
8594 if (client == g_capt1)
8595 {
8596 PrintToChatAll("\x01 \x09[\x04%s\x09]\x03 %N \x01vetoed \x07%s", CHAT_PREFIX, client, map);
8597 }
8598 else
8599 {
8600 PrintToChatAll("\x01 \x09[\x04%s\x09]\x06 %N \x01vetoed \x07%s", CHAT_PREFIX, client, map);
8601 }
8602 }
8603 else
8604 {
8605 LogVetoEvent("{\"event\": \"veto_select\", \"player\": \"%N\", \"team\": %d, \"selection\": \"%s\"}", client, GetClientTeam(client), map);
8606 if (client == g_capt1)
8607 {
8608 PrintToChatAll("\x01 \x09[\x04%s\x09]\x03 %N \x01chose \x07%s", CHAT_PREFIX, client, map);
8609 }
8610 else
8611 {
8612 PrintToChatAll("\x01 \x09[\x04%s\x09]\x06 %N \x01chose \x07%s", CHAT_PREFIX, client, map);
8613 }
8614 }
8615
8616 if (GetConVarInt(wm_veto) == 1) // Bo1
8617 {
8618 if (!g_veto_s) {
8619 if (g_MapListCount == (g_veto_number + 1)) {
8620 g_ChosenMap = GetFirstMapLeft();
8621 ChangeMap();
8622 g_veto_s = false;
8623 g_veto_number = 0;
8624 } else if (g_veto_number == (g_MapListCount - 2)) {
8625 if (GetConVarBool(wm_veto_random))
8626 {
8627 g_ChosenMap = GetRandomMapLeft();
8628 ChangeMap();
8629 }
8630 else
8631 {
8632 int other = OtherCaptain(client);
8633 if (GetConVarBool(wm_veto_select))
8634 {
8635 GiveVetoMenuSelect(other);
8636 }
8637 else
8638 {
8639 GiveVetoMenu(other);
8640 }
8641 DisplayVeto(other);
8642 }
8643 } else {
8644 int other = OtherCaptain(client);
8645 GiveVetoMenu(other);
8646 DisplayVeto(other);
8647 }
8648 } else {
8649 g_ChosenMap = index;
8650 ChangeMap();
8651 g_veto_s = false;
8652 g_veto_number = 0;
8653 }
8654 }
8655 else if (GetConVarInt(wm_veto) == 2) // Bo2
8656 {
8657 if (!g_veto_s)
8658 {
8659 if (g_veto_number == 2)
8660 {
8661 int other = OtherCaptain(client);
8662 GiveVetoMenuSelect(other);
8663 DisplayVeto(other);
8664 }
8665 else
8666 {
8667 int other = OtherCaptain(client);
8668 GiveVetoMenu(other);
8669 DisplayVeto(other);
8670 }
8671 }
8672 else
8673 {
8674 if (g_veto_number == 3)
8675 {
8676 g_ChosenMapBo2[1] = index;
8677 g_ChosenMap = index;
8678 int other = OtherCaptain(client);
8679 GiveVetoMenuSelect(other);
8680 DisplayVeto(other);
8681 g_veto_s = false;
8682 }
8683 else
8684 {
8685 g_ChosenMapBo2[1] = index;
8686 g_veto_bo2_active = true;
8687 ChangeMap();
8688 g_veto_s = false;
8689 g_veto_number = 0;
8690 }
8691 }
8692 }
8693 else if (GetConVarInt(wm_veto) == 3) // Bo3
8694 {
8695 if (!g_veto_s)
8696 {
8697 if (GetConVarBool(wm_veto_bo3) && g_veto_number == 2)
8698 {
8699 int other = OtherCaptain(client);
8700 GiveVetoMenuSelect(other);
8701 DisplayVeto(other);
8702 }
8703 else if (GetConVarBool(wm_veto_bo3) && g_veto_number == (g_MapListCount - 2)) //need to fix this?
8704 {
8705 g_ChosenMapBo3[g_bo3_count+1] = GetFirstMapLeft();
8706 GetArrayString(g_MapNames, g_ChosenMapBo3[g_bo3_count+1], map, PLATFORM_MAX_PATH);
8707 LogVetoEvent("{\"event\": \"veto_last_map\", \"selection\": %s}", map);
8708 g_ChosenMap = g_ChosenMapBo3[g_bo3_count-1];
8709 g_veto_map_number = 1;
8710 g_veto_bo3_active = true;
8711 ChangeMap();
8712 g_veto_number = 0;
8713 }
8714 else if (g_veto_number == (g_MapListCount - 3))
8715 {
8716 if (GetConVarBool(wm_veto_random))
8717 {
8718 g_ChosenMap = GetRandomMapLeft();
8719 g_veto_map_number = 1;
8720 g_veto_bo3_active = true;
8721 ChangeMap();
8722 }
8723 else
8724 {
8725 int other = OtherCaptain(client);
8726 GiveVetoMenuSelect(other);
8727 DisplayVeto(other);
8728 }
8729 }
8730 else if (g_veto_number == (g_MapListCount - 2))
8731 {
8732 if (GetConVarBool(wm_veto_random))
8733 {
8734 g_ChosenMap = GetRandomMapLeft();
8735 g_veto_map_number = 1;
8736 g_veto_bo3_active = true;
8737 ChangeMap();
8738 }
8739 else
8740 {
8741 int other = OtherCaptain(client);
8742 GiveVetoMenuSelect(other);
8743 DisplayVeto(other);
8744 }
8745 }
8746 else
8747 {
8748 int other = OtherCaptain(client);
8749 GiveVetoMenu(other);
8750 DisplayVeto(other);
8751 }
8752 }
8753 else
8754 {
8755 g_bo3_count = g_bo3_count + 1;
8756 g_ChosenMapBo3[g_bo3_count] = index;
8757 if (g_bo3_count == 1)
8758 {
8759 g_veto_s = false;
8760
8761 if (!GetConVarBool(wm_veto_bo3))
8762 {
8763 g_ChosenMapBo3[g_bo3_count+1] = GetFirstMapLeft();
8764 GetArrayString(g_MapNames, g_ChosenMapBo3[g_bo3_count+1], map, PLATFORM_MAX_PATH);
8765 LogVetoEvent("{\"event\": \"veto_last_map\", \"selection\": %s}", map);
8766 g_ChosenMap = g_ChosenMapBo3[g_bo3_count-1];
8767 g_veto_map_number = 1;
8768 g_veto_bo3_active = true;
8769 ChangeMap();
8770 g_veto_number = 0;
8771 }
8772 else
8773 {
8774 int other = OtherCaptain(client);
8775 GiveVetoMenu(other);
8776 DisplayVeto(other);
8777 }
8778 }
8779 else
8780 {
8781 int other = OtherCaptain(client);
8782 GiveVetoMenuSelect(other);
8783 DisplayVeto(other);
8784 }
8785 }
8786 }
8787 else if (GetConVarInt(wm_veto) == 5) // Bo5
8788 {
8789 if (!g_veto_s)
8790 {
8791 if (g_veto_number < 2)
8792 {
8793 int other = OtherCaptain(client);
8794 GiveVetoMenu(other);
8795 DisplayVeto(other);
8796 }
8797 else
8798 {
8799 int other = OtherCaptain(client);
8800 GiveVetoMenuSelect(other);
8801 DisplayVeto(other);
8802 }
8803 }
8804 else
8805 {
8806 g_bo5_count++;
8807 g_ChosenMapBo5[g_bo5_count] = index;
8808 if (g_bo5_count == 2 && g_veto_number < 5)
8809 {
8810 g_veto_s = false;
8811 int other = OtherCaptain(client);
8812 GiveVetoMenu(other);
8813 DisplayVeto(other);
8814 }
8815 else if (g_veto_number == 6)
8816 {
8817 g_ChosenMapBo5[g_bo5_count+1] = GetFirstMapLeft();
8818 GetArrayString(g_MapNames, g_ChosenMapBo5[g_bo5_count+1], map, PLATFORM_MAX_PATH);
8819 LogVetoEvent("{\"event\": \"veto_last_map\", \"selection\": %s}", map);
8820 g_ChosenMap = g_ChosenMapBo5[0];
8821 g_veto_map_number = 1;
8822 g_veto_bo5_active = true;
8823 ChangeMap();
8824 g_veto_number = 0;
8825 }
8826 else
8827 {
8828 int other = OtherCaptain(client);
8829 GiveVetoMenuSelect(other);
8830 DisplayVeto(other);
8831 }
8832 }
8833 }
8834 }
8835 else if (action == MenuAction_End)
8836 {
8837 CloseHandle(menu);
8838 }
8839}
8840
8841public void DisplayVeto(int other)
8842{
8843 for (int i = 1; i <= MaxClients; i++)
8844 {
8845 if (IsValidClient(i) && i != other)
8846 {
8847 VetoStatusDisplay(i);
8848 if (GetClientTeam(other) == GetClientTeam(i))
8849 {
8850 PrintHintText(i, "Your Team is voting");
8851 }
8852 else if (GetClientTeam(i) > 1)
8853 {
8854 PrintHintText(i, "Other Team is voting. Please Wait.");
8855 }
8856 else
8857 {
8858 char team[20];
8859 if (GetClientTeam(other) == 2)
8860 {
8861 team = "Terrorists";
8862 }
8863 else
8864 {
8865 team = "Counter-Terrorists";
8866 }
8867 PrintHintText(i, "%s are voting.", team);
8868 }
8869 }
8870 }
8871}
8872
8873static void VetoStatusDisplay(int client)
8874{
8875 char Temp[128];
8876 SetGlobalTransTarget(client);
8877 Handle g_m_maps_left = CreatePanel();
8878 Format(Temp, sizeof(Temp), "WarMod [BFG]- Veto Maps Left");
8879 SetPanelTitle(g_m_maps_left, Temp);
8880 DrawPanelText(g_m_maps_left, "\n \n");
8881 for (int i = 0; i < GetArraySize(g_MapNames); i++) {
8882 if (!GetArrayCell(g_MapVetoed, i)) {
8883 char map[PLATFORM_MAX_PATH];
8884 GetArrayString(g_MapNames, i, map, sizeof(map));
8885 Format(Temp, sizeof(Temp), "%s\n", map);
8886 DrawPanelItem(g_m_maps_left, Temp);
8887 }
8888 }
8889 DrawPanelText(g_m_maps_left, " \n");
8890 Format(Temp, sizeof(Temp), "Exit");
8891 DrawPanelItem(g_m_maps_left, Temp);
8892 SendPanelToClient(g_m_maps_left, client, Handler_DoNothing, 30);
8893 CloseHandle(g_m_maps_left);
8894}
8895
8896public void ChangeMap() {
8897 if (g_log_veto_file != INVALID_HANDLE) {
8898 // close log file
8899 FlushFile(g_log_veto_file);
8900 CloseHandle(g_log_veto_file);
8901 g_log_veto_file = INVALID_HANDLE;
8902 CreateTimer(5.0, LogFileUpload);
8903 }
8904
8905 if (g_ChosenMap != -1) {
8906 char map[PLATFORM_MAX_PATH];
8907 GetArrayString(g_MapNames, g_ChosenMap, map, sizeof(map));
8908 PrintToChatAll("Changing map to %s...", map);
8909 CreateTimer(3.0, Timer_DelayedChangeMap);
8910 g_veto_active = false;
8911 } else {
8912 PrintToChatAll("[Warmod] Something went wrong, please manually change level");
8913 LogError("Veto ChangeMap Error: g_ChosenMap = -1");
8914 }
8915}
8916
8917public Action Timer_DelayedChangeMap(Handle timer) {
8918 char map[PLATFORM_MAX_PATH];
8919 GetArrayString(g_MapNames, g_ChosenMap, map, sizeof(map));
8920 ServerCommand("changelevel %s", map);
8921 return Plugin_Handled;
8922}
8923
8924void VetoMapChange()
8925{
8926 if (g_veto_bo3_active)
8927 {
8928 g_ChosenMap = g_ChosenMapBo3[g_veto_map_number];
8929 }
8930 else if (g_veto_bo5_active)
8931 {
8932 g_ChosenMap = g_ChosenMapBo5[g_veto_map_number];
8933 }
8934 else
8935 {
8936 g_ChosenMap = g_ChosenMapBo2[g_veto_map_number];
8937 }
8938
8939 g_veto_map_number++;
8940
8941 char map[PLATFORM_MAX_PATH];
8942 GetArrayString(g_MapNames, g_ChosenMap, map, sizeof(map));
8943
8944 if (GetConVarBool(tv_delaymapchange))
8945 {
8946 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Waiting for GOTV delay.", CHAT_PREFIX);
8947 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Map will change to %s in %i seconds", CHAT_PREFIX, map, GetConVarInt(tv_delay));
8948 CreateTimer(GetConVarFloat(tv_delay), Timer_DelayedChangeMap);
8949 }
8950 else
8951 {
8952 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Changing map to %s in 10 seconds..", CHAT_PREFIX, map);
8953 CreateTimer(10.0, Timer_DelayedChangeMap);
8954 }
8955}
8956
8957public void GetMapList() {
8958 ClearArray(g_MapNames);
8959 ClearArray(g_MapVetoed);
8960
8961 // full file path
8962 char mapCvar[PLATFORM_MAX_PATH];
8963 GetConVarString(wm_pugsetup_maplist_file, mapCvar, sizeof(mapCvar));
8964
8965 char mapFile[PLATFORM_MAX_PATH];
8966 Format(mapFile, sizeof(mapFile), "cfg/%s", mapCvar);
8967
8968 if (!FileExists(mapFile)) {
8969 CreateDefaultMapFile();
8970 }
8971
8972 Handle mfile = OpenFile(mapFile, "r");
8973 char mapName[PLATFORM_MAX_PATH];
8974 while (!IsEndOfFile(mfile) && ReadFileLine(mfile, mapName, sizeof(mapName))) {
8975 TrimString(mapName);
8976 AddMap(mapName);
8977 }
8978 CloseHandle(mfile);
8979
8980 if (GetArraySize(g_MapNames) < 1) {
8981 LogError("The map file was empty: %s", mapFile);
8982 AddMap("de_dust2");
8983 AddMap("de_inferno");
8984 AddMap("de_mirage");
8985 AddMap("de_train");
8986 AddMap("de_overpass");
8987 AddMap("de_cache");
8988 AddMap("de_cbble");
8989 }
8990
8991 if (GetConVarBool(wm_pugsetup_randomize_maps)) {
8992 RandomizeMaps();
8993 }
8994
8995 g_MapListCount = GetNumMapsLeft();
8996}
8997
8998static void AddMap(const char[]mapName) {
8999 if (IsMapValid(mapName))
9000 {
9001 PushArrayString(g_MapNames, mapName);
9002 PushArrayCell(g_MapVetoed, false);
9003 }
9004 else if (strlen(mapName) >= 1)
9005 {
9006 // don't print errors on empty
9007 LogMessage("Invalid map name in mapfile: %s", mapName);
9008 }
9009}
9010
9011static void CreateDefaultMapFile()
9012{
9013 LogError("No map list was found, autogenerating one.");
9014 // full file path
9015 char mapCvar[PLATFORM_MAX_PATH];
9016 GetConVarString(wm_pugsetup_maplist_file, mapCvar, sizeof(mapCvar));
9017
9018 if (StrContains(mapCvar, "/") || StrContains(mapCvar, "\\"))
9019 {
9020 char g_FolderSplit[2][64];
9021 if (StrContains(mapCvar, "/"))
9022 {
9023 ExplodeString(mapCvar, "/", g_FolderSplit, 2, 64);
9024 }
9025 else
9026 {
9027 ExplodeString(mapCvar, "\\", g_FolderSplit, 2, 64);
9028 }
9029 char folderTest[PLATFORM_MAX_PATH];
9030 Format(folderTest, sizeof(folderTest), "cfg/%s", g_FolderSplit[0]);
9031 if (!DirExists(folderTest))
9032 {
9033 CreateDirectory(folderTest, 511);
9034 }
9035 }
9036
9037 char mapFile[PLATFORM_MAX_PATH];
9038 Format(mapFile, sizeof(mapFile), "cfg/%s", mapCvar);
9039
9040 Handle mfile = OpenFile(mapFile, "w");
9041 WriteFileLine(mfile, "de_dust2");
9042 WriteFileLine(mfile, "de_inferno");
9043 WriteFileLine(mfile, "de_mirage");
9044 WriteFileLine(mfile, "de_train");
9045 WriteFileLine(mfile, "de_overpass");
9046 WriteFileLine(mfile, "de_cache");
9047 WriteFileLine(mfile, "de_cbble", false); // no newline at the end
9048 CloseHandle(mfile);
9049}
9050
9051static void RandomizeMaps() {
9052 int n = GetArraySize(g_MapNames);
9053 for (int i = 0; i < n; i++) {
9054 int choice = GetRandomInt(0, n - 1);
9055 SwapArrayItems(g_MapNames, i, choice);
9056 }
9057}
9058
9059/**
9060 * Adds an integer to a menu as a string choice.
9061*/
9062public void AddMenuInt(Handle menu, any value, char[] display) {
9063 char buffer[8];
9064 IntToString(value, buffer, sizeof(buffer));
9065 AddMenuItem(menu, buffer, display);
9066}
9067
9068/**
9069 * Adds an integer to a menu, named by the integer itself.
9070*/
9071public void AddMenuInt2(Handle menu, any value) {
9072 char buffer[8];
9073 IntToString(value, buffer, sizeof(buffer));
9074 AddMenuItem(menu, buffer, buffer);
9075}
9076
9077/**
9078 * Gets an integer to a menu from a string choice.
9079*/
9080public int GetMenuInt(Handle menu, any param2) {
9081 char choice[8];
9082 GetMenuItem(menu, param2, choice, sizeof(choice));
9083 return StringToInt(choice);
9084}
9085
9086/**
9087 * Returns a random, uniform Integer number in the specified (inclusive) range.
9088 * This is safe to use multiple times in a function.
9089 * The seed is set automatically for each plugin.
9090 * Rewritten by MatthiasVance, thanks.
9091 *
9092 * @param min Min value used as lower border
9093 * @param max Max value used as upper border
9094 * @return Random Integer number between min and max
9095*/
9096#define SIZE_OF_INT 2147483647 // without 0
9097
9098stock int Math_GetRandomInt(int min, int max)
9099{
9100 int random = GetURandomInt();
9101 if (random == 0) {
9102 random++;
9103 }
9104 return RoundToCeil(float(random) / (float(SIZE_OF_INT) / float(max - min + 1))) + min - 1;
9105}
9106
9107/**
9108 * Gets all clients matching the specified flags filter.
9109 *
9110 * @param client Client Array, size should be MaxClients or MAXPLAYERS
9111 * @param flags Client Filter Flags (Use the CLIENTFILTER_ constants).
9112 * @return The number of clients stored in the array
9113*/
9114stock int Client_Get(int[] clients, int team)
9115{
9116 int x=0;
9117 for (int client = 1; client <= MaxClients; client++)
9118 {
9119 if (!IsValidClient(client) || IsFakeClient(client))
9120 {
9121 continue;
9122 }
9123 if (GetClientTeam(client) == team)
9124 {
9125 clients[x++] = client;
9126 }
9127 }
9128 return x;
9129}
9130/**
9131 * Gets a random client matching the specified flags filter.
9132 *
9133 * @param flags Client Filter Flags (Use the CLIENTFILTER_ constants).
9134 * @return Client Index or -1 if no client was found
9135*/
9136stock int Client_GetRandom(int team)
9137{
9138 int[] clients = new int[MaxClients];
9139 int num = Client_Get(clients, team);
9140 if (num == 0)
9141 {
9142 return -1;
9143 }
9144 else if (num == 1)
9145 {
9146 return clients[0];
9147 }
9148 int random = Math_GetRandomInt(0, num-1);
9149 return clients[random];
9150}
9151
9152/* Restore Match Backup */
9153public Action MatchRestore(int client, const char[]command, int args)
9154{
9155 char arg[128];
9156 if (GetCmdArg(1, arg, sizeof(arg)) < 1)
9157 {
9158 return Plugin_Handled;
9159 }
9160
9161 if (strcmp(arg, g_c_backup, false) == 0)
9162 {
9163 Format(g_c_backup, sizeof(g_c_backup), "");
9164 return Plugin_Continue;
9165 }
9166
9167 if (!StrEqual(arg[strlen(arg)-4], ".txt"))
9168 {
9169 ServerCommand("mp_backup_restore_load_file %s.txt", arg);
9170 return Plugin_Handled;
9171 }
9172
9173 MatchRestoreCMD(arg);
9174 return Plugin_Handled;
9175}
9176
9177public void MatchRestoreCMD(char[] arg)
9178{
9179 Handle kv = CreateKeyValues("SaveFile");
9180 FileToKeyValues(kv, arg);
9181 Format(g_c_backup, sizeof(g_c_backup), arg);
9182
9183 KvJumpToKey(kv, "FirstHalfScore", false);
9184 g_scores[SCORE_CT][SCORE_FIRST_HALF] = KvGetNum(kv, "team1", 0);
9185 g_scores[SCORE_T][SCORE_FIRST_HALF] = KvGetNum(kv, "team2", 0);
9186
9187 KvGoBack(kv);
9188
9189 if (!KvJumpToKey(kv, "SecondHalfScore", false))
9190 {
9191 g_live = false;
9192 g_restore = true;
9193 ReadySystem(true);
9194 ReadyChangeAll(0, false, true);
9195 ShowInfo(0, true, false, 0);
9196 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Restoring match. Scores: CT = %i, T = %i", CHAT_PREFIX, GetCTTotalScore(), GetTTotalScore());
9197 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Restoring match. Please ready up!", CHAT_PREFIX);
9198
9199 CloseHandle(kv);
9200 return;
9201 }
9202 SwitchScores();
9203
9204 g_scores[SCORE_T][SCORE_SECOND_HALF] = KvGetNum(kv, "team1", 0);
9205 g_scores[SCORE_CT][SCORE_SECOND_HALF] = KvGetNum(kv, "team2", 0);
9206
9207 KvGoBack(kv);
9208
9209 if (!KvJumpToKey(kv, "OvertimeScore", false))
9210 {
9211 g_first_half = false;
9212 g_live = false;
9213 g_restore = true;
9214 ReadySystem(true);
9215 ReadyChangeAll(0, false, true);
9216 ShowInfo(0, true, false, 0);
9217 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Restoring match. Scores: CT = %i, T = %i", CHAT_PREFIX, GetCTTotalScore(), GetTTotalScore());
9218 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Restoring match. Please ready up!", CHAT_PREFIX);
9219
9220 CloseHandle(kv);
9221 return;
9222 }
9223
9224 int team1_ot = KvGetNum(kv, "team1", 0);
9225 int team2_ot = KvGetNum(kv, "team2", 0);
9226 int ot_count = KvGetNum(kv, "OvertimeID", 0);
9227
9228 if (ot_count > 1)
9229 {
9230 for (int i = 0; i < (ot_count - 1); i++)
9231 {
9232 g_scores_overtime[SCORE_T][i][SCORE_FIRST_HALF] = ((GetConVarInt(mp_overtime_maxrounds)/2)/2);
9233 g_scores_overtime[SCORE_CT][i][SCORE_FIRST_HALF] = ((GetConVarInt(mp_overtime_maxrounds)/2)/2+1);
9234 SwitchScores();
9235 g_scores_overtime[SCORE_T][i][SCORE_SECOND_HALF] = ((GetConVarInt(mp_overtime_maxrounds)/2)/2+1);
9236 g_scores_overtime[SCORE_CT][i][SCORE_SECOND_HALF] = ((GetConVarInt(mp_overtime_maxrounds)/2)/2);
9237 team1_ot = team1_ot - (GetConVarInt(mp_overtime_maxrounds)/2);
9238 team2_ot = team2_ot - (GetConVarInt(mp_overtime_maxrounds)/2);
9239 g_overtime_count++;
9240 }
9241 }
9242
9243 g_scores_overtime[SCORE_T][(ot_count - 1)][SCORE_FIRST_HALF] = team2_ot;
9244 g_scores_overtime[SCORE_CT][(ot_count - 1)][SCORE_FIRST_HALF] = team1_ot;
9245
9246 if (team1_ot + team2_ot >= (GetConVarInt(mp_overtime_maxrounds)/2))
9247 {
9248 g_first_half = false;
9249 }
9250
9251 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Restoring match. Scores: CT = %i, T = %i", CHAT_PREFIX, GetCTTotalScore(), GetTTotalScore());
9252 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Restoring match. Please ready up!", CHAT_PREFIX);
9253
9254 CloseHandle(kv);
9255
9256 g_live = false;
9257 g_overtime = true;
9258 g_restore = true;
9259 ReadySystem(true);
9260 ReadyChangeAll(0, false, true);
9261 ShowInfo(0, true, false, 0);
9262}
9263
9264/* Warmod ForceTeam Command */
9265public Action ForceTeam(int args) {
9266 if (args < 2) {
9267 PrintToServer("Usage: wm_forceteam <steamid64> <team>");
9268 return Plugin_Handled;
9269 }
9270 char steam_id[64];
9271 char arg2[20];
9272 GetCmdArg(1, steam_id, 64);
9273 GetCmdArg(2, arg2, 20);
9274 int team;
9275
9276 if (StrEqual(arg2, "2", false) || StrEqual(arg2, "Terrorist", false) || StrEqual(arg2, "t", false) || StrEqual(arg2, "CS_TEAM_T", false)) {
9277 team = CS_TEAM_T;
9278 } else if (StrEqual(arg2, "3", false) || StrEqual(arg2, "Counter-Terrorist", false) || StrEqual(arg2, "CounterTerrorist", false) || StrEqual(arg2, "Counter Terrorist", false) || StrEqual(arg2, "ct", false) || StrEqual(arg2, "CS_TEAM_CT", false)) {
9279 team = CS_TEAM_CT;
9280 } else {
9281 PrintToServer("Usage: wm_forceteam <steamid64> <team>");
9282 PrintToServer("Must be Terrorist or Counter-Terrorist teams");
9283 return Plugin_Handled;
9284 }
9285
9286 int uindex = GetUseridBySteamId(steam_id);
9287 int count;
9288 int countfix;
9289 if (uindex == -1) {
9290 PrintToServer("No client could be found matching the given SteamID64");
9291 if (team == CS_TEAM_CT && force_team_ct_count < 10) {
9292 for (int i = 0; i < 10; i++) {
9293 if (strcmp(force_team_t[i], steam_id, false) == 0) {
9294 Format(force_team_t[i], 64, "");
9295 countfix = i;
9296 }
9297
9298 if (strcmp(force_team_ct[i], steam_id, false) == 0) {
9299 count++;
9300 }
9301 }
9302
9303 if (count == 0) {
9304 PrintToServer("Added to force team array CS_TEAM_CT");
9305 Format(force_team_ct[force_team_ct_count], 64, steam_id);
9306 force_team_ct_count++;
9307 } else {
9308 PrintToServer("Already added to force team array CS_TEAM_CT");
9309 }
9310
9311 if (countfix != 0) {
9312 for (int o = countfix; o < 9; o++) {
9313 Format(force_team_t[o], 64, force_team_t[o+1]);
9314 }
9315 force_team_t_count = force_team_t_count - 1;
9316 }
9317 } else if (team == CS_TEAM_T && force_team_t_count < 10) {
9318 for (int i = 0; i < 10; i++) {
9319 if (strcmp(force_team_ct[i], steam_id, false) == 0) {
9320 Format(force_team_ct[i], 64, "");
9321 countfix = i;
9322 }
9323
9324 if (strcmp(force_team_t[i], steam_id, false) == 0) {
9325 count++;
9326 }
9327 }
9328
9329 if (count == 0) {
9330 PrintToServer("Added to force team array CS_TEAM_T");
9331 Format(force_team_t[force_team_t_count], 64, steam_id);
9332 force_team_t_count++;
9333 } else {
9334 PrintToServer("Already added to force team array CS_TEAM_T");
9335 }
9336
9337 if (countfix != 0) {
9338 for (int o = countfix; o < 9; o++) {
9339 Format(force_team_ct[o], 64, force_team_ct[o+1]);
9340 }
9341 force_team_ct_count = force_team_ct_count - 1;
9342 }
9343 } else if (team == CS_TEAM_T || team == CS_TEAM_CT) {
9344 PrintToServer("No room in array. Please clear list for team %d", team);
9345 }
9346 return Plugin_Handled;
9347 }
9348 if (GetClientTeam(uindex) != team) {
9349 ChangeClientTeam(uindex, team);
9350 }
9351 return Plugin_Handled;
9352}
9353
9354void ClearForceTeamList (int team) {
9355 if (team == CS_TEAM_T || team == 4) {
9356 for (int i = 0; i < 10; i++) {
9357 Format(force_team_t[i], 64, "");
9358 }
9359 force_team_t_count = 0;
9360 PrintToServer("Cleared Force team CS_TEAM_T list");
9361 }
9362
9363 if (team == CS_TEAM_CT || team == 4) {
9364 for (int o = 0; o < 10; o++) {
9365 Format(force_team_ct[o], 64, "");
9366 }
9367 force_team_ct_count = 0;
9368 PrintToServer("Cleared Force team CS_TEAM_CT list");
9369 }
9370}
9371
9372public Action ClearForceTeamAll(int args) {
9373 PrintToServer("Clearing Force teams list");
9374 ClearForceTeamList(4);
9375 return Plugin_Handled;
9376}
9377
9378public Action ClearForceTeamT(int args) {
9379 PrintToServer("Clearing Force team CS_TEAM_T list");
9380 ClearForceTeamList(CS_TEAM_T);
9381 return Plugin_Handled;
9382}
9383
9384public Action ClearForceTeamCT(int args) {
9385 PrintToServer("Clearing Force team CS_TEAM_CT list");
9386 ClearForceTeamList(CS_TEAM_CT);
9387 return Plugin_Handled;
9388}
9389
9390/* Warmod ForceClientName Command */
9391public Action ForceClientName(int args)
9392{
9393 if (args < 2)
9394 {
9395 PrintToServer("Usage: wm_forcename <steamid64> <name>");
9396 return Plugin_Handled;
9397 }
9398 char steam_id[64];
9399 char name[16];
9400 GetCmdArg(1, steam_id, 64);
9401 GetCmdArg(2, name, 16);
9402
9403 int uindex = GetUseridBySteamId(steam_id);
9404 if (uindex == -1)
9405 {
9406 PrintToServer("No client could be found matching the given SteamID64");
9407 return Plugin_Handled;
9408 }
9409
9410 SetClientName(uindex, name);
9411 return Plugin_Handled;
9412}
9413
9414stock int GetUseridBySteamId(char[] authid)
9415{
9416 int clientIndex = -1;
9417 char CommunityID[18];
9418
9419 for (int i = 1; i <= MaxClients; i++)
9420 {
9421 if (IsClientConnected(i))
9422 {
9423 GetClientAuthId(i, AuthId_SteamID64, CommunityID, sizeof(CommunityID));
9424 if (strcmp(authid, CommunityID, false) == 0)
9425 {
9426 return i;
9427 }
9428 }
9429 }
9430 return clientIndex;
9431}
9432/* WarMod Status Command */
9433public Action WarMod_Status(int args)
9434{
9435 char log_string[384];
9436 int z = 0;
9437 LogToGame("{\"WarMod_Status\":");
9438 LogToGame("{\"Counter-Terrorists\":[");
9439 for (int i = 1; i <= MaxClients; i++)
9440 {
9441 if (IsClientInGame(i) && GetClientTeam(i) == CS_TEAM_CT)
9442 {
9443 CS_GetStatuString(i, log_string, sizeof(log_string));
9444 if (z == 0)
9445 {
9446 LogToGame("{\"player\": %s}", log_string);
9447 z++;
9448 }
9449 else
9450 {
9451 LogToGame(", {\"player\": %s}", log_string);
9452 }
9453 }
9454 }
9455 LogToGame("], \"Terrorists\":[");
9456 z = 0;
9457 for (int i = 1; i <= MaxClients; i++)
9458 {
9459 if (IsClientInGame(i) && GetClientTeam(i) == CS_TEAM_T)
9460 {
9461 CS_GetStatuString(i, log_string, sizeof(log_string));
9462
9463 if (z == 0)
9464 {
9465 LogToGame("{\"player\": %s}", log_string);
9466 z++;
9467 }
9468 else
9469 {
9470 LogToGame(", {\"player\": %s}", log_string);
9471 }
9472 }
9473 }
9474 LogToGame("], \"SPECTATOR\":[");
9475 z = 0;
9476 for (int i = 1; i <= MaxClients; i++)
9477 {
9478 if (IsClientInGame(i) && (GetClientTeam(i) == CS_TEAM_SPECTATOR || GetClientTeam(i) == CS_TEAM_NONE))
9479 {
9480 CS_GetStatuString(i, log_string, sizeof(log_string));
9481
9482 if (z == 0)
9483 {
9484 LogToGame("{\"player\": %s}", log_string);
9485 z++;
9486 }
9487 else
9488 {
9489 LogToGame(", {\"player\": %s}", log_string);
9490 }
9491 }
9492 }
9493 LogToGame("]}}");
9494 return Plugin_Handled;
9495}
9496
9497stock int CS_GetStatuString(int client, char[] LogString, int size)
9498{
9499 if (client == 0)
9500 {
9501 strcopy(LogString, size, "{\"name\": \"Console\", \"userId\": 0, \"uniqueId\": \"Console\", \"team\": 0}");
9502 return client;
9503 }
9504
9505 if (!IsClientInGame(client))
9506 {
9507 Format(LogString, size, "null");
9508 return -1;
9509 }
9510
9511 char player_name[64];
9512 char authid[32];
9513
9514 GetClientName(client, player_name, sizeof(player_name));
9515 GetClientAuthId(client, AuthId_Steam2, authid, sizeof(authid));
9516
9517 EscapeString(player_name, sizeof(player_name));
9518 EscapeString(authid, sizeof(authid));
9519 if (GetClientTeam(client) == CS_TEAM_SPECTATOR || GetClientTeam(client) == CS_TEAM_NONE)
9520 {
9521 Format(LogString, size, "{\"steamId\": \"%s\", \"name\": \"%s\"}", authid, player_name);
9522 }
9523 else
9524 {
9525 Format(LogString, size, "{\"steamId\": \"%s\", \"name\": \"%s\", \"kills\": %d, \"assists\": %d, \"deaths\": %d, \"score\": %d, \"money\": %d}", authid, player_name, GetClientFrags(client), CS_GetClientAssists(client), GetEntProp(client, Prop_Data, "m_iDeaths"), CS_GetClientContributionScore(client), GetEntData(client, g_iAccount));
9526 }
9527
9528 return client;
9529}
9530
9531void LogMoney()
9532{
9533 char log_string[384];
9534 for(int i = 1; i < MAXPLAYERS; i++)
9535 {
9536 if (IsClientInGame(i) && (GetClientTeam(i) == CS_TEAM_T))
9537 {
9538 CS_GetAdvLogString(i, log_string, sizeof(log_string));
9539 LogEvent("{\"event\": \"round_money\", \"round\": %i, \"player\": %s, \"kills\": %d, \"assists\": %d, \"deaths\": %d, \"score\": %d, \"money\": %d}", g_round, log_string, GetClientFrags(i), CS_GetClientAssists(i), GetEntProp(i, Prop_Data, "m_iDeaths"), CS_GetClientContributionScore(i), GetEntData(i, g_iAccount));
9540 }
9541 }
9542
9543 for(int o = 1; o < MAXPLAYERS; o++)
9544 {
9545 if (IsClientInGame(o) && (GetClientTeam(o) == CS_TEAM_CT))
9546 {
9547 CS_GetAdvLogString(o, log_string, sizeof(log_string));
9548 LogEvent("{\"event\": \"round_money\", \"round\": %i, \"player\": %s, \"kills\": %d, \"assists\": %d, \"deaths\": %d, \"score\": %d, \"money\": %d}", g_round, log_string, GetClientFrags(o), CS_GetClientAssists(o), GetEntProp(o, Prop_Data, "m_iDeaths"), CS_GetClientContributionScore(o), GetEntData(o, g_iAccount));
9549 }
9550 }
9551}
9552
9553// Returns count for players in game and not spectators
9554stock int CS_GetPlayerListCount()
9555{
9556 int clients = 0;
9557 for(int i = 1; i < MAXPLAYERS; i++)
9558 {
9559 if (IsClientInGame(i) && IsClientConnected(i) && !IsFakeClient(i))
9560 {
9561 if (GetClientTeam(i) > 1)
9562 {
9563 clients++;
9564 }
9565 }
9566 }
9567 return clients;
9568}
9569
9570stock bool IsEven(int num)
9571{
9572 return (num & 1) == 0;
9573}
9574
9575public Action SetTagClientDefault(Handle timer)
9576{
9577 if (!GetConVarBool(wm_warmod_safemode) && GetConVarBool(wm_ready_tag))
9578 {
9579 for (int i = 1; i <= MaxClients; i++)
9580 {
9581 if (IsValidClient(i))
9582 {
9583 if (StrEqual(g_clanTags[i], "NOT READY", false) || StrEqual(g_clanTags[i], "READY", false) || StrEqual(g_clanTags[i], "", false))
9584 {
9585 CS_SetClientClanTag(i, " ");
9586 }
9587 else
9588 {
9589 CS_SetClientClanTag(i, g_clanTags[i]);
9590 }
9591 }
9592 }
9593 }
9594}
9595
9596public void SetTagNotReady(int client)
9597{
9598 if (!GetConVarBool(wm_warmod_safemode) && IsValidClient(client) && GetConVarBool(wm_ready_tag))
9599 {
9600 if (!g_clanTagsChecked[client])
9601 {
9602 CS_GetClientClanTag(client, g_clanTags[client], sizeof(g_clanTags[]));
9603 g_clanTagsChecked[client] = true;
9604 if (StrEqual(g_clanTags[client], "NOT READY", false) || StrEqual(g_clanTags[client], "READY", false) || StrEqual(g_clanTags[client], "", false))
9605 {
9606 Format(g_clanTags[client], sizeof(g_clanTags[]), " ");
9607 }
9608 }
9609 CS_SetClientClanTag(client, "NOT READY");
9610 }
9611}
9612
9613public void SetTagReady(int client)
9614{
9615 if (!GetConVarBool(wm_warmod_safemode) && IsValidClient(client) && GetConVarBool(wm_ready_tag))
9616 {
9617 if (!g_clanTagsChecked[client])
9618 {
9619 CS_GetClientClanTag(client, g_clanTags[client], sizeof(g_clanTags[]));
9620 g_clanTagsChecked[client] = true;
9621 if (StrEqual(g_clanTags[client], "NOT READY", false) || StrEqual(g_clanTags[client], "READY", false) || StrEqual(g_clanTags[client], "", false))
9622 {
9623 Format(g_clanTags[client], sizeof(g_clanTags[]), " ");
9624 }
9625 }
9626 CS_SetClientClanTag(client, "READY");
9627 }
9628}
9629
9630public int Updater_OnPluginUpdated()
9631{
9632 ReloadPlugin();
9633}
9634
9635/* Team logo code */
9636stock void AddTeamLogosToDownloadTable()
9637{
9638 Handle dir = OpenDirectory("resource/flash/econ/tournaments/teams/");
9639 if (dir == null)
9640 {
9641 LogError("[SM] Unable to read directory: 'resource/flash/econ/tournaments/teams'");
9642 return;
9643 }
9644
9645 FileType type;
9646 char filename[PLATFORM_MAX_PATH];
9647 char fullpath[PLATFORM_MAX_PATH];
9648
9649 while (ReadDirEntry(dir, filename, sizeof(filename), type))
9650 {
9651 if (type != FileType_File)
9652 continue;
9653
9654 if (!StrEqual(filename[strlen(filename) - 4], ".png"))
9655 continue;
9656
9657 PrintToServer("[SM] Loading team logo: %s", filename);
9658 Format(fullpath, sizeof(fullpath), "resource/flash/econ/tournaments/teams/%s", filename);
9659 AddFileToDownloadsTable(fullpath);
9660 }
9661
9662 CloseHandle(dir);
9663}
9664
9665public Action SetLogo(int client, int args)
9666{
9667 if (!IsValidClient(client))
9668 {
9669 return Plugin_Handled;
9670 }
9671 else if (!g_p_ct_name && GetClientTeam(client) == 3)
9672 {
9673 return Plugin_Handled;
9674 }
9675 else if (!g_p_t_name && GetClientTeam(client) == 2)
9676 {
9677 return Plugin_Handled;
9678 }
9679 else if (GetClientTeam(client) < 2)
9680 {
9681 return Plugin_Handled;
9682 }
9683
9684 if (GetCmdArgs() < 1 || GetConVarBool(wm_logos_menu_only))
9685 {
9686 GiveDivPickMenu(client, "Divisions");
9687 }
9688 else if (GetCmdArgs() > 0 && client != 0)
9689 {
9690 char logocode[8];
9691 char flag[4];
9692 char name[64];
9693 GetCmdArgString(logocode, sizeof(logocode));
9694 StripQuotes(logocode);
9695 if (GetNameFromLogocode(logocode, flag, sizeof(flag), name, sizeof(name)))
9696 {
9697 if (g_p_t_name && GetClientTeam(client) == 2)
9698 {
9699 char name_old[64];
9700 Format(name_old, sizeof(name_old), "%s", g_t_name);
9701 Format(g_t_name, sizeof(g_t_name), "%s", name);
9702 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_t_name);
9703 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
9704 LogEvent("{\"event\": \"name_change\", \"team\": 2, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_t_name);
9705 ServerCommand("mp_teamname_2 %s", g_t_name);
9706 ServerCommand("mp_teamflag_2 %s", flag);
9707 ServerCommand("mp_teamlogo_2 %s", logocode);
9708 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x09%s", CHAT_PREFIX, g_t_name);
9709 g_p_t_name = false;
9710 }
9711
9712 if (g_p_ct_name && GetClientTeam(client) == 3)
9713 {
9714 char name_old[64];
9715 Format(name_old, sizeof(name_old), "%s", g_ct_name);
9716 Format(g_ct_name, sizeof(g_ct_name), "%s", name);
9717 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_ct_name);
9718 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
9719 LogEvent("{\"event\": \"name_change\", \"team\": 3, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_ct_name);
9720 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x09%s", CHAT_PREFIX, g_ct_name);
9721 ServerCommand("mp_teamname_1 %s", g_ct_name);
9722 ServerCommand("mp_teamflag_1 %s", flag);
9723 ServerCommand("mp_teamlogo_1 %s", logocode);
9724 g_p_ct_name = false;
9725 }
9726 }
9727 else if (StrEqual(logocode, "none", false))
9728 {
9729 if (g_p_t_name && GetClientTeam(client) == 2)
9730 {
9731 ServerCommand("mp_teamlogo_2 %s", logocode);
9732 }
9733 else if (g_p_ct_name && GetClientTeam(client) == 3)
9734 {
9735 ServerCommand("mp_teamlogo_1 %s", logocode);
9736 }
9737 }
9738 else
9739 {
9740 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Team Name not in file", CHAT_PREFIX);
9741 }
9742 CheckReady();
9743 }
9744 return Plugin_Handled;
9745}
9746
9747bool GetConfigFromDiv(const char[] div)
9748{
9749 Handle kv = CreateKeyValues("TeamLogos");
9750 char config[64];
9751 char fdiv[4];
9752 fdiv[0] = div[0];
9753 FileToKeyValues(kv, "cfg/warmod/team_logos.txt");
9754 KvJumpToKey(kv, "Divisions");
9755 if (!KvJumpToKey(kv, fdiv))
9756 {
9757 CloseHandle(kv);
9758 return false;
9759 }
9760 KvGetString(kv, "config", config, sizeof(config));
9761 CloseHandle(kv);
9762 if (!StrEqual(config, ""))
9763 {
9764 ServerCommand("wm_match_config %s", config);
9765 }
9766 return true;
9767}
9768
9769bool GetDivFromLogocode(const char[] logocode, char[] div, int divlength)
9770{
9771 Handle kv = CreateKeyValues("TeamLogos");
9772 FileToKeyValues(kv, "cfg/warmod/team_logos.txt");
9773 KvJumpToKey(kv, "Teams");
9774 PrintToChatAll("GetDivFromLogocode, code = %s", logocode);
9775 if (!KvJumpToKey(kv, logocode))
9776 {
9777 CloseHandle(kv);
9778 return false;
9779 }
9780 KvGetString(kv, "div", div, divlength);
9781 CloseHandle(kv);
9782 return true;
9783}
9784
9785bool GetNameFromLogocode(const char[] logocode, char[] flag, int flaglength, char[] name, int namelength)
9786{
9787 Handle kv = CreateKeyValues("TeamLogos");
9788 FileToKeyValues(kv, "cfg/warmod/team_logos.txt");
9789 KvJumpToKey(kv, "Teams");
9790 if (!KvJumpToKey(kv, logocode))
9791 {
9792 CloseHandle(kv);
9793 return false;
9794 }
9795 KvGetString(kv, "name", name, namelength);
9796 KvGetString(kv, "flag", flag, flaglength);
9797 CloseHandle(kv);
9798 return true;
9799}
9800
9801public Action GiveDivPickMenu(int client, char[] selectDiv)
9802{
9803 Handle kv = CreateKeyValues("TeamLogos");
9804 FileToKeyValues(kv, "cfg/warmod/team_logos.txt");
9805 char kdiv[8];
9806 char name[64];
9807 char title[128];
9808 Menu menu = new Menu(DivPickHandler);
9809 SetMenuExitButton(menu, false);
9810 KvJumpToKey(kv, "Divisions");
9811 if (StrEqual(selectDiv, "Divisions", false))
9812 {
9813 Format(title, sizeof(title), "Warmod [BFG] Division Select");
9814 }
9815 else
9816 {
9817 Format(title, sizeof(title), "Warmod [BFG] Division Select %s", selectDiv);
9818 KvJumpToKey(kv, selectDiv);
9819 }
9820
9821 SetMenuTitle(menu, title);
9822 KvGotoFirstSubKey(kv);
9823 do
9824 {
9825 KvGetSectionName(kv, kdiv, sizeof(kdiv));
9826 KvGetString(kv, "name", name, sizeof(name));
9827 AddMenuItem(menu,kdiv,name);
9828
9829 } while (KvGotoNextKey(kv));
9830 AddMenuItem(menu, "None", "None");
9831 CloseHandle(kv);
9832 SetMenuExitButton(menu, true);
9833 DisplayMenu(menu, client, MENU_TIME_FOREVER);
9834}
9835
9836public int DivPickHandler(Menu menu, MenuAction action, int param1, int param2)
9837{
9838 if (action == MenuAction_Select)
9839 {
9840 int client = param1;
9841 char info[32];
9842 char keyjump[32];
9843 int pos_keyjump = 0;
9844 GetMenuItem(menu, param2, info, sizeof(info));
9845
9846 if (StrEqual(info, "none", false))
9847 {
9848 if (g_p_t_name && GetClientTeam(client) == 2)
9849 {
9850 ServerCommand("mp_teamlogo_2 %s", info);
9851 }
9852 else if (g_p_ct_name && GetClientTeam(client) == 3)
9853 {
9854 ServerCommand("mp_teamlogo_1 %s", info);
9855 }
9856 CheckReady();
9857 return;
9858 }
9859
9860 Handle kv = CreateKeyValues("TeamLogos");
9861 FileToKeyValues(kv, "cfg/warmod/team_logos.txt");
9862 KvJumpToKey(kv, "Divisions");
9863 int length = strlen(info);
9864
9865 for (int i = 0; i < length; i++)
9866 {
9867 keyjump[pos_keyjump++] = info[i];
9868 KvJumpToKey(kv, keyjump);
9869 }
9870
9871 if (KvGotoFirstSubKey(kv))
9872 {
9873 CloseHandle(kv);
9874 GiveDivPickMenu(client, info);
9875 }
9876 else
9877 {
9878 CloseHandle(kv);
9879 GiveLogoPickMenu(client, info);
9880 }
9881 }
9882 else if (action == MenuAction_End)
9883 {
9884 CloseHandle(menu);
9885 }
9886}
9887
9888public Action GiveLogoPickMenu(int client, char[] div)
9889{
9890 Handle kv = CreateKeyValues("TeamLogos");
9891 FileToKeyValues(kv, "cfg/warmod/team_logos.txt");
9892 char kdiv[8];
9893 char logocode[8];
9894 char name[64];
9895 Menu menu = new Menu(LogoPickHandler);
9896 SetMenuExitButton(menu, false);
9897 SetMenuTitle(menu, "Warmod [BFG] Logo Select");
9898 KvJumpToKey(kv, "Teams");
9899 KvGotoFirstSubKey(kv);
9900 do
9901 {
9902 KvGetSectionName(kv, logocode, sizeof(logocode));
9903 KvGetString(kv, "div", kdiv, sizeof(kdiv));
9904 KvGetString(kv, "name", name, sizeof(name));
9905
9906 if (StrEqual(kdiv, div, false))
9907 {
9908 AddMenuItem(menu,logocode,name);
9909 }
9910 } while (KvGotoNextKey(kv));
9911 AddMenuItem(menu, "None", "None");
9912 CloseHandle(kv);
9913 SetMenuExitButton(menu, true);
9914 DisplayMenu(menu, client, MENU_TIME_FOREVER);
9915}
9916
9917public int LogoPickHandler(Menu menu, MenuAction action, int param1, int param2)
9918{
9919 if (action == MenuAction_Select)
9920 {
9921 int client = param1;
9922 char logocode[8];
9923 char flag[4];
9924 char name[64];
9925 GetMenuItem(menu, param2, logocode, sizeof(logocode));
9926 StripQuotes(logocode);
9927 if (GetNameFromLogocode(logocode, flag, sizeof(flag), name, sizeof(name)))
9928 {
9929 if (g_p_t_name && GetClientTeam(client) == 2)
9930 {
9931 char name_old[64];
9932 Format(name_old, sizeof(name_old), "%s", g_t_name);
9933 Format(g_t_name, sizeof(g_t_name), "%s", name);
9934 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_t_name);
9935 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
9936 LogEvent("{\"event\": \"name_change\", \"team\": 2, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_t_name);
9937 ServerCommand("mp_teamname_2 %s", g_t_name);
9938 ServerCommand("mp_teamflag_2 %s", flag);
9939 ServerCommand("mp_teamlogo_2 %s", logocode);
9940 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x09%s", CHAT_PREFIX, g_t_name);
9941 g_p_t_name = false;
9942 }
9943
9944 if (g_p_ct_name && GetClientTeam(client) == 3)
9945 {
9946 char name_old[64];
9947 Format(name_old, sizeof(name_old), "%s", g_ct_name);
9948 Format(g_ct_name, sizeof(g_ct_name), "%s", name);
9949 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_ct_name);
9950 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
9951 LogEvent("{\"event\": \"name_change\", \"team\": 3, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_ct_name);
9952 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x09%s", CHAT_PREFIX, g_ct_name);
9953 ServerCommand("mp_teamname_1 %s", g_ct_name);
9954 ServerCommand("mp_teamflag_1 %s", flag);
9955 ServerCommand("mp_teamlogo_1 %s", logocode);
9956 g_p_ct_name = false;
9957 }
9958
9959 char div[8];
9960 if (GetDivFromLogocode(logocode, div, sizeof(div)))
9961 {
9962 if (GetConfigFromDiv(div))
9963 {
9964
9965 }
9966 }
9967 }
9968 else if (StrEqual(logocode, "none", false))
9969 {
9970 if (g_p_t_name && GetClientTeam(client) == 2)
9971 {
9972 ServerCommand("mp_teamlogo_2 %s", logocode);
9973 }
9974 else if (g_p_ct_name && GetClientTeam(client) == 3)
9975 {
9976 ServerCommand("mp_teamlogo_1 %s", logocode);
9977 }
9978 }
9979 else
9980 {
9981 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Team Name not in file", CHAT_PREFIX);
9982 }
9983 CheckReady();
9984 }
9985 else if (action == MenuAction_End)
9986 {
9987 CloseHandle(menu);
9988 }
9989}
9990
9991public Action SetName(int client, int args)
9992{
9993 if (!IsValidClient(client))
9994 {
9995 return Plugin_Handled;
9996 }
9997 else if (!g_p_ct_name && GetClientTeam(client) == 3)
9998 {
9999 return Plugin_Handled;
10000 }
10001 else if (!g_p_t_name && GetClientTeam(client) == 2)
10002 {
10003 return Plugin_Handled;
10004 }
10005 else if (GetClientTeam(client) < 2)
10006 {
10007 return Plugin_Handled;
10008 }
10009
10010 char sName[64];
10011 GetCmdArgString(sName, sizeof(sName));
10012 StripQuotes(sName);
10013
10014 if (g_p_t_name && GetClientTeam(client) == 2)
10015 {
10016 char name_old[64];
10017 Format(name_old, sizeof(name_old), "%s", g_t_name);
10018 Format(g_t_name, sizeof(g_t_name), "%s", sName);
10019 Format(g_t_name_escaped, sizeof(g_t_name_escaped), g_t_name);
10020 EscapeString(g_t_name_escaped, sizeof(g_t_name_escaped));
10021 LogEvent("{\"event\": \"name_change\", \"team\": 2, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_t_name);
10022 ServerCommand("mp_teamname_2 %s", g_t_name);
10023 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Terrorists are called \x09%s", CHAT_PREFIX, g_t_name);
10024 g_p_t_name = false;
10025 }
10026
10027 if (g_p_ct_name && GetClientTeam(client) == 3)
10028 {
10029 char name_old[64];
10030 Format(name_old, sizeof(name_old), "%s", g_ct_name);
10031 Format(g_ct_name, sizeof(g_ct_name), "%s", sName);
10032 Format(g_ct_name_escaped, sizeof(g_ct_name_escaped), g_ct_name);
10033 EscapeString(g_ct_name_escaped, sizeof(g_ct_name_escaped));
10034 LogEvent("{\"event\": \"name_change\", \"team\": 3, \"old\": \"%s\", \"new\": \"%s\"}", name_old, g_ct_name);
10035 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Counter Terrorists are called \x09%s", CHAT_PREFIX, g_ct_name);
10036 ServerCommand("mp_teamname_1 %s", g_ct_name);
10037 g_p_ct_name = false;
10038 }
10039
10040 CheckReady();
10041 return Plugin_Handled;
10042}
10043
10044void SetLastMatchScores() {
10045 lt_match_length = RoundFloat(GetEngineTime() - g_match_start);
10046 Format(lt_map, sizeof(lt_map), g_map);
10047 lt_max_rounds = (GetConVarInt(mp_maxrounds)/2);
10048 lt_overtime_max_rounds = 0;
10049 if (GetConVarBool(mp_overtime_enable)) {
10050 lt_overtime_max_rounds = (GetConVarInt(mp_overtime_maxrounds)/2);
10051 }
10052 lt_overtime_count = g_overtime_count;
10053 if (GetConVarBool(mp_match_can_clinch)) {
10054 lt_played_out = 0;
10055 } else {
10056 lt_played_out = 1;
10057 }
10058 Format(lt_t_name, sizeof(lt_t_name), g_t_name);
10059 lt_t_overall_score = GetTTotalScore();
10060 lt_t_first_half_score = g_scores[SCORE_T][SCORE_FIRST_HALF];
10061 lt_t_second_half_score = g_scores[SCORE_T][SCORE_SECOND_HALF];
10062 lt_t_overtime_score = GetTOTTotalScore();
10063 Format(lt_ct_name, sizeof(lt_ct_name), g_ct_name);
10064 lt_ct_overall_score = GetCTTotalScore();
10065 lt_ct_first_half_score = g_scores[SCORE_CT][SCORE_FIRST_HALF];
10066 lt_ct_second_half_score = g_scores[SCORE_CT][SCORE_SECOND_HALF];
10067 lt_ct_overtime_score = GetCTOTTotalScore();
10068 Format(lt_log_file_name, sizeof(lt_log_file_name), g_log_filename);
10069}
10070
10071void StartSQL(int upload) {
10072 if (GetConVarBool(wm_upload_results)) {
10073 if (SQL_CheckConfig("warmod")) {
10074 SQL_TConnect(GotDatabase, "warmod", upload);
10075 } else {
10076 LogError("No warmod database configuration found (note: case-sensitive)!");
10077 }
10078 }
10079}
10080
10081public void GotDatabase(Handle owner, Handle hndl, const char[] error, any data)
10082{
10083 if (hndl == INVALID_HANDLE) {
10084 LogError("Database failure: %s", error);
10085 } else {
10086 hDatabase = hndl;
10087 MySQL_CreateTable(data);
10088 }
10089}
10090
10091void MySQL_CreateTable(any data) {
10092 char query[1024];
10093 char table_name[128];
10094 /*GetConVarString(wm_table_name_players, table_name, sizeof(table_name));
10095 Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `%s` (`key_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `match_id` INT(11) UNSIGNED NOT NULL, `steamid64` VARCHAR(64) NOT NULL, `player_name` VARCHAR(64) NOT NULL, `team` TINYINT(2) unsigned NOT NULL, PRIMARY KEY (`key_id`));", table_name);
10096 if (SQL_DEBUG) {
10097 LogError(query);
10098 }
10099 SQL_TQuery(hDatabase, MySQL_CreateTablePlayersReturn, query);*/
10100
10101 GetConVarString(wm_table_round_stats, table_name, sizeof(table_name));
10102 Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `%s` (`key_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `match_id` INT(11) unsigned NOT NULL, `rounds_played` TINYINT(3) unsigned NOT NULL, `player_name` VARCHAR(64) NOT NULL, `steam_id_64` VARCHAR(20) NOT NULL, `team` TINYINT(1) NOT NULL, `kills` TINYINT(2) NOT NULL, `deaths` TINYINT(2) NOT NULL, `assists` TINYINT(2) NOT NULL, `head_shots` TINYINT(2) NOT NULL, `team_kills` TINYINT(2) NOT NULL, `assists_team_attack` TINYINT(2) NOT NULL, `damage` INT(4) NOT NULL, `hits` INT(4) NOT NULL, `shots` INT(4) NOT NULL, `last_alive` TINYINT(1) NOT NULL, `clutch_won` TINYINT(1) NOT NULL, `1k` TINYINT(2) NOT NULL, `2k` TINYINT(2) NOT NULL, `3k` TINYINT(2) NOT NULL, `4k` TINYINT(2) NOT NULL, `5k` TINYINT(2) NOT NULL, PRIMARY KEY (`key_id`));", table_name);
10103 if (SQL_DEBUG) {
10104 LogError(query);
10105 }
10106 SQL_TQuery(hDatabase, MySQL_CreateTablePlayerStatsReturn, query);
10107
10108 GetConVarString(wm_table_name, table_name, sizeof(table_name));
10109 Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `%s` (`match_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `match_start` DATETIME NOT NULL, `match_end` DATETIME NOT NULL, `map` VARCHAR(64) NOT NULL, `max_rounds` TINYINT(3) unsigned NOT NULL, `overtime_max_rounds` TINYINT(3) UNSIGNED NOT NULL, `overtime_count` TINYINT(3) UNSIGNED NOT NULL, `played_out` TINYINT(1) NOT NULL, `t_name` VARCHAR(128) NOT NULL, `t_overall_score` TINYINT(3) UNSIGNED NOT NULL, `t_first_half_score` TINYINT(3) UNSIGNED NOT NULL, `t_second_half_score` TINYINT(3) UNSIGNED NOT NULL, `t_overtime_score` TINYINT(3) UNSIGNED NOT NULL, `ct_name` VARCHAR(128) NOT NULL, `ct_overall_score` TINYINT(3) UNSIGNED NOT NULL, `ct_first_half_score` TINYINT(3) UNSIGNED NOT NULL, `ct_second_half_score` TINYINT(3) UNSIGNED NOT NULL, `ct_overtime_score` TINYINT(3) UNSIGNED NOT NULL, `demo` VARCHAR(128) NOT NULL, PRIMARY KEY (`match_id`));", table_name);
10110 if (SQL_DEBUG) {
10111 LogError(query);
10112 }
10113 SQL_TQuery(hDatabase, MySQL_CreateTableReturn, query, data);
10114}
10115
10116public void MySQL_CreateTablePlayerStatsReturn(Handle owner, Handle hndl, const char[] error, any data) {
10117 if (hndl == INVALID_HANDLE) {
10118 LogError("Query failed! %s", error);
10119 }
10120}
10121
10122public void MySQL_CreateTableReturn(Handle owner, Handle hndl, const char[] error, any data) {
10123 if (hndl == INVALID_HANDLE) {
10124 LogError("Query failed! %s", error);
10125 } else {
10126 if (data == 1) {
10127 MySQL_UploadResults();
10128 } else if (data == 2) {
10129 MySQL_CreateResultKey();
10130 }
10131 }
10132}
10133
10134void MySQL_UploadResultsRound() {
10135 char query[1024];
10136 char table_name[128];
10137 int g_overtime_rounds;
10138 int g_played_out;
10139 GetConVarString(wm_table_name, table_name, sizeof(table_name));
10140 if (!GetConVarBool(mp_match_can_clinch)) {
10141 g_played_out = 1;
10142 }
10143 if (GetConVarBool(mp_overtime_enable)) {
10144 g_overtime_rounds = (GetConVarInt(mp_overtime_maxrounds)/2);
10145 }
10146 if (match_id != 0) {
10147 if (team_switch) {
10148 Format(query, sizeof(query), "UPDATE `%s` SET `match_end` = UTC_TIMESTAMP(), `map` = '%s', `max_rounds` = %i, `overtime_max_rounds` = %i, `overtime_count` = %i, `played_out` = %i, `t_name` = '%s', `t_overall_score` = %i, `t_first_half_score` = %i, `t_second_half_score` = %i, `t_overtime_score` = %i, `ct_name` = '%s', `ct_overall_score` = %i, `ct_first_half_score` = %i, `ct_second_half_score` = %i, `ct_overtime_score` = %i, `demo` = '%s' WHERE `match_id` = %i;", table_name, g_map, (GetConVarInt(mp_maxrounds)/2), g_overtime_rounds, g_overtime_count, g_played_out, g_ct_name_escaped, GetCTTotalScore(), g_scores[SCORE_CT][SCORE_FIRST_HALF], g_scores[SCORE_CT][SCORE_SECOND_HALF], GetCTOTTotalScore(), g_t_name_escaped, GetTTotalScore(), g_scores[SCORE_T][SCORE_FIRST_HALF], g_scores[SCORE_T][SCORE_SECOND_HALF], GetTOTTotalScore(), g_log_filename, match_id);
10149 } else {
10150 Format(query, sizeof(query), "UPDATE `%s` SET `match_end` = UTC_TIMESTAMP(), `map` = '%s', `max_rounds` = %i, `overtime_max_rounds` = %i, `overtime_count` = %i, `played_out` = %i, `t_name` = '%s', `t_overall_score` = %i, `t_first_half_score` = %i, `t_second_half_score` = %i, `t_overtime_score` = %i, `ct_name` = '%s', `ct_overall_score` = %i, `ct_first_half_score` = %i, `ct_second_half_score` = %i, `ct_overtime_score` = %i, `demo` = '%s' WHERE `match_id` = %i;", table_name, g_map, (GetConVarInt(mp_maxrounds)/2), g_overtime_rounds, g_overtime_count, g_played_out, g_t_name_escaped, GetTTotalScore(), g_scores[SCORE_T][SCORE_FIRST_HALF], g_scores[SCORE_T][SCORE_SECOND_HALF], GetTOTTotalScore(), g_ct_name_escaped, GetCTTotalScore(), g_scores[SCORE_CT][SCORE_FIRST_HALF], g_scores[SCORE_CT][SCORE_SECOND_HALF], GetCTOTTotalScore(), g_log_filename, match_id);
10151 }
10152 if (SQL_DEBUG) {
10153 LogError(query);
10154 }
10155 SQL_TQuery(hDatabase, MySQL_UploadResultsRoundReturn, query, false);
10156 } else {
10157 if (team_switch) {
10158 Format(query, sizeof(query), "INSERT INTO `%s` (`match_id`, `match_start`, `match_end`, `map`, `max_rounds`, `overtime_max_rounds`, `overtime_count`, `played_out`, `t_name`, `t_overall_score`, `t_first_half_score`, `t_second_half_score`, `t_overtime_score`, `ct_name`, `ct_overall_score`, `ct_first_half_score`, `ct_second_half_score`, `ct_overtime_score`, `demo`) VALUES (NULL, UTC_TIMESTAMP(), UTC_TIMESTAMP(), '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s')", table_name, g_map, (GetConVarInt(mp_maxrounds)/2), g_overtime_rounds, g_overtime_count, g_played_out, g_ct_name_escaped, GetCTTotalScore(), g_scores[SCORE_CT][SCORE_FIRST_HALF], g_scores[SCORE_CT][SCORE_SECOND_HALF], GetCTOTTotalScore(), g_t_name_escaped, GetTTotalScore(), g_scores[SCORE_T][SCORE_FIRST_HALF], g_scores[SCORE_T][SCORE_SECOND_HALF], GetTOTTotalScore(), g_log_filename);
10159 } else {
10160 Format(query, sizeof(query), "INSERT INTO `%s` (`match_id`, `match_start`, `match_end`, `map`, `max_rounds`, `overtime_max_rounds`, `overtime_count`, `played_out`, `t_name`, `t_overall_score`, `t_first_half_score`, `t_second_half_score`, `t_overtime_score`, `ct_name`, `ct_overall_score`, `ct_first_half_score`, `ct_second_half_score`, `ct_overtime_score`, `demo`) VALUES (NULL, UTC_TIMESTAMP(), UTC_TIMESTAMP(), '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s')", table_name, g_map, (GetConVarInt(mp_maxrounds)/2), g_overtime_rounds, g_overtime_count, g_played_out, g_t_name_escaped, GetTTotalScore(), g_scores[SCORE_T][SCORE_FIRST_HALF], g_scores[SCORE_T][SCORE_SECOND_HALF], GetTOTTotalScore(), g_ct_name_escaped, GetCTTotalScore(), g_scores[SCORE_CT][SCORE_FIRST_HALF], g_scores[SCORE_CT][SCORE_SECOND_HALF], GetCTOTTotalScore(), g_log_filename);
10161 }
10162 if (SQL_DEBUG) {
10163 LogError(query);
10164 }
10165 SQL_TQuery(hDatabase, MySQL_UploadResultsRoundReturn, query, true);
10166 }
10167}
10168
10169public void MySQL_UploadResultsRoundReturn(Handle owner, Handle hndl, const char[] error, any data) {
10170 if (hndl == INVALID_HANDLE) {
10171 LogError("Query failed! %s", error);
10172 } else if (data) {
10173 match_id = SQL_GetInsertId(hDatabase);
10174 char g_def_backup[128];
10175 GetConVarString(FindConVar("mp_backup_round_file_pattern"), g_def_backup, sizeof(g_def_backup));
10176 Format(g_def_backup, sizeof(g_def_backup), "%i_%s", match_id, g_def_backup);
10177 ServerCommand("mp_backup_round_file_pattern %s", g_def_backup);
10178 }
10179}
10180
10181void MySQL_UploadResults() {
10182 char query[1024];
10183 char table_name[128];
10184 GetConVarString(wm_table_name, table_name, sizeof(table_name));
10185 if (match_id != 0) {
10186 if (team_switch) {
10187 Format(query, sizeof(query), "UPDATE `%s` SET `match_start` = DATE_SUB(UTC_TIMESTAMP(), INTERVAL %i SECOND), `match_end` = UTC_TIMESTAMP(), `map` = '%s', `max_rounds` = %i, `overtime_max_rounds` = %i, `overtime_count` = %i, `played_out` = %i, `t_name` = '%s', `t_overall_score` = %i, `t_first_half_score` = %i, `t_second_half_score` = %i, `t_overtime_score` = %i, `ct_name` = '%s', `ct_overall_score` = %i, `ct_first_half_score` = %i, `ct_second_half_score` = %i, `ct_overtime_score` = %i, `demo` = '%s' WHERE `match_id` = %i;", table_name, lt_match_length, lt_map, lt_max_rounds, lt_overtime_max_rounds, lt_overtime_count, lt_played_out, lt_ct_name, lt_ct_overall_score, lt_ct_first_half_score, lt_ct_second_half_score, lt_ct_overtime_score, lt_t_name, lt_t_overall_score, lt_t_first_half_score, lt_t_second_half_score, lt_t_overtime_score, lt_log_file_name, match_id);
10188 } else {
10189 Format(query, sizeof(query), "UPDATE `%s` SET `match_start` = DATE_SUB(UTC_TIMESTAMP(), INTERVAL %i SECOND), `match_end` = UTC_TIMESTAMP(), `map` = '%s', `max_rounds` = %i, `overtime_max_rounds` = %i, `overtime_count` = %i, `played_out` = %i, `t_name` = '%s', `t_overall_score` = %i, `t_first_half_score` = %i, `t_second_half_score` = %i, `t_overtime_score` = %i, `ct_name` = '%s', `ct_overall_score` = %i, `ct_first_half_score` = %i, `ct_second_half_score` = %i, `ct_overtime_score` = %i, `demo` = '%s' WHERE `match_id` = %i;", table_name, lt_match_length, lt_map, lt_max_rounds, lt_overtime_max_rounds, lt_overtime_count, lt_played_out, lt_t_name, lt_t_overall_score, lt_t_first_half_score, lt_t_second_half_score, lt_t_overtime_score, lt_ct_name, lt_ct_overall_score, lt_ct_first_half_score, lt_ct_second_half_score, lt_ct_overtime_score, lt_log_file_name, match_id);
10190 }
10191 if (SQL_DEBUG) {
10192 LogError(query);
10193 }
10194 SQL_TQuery(hDatabase, MySQL_UploadResultsReturn, query, false);
10195 } else {
10196 if (team_switch) {
10197 Format(query, sizeof(query), "INSERT INTO `%s` (`match_id`, `match_start`, `match_end`, `map`, `max_rounds`, `overtime_max_rounds`, `overtime_count`, `played_out`, `t_name`, `t_overall_score`, `t_first_half_score`, `t_second_half_score`, `t_overtime_score`, `ct_name`, `ct_overall_score`, `ct_first_half_score`, `ct_second_half_score`, `ct_overtime_score`, `demo`) VALUES (NULL, DATE_SUB(UTC_TIMESTAMP(), INTERVAL %i SECOND), UTC_TIMESTAMP(), '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s')", table_name, lt_match_length, lt_map, lt_max_rounds, lt_overtime_max_rounds, lt_overtime_count, lt_played_out, lt_ct_name, lt_ct_overall_score, lt_ct_first_half_score, lt_ct_second_half_score, lt_ct_overtime_score, lt_t_name, lt_t_overall_score, lt_t_first_half_score, lt_t_second_half_score, lt_t_overtime_score, lt_log_file_name);
10198 } else {
10199 Format(query, sizeof(query), "INSERT INTO `%s` (`match_id`, `match_start`, `match_end`, `map`, `max_rounds`, `overtime_max_rounds`, `overtime_count`, `played_out`, `t_name`, `t_overall_score`, `t_first_half_score`, `t_second_half_score`, `t_overtime_score`, `ct_name`, `ct_overall_score`, `ct_first_half_score`, `ct_second_half_score`, `ct_overtime_score`, `demo`) VALUES (NULL, DATE_SUB(UTC_TIMESTAMP(), INTERVAL %i SECOND), UTC_TIMESTAMP(), '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s', %i, %i, %i, %i, '%s')", table_name, lt_match_length, lt_map, lt_max_rounds, lt_overtime_max_rounds, lt_overtime_count, lt_played_out, lt_t_name, lt_t_overall_score, lt_t_first_half_score, lt_t_second_half_score, lt_t_overtime_score, lt_ct_name, lt_ct_overall_score, lt_ct_first_half_score, lt_ct_second_half_score, lt_ct_overtime_score, lt_log_file_name);
10200 }
10201 if (SQL_DEBUG) {
10202 LogError(query);
10203 }
10204 SQL_TQuery(hDatabase, MySQL_UploadResultsReturn, query, true);
10205 }
10206}
10207
10208public void MySQL_UploadResultsReturn(Handle owner, Handle hndl, const char[] error, any data) {
10209 if (hndl == INVALID_HANDLE) {
10210 LogError("Query failed! %s", error);
10211 } else {
10212 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 MySQL data uploaded", CHAT_PREFIX);
10213
10214 if (data) {
10215 match_id = SQL_GetInsertId(hDatabase);
10216 char g_def_backup[128];
10217 GetConVarString(FindConVar("mp_backup_round_file_pattern"), g_def_backup, sizeof(g_def_backup));
10218 Format(g_def_backup, sizeof(g_def_backup), "%i_%s", match_id, g_def_backup);
10219 ServerCommand("mp_backup_round_file_pattern %s", g_def_backup);
10220 }
10221
10222 /*char query[1024];
10223 char table_name[128];
10224 GetConVarString(wm_table_name_players, table_name, sizeof(table_name));
10225 for (int i = 0; i <= sql_player_count; i++) {
10226 if (sql_player_team[i] > 1) {
10227 Format(query, sizeof(query), "INSERT INTO `%s` (`key_id`, `match_id`, `steamid64`, `player_name`, `team`) VALUES (NULL, %i, '%s', '%s', %i);", table_name, match_id, sql_steamid64[i], sql_player_name[i], sql_player_team[i]);
10228 if (SQL_DEBUG) {
10229 LogError(query);
10230 }
10231 SQL_TQuery(hDatabase, MySQL_UploadPlayersReturn, query);
10232 }
10233 }*/
10234 }
10235}
10236/*
10237public void MySQL_UploadPlayersReturn(Handle owner, Handle hndl, const char[] error, any data) {
10238 if (hndl == INVALID_HANDLE) {
10239 LogError("Query failed! %s", error);
10240 }
10241}*/
10242
10243void MySQL_CreateResultKey() {
10244 char query[1024];
10245 char table_name[128];
10246 int g_overtime_rounds;
10247 int g_played_out;
10248 GetConVarString(wm_table_name, table_name, sizeof(table_name));
10249 if (!GetConVarBool(mp_match_can_clinch)) {
10250 g_played_out = 1;
10251 }
10252 if (GetConVarBool(mp_overtime_enable)) {
10253 g_overtime_rounds = (GetConVarInt(mp_overtime_maxrounds)/2);
10254 }
10255 Format(query, sizeof(query), "INSERT INTO `%s` (`match_id`, `match_start`, `match_end`, `map`, `max_rounds`, `overtime_max_rounds`, `overtime_count`, `played_out`, `t_name`, `t_overall_score`, `t_first_half_score`, `t_second_half_score`, `t_overtime_score`, `ct_name`, `ct_overall_score`, `ct_first_half_score`, `ct_second_half_score`, `ct_overtime_score`, `demo`) VALUES (NULL, UTC_TIMESTAMP(), UTC_TIMESTAMP(), '%s', %i, %i, 0, %i, '%s', 0, 0, 0, 0, '%s', 0, 0, 0, 0, '%s')", table_name, g_map, (GetConVarInt(mp_maxrounds)/2), g_overtime_rounds, g_played_out, g_t_name_escaped, g_ct_name_escaped, g_log_filename);
10256 if (SQL_DEBUG) {
10257 LogError(query);
10258 }
10259 SQL_TQuery(hDatabase, MySQL_CreateResultKeyReturn, query);
10260}
10261
10262public void MySQL_CreateResultKeyReturn(Handle owner, Handle hndl, const char[] error, any data) {
10263 if (hndl == INVALID_HANDLE) {
10264 LogError("Query failed! %s", error);
10265 }
10266 match_id = SQL_GetInsertId(hDatabase);
10267 char g_def_backup[128];
10268 GetConVarString(FindConVar("mp_backup_round_file_pattern"), g_def_backup, sizeof(g_def_backup));
10269 Format(g_def_backup, sizeof(g_def_backup), "%i_%s", match_id, g_def_backup);
10270 ServerCommand("mp_backup_round_file_pattern %s", g_def_backup);
10271 PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 MySQL Match_ID = %i", CHAT_PREFIX, match_id);
10272}
10273/*
10274void SQL_Player_Info () {
10275 char authid[32];
10276 for (int i = 1; i <= MaxClients; i++) {
10277 if (IsClientInGame(i) && GetClientTeam(i) > 1) {
10278 GetClientAuthId(i, AuthId_SteamID64, authid, sizeof(authid));
10279 if (StrEqual("", authid, false)) {
10280 Format(authid, sizeof(authid), "BOT");
10281 }
10282 Format(sql_steamid64[sql_player_count], 64, authid);
10283 GetClientName(i, sql_player_name[sql_player_count], 64);
10284 sql_player_team[sql_player_count] = GetClientTeam(i);
10285 sql_player_count++;
10286 }
10287 }
10288}
10289
10290public Action SQL_Player_Info_Clear(Handle timer) {
10291 for (int i = 0; i <= MaxClients; i++) {
10292 Format(sql_steamid64[i], 64, "");
10293 Format(sql_player_name[i], 64, "");
10294 sql_player_team[i] = 0;
10295 }
10296 sql_player_count = 0;
10297 match_id = 0;
10298}
10299
10300void Round_Start_Player_Names () {
10301 for (int client = 1; client <= MaxClients; client++) {
10302 if (IsClientInGame(client) && g_match && GetClientTeam(client) > 1) {
10303 char authid[32];
10304 int count;
10305 GetClientAuthId(client, AuthId_SteamID64, authid, sizeof(authid));
10306 if (StrEqual("", authid, false)) {
10307 char player_name_temp[64];
10308 Format(authid, sizeof(authid), "BOT");
10309 GetClientName(client, player_name_temp, 64);
10310 for (int i = 0; i <= MaxClients; i++) {
10311 if (strcmp(sql_player_name[i], player_name_temp, false) == 0) {
10312 count++;
10313 }
10314 }
10315 } else {
10316 for (int i = 0; i <= MaxClients; i++) {
10317 if (strcmp(sql_steamid64[i], authid, false) == 0) {
10318 count++;
10319 }
10320 }
10321 }
10322 if (count == 0) {
10323 Format(sql_steamid64[sql_player_count], 64, authid);
10324 GetClientName(client, sql_player_name[sql_player_count], 64);
10325 sql_player_team[sql_player_count] = GetClientTeam(client);
10326 sql_player_count++;
10327 }
10328 }
10329 }
10330}*/
10331
10332/* Print Damage Info */
10333/* From splewis CS:GO PugSetup: damage printer*/
10334static void PrintDamageInfo(int client) {
10335 if (!IsValidClient(client))
10336 return;
10337
10338 int team = GetClientTeam(client);
10339 if (team != CS_TEAM_T && team != CS_TEAM_CT)
10340 return;
10341
10342 char message[256];
10343
10344 int otherTeam = (team == CS_TEAM_T) ? CS_TEAM_CT : CS_TEAM_T;
10345 PrintToChat(client, "\x01 \x09[\x04%s\x09]\x01 Damage Report:", CHAT_PREFIX);
10346 for (int i = 1; i <= MaxClients; i++) {
10347 if (IsValidClient(i) && GetClientTeam(i) == otherTeam) {
10348 if (g_DamageDone[client][i] > 0 || g_DamageDone[i][client] > 0) {
10349 int health = IsPlayerAlive(i) ? GetClientHealth(i) : 0;
10350 char name[64];
10351 GetClientName(i, name, sizeof(name));
10352
10353 wm_damageprint_format.GetString(message, sizeof(message));
10354
10355 if (wm_damageprint_auto_color.IntValue == 0) {
10356 ReplaceStringWithInt(message, sizeof(message), "{DMG_TO}", g_DamageDone[client][i]);
10357 ReplaceStringWithInt(message, sizeof(message), "{HITS_TO}", g_DamageDoneHits[client][i]);
10358 ReplaceStringWithInt(message, sizeof(message), "{DMG_FROM}", g_DamageDone[i][client]);
10359 ReplaceStringWithInt(message, sizeof(message), "{HITS_FROM}", g_DamageDoneHits[i][client]);
10360 ReplaceString(message, sizeof(message), "{NAME}", name);
10361 ReplaceStringWithInt(message, sizeof(message), "{HEALTH}", health);
10362 Colorize(message, sizeof(message));
10363 } else {
10364 // Strip colors first.
10365 Colorize(message, sizeof(message), true);
10366 char color[16];
10367
10368 GetDamageColor(color, true, g_DamageDone[client][i], g_GotKill[client][i]);
10369 ReplaceStringWithColoredInt(message, sizeof(message), "{DMG_TO}", g_DamageDone[client][i], color);
10370 ReplaceStringWithColoredInt(message, sizeof(message), "{HITS_TO}", g_DamageDoneHits[client][i], color);
10371
10372 GetDamageColor(color, false, g_DamageDone[i][client], g_GotKill[i][client]);
10373 ReplaceStringWithColoredInt(message, sizeof(message), "{DMG_FROM}", g_DamageDone[i][client], color);
10374 ReplaceStringWithColoredInt(message, sizeof(message), "{HITS_FROM}", g_DamageDoneHits[i][client], color);
10375
10376 ReplaceString(message, sizeof(message), "{NAME}", name);
10377 ReplaceStringWithInt(message, sizeof(message), "{HEALTH}", health);
10378 Colorize(message, sizeof(message));
10379 }
10380
10381 PrintToChat(client, message);
10382 }
10383 }
10384 }
10385}
10386
10387stock void ReplaceStringWithInt(char[] buffer, int len, const char[] replace, int value, bool caseSensitive=false) {
10388 char intString[16];
10389 IntToString(value, intString, sizeof(intString));
10390 ReplaceString(buffer, len, replace, intString, caseSensitive);
10391}
10392
10393stock void ReplaceStringWithColoredInt(char[] buffer, int len, const char[] replace, int value, const char[] color, bool caseSensitive=false) {
10394 char intString[48];
10395 Format(intString, sizeof(intString), "{%s}%d{NORMAL}", color, value);
10396 ReplaceString(buffer, len, replace, intString, caseSensitive);
10397}
10398
10399static char _colorNames[][] = {"{NORMAL}", "{DARK_RED}", "{PINK}", "{GREEN}", "{YELLOW}", "{LIGHT_GREEN}", "{LIGHT_RED}", "{GRAY}", "{ORANGE}", "{LIGHT_BLUE}", "{DARK_BLUE}", "{PURPLE}"};
10400static char _colorCodes[][] = {"\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0B", "\x0C", "\x0E"};
10401
10402stock void Colorize(char[] msg, int size, bool stripColor=false) {
10403 for (int i = 0; i < sizeof(_colorNames); i ++) {
10404 if (stripColor)
10405 ReplaceString(msg, size, _colorNames[i], "\x01"); // replace with white
10406 else
10407 ReplaceString(msg, size, _colorNames[i], _colorCodes[i]);
10408 }
10409}
10410
10411static void GetDamageColor(char color[16], bool damageGiven, int damage, bool gotKill) {
10412 if (damage == 0) {
10413 Format(color, sizeof(color), "NORMAL");
10414 } else if (damageGiven) {
10415 if (gotKill) {
10416 Format(color, sizeof(color), "GREEN");
10417 } else {
10418 Format(color, sizeof(color), "LIGHT_GREEN");
10419 }
10420 } else {
10421 if (gotKill) {
10422 Format(color, sizeof(color), "DARK_RED");
10423 } else {
10424 Format(color, sizeof(color), "LIGHT_RED");
10425 }
10426 }
10427}