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