· 7 years ago · Oct 04, 2018, 08:26 PM
1/* [CS:GO] Jailbreak Squads
2 *
3 * Copyright (C) 2017 Michael Flaherty // michaelwflaherty.com // michaelwflaherty@me.com
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, either version 3 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see http://www.gnu.org/licenses/.
16 */
17
18#include <sourcemod>
19#include <sdkhooks>
20#include <autoexecconfig>
21#include <hl_squads>
22
23#undef REQUIRE_PLUGIN
24#include <hosties>
25#include <lastrequest>
26#include <store>
27#include <hl_squads_credits>
28#include <myjailshop>
29#include <shop>
30#define REQUIRE_PLUGIN
31
32#define TAG " \x03[Squads]\x04"
33
34/* Compiler Instructions */
35#pragma semicolon 1
36#pragma newdecls required
37
38/* ConVars */
39ConVar gcv_bPluginEnabled;
40ConVar gcv_sDatabase;
41ConVar gcv_iMaxSquadSize;
42ConVar gcv_bInviteStyle;
43ConVar gcv_iHealthPrice;
44ConVar gcv_iDamagePrice;
45ConVar gcv_iGravityPrice;
46ConVar gcv_iSpeedPrice;
47ConVar gcv_iCreateSquadPrice;
48ConVar gcv_iRenamePrice;
49ConVar gcv_iSizePrice;
50ConVar gcv_iBunnyhopPrice;//
51ConVar gcv_iPriceModifier;
52ConVar gcv_bDisableSpeed;
53ConVar gcv_bDisableGravity;
54ConVar gcv_bDisableHealth;
55ConVar gcv_bDisableBunnyhop;//
56ConVar gcv_bDisableDamage;
57ConVar gcv_bDisableSize;
58ConVar gcv_fDamageModifier;
59ConVar gcv_fGravityModifier;
60ConVar gcv_fSpeedModifier;
61ConVar gcv_fHealthModifier;
62ConVar gcv_fBunnyhopModifier;//
63ConVar gcv_iSquadSizeMaxUpgrades;
64ConVar gcv_bTerroristOnly;
65ConVar gcv_bCTKillsOrLRs;
66
67/* Forwards */
68Handle g_hOnMainMenu;
69Handle g_hOnMainMenuCallback;
70Handle g_hOnPerkMenu;
71Handle g_hOnPerkMenuCallback;
72Handle g_hOnSquadPerksSetPre;
73
74/* Squad Globals */
75SquadRank ga_iRank[MAXPLAYERS + 1] = {Rank_Invalid, ...};
76int ga_iSquadSize[MAXPLAYERS + 1] = {-1, ...};
77int ga_iInvitation[MAXPLAYERS + 1] = {-1, ...};
78int ga_iDateJoined[MAXPLAYERS + 1] = {-1, ...};
79int ga_iHealth[MAXPLAYERS + 1] = {0, ...};
80int ga_iDamage[MAXPLAYERS + 1] = {0, ...};
81int ga_iGravity[MAXPLAYERS + 1] = {0, ...};
82int ga_iSpeed[MAXPLAYERS + 1] = {0, ...};
83int ga_iSize[MAXPLAYERS + 1] = {0, ...};
84int ga_iBunnyhop[MAXPLAYERS + 1] = {0, ...};//
85int ga_iTimer[MAXPLAYERS + 1] = {0, ...};
86int ga_iCTKills[MAXPLAYERS + 1] = {0, ...};
87int ga_iTempInt[MAXPLAYERS + 1] = {0, ...};
88int ga_iTempInt2[MAXPLAYERS + 1] = {0, ...};
89int ga_iTempInt3[MAXPLAYERS + 1] = {0, ...};
90int ga_iLastRequests[MAXPLAYERS + 1] = {0, ...};
91int g_iSquadAmmount = 0;
92
93char ga_sSquadName[MAXPLAYERS + 1][128];
94char ga_sInvitedBy[MAXPLAYERS + 1][128];
95
96bool ga_bSetName[MAXPLAYERS + 1] = {false, ...};
97bool ga_bIsPlayerInDatabase[MAXPLAYERS + 1] = {false, ...};
98bool ga_bIsSquadInDatabase[MAXPLAYERS + 1] = {false, ...};
99bool ga_bHasSquad[MAXPLAYERS + 1] = {false, ...};
100bool ga_bRename[MAXPLAYERS + 1] = {false, ...};
101bool ga_bHasPref[MAXPLAYERS + 1] = {false, ...};
102bool ga_bBlockInvites[MAXPLAYERS + 1] = {false, ...};
103bool g_bDisablePerks = false;
104
105/* Supported Store Modules */
106bool g_bZepyhrus = false;
107bool g_bShanapu = false;
108bool g_bDefault = false;
109bool g_bFrozdark = false;
110
111
112/* Player Globals */
113char ga_sSteamID[MAXPLAYERS + 1][30];
114bool g_bLateLoad = false;
115bool ga_bLoaded[MAXPLAYERS + 1] = {false, ...};
116float ga_fChangedGravity[MAXPLAYERS + 1] = {0.0, ...};
117
118/* Database Globals */
119Database g_hDatabase = null;
120char g_sDatabaseName[60];
121
122public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int err_max)
123{
124 MarkNativeAsOptional("Store_GetClientCredits");
125 MarkNativeAsOptional("Store_SetClientCredits");
126 MarkNativeAsOptional("Squads_GetCredits");
127 MarkNativeAsOptional("Squads_SetCredits");
128 MarkNativeAsOptional("MyJailShop_SetCredits");
129 MarkNativeAsOptional("MyJailShop_GetCredits");
130
131
132 CreateNative("Squads_GetDamageModifier", Native_GetDmgModifier);
133 CreateNative("Squads_GetSquadName", Native_GetSquadName);
134 CreateNative("Squads_GetSquadRank", Native_GetSquadRank);
135 CreateNative("Squads_HasSquad", Native_HasSquad);
136 CreateNative("Squads_GetSquadSize", Native_GetSquadSize);
137 CreateNative("Squads_Message", Native_Message);
138 CreateNative("Squads_MessageToAll", Native_MessageToAll);
139
140 RegPluginLibrary("hl_squads");
141
142 g_bLateLoad = bLate;
143 return APLRes_Success;
144}
145
146public int Native_MessageToAll(Handle plugin, int numParams)
147{
148 char phrase[1024];
149 int bytes;
150
151 FormatNativeString(0, 1, 2, sizeof(phrase), bytes, phrase);
152
153 PrintToChatAll("%s %s", TAG, phrase);
154}
155
156public int Native_Message(Handle plugin, int numParams)
157{
158 int client = GetNativeCell(1);
159
160 if (!IsValidClient(client))
161 {
162 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
163 }
164
165 char phrase[1024];
166 int bytes;
167
168 FormatNativeString(0, 2, 3, sizeof(phrase), bytes, phrase);
169
170 PrintToChat(client, "%s %s", TAG, phrase);
171 return 0;
172}
173
174public int Native_GetDmgModifier(Handle plugin, int numParams)
175{
176 int client = GetNativeCell(1);
177
178 if (!IsValidClient(client))
179 {
180 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
181 }
182
183 float fDamage = ga_iDamage[client] * gcv_fDamageModifier.FloatValue;
184 return view_as<int>(fDamage);
185}
186
187public int Native_GetSquadName(Handle plugin, int numParams)
188{
189 int client = GetNativeCell(1);
190
191 if (!IsValidClient(client))
192 {
193 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
194 }
195
196 SetNativeString(2, ga_sSquadName[client], GetNativeCell(3));
197 return 0;
198}
199
200public int Native_GetSquadRank(Handle plugin, int numParams)
201{
202 int client = GetNativeCell(1);
203
204 if (!IsValidClient(client))
205 {
206 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
207 }
208
209 return view_as<int>(ga_iRank[client]);
210}
211
212public int Native_HasSquad(Handle plugin, int numParams)
213{
214 int client = GetNativeCell(1);
215
216 if (!IsValidClient(client))
217 {
218 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
219 }
220
221 return view_as<int>(ga_bHasSquad[client]);
222}
223
224public int Native_GetSquadSize(Handle plugin, int numParams)
225{
226 int client = GetNativeCell(1);
227
228 if (!IsValidClient(client))
229 {
230 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
231 }
232
233 return ga_iSquadSize[client];
234}
235
236public Plugin myinfo =
237{
238 name = "[CS:GO/CS:S] Jailbreak Squads",
239 author = "Headline",
240 description = "An SQL-based squad plugin",
241 version = SQUADS_VERSION,
242 url = "http://michaelwflaherty.com"
243};
244
245public void OnPluginStart()
246{
247 LoadTranslations("hl_squads.phrases");
248 LoadTranslations("core.phrases");
249 LoadTranslations("common.phrases");
250
251 AutoExecConfig_SetFile("hl_squads");
252
253 AutoExecConfig_CreateConVar("hl_squads_version", SQUADS_VERSION, "Headline's Squads Plugin : Version", FCVAR_NOTIFY|FCVAR_DONTRECORD);
254
255 gcv_bPluginEnabled = AutoExecConfig_CreateConVar("hl_squads_enabled", "1", "Enable the plugin? (1 = Yes, 0 = No)", FCVAR_NOTIFY, true, 0.0, true, 1.0);
256
257 gcv_bInviteStyle = AutoExecConfig_CreateConVar("hl_squads_invite_style", "1", "Set invite style to pop up a Menu? \n (1 = Menu, 0 = Registered Command)", FCVAR_NOTIFY, true, 0.0, true, 1.0);
258
259 gcv_sDatabase = AutoExecConfig_CreateConVar("hl_squads_database_name", "hl_squads", "Name of the database for the plugin.");
260
261 gcv_iMaxSquadSize = AutoExecConfig_CreateConVar("hl_squads_max_size", "6", "Initial size for a squad");
262
263 gcv_iSizePrice = AutoExecConfig_CreateConVar("hl_squads_size_price", "20", "Price of the Size perk");
264
265 gcv_iSquadSizeMaxUpgrades = AutoExecConfig_CreateConVar("hl_squads_size_max_upgrades", "9", "The maximum amount of size upgrades that may occur");
266
267 gcv_iHealthPrice = AutoExecConfig_CreateConVar("hl_squads_health_price", "20", "Price of the Health perk");
268
269 gcv_fHealthModifier = AutoExecConfig_CreateConVar("hl_squads_health_modifier", "1.0", "Knife Damage perk modifier. 1.0 default");
270
271 gcv_iBunnyhopPrice = AutoExecConfig_CreateConVar("hl_squads_bunnyhop_price", "20", "Price of the Bunnyhop perk");//
272
273 gcv_fBunnyhopModifier = AutoExecConfig_CreateConVar("hl_squads_bunnyhop_modifier", "1.0", "Knife Damage perk modifier. 1.0 default");//
274
275 gcv_iDamagePrice = AutoExecConfig_CreateConVar("hl_squads_damage_price", "20", "Price of the Damage perk");
276
277 gcv_fDamageModifier = AutoExecConfig_CreateConVar("hl_squads_damage_modifier", "1.5", "Knife Damage perk modifier. 1.5 default");
278
279 gcv_iGravityPrice = AutoExecConfig_CreateConVar("hl_squads_gravity_price", "20", "Price of the Gravity perk");
280
281 gcv_fGravityModifier = AutoExecConfig_CreateConVar("hl_squads_gravity_modifier", "0.02", "Gravity perk modifier. 0.02 default");
282
283 gcv_iSpeedPrice = AutoExecConfig_CreateConVar("hl_squads_speed_price", "20", "Price of the Speed perk");
284
285 gcv_fSpeedModifier = AutoExecConfig_CreateConVar("hl_squads_speed_modifier", "0.02", "Speed perk modifier. 0.02 default");
286
287
288 gcv_iCreateSquadPrice = AutoExecConfig_CreateConVar("hl_squads_creation_price", "20", "Price of squad creation");
289
290 gcv_iRenamePrice = AutoExecConfig_CreateConVar("hl_squads_rename_price", "40", "Price to rename");
291
292 gcv_iPriceModifier = AutoExecConfig_CreateConVar("hl_squads_price_modifier", "0", "Price modifier for perks\n Set 0 to disable");
293
294 gcv_bTerroristOnly = AutoExecConfig_CreateConVar("hl_squads_terrorist_only", "1", "Determines if perks are only for terrorists\n Set 1 for default jailbreak behavior");
295
296 gcv_bCTKillsOrLRs = AutoExecConfig_CreateConVar("hl_squads_stats_mode", "1", "Sets the type of statistic tracking\n Set 1 for ct kills, 0 for last requests (hosties required)");
297
298 /* Perk Disabling */
299 gcv_bDisableDamage = AutoExecConfig_CreateConVar("hl_squads_damage", "0", "Disable the damage perk?\n Set 1 to disable");
300 gcv_bDisableHealth = AutoExecConfig_CreateConVar("hl_squads_health", "0", "Disable the health perk?\n Set 1 to disable");
301 gcv_bDisableBunnyhop = AutoExecConfig_CreateConVar("hl_squads_bunnyhop", "0", "Disable the Bunnyhop perk?\n Set 1 to disable");//
302 gcv_bDisableSpeed = AutoExecConfig_CreateConVar("hl_squads_speed", "0", "Disable the speed perk?\n Set 1 to disable");
303 gcv_bDisableGravity = AutoExecConfig_CreateConVar("hl_squads_gravity", "0", "Disable the gravity perk?\n Set 1 to disable");
304 gcv_bDisableSize = AutoExecConfig_CreateConVar("hl_squads_size", "0", "Disable the size perk?\n Set 1 to disable");
305
306 AutoExecConfig_ExecuteFile();
307 AutoExecConfig_CleanFile();
308
309 gcv_sDatabase.GetString(g_sDatabaseName, sizeof(g_sDatabaseName));
310
311
312 /* Forwards */
313 g_hOnMainMenuCallback = CreateGlobalForward("Squads_OnMenuCallback", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
314 g_hOnMainMenu = CreateGlobalForward("Squads_OnMenuCreated", ET_Ignore, Param_Cell, Param_Cell);
315 g_hOnPerkMenuCallback = CreateGlobalForward("Squads_OnPerkMenuCallback", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
316 g_hOnPerkMenu = CreateGlobalForward("Squads_OnPerkMenuCreated", ET_Ignore, Param_Cell, Param_Cell);
317 g_hOnSquadPerksSetPre = CreateGlobalForward("Squads_OnPerksSetPre", ET_Ignore, Param_Cell, Param_CellByRef);
318
319 /* Events */
320 HookEvent("player_spawn", Event_PlayerSpawn);
321 HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
322 HookEvent("round_start", Event_RoundStart);
323 HookEvent("round_end", Event_RoundEnd);
324
325 RegConsoleCmd("sm_squad", Command_Squad, "Open the squad menu!");
326 RegConsoleCmd("sm_squads", Command_Squad, "Open the squad menu!");
327
328 if (gcv_bInviteStyle.BoolValue)
329 {
330 RegConsoleCmd("sm_accept", Command_Accept, "Accept an invitation!");
331 }
332
333 AddCommandListener(OnSay, "say");
334 AddCommandListener(OnSay, "say_team");
335
336 for(int i = 1; i <= MaxClients; i++)
337 {
338 if(IsValidClient(i))
339 {
340 LoadSteamID(i);
341 OnClientPutInServer(i);
342 }
343 }
344
345 g_bZepyhrus = LibraryExists("store_zephyrus");
346 if (g_bZepyhrus)
347 {
348 return; // Don't bother checking if others exist
349 }
350
351 g_bShanapu = LibraryExists("myjailshop");
352 if (g_bShanapu)
353 {
354 return; // Don't bother checking if others exist
355 }
356
357 g_bFrozdark = LibraryExists("shop");
358 if (g_bFrozdark)
359 {
360 return; // Don't bother checking if others exist
361 }
362
363 /* Stores */
364 g_bDefault = LibraryExists("hl_squads_credits");
365 if (g_bDefault)
366 {
367 return; // Don't bother checking if others exist
368 }
369}
370
371public void OnClientConnected(int client)
372{
373 if (gcv_bPluginEnabled.BoolValue)
374 {
375 ResetVariables(client);
376 }
377}
378
379public void OnClientDisconnect(int client)
380{
381 if (gcv_bPluginEnabled.BoolValue)
382 {
383 UpdateSQL(client);
384
385 ResetVariables(client);
386 }
387}
388
389public void OnConfigsExecuted()
390{
391 if (gcv_bPluginEnabled.BoolValue)
392 {
393 if (g_hDatabase == null)
394 {
395 SetDB();
396 }
397 if (g_bLateLoad)
398 {
399 for (int i = 1; i <= MaxClients; i++)
400 {
401 if (IsValidClient(i))
402 {
403 GetClientAuthId(i, AuthId_Steam2, ga_sSteamID[i], sizeof(ga_sSteamID[]));
404
405 if (StrContains(ga_sSteamID[i], "STEAM_", true) != -1)
406 {
407 LoadSteamID(i);
408 }
409 else
410 {
411 CreateTimer(10.0, RefreshSteamID, GetClientUserId(i), TIMER_FLAG_NO_MAPCHANGE);
412 }
413 }
414 }
415 }
416 }
417}
418
419public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
420{
421 g_bDisablePerks = false;
422}
423
424public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
425{
426 g_bDisablePerks = false;
427}
428
429public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
430{
431 int client = GetClientOfUserId(event.GetInt("userid"));
432
433
434 if (IsValidClient(client) && IsPlayerSquadable(client))
435 {
436 if (ga_bHasSquad[client])
437 {
438 bool shouldSetPerks = true;
439 Call_StartForward(g_hOnSquadPerksSetPre);
440 Call_PushCell(client);
441 Call_PushCellRef(shouldSetPerks);
442 Call_Finish();
443
444 if (!shouldSetPerks)
445 {
446 return Plugin_Continue;
447 }
448
449 if (ga_iHealth[client] != 0 && !gcv_bDisableHealth.BoolValue)
450 {
451 int iHealth = ga_iHealth[client] * gcv_fHealthModifier.IntValue + 100;
452 SetEntProp(client, Prop_Send, "m_iHealth", iHealth);
453 }
454 if (ga_iGravity[client] != 0 && !gcv_bDisableGravity.BoolValue)
455 {
456 SetEntityGravity(client, GetClientGravityAmmount(client));
457 ga_iTimer[client] = 0;
458 CreateTimer(0.4, Timer_CheckSetGravity, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
459 }
460 if (ga_iSpeed[client] != 0 && !gcv_bDisableSpeed.BoolValue)
461 {
462 SetEntPropFloat(client, Prop_Send, "m_flLaggedMovementValue", GetClientSpeedAmmount(client));
463 }
464 //
465 if (ga_iBunnyhop[client] != 0 && !gcv_bDisableBunnyhop.BoolValue)
466 {
467 int iBunnyhop = ga_iBunnyhop[client] * gcv_fBunnyhopModifier.IntValue + 100;
468 SetEntProp(client, Prop_Send, "m_iBunnyhop", iBunnyhop);
469 }
470 }
471 }
472
473 return Plugin_Continue;
474}
475
476public Action Timer_CheckSetGravity(Handle hHandle, int iUserid)
477{
478 int client = GetClientOfUserId(iUserid);
479 if (ga_iTimer[client] == 0)
480 {
481 if (GetEntityGravity(client) != 1.0 && GetEntityGravity(client) != GetClientGravityAmmount(client))
482 {
483 ga_fChangedGravity[client] = GetEntityGravity(client);
484 }
485 }
486 else
487 {
488 if(GetEntityGravity(client) != ga_fChangedGravity[client])
489 {
490 SetEntityGravity(client, GetClientGravityAmmount(client));
491 return Plugin_Stop;
492 }
493 }
494 ga_iTimer[client]++;
495 return Plugin_Continue;
496}
497
498
499public Action RefreshSteamID(Handle hTimer, int iUserID)
500{
501 int client = GetClientOfUserId(iUserID);
502 if (!IsValidClient(client))
503 {
504 return;
505 }
506
507 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
508
509 if (StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //still invalid - retry again
510 {
511
512 CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
513 }
514 else
515 {
516 LoadSteamID(client);
517 }
518}
519
520public void OnClientPutInServer(int client)
521{
522 SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
523
524 if (IsValidClient(client))
525 {
526 CreateTimer(2.0, Timer_AlertSquad, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
527 }
528}
529
530public Action Timer_AlertSquad(Handle hTimer, int userid)
531{
532 int client = GetClientOfUserId(userid);
533
534 if (!IsValidClient(client))
535 {
536 return;
537 }
538
539 char name[MAX_NAME_LENGTH];
540 GetClientName(client, name, sizeof(name));
541 PrintToSquad(client, false, "%s %T", TAG, "SquadAlert", LANG_SERVER, name);
542}
543
544
545public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
546{
547 if (gcv_bDisableDamage.BoolValue)
548 {
549 return Plugin_Continue;
550 }
551
552 if (!g_bDisablePerks && IsValidClient(attacker) && IsValidClient(victim) && ga_bHasSquad[attacker] && attacker != victim && GetClientTeam(victim) == 3 && IsPlayerSquadable(attacker))
553 {
554 char sWeapon[32];
555 GetClientWeapon(attacker, sWeapon, sizeof(sWeapon));
556 if (StrContains(sWeapon, "knife") != -1)
557 {
558 damage = damage + ga_iDamage[attacker] * gcv_fDamageModifier.FloatValue;
559 return Plugin_Changed;
560 }
561 }
562 return Plugin_Continue;
563}
564
565public void OnClientPostAdminCheck(int client)
566{
567 if (gcv_bPluginEnabled.BoolValue)
568 {
569 LoadSteamID(client);
570 }
571}
572
573public void OnLibraryAdded(const char[] name)
574{
575 if (StrEqual(name, "store_zephyrus"))
576 {
577 g_bZepyhrus = true;
578 }
579 else if (StrEqual(name, "myjailshop"))
580 {
581 g_bShanapu = true;
582 }
583 else if (StrEqual(name, "shop"))
584 {
585 g_bFrozdark = true;
586 }
587 else if (StrEqual(name, "hl_squads_credits"))
588 {
589 g_bDefault = true;
590 }
591}
592
593public void OnLibraryRemoved(const char[] name)
594{
595 if (StrEqual(name, "store_zephyrus"))
596 {
597 g_bZepyhrus = false;
598 }
599 else if (StrEqual(name, "myjailshop"))
600 {
601 g_bShanapu = false;
602 }
603 else if (StrEqual(name, "shop"))
604 {
605 g_bFrozdark = false;
606 }
607 else if (StrEqual(name, "hl_squads_credits"))
608 {
609 g_bDefault = false;
610 }
611}
612
613public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
614{
615 int client = GetClientOfUserId(event.GetInt("userid"));
616 int attacker = GetClientOfUserId(event.GetInt("attacker"));
617
618 if (GetPlayerAliveCount(2) == 1 && GetPlayerAliveCount(3) > 0 && LibraryExists("hosties"))
619 {
620 OnAvailableLR(0);
621 }
622
623 if (IsValidClient(attacker) && IsValidClient(client) && client != attacker && ga_bHasSquad[attacker])
624 {
625 if (IsPlayerSquadable(attacker) && GetClientTeam(client) == 3 && !StrEqual(ga_sSquadName[attacker], ga_sSquadName[client]))
626 {
627 ga_iCTKills[attacker]++;
628 char sQuery[300];
629 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_statistics SET ctkills = %i WHERE squad=\"%s\"", ga_iCTKills[attacker], ga_sSquadName[attacker]);
630
631 for (int i = 1; i <= MaxClients; i++)
632 {
633 if (IsValidClient(i))
634 {
635 if (StrEqual(ga_sSquadName[i], ga_sSquadName[attacker]))
636 {
637 ga_iCTKills[i]++;
638 }
639 }
640 }
641
642 g_hDatabase.Query(SQLCallback_Void, sQuery);
643 }
644 }
645}
646
647/* SQL Callback On First Connection */
648public void SQLCallback_Connect(Database db, const char[] error, any data)
649{
650 if (db == null)
651 {
652 SetFailState(error);
653 }
654 else
655 {
656 g_hDatabase = db;
657
658 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_squads_players` (`id` int(20) NOT NULL AUTO_INCREMENT, `steamid` varchar(32) NOT NULL, `playername` varchar(32) NOT NULL, `squad` varchar(32) NOT NULL, `rank` int(16) NOT NULL, `invitedby` varchar(32) NOT NULL, `date` int(32) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
659 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_squads_groups` (`id` int(20) NOT NULL AUTO_INCREMENT, `squad` varchar(32) NOT NULL, `health` int(16) NOT NULL, `bunnyhop` int(16) NOT NULL, `damage` int(16) NOT NULL, `gravity` int(16) NOT NULL, `speed` int(16) NOT NULL, `size` int(16) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
660 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_squads_statistics` (`id` int(20) NOT NULL AUTO_INCREMENT, `squad` varchar(32) NOT NULL, `ctkills` int(16) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
661 g_hDatabase.Query(SQLCallback_Void, "CREATE TABLE IF NOT EXISTS `hl_squads_prefs` (`id` int(20) NOT NULL AUTO_INCREMENT, `steamid` varchar(32) NOT NULL, `pref` int(16) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1", 1);
662 g_hDatabase.Query(SQLCallback_Void, "ALTER TABLE `hl_squads_groups` MODIFY COLUMN `squad` varchar(32) NOT NULL unique", 1);
663 g_hDatabase.Query(SQLCallback_Void, "ALTER TABLE `hl_squads_statistics` MODIFY COLUMN `squad` varchar(32) NOT NULL unique", 1);
664 g_hDatabase.Query(SQLCallback_Void, "ALTER TABLE `hl_squads_statistics` ADD COLUMN `lastrequests` int(16) NOT NULL", 1);
665
666 DeleteDuplicates();
667 }
668}
669
670void LoadSteamID(int client)
671{
672 if (gcv_bPluginEnabled.BoolValue)
673 {
674 if (!IsValidClient(client))
675 {
676 return;
677 }
678 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
679
680 if (StrContains(ga_sSteamID[client], "STEAM_", true) == -1) //if ID is invalid
681 {
682 CreateTimer(10.0, RefreshSteamID, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
683 }
684
685 if (g_hDatabase == null) //connect not loaded - retry to give it time
686 {
687 CreateTimer(1.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
688 }
689 else
690 {
691 char sQuery[300];
692 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_players WHERE steamid=\"%s\"", ga_sSteamID[client]);
693 g_hDatabase.Query(SQLCallback_CheckSQL_Player, sQuery, GetClientUserId(client));
694
695 Format(sQuery, sizeof(sQuery), "SELECT pref FROM hl_squads_prefs WHERE steamid=\"%s\"", ga_sSteamID[client]);
696 g_hDatabase.Query(SQLCallback_GetPreference, sQuery, GetClientUserId(client));
697 }
698 }
699}
700
701public void SQLCallback_GetPreference(Database db, DBResultSet results, const char[] error, int data)
702{
703 if (db == null)
704 {
705 SetDB();
706 }
707 if (results == null)
708 {
709 LogError(error);
710 return;
711 }
712
713 int client = GetClientOfUserId(data);
714 if (!IsValidClient(client))
715 {
716 return;
717 }
718 else
719 {
720 if (results.RowCount > 0)
721 {
722 results.FetchRow();
723 ga_bBlockInvites[client] = view_as<bool>(results.FetchInt(0));
724 ga_bHasPref[client] = true;
725 }
726 else
727 {
728 ga_bBlockInvites[client] = false;
729 ga_bHasPref[client] = false;
730 }
731 }
732}
733
734public void SQLCallback_CheckSQL_Player(Database db, DBResultSet results, const char[] error, int data)
735{
736 if (db == null)
737 {
738 SetDB();
739 }
740 if (results == null)
741 {
742 LogError(error);
743 return;
744 }
745
746 int client = GetClientOfUserId(data);
747 if (!IsValidClient(client))
748 {
749 return;
750 }
751 else
752 {
753 if (results.RowCount == 1)
754 {
755 results.FetchRow();
756
757 results.FetchString(3, ga_sSquadName[client], sizeof(ga_sSquadName[]));
758 ga_iRank[client] = view_as<SquadRank>(results.FetchInt(4));
759 results.FetchString(5, ga_sInvitedBy[client], sizeof(ga_sInvitedBy[]));
760 ga_iDateJoined[client] = results.FetchInt(6);
761
762 ga_bIsPlayerInDatabase[client] = true;
763 ga_bHasSquad[client] = true;
764
765 ga_iHealth[client] = 0;
766 ga_iDamage[client] = 0;
767 ga_iGravity[client] = 0;
768 ga_iSpeed[client] = 0;
769 ga_iBunnyhop[client] = 0;//
770 ga_iSize[client] = 0;
771
772 char sQuery_2[300];
773 Format(sQuery_2, sizeof(sQuery_2), "SELECT * FROM hl_squads_groups WHERE squad=\"%s\"", ga_sSquadName[client]);
774 g_hDatabase.Query(SQLCallback_CheckSQL_Groups, sQuery_2, GetClientUserId(client));
775 }
776 else
777 {
778 if (results.RowCount > 1)
779 {
780 LogError("Player %L has multiple entries under their ID. Running script to clean up duplicates and keep original entry (oldest)", client);
781 DeleteDuplicates();
782 CreateTimer(20.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
783 }
784 else if (g_hDatabase == null)
785 {
786 CreateTimer(2.0, RepeatCheckRank, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
787 }
788 else
789 {
790 ga_bHasSquad[client] = false;
791 ga_bLoaded[client] = true;
792 }
793 }
794 }
795}
796
797public void SQLCallback_CheckSQL_Groups(Database db, DBResultSet results, const char[] error, int data)
798{
799 if (db == null)
800 {
801 SetDB();
802 }
803 if (results == null)
804 {
805 LogError(error);
806 return;
807 }
808
809 int client = GetClientOfUserId(data);
810 if (!IsValidClient(client))
811 {
812 return;
813 }
814 else
815 {
816 if (results.RowCount == 1)
817 {
818 results.FetchRow();
819
820 ga_iHealth[client] = results.FetchInt(2);
821 ga_iDamage[client] = results.FetchInt(3);
822 ga_iGravity[client] = results.FetchInt(4);
823 ga_iSpeed[client] = results.FetchInt(5);
824 ga_iBunnyhop[client] = results.FetchInt(9);//
825 ga_iSize[client] = results.FetchInt(6);
826
827 char sQuery[300];
828 Format(sQuery, sizeof(sQuery), "SELECT ctkills,lastrequests FROM hl_squads_statistics WHERE squad=\"%s\"", ga_sSquadName[client]);
829 g_hDatabase.Query(SQL_Callback_CTKills, sQuery, GetClientUserId(client));
830 }
831 }
832}
833
834public void SQL_Callback_CTKills(Database db, DBResultSet results, const char[] error, int data)
835{
836 if (db == null)
837 {
838 SetDB();
839 }
840 if (results == null)
841 {
842 LogError(error);
843 return;
844 }
845
846 int client = GetClientOfUserId(data);
847 if (!IsValidClient(client))
848 {
849 return;
850 }
851 else
852 {
853 if (results.FetchRow()) // row exists
854 {
855 ga_bLoaded[client] = true;
856 ga_iCTKills[client] = results.FetchInt(0);
857 ga_iLastRequests[client] = results.FetchInt(1);
858 }
859 }
860}
861
862
863public Action RepeatCheckRank(Handle timer, int iUserID)
864{
865 int client = GetClientOfUserId(iUserID);
866 LoadSteamID(client);
867}
868
869public void SQLCallback_Void(Database db, DBResultSet results, const char[] error, int data)
870{
871 if (db == null)
872 {
873 LogError("Error (%i): %s", data, error);
874 }
875}
876
877public Action Command_Accept(int client, int args)
878{
879 if (!gcv_bPluginEnabled.BoolValue)
880 {
881 ReplyToCommand(client, "%t", "DisabledPlugin");
882 return Plugin_Handled;
883 }
884 if (gcv_bInviteStyle.BoolValue)
885 {
886 ReplyToCommand(client, "%t","DisabledAcceptCommand");
887 return Plugin_Handled;
888 }
889
890 if (!IsValidClient(client))
891 {
892 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame");
893 return Plugin_Handled;
894 }
895 if (!IsPlayerSquadable(client))
896 {
897 ReplyToCommand(client, "[SM] %t", "WrongTeam");
898 return Plugin_Handled;
899 }
900 if (ga_bHasSquad[client])
901 {
902 ReplyToCommand(client, "%s %t", TAG, "AlreadyInSquad");
903 return Plugin_Handled;
904 }
905 if (ga_iInvitation[client] == -1)
906 {
907 ReplyToCommand(client, "%s %t", TAG, "NotInvited");
908 return Plugin_Handled;
909 }
910
911 int sender = GetClientOfUserId(ga_iInvitation[client]);
912 if (ga_iSquadSize[sender] >= gcv_iMaxSquadSize.IntValue + ga_iSize[sender] && !gcv_bDisableSize.BoolValue)
913 {
914 ReplyToCommand(client, "%s %t", TAG, "SquadIsFull");
915 return Plugin_Handled;
916 }
917
918 ga_sSquadName[client] = ga_sSquadName[sender];
919 ga_iDateJoined[client] = GetTime();
920 ga_bHasSquad[client] = true;
921 ga_bSetName[client] = false;
922
923 char sName[MAX_NAME_LENGTH];
924 GetClientName(sender, sName, sizeof(sName));
925
926 ga_iHealth[client] = ga_iHealth[sender];
927 ga_iBunnyhop[client] = ga_iBunnyhop[sender];//
928 ga_iDamage[client] = ga_iDamage[sender];
929 ga_iGravity[client] = ga_iGravity[sender];
930 ga_iSpeed[client] = ga_iSpeed[sender];
931 ga_iCTKills[client] = ga_iCTKills[sender];
932 ga_iLastRequests[client] = ga_iLastRequests[sender];
933 ga_iSize[client] = ga_iSize[sender];
934 ga_iSquadSize[client] = ++ga_iSquadSize[sender];
935
936 ga_sInvitedBy[client] = sName;
937 ga_iRank[client] = Rank_Normal;
938 UpdateSQL(client);
939 return Plugin_Handled;
940}
941
942public Action Command_Squad(int client, int args)
943{
944 if (!IsValidClient(client))
945 {
946 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame");
947 return Plugin_Handled;
948 }
949 if (!IsPlayerSquadable(client))
950 {
951 ReplyToCommand(client, "[SM] %t", "WrongTeam");
952 return Plugin_Handled;
953 }
954 StartOpeningSquadMenu(client);
955 return Plugin_Handled;
956}
957
958
959/*****************************************************************
960*********************** MAIN GANG MENU **************************
961******************************************************************/
962
963
964void StartOpeningSquadMenu(int client)
965{
966 if (!StrEqual(ga_sSquadName[client], ""))
967 {
968 char sQuery[300];
969 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_players WHERE squad = \"%s\"", ga_sSquadName[client]);
970 g_hDatabase.Query(SQLCallback_OpenSquadMenu, sQuery, GetClientUserId(client));
971 }
972 else
973 {
974 OpenSquadsMenu(client);
975 }
976}
977
978public void SQLCallback_OpenSquadMenu(Database db, DBResultSet results, const char[] error, int data)
979{
980 if (db == null)
981 {
982 SetDB();
983 }
984
985 if (results == null)
986 {
987 LogError(error);
988 return;
989 }
990
991 int client = GetClientOfUserId(data);
992 if (!IsValidClient(client))
993 {
994 return;
995 }
996 else
997 {
998 ga_iSquadSize[client] = results.RowCount;
999 }
1000 OpenSquadsMenu(client);
1001}
1002
1003void OpenSquadsMenu(int client)
1004{
1005 Menu menu = CreateMenu(SquadsMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1006 if (ga_bHasSquad[client])
1007 {
1008 char sSquadSizeString[64];
1009 if (!gcv_bDisableSize.BoolValue)
1010 {
1011 Format(sSquadSizeString, sizeof(sSquadSizeString), "%i/%i", ga_iSquadSize[client], gcv_iMaxSquadSize.IntValue + ga_iSize[client]);
1012 }
1013 else
1014 {
1015 Format(sSquadSizeString, sizeof(sSquadSizeString), "%i/0", ga_iSquadSize[client]);
1016 }
1017
1018 Format(sSquadSizeString, sizeof(sSquadSizeString), "");
1019 char sString[128];
1020 Format(sString, sizeof(sString), "%T \n%T %i \n%T: %s %s", "SquadsMenuTitle", client
1021 , "Credits", client
1022 , GetClientCredits(client)
1023 , "CurrentSquad", client
1024 , ga_sSquadName[client], sSquadSizeString);
1025 SetMenuTitle(menu, sString);
1026 }
1027 else
1028 {
1029 char sString[128];
1030 Format(sString, sizeof(sString), "%T \n%T: %i \n%T N/A", "SquadsMenuTitle", client
1031 , "Credits", client
1032 , GetClientCredits(client)
1033 , "CurrentSquad", client);
1034 SetMenuTitle(menu, sString);
1035 }
1036 char sDisplayBuffer[128];
1037
1038 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i %T]", "CreateASquad", client, gcv_iCreateSquadPrice.IntValue, "Credits", client);
1039 menu.AddItem("create", sDisplayBuffer, (ga_bHasSquad[client] || GetClientCredits(client) < gcv_iCreateSquadPrice.IntValue)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1040
1041 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "InviteToSquad", client);
1042 menu.AddItem("invite", sDisplayBuffer, (ga_bHasSquad[client] && ga_iRank[client] > Rank_Normal && ga_iSquadSize[client] < gcv_iMaxSquadSize.IntValue + ga_iSize[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1043
1044 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "SquadMembers", client);
1045 menu.AddItem("members", sDisplayBuffer, (ga_bHasSquad[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1046
1047 if (gcv_bDisableDamage.BoolValue && gcv_bDisableGravity.BoolValue && gcv_bDisableHealth.BoolValue && gcv_bDisableSize.BoolValue && gcv_bDisableSpeed.BoolValue && gcv_bDisableBunnyhop.BoolValue)
1048 {
1049 // draw nothing
1050 }
1051 else
1052 {
1053 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "SquadPerks", client);
1054 menu.AddItem("perks", sDisplayBuffer, (ga_bHasSquad[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1055 }
1056
1057 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "SquadAdmin", client);
1058 menu.AddItem("admin", sDisplayBuffer, (ga_iRank[client] >= Rank_Admin)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1059
1060 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "LeaveSquad", client);
1061 menu.AddItem("leave", sDisplayBuffer, (ga_bHasSquad[client])?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1062
1063 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "TopSquads", client);
1064 menu.AddItem("topsquads", sDisplayBuffer);
1065
1066 if (!ga_bBlockInvites[client])
1067 {
1068 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "BlockInvites", client);
1069 }
1070 else
1071 {
1072 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T", "UnblockInvites", client);
1073 }
1074 menu.AddItem("blockinvites", sDisplayBuffer);
1075
1076 Call_StartForward(g_hOnMainMenu);
1077 Call_PushCell(client);
1078 Call_PushCell(menu);
1079 Call_Finish();
1080
1081
1082 menu.Display(client, MENU_TIME_FOREVER);
1083}
1084
1085public int SquadsMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1086{
1087 Call_StartForward(g_hOnMainMenuCallback);
1088 Call_PushCell(menu);
1089 Call_PushCell(action);
1090 Call_PushCell(param1);
1091 Call_PushCell(param2);
1092 Call_Finish();
1093
1094 if (!IsValidClient(param1))
1095 {
1096 return;
1097 }
1098
1099 switch (action)
1100 {
1101 case MenuAction_Select:
1102 {
1103 char sInfo[64];
1104 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1105 if (StrEqual(sInfo, "create"))
1106 {
1107 SetClientCredits(param1, GetClientCredits(param1) - gcv_iCreateSquadPrice.IntValue);
1108 StartSquadCreation(param1);
1109 }
1110 else if (StrEqual(sInfo, "invite"))
1111 {
1112 OpenInvitationMenu(param1);
1113 }
1114 else if (StrEqual(sInfo, "members"))
1115 {
1116 StartOpeningMembersMenu(param1);
1117 }
1118 else if (StrEqual(sInfo, "perks"))
1119 {
1120 StartOpeningPerkMenu(param1);
1121 }
1122 else if (StrEqual(sInfo, "admin"))
1123 {
1124 OpenAdministrationMenu(param1);
1125 }
1126 else if (StrEqual(sInfo, "leave"))
1127 {
1128 OpenLeaveConfirmation(param1);
1129 }
1130 else if (StrEqual(sInfo, "topsquads"))
1131 {
1132 StartOpeningTopSquadsMenu(param1);
1133 }
1134 else if (StrEqual(sInfo, "blockinvites"))
1135 {
1136 BlockInvites(param1);
1137 }
1138
1139 }
1140 case MenuAction_End:
1141 {
1142 delete menu;
1143 }
1144 }
1145 return;
1146}
1147
1148void BlockInvites(int client)
1149{
1150 if (!IsValidClient(client))
1151 {
1152 return;
1153 }
1154
1155 ga_bBlockInvites[client] = !ga_bBlockInvites[client]; // toggle
1156
1157 char sQuery[128];
1158 if (!ga_bHasPref[client])
1159 {
1160 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_squads_prefs (pref, steamid) VALUES(%i, \"%s\")", ga_bBlockInvites[client], ga_sSteamID[client]);
1161 ga_bHasPref[client] = true;
1162 }
1163 else
1164 {
1165 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_prefs SET pref=%i WHERE steamid=\"%s\"", ga_bBlockInvites[client], ga_sSteamID[client]);
1166 }
1167 g_hDatabase.Query(SQLCallback_Void, sQuery);
1168}
1169
1170/*****************************************************************
1171*********************** GANG CREATION **************************
1172******************************************************************/
1173
1174
1175
1176void StartSquadCreation(int client)
1177{
1178 if (!IsValidClient(client))
1179 {
1180 ReplyToCommand(client, "[SM] %t", "PlayerNotInGame", client);
1181 return;
1182 }
1183 if (!IsPlayerSquadable(client))
1184 {
1185 ReplyToCommand(client, "[SM] %t", "WrongTeam", client);
1186 return;
1187 }
1188 for (int i = 0; i <= 5; i++)
1189 {
1190 PrintToChat(client, "%s %t", TAG, "SquadName");
1191 }
1192 ga_bSetName[client] = true;
1193}
1194
1195public Action OnSay(int client, const char[] command, int args)
1196{
1197 if (!IsValidClient(client))
1198 {
1199 return Plugin_Continue;
1200 }
1201 if (ga_bSetName[client])
1202 {
1203 char sText[64], sFormattedText[2*sizeof(sText)+1];
1204 GetCmdArgString(sText, sizeof(sText));
1205 StripQuotes(sText);
1206
1207 g_hDatabase.Escape(sText, sFormattedText, sizeof(sFormattedText));
1208 TrimString(sFormattedText);
1209
1210 if (strlen(sText) > 16)
1211 {
1212 PrintToChat(client, "%s %t", TAG, "NameTooLong");
1213 return Plugin_Handled;
1214 }
1215 else if (strlen(sText) == 0)
1216 {
1217 return Plugin_Handled;
1218 }
1219
1220 DataPack data = new DataPack();
1221 data.WriteCell(client);
1222 data.WriteString(sText);
1223 data.Reset();
1224
1225 char sQuery[300];
1226 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_groups WHERE squad=\"%s\"", sFormattedText);
1227 g_hDatabase.Query(SQL_Callback_CheckName, sQuery, data);
1228
1229 return Plugin_Handled;
1230 }
1231 else if (ga_bRename[client])
1232 {
1233 char sText[64], sFormattedText[2*sizeof(sText)+1];
1234 GetCmdArgString(sText, sizeof(sText));
1235 StripQuotes(sText);
1236
1237 g_hDatabase.Escape(sText, sFormattedText, sizeof(sFormattedText));
1238 TrimString(sFormattedText);
1239
1240 if (strlen(sText) > 16)
1241 {
1242 PrintToChat(client, "%s %t", TAG, "NameTooLong");
1243 return Plugin_Handled;
1244 }
1245 else if (strlen(sText) == 0)
1246 {
1247 return Plugin_Handled;
1248 }
1249
1250 DataPack data = new DataPack();
1251 data.WriteCell(client);
1252 data.WriteString(sText);
1253 data.Reset();
1254
1255 char sQuery[300];
1256 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_groups WHERE squad=\"%s\"", sFormattedText);
1257 g_hDatabase.Query(SQL_Callback_CheckName, sQuery, data);
1258
1259 return Plugin_Handled;
1260 }
1261 return Plugin_Continue;
1262}
1263
1264public void SQL_Callback_CheckName(Database db, DBResultSet results, const char[] error, DataPack data)
1265{
1266 if (db == null)
1267 {
1268 SetDB();
1269 }
1270
1271 if (results == null)
1272 {
1273 LogError(error);
1274 return;
1275 }
1276
1277 char sText[64];
1278 int client = data.ReadCell();
1279 data.ReadString(sText, sizeof(sText));
1280 delete data;
1281
1282 if (!IsValidClient(client))
1283 {
1284 return;
1285 }
1286 else
1287 {
1288 if (ga_bSetName[client])
1289 {
1290 if (results.RowCount == 0)
1291 {
1292
1293 strcopy(ga_sSquadName[client], sizeof(ga_sSquadName[]), sText);
1294 ga_bHasSquad[client] = true;
1295 ga_iDateJoined[client] = GetTime();
1296 ga_bHasSquad[client] = true;
1297 ga_sInvitedBy[client] = "N/A";
1298 ga_iRank[client] = Rank_Owner;
1299 ga_iSquadSize[client] = 1;
1300
1301 ga_iHealth[client] = 0;
1302 ga_iDamage[client] = 0;
1303 ga_iBunnyhop[client] = 0;//
1304 ga_iGravity[client] = 0;
1305 ga_iSpeed[client] = 0;
1306 ga_iSize[client] = 0;
1307
1308 UpdateSQL(client);
1309
1310 CreateTimer(0.2, Timer_OpenSquadMenu, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
1311
1312 char name[MAX_NAME_LENGTH];
1313 GetClientName(client, name, sizeof(name));
1314 PrintToChatAll("%s %T", TAG, "SquadCreated", LANG_SERVER, name, ga_sSquadName[client]);
1315
1316 }
1317 else
1318 {
1319 PrintToChat(client, "%s %t", TAG, "NameAlreadyUsed");
1320 }
1321
1322 ga_bSetName[client] = false;
1323 }
1324 else if (ga_bRename[client])
1325 {
1326 if (results.RowCount == 0)
1327 {
1328 char sOldName[32];
1329 strcopy(sOldName, sizeof(sOldName), ga_sSquadName[client]);
1330 strcopy(ga_sSquadName[client], sizeof(ga_sSquadName[]), sText);
1331 for (int i = 1; i <= MaxClients; i++)
1332 {
1333 if (IsValidClient(i) && StrEqual(ga_sSquadName[i], sOldName))
1334 {
1335 strcopy(ga_sSquadName[i], sizeof(ga_sSquadName[]), sText);
1336 }
1337 }
1338 char sQuery[300];
1339 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_players SET squad=\"%s\" WHERE squad=\"%s\"", sText, sOldName);
1340
1341 g_hDatabase.Query(SQLCallback_Void, sQuery);
1342
1343 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET squad=\"%s\" WHERE squad=\"%s\"", sText, sOldName);
1344
1345 g_hDatabase.Query(SQLCallback_Void, sQuery);
1346
1347 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_statistics SET squad=\"%s\" WHERE squad=\"%s\"", sText, sOldName);
1348
1349 g_hDatabase.Query(SQLCallback_Void, sQuery);
1350
1351 char name[MAX_NAME_LENGTH];
1352 GetClientName(client, name, sizeof(name));
1353 PrintToChatAll("%s %T", TAG, "SquadNameChange", LANG_SERVER, name, sOldName, sText);
1354
1355 StartOpeningSquadMenu(client);
1356
1357 }
1358 else
1359 {
1360 PrintToChat(client, "%s %t", TAG, "NameAlreadyUsed");
1361 }
1362
1363 ga_bRename[client] = false;
1364 }
1365 }
1366}
1367
1368public Action Timer_OpenSquadMenu(Handle hTimer, int userid)
1369{
1370 int client = GetClientOfUserId(userid);
1371 if(IsValidClient(client))
1372 {
1373 StartOpeningSquadMenu(client);
1374 }
1375}
1376
1377
1378/*****************************************************************
1379*********************** MEMBER LIST MENU *************************
1380******************************************************************/
1381
1382
1383void StartOpeningMembersMenu(int client)
1384{
1385 if (!StrEqual(ga_sSquadName[client], ""))
1386 {
1387 char sQuery[300];
1388 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_players WHERE squad=\"%s\"", ga_sSquadName[client]);
1389
1390 g_hDatabase.Query(SQLCallback_OpenMembersMenu, sQuery, GetClientUserId(client));
1391 }
1392}
1393
1394public void SQLCallback_OpenMembersMenu(Database db, DBResultSet results, const char[] error, int data)
1395{
1396 if (db == null)
1397 {
1398 SetDB();
1399 }
1400 int client = GetClientOfUserId(data);
1401 if (!IsValidClient(client))
1402 {
1403 return;
1404 }
1405 else
1406 {
1407 Menu menu = CreateMenu(MemberListMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1408
1409 char sTitleString[128];
1410 Format(sTitleString, sizeof(sTitleString), "%T", "MemberList", client);
1411 SetMenuTitle(menu, sTitleString);
1412
1413 while (results.FetchRow())
1414 {
1415 char a_sTempArray[5][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
1416 results.FetchString(1, a_sTempArray[0], sizeof(a_sTempArray[])); // Steam-ID
1417 results.FetchString(2, a_sTempArray[1], sizeof(a_sTempArray[])); // Player Name
1418 results.FetchString(5, a_sTempArray[2], sizeof(a_sTempArray[])); // Invited By
1419 IntToString(results.FetchInt(4), a_sTempArray[3], sizeof(a_sTempArray[])); // Rank
1420 IntToString(results.FetchInt(6), a_sTempArray[4], sizeof(a_sTempArray[])); // Date
1421
1422
1423 char sInfoString[128];
1424 char sDisplayString[128];
1425
1426 Format(sInfoString, sizeof(sInfoString), "%s;%s;%s;%i;%i", a_sTempArray[0], a_sTempArray[1], a_sTempArray[2], StringToInt(a_sTempArray[3]), StringToInt(a_sTempArray[4]));
1427
1428 if (StrEqual(a_sTempArray[3], "0"))
1429 {
1430 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "MemberRank", client);
1431 }
1432 else if (StrEqual(a_sTempArray[3], "1"))
1433 {
1434 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "AdminRank", client);
1435 }
1436 else if (StrEqual(a_sTempArray[3], "2"))
1437 {
1438 Format(sDisplayString, sizeof(sDisplayString), "%s (%T)", a_sTempArray[1], "OwnerRank", client);
1439 }
1440 menu.AddItem(sInfoString, sDisplayString);
1441 }
1442 menu.ExitBackButton = true;
1443
1444 menu.Display(client, MENU_TIME_FOREVER);
1445 }
1446}
1447
1448public int MemberListMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
1449{
1450 switch (action)
1451 {
1452 case MenuAction_Select:
1453 {
1454 char sInfo[128];
1455 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1456 OpenIndividualMemberMenu(param1, sInfo);
1457 }
1458 case MenuAction_Cancel:
1459 {
1460 StartOpeningSquadMenu(param1);
1461 }
1462 case MenuAction_End:
1463 {
1464 delete menu;
1465 }
1466 }
1467 return;
1468}
1469
1470void OpenIndividualMemberMenu(int client, char[] sInfo)
1471{
1472 Menu menu = CreateMenu(IndividualMemberMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1473 SetMenuTitle(menu, "Information On : ");
1474
1475 char sTempArray[5][64]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
1476 char sDisplayBuffer[32];
1477
1478 ExplodeString(sInfo, ";", sTempArray, 5, sizeof(sTempArray[]));
1479
1480 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "Name", client, sTempArray[1]);
1481 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1482
1483 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "Steam ID : %s", sTempArray[0]);
1484 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1485
1486 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "InvitedBy", client, sTempArray[2]);
1487 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1488
1489
1490 if (StrEqual(sTempArray[3], "0"))
1491 {
1492 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "MemberRank", client);
1493 }
1494 else if (StrEqual(sTempArray[3], "1"))
1495 {
1496 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "AdminRank", client);
1497 }
1498 else if (StrEqual(sTempArray[3], "2"))
1499 {
1500 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %T", "Rank", client, "OwnerRank", client);
1501 }
1502 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1503
1504 char sFormattedTime[64];
1505 FormatTime(sFormattedTime, sizeof(sFormattedTime), "%x", StringToInt(sTempArray[4]));
1506 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T %s", "DateJoined", client, sFormattedTime);
1507
1508 menu.AddItem("", sDisplayBuffer, ITEMDRAW_DISABLED);
1509
1510 menu.ExitBackButton = true;
1511
1512
1513 menu.Display(client, MENU_TIME_FOREVER);
1514}
1515
1516public int IndividualMemberMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1517{
1518 switch (action)
1519 {
1520 case MenuAction_Select:
1521 {
1522
1523 }
1524 case MenuAction_Cancel:
1525 {
1526 StartOpeningMembersMenu(param1);
1527 }
1528 case MenuAction_End:
1529 {
1530 delete menu;
1531 }
1532 }
1533 return;
1534}
1535/*****************************************************************
1536*********************** INVITATION MENU **************************
1537******************************************************************/
1538
1539
1540
1541void OpenInvitationMenu(int client)
1542{
1543 Menu menu = CreateMenu(InvitationMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1544
1545 char sInfoString[64];
1546 char sDisplayString[64];
1547 char sMenuString[32];
1548
1549 Format(sMenuString, sizeof(sMenuString), "%T", "InviteToSquad", client);
1550 SetMenuTitle(menu, sMenuString);
1551
1552 for (int i = 1; i <= MaxClients; i++)
1553 {
1554 if (IsValidClient(i) && i != client)
1555 {
1556 Format(sInfoString, sizeof(sInfoString), "%i", GetClientUserId(i));
1557 Format(sDisplayString, sizeof(sDisplayString), "%N", i);
1558 SanitizeName(sDisplayString);
1559
1560 menu.AddItem(sInfoString, sDisplayString, (ga_bHasSquad[i] || ga_iRank[client] == Rank_Normal || ga_bBlockInvites[i])?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1561 }
1562 }
1563
1564 menu.Display(client, MENU_TIME_FOREVER);
1565
1566}
1567
1568public int InvitationMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1569{
1570 switch (action)
1571 {
1572 case MenuAction_Select:
1573 {
1574 char sInfo[64];
1575 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1576 int iUserID = StringToInt(sInfo);
1577
1578 ga_iInvitation[GetClientOfUserId(iUserID)] = GetClientUserId(param1);
1579
1580 if (ga_iSquadSize[param1] >= gcv_iMaxSquadSize.IntValue + ga_iSize[param1]
1581 && !gcv_bDisableSize.BoolValue)
1582 {
1583 PrintToChat(param1, "%s %t", TAG, "SquadIsFull");
1584 return;
1585 }
1586
1587 if (!gcv_bInviteStyle.BoolValue)
1588 {
1589 PrintToChat(GetClientOfUserId(iUserID), "%s %t", TAG, "AcceptInstructions", ga_sSquadName[param1]);
1590 }
1591 else
1592 {
1593 OpenSquadInvitationMenu(GetClientOfUserId(iUserID));
1594 }
1595 StartOpeningSquadMenu(param1);
1596 }
1597 case MenuAction_Cancel:
1598 {
1599 StartOpeningSquadMenu(param1);
1600 }
1601 case MenuAction_End:
1602 {
1603 delete menu;
1604 }
1605 }
1606 return;
1607}
1608
1609
1610void OpenSquadInvitationMenu(int client)
1611{
1612 if (!IsValidClient(client))
1613 {
1614 return;
1615 }
1616 Menu menu = CreateMenu(SentInviteMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1617 char sDisplayString[64];
1618 char sTitleString[64];
1619
1620 Format(sTitleString, sizeof(sTitleString), "%T", "SquadInvitation", client);
1621 SetMenuTitle(menu, sTitleString);
1622
1623 int sender = GetClientOfUserId(ga_iInvitation[client]);
1624 char senderName[MAX_NAME_LENGTH];
1625 GetClientName(sender, senderName, sizeof(senderName));
1626 SanitizeName(senderName);
1627
1628 Format(sDisplayString, sizeof(sDisplayString), "%T", "InviteString", client, senderName);
1629 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
1630
1631 Format(sDisplayString, sizeof(sDisplayString), "%T", "WouldYouLikeToJoin", client, ga_sSquadName[sender]);
1632 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
1633
1634 Format(sDisplayString, sizeof(sDisplayString), "%T", "IWouldLikeTo", client);
1635 menu.AddItem("yes", sDisplayString);
1636
1637 Format(sDisplayString, sizeof(sDisplayString), "%T", "IWouldNotLikeTo", client);
1638 menu.AddItem("no", sDisplayString);
1639
1640 menu.Display(client, MENU_TIME_FOREVER);
1641}
1642
1643
1644public int SentInviteMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
1645{
1646 if (!IsValidClient(param1))
1647 {
1648 return;
1649 }
1650 switch (action)
1651 {
1652 case MenuAction_Select:
1653 {
1654 char sInfo[64];
1655 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1656 if (StrEqual(sInfo, "yes"))
1657 {
1658 int sender = GetClientOfUserId(ga_iInvitation[param1]);
1659
1660 if (ga_iSquadSize[param1] >= gcv_iMaxSquadSize.IntValue + ga_iSize[param1] && !gcv_bDisableSize.BoolValue)
1661 {
1662 PrintToChat(param1, "%s %t", TAG, "SquadIsFull");
1663 return;
1664 }
1665 ga_sSquadName[param1] = ga_sSquadName[sender];
1666 ga_iDateJoined[param1] = GetTime();
1667 ga_bHasSquad[param1] = true;
1668 ga_bSetName[param1] = false;
1669
1670 ga_iHealth[param1] = ga_iHealth[sender];
1671 ga_iBunnyhop[param1] = ga_iBunnyhop[sender];//
1672 ga_iDamage[param1] = ga_iDamage[sender];
1673 ga_iGravity[param1] = ga_iGravity[sender];
1674 ga_iSpeed[param1] = ga_iSpeed[sender];
1675 ga_iSize[param1] = ga_iSize[sender];
1676 ga_iCTKills[param1] = ga_iCTKills[sender];
1677 ga_iLastRequests[param1] = ga_iLastRequests[sender];
1678 ga_iSquadSize[param1] = ++ga_iSquadSize[sender];
1679
1680
1681 char sName[MAX_NAME_LENGTH];
1682 GetClientName(sender, sName, sizeof(sName));
1683 ga_sInvitedBy[param1] = sName;
1684 ga_iRank[param1] = Rank_Normal;
1685 UpdateSQL(param1);
1686
1687 char name[MAX_NAME_LENGTH];
1688 GetClientName(param1, name, sizeof(name));
1689
1690 PrintToChatAll("%s %T", TAG, "SquadJoined", LANG_SERVER, name, ga_sSquadName[param1]);
1691 }
1692 else if (StrEqual(sInfo, "no"))
1693 {
1694 // Do Nothing
1695 }
1696 }
1697 case MenuAction_Cancel:
1698 {
1699 StartOpeningSquadMenu(param1);
1700 }
1701 case MenuAction_End:
1702 {
1703 delete menu;
1704 }
1705 }
1706 return;
1707}
1708
1709
1710/*****************************************************************
1711*********************** PERK MENU *************************
1712******************************************************************/
1713
1714
1715public void StartOpeningPerkMenu(int client)
1716{
1717 if (IsValidClient(client))
1718 {
1719 char sQuery[300];
1720 Format(sQuery, sizeof(sQuery), "SELECT health, damage, gravity, speed, size, bunnyhop FROM hl_squads_groups WHERE squad=\"%s\"", ga_sSquadName[client]);
1721 g_hDatabase.Query(SQLCallback_Perks, sQuery, GetClientUserId(client));
1722 }
1723}
1724
1725public void SQLCallback_Perks(Database db, DBResultSet results, const char[] error, int data)
1726{
1727 if (db == null)
1728 {
1729 SetDB();
1730 }
1731
1732 int client = GetClientOfUserId(data);
1733
1734 if (!IsValidClient(client))
1735 {
1736 return;
1737 }
1738 else
1739 {
1740 Menu menu = CreateMenu(PerksMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
1741
1742 char sTitleString[64];
1743
1744 Format(sTitleString, sizeof(sTitleString), "%T", "SquadPerks", client);
1745 SetMenuTitle(menu, sTitleString);
1746
1747 if (results.RowCount == 1 && results.FetchRow())
1748 {
1749 ga_iHealth[client] = results.FetchInt(0); // Health
1750 ga_iDamage[client] = results.FetchInt(1); // Damage
1751 ga_iGravity[client] = results.FetchInt(2); // Gravity
1752 ga_iSpeed[client] = results.FetchInt(3); // Speed
1753 ga_iSize[client] = results.FetchInt(4);
1754 ga_iBunnyhop[client] = results.FetchInt(8);//Bunnyhop
1755 }
1756
1757 char sDisplayBuffer[64];
1758
1759 int price;
1760
1761 if (!gcv_bDisableHealth.BoolValue)
1762 {
1763 price = gcv_iHealthPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iHealth[client]);
1764 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/10] [%i %T]", "Health", client, ga_iHealth[client], price, "Credits", client);
1765 menu.AddItem("health", sDisplayBuffer, (ga_iHealth[client] >= 10 || GetClientCredits(client) < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1766 }
1767
1768 if (!gcv_bDisableDamage.BoolValue)
1769 {
1770 price = gcv_iDamagePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iDamage[client]);
1771 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/10] [%i %T]", "KnifeDamage", client, ga_iDamage[client], price, "Credits", client);
1772 menu.AddItem("damage", sDisplayBuffer, (ga_iDamage[client] >= 10 || GetClientCredits(client) < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1773 }
1774
1775 if (!gcv_bDisableGravity.BoolValue)
1776 {
1777 price = gcv_iGravityPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iGravity[client]);
1778 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/10] [%i %T]", "Gravity", client, ga_iGravity[client], price, "Credits", client);
1779 menu.AddItem("gravity", sDisplayBuffer, (ga_iGravity[client] >= 10 || GetClientCredits(client) < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1780 }
1781
1782 if (!gcv_bDisableSpeed.BoolValue)
1783 {
1784 price = gcv_iSpeedPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSpeed[client]);
1785 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/10] [%i %T]", "Speed", client, ga_iSpeed[client], price, "Credits", client);
1786 menu.AddItem("speed", sDisplayBuffer, (ga_iSpeed[client] >= 10 || GetClientCredits(client) < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1787 }
1788
1789 if (!gcv_bDisableSize.BoolValue && gcv_iMaxSquadSize.IntValue != 0)
1790 {
1791 price = gcv_iSizePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSize[client]);
1792 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/%i] [%i %T]", "SquadSize", client, ga_iSize[client], gcv_iSquadSizeMaxUpgrades.IntValue, price, "Credits", client);
1793 menu.AddItem("size", sDisplayBuffer, (ga_iSize[client] >= gcv_iSquadSizeMaxUpgrades.IntValue || GetClientCredits(client) < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1794 }
1795 //
1796 if (!gcv_bDisableBunnyhop.BoolValue)
1797 {
1798 price = gcv_iBunnyhopPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iBunnyhop[client]);
1799 Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%T [%i/10] [%i %T]", "Bunnyhop", client, ga_iBunnyhop[client], price, "Credits", client);
1800 menu.AddItem("bunnyhop", sDisplayBuffer, (ga_iBunnyhop[client] >= 10 || GetClientCredits(client) < price)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1801 }
1802
1803
1804
1805 Call_StartForward(g_hOnPerkMenu);
1806 Call_PushCell(client);
1807 Call_PushCell(menu);
1808 Call_Finish();
1809
1810 menu.ExitBackButton = true;
1811
1812 menu.Display(client, MENU_TIME_FOREVER);
1813 }
1814}
1815
1816public int PerksMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
1817{
1818 Call_StartForward(g_hOnPerkMenuCallback);
1819 Call_PushCell(menu);
1820 Call_PushCell(action);
1821 Call_PushCell(param1);
1822 Call_PushCell(param2);
1823 Call_Finish();
1824
1825 if (!IsValidClient(param1))
1826 {
1827 return;
1828 }
1829 switch (action)
1830 {
1831 case MenuAction_Select:
1832 {
1833 char sInfo[64];
1834 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1835 char sQuery[300];
1836
1837 if (StrEqual(sInfo, "health"))
1838 {
1839 int price = gcv_iHealthPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iHealth[param1]);
1840 SetClientCredits(param1, GetClientCredits(param1) - price);
1841 ++ga_iHealth[param1];
1842 PrintToSquad(param1, true, "%s %T", TAG, "HealthUpgrade", LANG_SERVER);
1843 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET health=%i WHERE squad=\"%s\"", ga_iHealth[param1], ga_sSquadName[param1]);
1844 }
1845 else if (StrEqual(sInfo, "damage"))
1846 {
1847 int price = gcv_iDamagePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iDamage[param1]);
1848 SetClientCredits(param1, GetClientCredits(param1) - price);
1849 ++ga_iDamage[param1];
1850 PrintToSquad(param1, true, "%s %T", TAG, "DamageUpgrade", LANG_SERVER);
1851 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET damage=%i WHERE squad=\"%s\"", ga_iDamage[param1], ga_sSquadName[param1]);
1852 }
1853 else if (StrEqual(sInfo, "gravity"))
1854 {
1855 int price = gcv_iGravityPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iGravity[param1]);
1856 SetClientCredits(param1, GetClientCredits(param1) - price);
1857 PrintToSquad(param1, true, "%s %T", TAG, "GravityUpgrade", LANG_SERVER);
1858 ++ga_iGravity[param1];
1859 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET gravity=%i WHERE squad=\"%s\"", ga_iGravity[param1], ga_sSquadName[param1]);
1860 SetEntityGravity(param1, GetClientGravityAmmount(param1));
1861 }
1862 else if (StrEqual(sInfo, "speed"))
1863 {
1864 int price = gcv_iSpeedPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSpeed[param1]);
1865 SetClientCredits(param1, GetClientCredits(param1) - price);
1866 PrintToSquad(param1, true, "%s %T", TAG, "SpeedUpgrade", LANG_SERVER);
1867 ++ga_iSpeed[param1];
1868 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET speed=%i WHERE squad=\"%s\"", ga_iSpeed[param1], ga_sSquadName[param1]);
1869 SetEntPropFloat(param1, Prop_Send, "m_flLaggedMovementValue", GetClientSpeedAmmount(param1));
1870 }
1871 else if (StrEqual(sInfo, "size"))
1872 {
1873 int price = gcv_iSizePrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iSize[param1]);
1874 SetClientCredits(param1, GetClientCredits(param1) - price);
1875 PrintToSquad(param1, true, "%s %T", TAG, "SizeUpgrade", LANG_SERVER);
1876 ++ga_iSize[param1];
1877 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET size=%i WHERE squad=\"%s\"", ga_iSize[param1], ga_sSquadName[param1]);
1878 }
1879 //
1880 else if (StrEqual(sInfo, "bunnyhop"))
1881 {
1882 int price = gcv_iBunnyhopPrice.IntValue + (gcv_iPriceModifier.IntValue * ga_iBunnyhop[param1]);
1883 SetClientCredits(param1, GetClientCredits(param1) - price);
1884 ++ga_iBunnyhop[param1];
1885 PrintToSquad(param1, true, "%s %T", TAG, "BunnyhopUpgrade", LANG_SERVER);
1886 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET bunnyhop=%i WHERE squad=\"%s\"", ga_iBunnyhop[param1], ga_sSquadName[param1]);
1887 }
1888 g_hDatabase.Query(SQLCallback_Void, sQuery, GetClientUserId(param1));
1889
1890 StartOpeningPerkMenu(param1);
1891 }
1892 case MenuAction_Cancel:
1893 {
1894 StartOpeningSquadMenu(param1);
1895 }
1896 case MenuAction_End:
1897 {
1898 delete menu;
1899 }
1900 }
1901 return;
1902}
1903
1904
1905/*****************************************************************
1906******************* LEAVE CONFIRMATION ********************
1907******************************************************************/
1908
1909
1910void OpenLeaveConfirmation(int client)
1911{
1912 Menu menu = CreateMenu(LeaveConfirmation_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1913
1914 char tempBuffer[128];
1915
1916 Format(tempBuffer, sizeof(tempBuffer), "%T", "LeaveSquad", client);
1917 SetMenuTitle(menu, tempBuffer);
1918
1919 Format(tempBuffer, sizeof(tempBuffer), "%T", "AreYouSure", client);
1920 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
1921 if (ga_iRank[client] == Rank_Owner)
1922 {
1923 Format(tempBuffer, sizeof(tempBuffer), "%T", "OwnerWarning", client);
1924 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
1925 }
1926
1927 Format(tempBuffer, sizeof(tempBuffer), "%T", "YesLeave", client);
1928 menu.AddItem("yes", tempBuffer);
1929
1930 Format(tempBuffer, sizeof(tempBuffer), "%T", "NoLeave", client);
1931 menu.AddItem("no", tempBuffer);
1932
1933 menu.ExitBackButton = true;
1934
1935 menu.Display(client, MENU_TIME_FOREVER);
1936}
1937
1938public int LeaveConfirmation_Callback(Menu menu, MenuAction action, int param1, int param2)
1939{
1940 switch (action)
1941 {
1942 case MenuAction_Select:
1943 {
1944 char sInfo[64];
1945 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
1946 if (StrEqual(sInfo, "yes"))
1947 {
1948 RemoveFromSquad(param1);
1949 }
1950 else if (StrEqual(sInfo, "no"))
1951 {
1952 StartOpeningSquadMenu(param1);
1953 }
1954
1955 }
1956 case MenuAction_Cancel:
1957 {
1958 StartOpeningSquadMenu(param1);
1959 }
1960 case MenuAction_End:
1961 {
1962 delete menu;
1963 }
1964 }
1965 return;
1966}
1967
1968
1969
1970
1971/*****************************************************************
1972********************* ADMIN MAIN MENU **************************
1973******************************************************************/
1974
1975
1976void OpenAdministrationMenu(int client)
1977{
1978 if (!IsValidClient(client))
1979 {
1980 return;
1981 }
1982 Menu menu = CreateMenu(AdministrationMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
1983
1984 char tempBuffer[128];
1985 Format(tempBuffer, sizeof(tempBuffer), "%T", "SquadAdmin", client);
1986 SetMenuTitle(menu, tempBuffer);
1987
1988 char sDisplayString[128];
1989
1990 Format(sDisplayString, sizeof(sDisplayString), "%T", "KickAMember", client);
1991 menu.AddItem("kick", "Kick a member", (ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1992
1993 Format(sDisplayString, sizeof(sDisplayString), "%T [%i %T]", "RenameSquad", client, gcv_iRenamePrice.IntValue, "Credits", client);
1994 menu.AddItem("rename", sDisplayString, (ga_iRank[client] == Rank_Owner && GetClientCredits(client) >= gcv_iRenamePrice.IntValue)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
1995
1996 Format(sDisplayString, sizeof(sDisplayString), "%T", "Promote", client);
1997 menu.AddItem("promote", sDisplayString, (ga_iRank[client] == Rank_Normal)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
1998
1999 Format(sDisplayString, sizeof(sDisplayString), "%T", "Disband", client);
2000 menu.AddItem("disband", sDisplayString, (ga_iRank[client] == Rank_Owner)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2001
2002
2003 menu.ExitBackButton = true;
2004
2005 menu.Display(client, MENU_TIME_FOREVER);
2006
2007}
2008
2009public int AdministrationMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
2010{
2011 if (!IsValidClient(param1))
2012 {
2013 return;
2014 }
2015 switch (action)
2016 {
2017 case MenuAction_Select:
2018 {
2019 char sInfo[64];
2020 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2021 if (StrEqual(sInfo, "kick"))
2022 {
2023 OpenAdministrationKickMenu(param1);
2024 }
2025 else if (StrEqual(sInfo, "rename"))
2026 {
2027 SetClientCredits(param1, GetClientCredits(param1) - 100);
2028 for (int i = 1; i <= 5; i++)
2029 {
2030 PrintToChat(param1, "%s %t", TAG, "SquadName");
2031 }
2032 ga_bRename[param1] = true;
2033 }
2034 else if (StrEqual(sInfo, "promote"))
2035 {
2036 OpenAdministrationPromotionMenu(param1);
2037 }
2038 else if (StrEqual(sInfo, "disband"))
2039 {
2040 OpenDisbandMenu(param1);
2041 }
2042 }
2043 case MenuAction_Cancel:
2044 {
2045 StartOpeningSquadMenu(param1);
2046 }
2047 case MenuAction_End:
2048 {
2049 delete menu;
2050 }
2051 }
2052 return;
2053}
2054
2055
2056
2057/*****************************************************************
2058******************* ADMIN PROMOTION MENU ***********************
2059******************************************************************/
2060
2061
2062
2063
2064void OpenAdministrationPromotionMenu(int client)
2065{
2066 if (!StrEqual(ga_sSquadName[client], ""))
2067 {
2068 char sQuery[200];
2069 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_players WHERE squad=\"%s\"", ga_sSquadName[client]);
2070
2071 g_hDatabase.Query(SQLCallback_AdministrationPromotionMenu, sQuery, GetClientUserId(client));
2072 }
2073}
2074
2075public void SQLCallback_AdministrationPromotionMenu(Database db, DBResultSet results, const char[] error, int data)
2076{
2077 if (db == null)
2078 {
2079 SetDB();
2080 }
2081 int client = GetClientOfUserId(data);
2082 if (!IsValidClient(client))
2083 {
2084 return;
2085 }
2086 else
2087 {
2088 Menu menu = CreateMenu(AdministrationPromoMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2089
2090 char tempBuffer[128];
2091 Format(tempBuffer, sizeof(tempBuffer), "%T", "Promote", client);
2092 SetMenuTitle(menu, tempBuffer);
2093
2094 while (results.FetchRow())
2095 {
2096 char sTempArray[3][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
2097 results.FetchString(1, sTempArray[0], sizeof(sTempArray[])); // Steam-ID
2098 results.FetchString(2, sTempArray[1], sizeof(sTempArray[])); // Player Name
2099 IntToString(results.FetchInt(4), sTempArray[2], sizeof(sTempArray[])); // Rank
2100
2101 char sSteamID[34];
2102 GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2103
2104 if (!StrEqual(sSteamID, sTempArray[0]))
2105 {
2106 char sInfoString[128];
2107 char sDisplayString[128];
2108 Format(sInfoString, sizeof(sInfoString), "%s;%s;%i", sTempArray[0], sTempArray[1], StringToInt(sTempArray[2]));
2109 Format(sDisplayString, sizeof(sDisplayString), "%s (%s)", sTempArray[1], sTempArray[0]);
2110 menu.AddItem(sInfoString, sDisplayString, (ga_iRank[client] == Rank_Owner)?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2111 }
2112 }
2113 menu.ExitBackButton = true;
2114
2115 menu.Display(client, MENU_TIME_FOREVER);
2116 }
2117}
2118
2119public int AdministrationPromoMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2120{
2121 switch (action)
2122 {
2123 case MenuAction_Select:
2124 {
2125 char sInfo[256];
2126 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2127
2128 OpenPromoteDemoteMenu(param1, sInfo);
2129 }
2130 case MenuAction_Cancel:
2131 {
2132 OpenAdministrationMenu(param1);
2133 }
2134 case MenuAction_End:
2135 {
2136 delete menu;
2137 }
2138 }
2139 return;
2140}
2141
2142
2143void OpenPromoteDemoteMenu(int client, const char[] sInfo)
2144{
2145 char sTempArray[3][32];
2146 ExplodeString(sInfo, ";", sTempArray, 3, 32);
2147
2148 Menu menu = CreateMenu(AdministrationPromoDemoteMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2149
2150 char tempBuffer[128];
2151 Format(tempBuffer, sizeof(tempBuffer), "%T", "SquadMembersRanks", client);
2152 SetMenuTitle(menu, tempBuffer);
2153
2154 char sInfoString[32];
2155
2156 Format(tempBuffer, sizeof(tempBuffer), "%T", "Simply", client);
2157 menu.AddItem("", tempBuffer, ITEMDRAW_DISABLED);
2158
2159 Format(sInfoString, sizeof(sInfoString), "%s;normal", sTempArray[0]);
2160 Format(tempBuffer, sizeof(tempBuffer), "%T", "MemberRank", client);
2161 menu.AddItem(sInfoString, tempBuffer, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2162
2163 Format(sInfoString, sizeof(sInfoString), "%s;admin", sTempArray[0]);
2164 Format(tempBuffer, sizeof(tempBuffer), "%T", "AdminRank", client);
2165 menu.AddItem(sInfoString, tempBuffer, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2166
2167 menu.ExitBackButton = true;
2168
2169 menu.Display(client, MENU_TIME_FOREVER);
2170}
2171
2172public int AdministrationPromoDemoteMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2173{
2174 switch (action)
2175 {
2176 case MenuAction_Select:
2177 {
2178 char sInfo[256];
2179 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2180 char sTempArray[2][32];
2181 ExplodeString(sInfo, ";", sTempArray, 2, 32);
2182
2183 char sQuery[300];
2184
2185 if (StrEqual(sTempArray[1], "normal"))
2186 {
2187 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_players SET rank=0 WHERE steamid=\"%s\"", sTempArray[0]);
2188 }
2189 else if (StrEqual(sTempArray[1], "admin"))
2190 {
2191 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_players SET rank=1 WHERE steamid=\"%s\"", sTempArray[0]);
2192 }
2193
2194 g_hDatabase.Query(SQLCallback_Void, sQuery);
2195 char sSteamID[32];
2196 for (int i = 1; i <= MaxClients; i++)
2197 {
2198 if (IsValidClient(i))
2199 {
2200 GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2201 if (StrEqual(sSteamID, sTempArray[0]))
2202 {
2203 LoadSteamID(i);
2204 break;
2205 }
2206 }
2207 }
2208 }
2209 case MenuAction_Cancel:
2210 {
2211 OpenAdministrationMenu(param1);
2212 }
2213 case MenuAction_End:
2214 {
2215 delete menu;
2216 }
2217 }
2218 return;
2219}
2220
2221
2222
2223
2224
2225/*****************************************************************
2226********************* DISBAND MENU **************************
2227******************************************************************/
2228
2229
2230
2231
2232
2233
2234
2235void OpenDisbandMenu(int client)
2236{
2237 Menu menu = CreateMenu(DisbandMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2238
2239 char tempString[128];
2240
2241 Format(tempString, sizeof(tempString), "%T", "DisbandSquad", client);
2242 SetMenuTitle(menu, tempString);
2243
2244 Format(tempString, sizeof(tempString), "%T", "DisbandConfirmation", client);
2245 menu.AddItem("", tempString, ITEMDRAW_DISABLED);
2246
2247 Format(tempString, sizeof(tempString), "%T", "YesDisband", client);
2248 menu.AddItem("disband", tempString, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2249
2250 Format(tempString, sizeof(tempString), "%T", "NoDisband", client);
2251 menu.AddItem("no", tempString, (ga_iRank[client] != Rank_Owner)?ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
2252
2253 menu.ExitBackButton = true;
2254
2255 menu.Display(client, MENU_TIME_FOREVER);
2256}
2257
2258public int DisbandMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2259{
2260 switch (action)
2261 {
2262 case MenuAction_Select:
2263 {
2264 char sInfo[256];
2265 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2266 if (StrEqual(sInfo, "disband"))
2267 {
2268 RemoveFromSquad(param1);
2269 }
2270 }
2271 case MenuAction_Cancel:
2272 {
2273 OpenAdministrationMenu(param1);
2274 }
2275 case MenuAction_End:
2276 {
2277 delete menu;
2278 }
2279 }
2280 return;
2281}
2282
2283/*****************************************************************
2284********************* ADMIN KICK MENU **************************
2285******************************************************************/
2286
2287void OpenAdministrationKickMenu(int client)
2288{
2289 if (!StrEqual(ga_sSquadName[client], ""))
2290 {
2291 char sQuery[200];
2292 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_players WHERE squad=\"%s\"", ga_sSquadName[client]);
2293
2294 g_hDatabase.Query(SQLCallback_AdministrationKickMenu, sQuery, GetClientUserId(client));
2295 }
2296}
2297
2298public void SQLCallback_AdministrationKickMenu(Database db, DBResultSet results, const char[] error, int data)
2299{
2300 if (db == null)
2301 {
2302 SetDB();
2303 }
2304 int client = GetClientOfUserId(data);
2305 if (!IsValidClient(client))
2306 {
2307 return;
2308 }
2309 else
2310 {
2311
2312 Menu menu = CreateMenu(AdministrationKickMenu_CallBack, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem | MenuAction_Cancel);
2313
2314 char tempString[128];
2315
2316 Format(tempString, sizeof(tempString), "%T", "KickSquadMembers", client);
2317 SetMenuTitle(menu, tempString);
2318
2319 while (results.FetchRow())
2320 {
2321 char sTempArray[3][128]; // 0 - SteamID | 1 - Name | 2 - Invited By | 3 - Rank | 4 - Date (UTF)
2322 results.FetchString(1, sTempArray[0], sizeof(sTempArray[])); // Steam-ID
2323 results.FetchString(2, sTempArray[1], sizeof(sTempArray[])); // Player Name
2324 IntToString(results.FetchInt(4), sTempArray[2], sizeof(sTempArray[])); // Rank
2325
2326
2327 char sInfoString[128];
2328 char sDisplayString[128];
2329
2330 Format(sInfoString, sizeof(sInfoString), "%s;%s", sTempArray[0], sTempArray[1]);
2331 Format(sDisplayString, sizeof(sDisplayString), "%s (%s)", sTempArray[1], sTempArray[0]);
2332 menu.AddItem(sInfoString, sDisplayString, (ga_iRank[client] > view_as<SquadRank>(StringToInt(sTempArray[2])))?ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
2333 }
2334 menu.ExitBackButton = true;
2335
2336 menu.Display(client, MENU_TIME_FOREVER);
2337 }
2338}
2339
2340public int AdministrationKickMenu_CallBack(Menu menu, MenuAction action, int param1, int param2)
2341{
2342 switch (action)
2343 {
2344 case MenuAction_Select:
2345 {
2346 char sInfo[256];
2347 char sTempArray[2][128];
2348 char sQuery1[128];
2349
2350 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2351
2352 ExplodeString(sInfo, ";", sTempArray, 2, 128);
2353
2354 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_squads_players WHERE steamid = \"%s\"", sTempArray[0]);
2355 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2356
2357 PrintToChatAll("%s %T", TAG, "SquadMemberKick", LANG_SERVER, sTempArray[1], ga_sSquadName[param1]);
2358
2359 char sSteamID[64];
2360 for (int i = 1; i <= MaxClients; i++)
2361 {
2362 if (IsValidClient(i))
2363 {
2364 GetClientAuthId(i, AuthId_Steam2, sSteamID, sizeof(sSteamID));
2365 if (StrEqual(sSteamID, sTempArray[0]))
2366 {
2367 ResetVariables(i, false);
2368 }
2369 }
2370 }
2371 }
2372 case MenuAction_Cancel:
2373 {
2374 OpenAdministrationMenu(param1);
2375 }
2376 case MenuAction_End:
2377 {
2378 delete menu;
2379 }
2380 }
2381}
2382
2383
2384/*****************************************************************
2385********************** TOP GANGS MENU **************************
2386******************************************************************/
2387
2388
2389
2390void StartOpeningTopSquadsMenu(int client)
2391{
2392 if (IsValidClient(client))
2393 {
2394 if (gcv_bCTKillsOrLRs.BoolValue)
2395 {
2396 g_hDatabase.Query(SQL_Callback_TopMenu, "SELECT * FROM hl_squads_statistics ORDER BY ctkills DESC", GetClientUserId(client));
2397 }
2398 else
2399 {
2400 g_hDatabase.Query(SQL_Callback_TopMenu, "SELECT * FROM hl_squads_statistics ORDER BY lastrequests DESC", GetClientUserId(client));
2401 }
2402 }
2403}
2404
2405public void SQL_Callback_TopMenu(Database db, DBResultSet results, const char[] error, int data)
2406{
2407 if (db == null)
2408 {
2409 SetDB();
2410 }
2411
2412 if (results == null)
2413 {
2414 LogError(error);
2415 return;
2416 }
2417
2418 int client = GetClientOfUserId(data);
2419 if (!IsValidClient(client))
2420 {
2421 return;
2422 }
2423 else
2424 {
2425 Menu menu = CreateMenu(TopSquadsMenu_Callback, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
2426
2427 char menuTitle[64];
2428 Format(menuTitle, sizeof(menuTitle), "%T", "TopSquads", client);
2429 menu.SetTitle(menuTitle);
2430 if (results.RowCount == 0)
2431 {
2432 PrintToChat(client, "%s %t", TAG, "NoSquads");
2433
2434 delete menu;
2435 return;
2436 }
2437 char sSquadName[128];
2438 char sInfoString[128];
2439
2440
2441 ga_iTempInt2[client] = 0;
2442 g_iSquadAmmount = 0;
2443 while (results.FetchRow())
2444 {
2445 g_iSquadAmmount++;
2446 ga_iTempInt2[client]++;
2447
2448 results.FetchString(1, sSquadName, sizeof(sSquadName));
2449
2450 Format(sInfoString, sizeof(sInfoString), "%i;%s;%i;%i", ga_iTempInt2[client], sSquadName, results.FetchInt(2), results.FetchInt(3));
2451
2452 menu.AddItem(sInfoString, sSquadName);
2453 }
2454
2455 menu.ExitBackButton = true;
2456
2457 menu.Display(client, MENU_TIME_FOREVER);
2458 }
2459}
2460
2461public int TopSquadsMenu_Callback(Menu menu, MenuAction action, int param1, int param2)
2462{
2463 switch (action)
2464 {
2465 case MenuAction_Select:
2466 {
2467 char sInfo[300];
2468 char sQuery[300];
2469 char sTempArray[4][128];
2470 GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
2471
2472 ExplodeString(sInfo, ";", sTempArray, 4, sizeof(sTempArray[]));
2473
2474 ga_iTempInt2[param1] = StringToInt(sTempArray[0]);
2475 ga_iTempInt[param1] = StringToInt(sTempArray[2]);
2476 ga_iTempInt3[param1] = StringToInt(sTempArray[3]);
2477
2478 Format(sQuery, sizeof(sQuery), "SELECT * FROM `hl_squads_players` WHERE `squad` = \"%s\" AND `rank` = 2", sTempArray[1]);
2479 g_hDatabase.Query(SQL_Callback_SquadStatistics, sQuery, GetClientUserId(param1));
2480 }
2481 case MenuAction_Cancel:
2482 {
2483 StartOpeningSquadMenu(param1);
2484 }
2485 case MenuAction_End:
2486 {
2487 delete menu;
2488 }
2489 }
2490 return;
2491}
2492
2493
2494public void SQL_Callback_SquadStatistics(Database db, DBResultSet results, const char[] error, int data)
2495{
2496 if (db == null)
2497 {
2498 SetDB();
2499 }
2500
2501 if (results == null)
2502 {
2503 LogError(error);
2504 return;
2505 }
2506
2507 int client = GetClientOfUserId(data);
2508 if (!IsValidClient(client))
2509 {
2510 return;
2511 }
2512 else
2513 {
2514 char sTempArray[2][128]; // Squad Name | Player Name
2515 char sFormattedTime[64];
2516 char sDisplayString[128];
2517
2518 results.FetchRow();
2519
2520
2521 results.FetchString(3, sTempArray[0], sizeof(sTempArray[]));
2522 results.FetchString(2, sTempArray[1], sizeof(sTempArray[]));
2523 int iDate = results.FetchInt(6);
2524
2525 Menu menu = CreateMenu(MenuCallback_Void, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
2526 menu.SetTitle("Top Squads");
2527
2528 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "MenuSquadName", client, sTempArray[0]);
2529 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2530
2531 Format(sDisplayString, sizeof(sDisplayString), "%T : %i/%i", "SquadRank", client, ga_iTempInt2[client], g_iSquadAmmount);
2532 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2533
2534 FormatTime(sFormattedTime, sizeof(sFormattedTime), "%x", iDate);
2535 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "DateCreated", client, sFormattedTime);
2536 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2537
2538 Format(sDisplayString, sizeof(sDisplayString), "%T : %s", "CreatedBy", client, sTempArray[1]);
2539 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2540
2541 if (gcv_bCTKillsOrLRs.BoolValue)
2542 {
2543 Format(sDisplayString, sizeof(sDisplayString), "%T : %i ", "CTKills", client, ga_iTempInt[client]);
2544 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2545 Format(sDisplayString, sizeof(sDisplayString), "%T : %i ", "LastRequests", client, ga_iTempInt3[client]);
2546 }
2547 else
2548 {
2549 Format(sDisplayString, sizeof(sDisplayString), "%T : %i ", "LastRequests", client, ga_iTempInt3[client]);
2550 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2551 Format(sDisplayString, sizeof(sDisplayString), "%T : %i ", "CTKills", client, ga_iTempInt[client]);
2552 }
2553 menu.AddItem("", sDisplayString, ITEMDRAW_DISABLED);
2554
2555 menu.ExitBackButton = true;
2556
2557 menu.Display(client, MENU_TIME_FOREVER);
2558 }
2559}
2560
2561public int MenuCallback_Void(Menu menu, MenuAction action, int param1, int param2)
2562{
2563 switch (action)
2564 {
2565 case MenuAction_Select:
2566 {
2567 // Do Nothing
2568 }
2569 case MenuAction_Cancel:
2570 {
2571 StartOpeningTopSquadsMenu(param1);
2572 }
2573 case MenuAction_End:
2574 {
2575 delete menu;
2576 }
2577 }
2578 return;
2579}
2580
2581/*****************************************************************
2582*********************** HELPER FUNCTIONS ***********************
2583******************************************************************/
2584
2585
2586void UpdateSQL(int client)
2587{
2588 DeleteDuplicates();
2589
2590 /* We need to ensure that users are completely loaded in before calling save queries.
2591 * This may prevent errors where CT kills are reset to zero. */
2592 if (ga_bHasSquad[client] && ga_bLoaded[client])
2593 {
2594 GetClientAuthId(client, AuthId_Steam2, ga_sSteamID[client], sizeof(ga_sSteamID[]));
2595
2596 char sQuery[300];
2597 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_players WHERE steamid=\"%s\"", ga_sSteamID[client]);
2598
2599 g_hDatabase.Query(SQLCallback_CheckIfInDatabase_Player, sQuery, GetClientUserId(client));
2600 }
2601}
2602
2603public void SQLCallback_CheckIfInDatabase_Player(Database db, DBResultSet results, const char[] error, int data)
2604{
2605 if (db == null)
2606 {
2607 SetDB();
2608 }
2609
2610 int client = GetClientOfUserId(data);
2611
2612 if (!IsValidClient(client))
2613 {
2614 return;
2615 }
2616 if (results.RowCount == 0)
2617 {
2618 ga_bIsPlayerInDatabase[client] = false;
2619 }
2620 else
2621 {
2622 ga_bIsPlayerInDatabase[client] = true;
2623 }
2624
2625 char sQuery[300];
2626 char playerName[MAX_NAME_LENGTH], escapedName[MAXPLAYERS*2+1];
2627
2628 GetClientName(client, playerName, sizeof(playerName));
2629 g_hDatabase.Escape(playerName, escapedName, sizeof(escapedName));
2630
2631 if (!ga_bIsPlayerInDatabase[client])
2632 {
2633 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_squads_players (squad, invitedby, rank, date, steamid, playername) VALUES(\"%s\", \"%s\", %i, %i, \"%s\", \"%s\")", ga_sSquadName[client], ga_sInvitedBy[client], ga_iRank[client], ga_iDateJoined[client], ga_sSteamID[client], escapedName);
2634 }
2635 else
2636 {
2637 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_players SET squad=\"%s\",invitedby=\"%s\",playername=\"%s\",rank=%i,date=%i WHERE steamid=\"%s\"", ga_sSquadName[client], ga_sInvitedBy[client], escapedName, ga_iRank[client], ga_iDateJoined[client], ga_sSteamID[client]);
2638 }
2639 g_hDatabase.Query(SQLCallback_Void, sQuery);
2640
2641 char sQuery2[128];
2642
2643 Format(sQuery2, sizeof(sQuery2), "SELECT * FROM hl_squads_groups WHERE squad=\"%s\"", ga_sSquadName[client]);
2644
2645 g_hDatabase.Query(SQLCALLBACK_GROUPS, sQuery2, GetClientUserId(client));
2646}
2647
2648public void SQLCALLBACK_GROUPS(Database db, DBResultSet results, const char[] error, int data)
2649{
2650 if (db == null)
2651 {
2652 SetDB();
2653 }
2654
2655 int client = GetClientOfUserId(data);
2656
2657 if (!IsValidClient(client))
2658 {
2659 return;
2660 }
2661
2662 if (results.RowCount == 0)
2663 {
2664 ga_bIsSquadInDatabase[client] = false;
2665 }
2666 else
2667 {
2668 ga_bIsSquadInDatabase[client] = true;
2669 }
2670
2671 char sQuery[300];
2672 if (!ga_bIsSquadInDatabase[client])
2673 {
2674 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_squads_groups (squad, health, damage, gravity, speed, size, bunnyhop,) VALUES(\"%s\", %i, %i, %i, %i, %i)", ga_sSquadName[client], ga_iHealth[client], ga_iDamage[client], ga_iGravity[client], ga_iSpeed[client], ga_iSize[client], ga_iBunnyhop[client]);
2675 }
2676 else
2677 {
2678 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_groups SET health=%i,damage=%i,gravity=%i,speed=%i,size=%i,bunnyhop=%i, WHERE squad=\"%s\"", ga_iHealth[client], ga_iDamage[client], ga_iGravity[client], ga_iSpeed[client], ga_iSize[client], ga_iBunnyhop[client], ga_sSquadName[client]);
2679
2680 }
2681
2682 g_hDatabase.Query(SQLCallback_Void, sQuery);
2683
2684 Format(sQuery, sizeof(sQuery), "SELECT * FROM hl_squads_statistics WHERE squad = \"%s\"", ga_sSquadName[client]);
2685 g_hDatabase.Query(SQL_Callback_LoadStatistics, sQuery, GetClientUserId(client));
2686
2687}
2688
2689
2690public void SQL_Callback_LoadStatistics(Database db, DBResultSet results, const char[] error, int data)
2691{
2692 if (db == null)
2693 {
2694 SetDB();
2695 }
2696 if (results == null)
2697 {
2698 LogError(error);
2699 return;
2700 }
2701
2702 int client = GetClientOfUserId(data);
2703
2704 if (!IsValidClient(client))
2705 {
2706 return;
2707 }
2708
2709 if (results.RowCount == 0)
2710 {
2711 ga_bIsSquadInDatabase[client] = false;
2712 }
2713 else
2714 {
2715 ga_bIsSquadInDatabase[client] = true;
2716 }
2717
2718 char sQuery[300];
2719 if (!ga_bIsSquadInDatabase[client])
2720 {
2721 Format(sQuery, sizeof(sQuery), "INSERT INTO hl_squads_statistics (squad, ctkills, lastrequests) VALUES(\"%s\", %i, %i)", ga_sSquadName[client], ga_iCTKills[client], ga_iLastRequests[client]);
2722 }
2723 else
2724 {
2725 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_statistics SET ctkills=%i,lastrequests=%i WHERE squad=\"%s\"", ga_iCTKills[client], ga_iLastRequests[client], ga_sSquadName[client]);
2726 }
2727
2728 g_hDatabase.Query(SQLCallback_Void, sQuery);
2729
2730}
2731
2732void SetDB()
2733{
2734 if (g_hDatabase == null)
2735 {
2736 gcv_sDatabase.GetString(g_sDatabaseName, sizeof(g_sDatabaseName));
2737 Database.Connect(SQLCallback_Connect, g_sDatabaseName);
2738 }
2739}
2740
2741void DeleteDuplicates()
2742{
2743 if (g_hDatabase != null)
2744 {
2745 g_hDatabase.Query(SQLCallback_Void, "delete hl_squads_players from hl_squads_players inner join (select min(id) minid, steamid from hl_squads_players group by steamid having count(1) > 1) as duplicates on (duplicates.steamid = hl_squads_players.steamid and duplicates.minid <> hl_squads_players.id)", 4);
2746 g_hDatabase.Query(SQLCallback_Void, "delete hl_squads_groups from hl_squads_groups inner join (select min(id) minid, squad from hl_squads_groups group by squad having count(1) > 1) as duplicates on (duplicates.squad = hl_squads_groups.squad and duplicates.minid <> hl_squads_groups.id)", 4);
2747 g_hDatabase.Query(SQLCallback_Void, "delete hl_squads_statistics from hl_squads_statistics inner join (select min(id) minid, squad from hl_squads_statistics group by squad having count(1) > 1) as duplicates on (duplicates.squad = hl_squads_statistics.squad and duplicates.minid <> hl_squads_statistics.id)", 4);
2748 }
2749}
2750
2751int GetClientCredits(int client)
2752{
2753 if (g_bZepyhrus)
2754 {
2755 return Store_GetClientCredits(client);
2756 }
2757 else if (g_bShanapu)
2758 {
2759 return MyJailShop_GetCredits(client);
2760 }
2761 else if (g_bFrozdark)
2762 {
2763 return Shop_GetClientCredits(client);
2764 }
2765 else if (g_bDefault)
2766 {
2767 return Squads_GetCredits(client);
2768 }
2769 else
2770 {
2771 SetFailState("ERROR: No supported credits plugin loaded!");
2772 return 0;
2773 }
2774}
2775
2776void SetClientCredits(int client, int iAmmount)
2777{
2778 if (g_bZepyhrus)
2779 {
2780 Store_SetClientCredits(client, iAmmount);
2781 }
2782 else if (g_bShanapu)
2783 {
2784 MyJailShop_SetCredits(client, iAmmount);
2785 }
2786 else if (g_bFrozdark)
2787 {
2788 Shop_SetClientCredits(client, iAmmount);
2789 }
2790 else if (g_bDefault)
2791 {
2792 Squads_SetCredits(client, iAmmount);
2793 }
2794 else
2795 {
2796 SetFailState("ERROR: No supported credits plugin loaded!");
2797 }
2798}
2799
2800void RemoveFromSquad(int client)
2801{
2802 if (ga_iRank[client] == Rank_Owner)
2803 {
2804 char sQuery1[300];
2805 char sQuery2[300];
2806 char sQuery3[300];
2807 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_squads_players WHERE squad = \"%s\"", ga_sSquadName[client]);
2808 Format(sQuery2, sizeof(sQuery2), "DELETE FROM hl_squads_groups WHERE squad = \"%s\"", ga_sSquadName[client]);
2809 Format(sQuery3, sizeof(sQuery3), "DELETE FROM hl_squads_statistics WHERE squad = \"%s\"", ga_sSquadName[client]);
2810
2811 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2812 g_hDatabase.Query(SQLCallback_Void, sQuery2);
2813 g_hDatabase.Query(SQLCallback_Void, sQuery3);
2814
2815 char name[MAX_NAME_LENGTH];
2816 GetClientName(client, name, sizeof(name));
2817 PrintToChatAll("%s %T", TAG, "SquadDisbanded", LANG_SERVER, name, ga_sSquadName[client]);
2818 for (int i = 1; i <= MaxClients; i++)
2819 {
2820 if (IsValidClient(i) && StrEqual(ga_sSquadName[i], ga_sSquadName[client]) && i != client)
2821 {
2822 ResetVariables(i, false);
2823 }
2824 }
2825 ResetVariables(client, false);
2826 }
2827 else
2828 {
2829 char sQuery1[128];
2830 Format(sQuery1, sizeof(sQuery1), "DELETE FROM hl_squads_players WHERE steamid = \"%s\"", ga_sSteamID[client]);
2831 g_hDatabase.Query(SQLCallback_Void, sQuery1);
2832
2833 char name[MAX_NAME_LENGTH];
2834 GetClientName(client, name, sizeof(name));
2835 PrintToChatAll("%s %T", TAG, "LeftSquad", LANG_SERVER, name, ga_sSquadName[client]);
2836 ResetVariables(client, false);
2837 }
2838}
2839
2840
2841float GetClientGravityAmmount(int client)
2842{
2843 float fGravityAmmount;
2844 fGravityAmmount = (1 - (gcv_fGravityModifier.FloatValue*ga_iGravity[client]));
2845 return fGravityAmmount;
2846}
2847
2848
2849float GetClientSpeedAmmount(int client)
2850{
2851 return (ga_iSpeed[client]*gcv_fSpeedModifier.FloatValue) + 1.0;
2852}
2853
2854void PrintToSquad(int client, bool bPrintToClient = false, const char[] sMsg, any ...)
2855{
2856 if(!IsValidClient(client))
2857 {
2858 return;
2859 }
2860 char sFormattedMsg[256];
2861 VFormat(sFormattedMsg, sizeof(sFormattedMsg), sMsg, 4);
2862
2863 for (int i = 1; i <= MaxClients; i++)
2864 {
2865 if (IsValidClient(i) && StrEqual(ga_sSquadName[i], ga_sSquadName[client]) && !StrEqual(ga_sSquadName[client], ""))
2866 {
2867 if (bPrintToClient)
2868 {
2869 PrintToChat(i, sFormattedMsg);
2870 }
2871 else
2872 {
2873 if (i == client)
2874 {
2875 // Do nothing
2876 }
2877 else
2878 {
2879 PrintToChat(i, sFormattedMsg);
2880 }
2881 }
2882 }
2883 }
2884}
2885
2886
2887void ResetVariables(int client, bool full = true)
2888{
2889 ga_iRank[client] = Rank_Invalid;
2890 ga_iSquadSize[client] = -1;
2891 ga_iInvitation[client] = -1;
2892 ga_iDateJoined[client] = -1;
2893 ga_iHealth[client] = 0;
2894 ga_iDamage[client] = 0;
2895 ga_iGravity[client] = 0;
2896 ga_iSpeed[client] = 0;
2897 ga_iBunnyhop[client] = 0;//
2898 ga_iSize[client] = 0;
2899 ga_iTimer[client] = 0;
2900 ga_iCTKills[client] = 0;
2901 ga_iLastRequests[client] = 0;
2902 ga_iTempInt[client] = 0;
2903 ga_iTempInt2[client] = 0;
2904 ga_iTempInt3[client] = 0;
2905 ga_sSquadName[client] = "";
2906 ga_sInvitedBy[client] = "";
2907 ga_bSetName[client] = false;
2908 ga_bIsPlayerInDatabase[client] = false;
2909 ga_bIsSquadInDatabase[client] = false;
2910 ga_bHasSquad[client] = false;
2911 ga_bRename[client] = false;
2912 ga_bBlockInvites[client] = false;
2913 ga_bHasPref[client] = false;
2914 ga_fChangedGravity[client] = 0.0;
2915 if (full)
2916 {
2917 ga_sSteamID[client] = "";
2918 ga_bLoaded[client] = false;
2919 }
2920}
2921
2922public void OnAvailableLR(int announce)
2923{
2924 if (g_bDisablePerks)
2925 {
2926 return;
2927 }
2928
2929 /* Disable Perks */
2930 g_bDisablePerks = true;
2931 for (int i = 1; i <= MaxClients; i++)
2932 {
2933 if (IsValidClient(i))
2934 {
2935 if (IsPlayerAlive(i) && IsPlayerSquadable(i))
2936 {
2937 if (ga_bHasSquad[i])
2938 {
2939 PrintToChat(i, "%s %t", TAG, "GamePerksDisabled");
2940 if (GetClientHealth(i) > 100)
2941 {
2942 SetEntProp(i, Prop_Send, "m_iHealth", 100);
2943 }
2944 if (GetEntPropFloat(i, Prop_Send, "m_flLaggedMovementValue") != 1.0)
2945 {
2946 SetEntPropFloat(i, Prop_Send, "m_flLaggedMovementValue", 1.0);
2947 }
2948 SetEntityGravity(i, 1.0);
2949
2950 /* Update Squad Member's Last Request Count */
2951 for (int j = 0; j <= MaxClients; j++)
2952 {
2953 if (IsValidClient(j))
2954 {
2955 if (ga_bHasSquad[j] && StrEqual(ga_sSquadName[j], ga_sSquadName[i]))
2956 {
2957 ga_iLastRequests[j]++;
2958 }
2959 }
2960 }
2961
2962 char sQuery[256];
2963 /* Reflect it to db */
2964 Format(sQuery, sizeof(sQuery), "UPDATE hl_squads_statistics SET lastrequests = %i WHERE squad=\"%s\"", ga_iLastRequests[i], ga_sSquadName[i]);
2965 g_hDatabase.Query(SQLCallback_Void, sQuery);
2966 }
2967 }
2968 }
2969 }
2970
2971
2972}
2973
2974int GetPlayerAliveCount(int team)
2975 {
2976 int iAmmount = 0;
2977 for (int i = 1; i <= MaxClients; i++)
2978 {
2979 if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == team)
2980 {
2981 iAmmount++;
2982 }
2983 }
2984 return iAmmount;
2985}
2986
2987// to avoid this https://user-images.githubusercontent.com/3672466/28637962-0d324952-724c-11e7-8b27-15ff021f0a59.png
2988void SanitizeName(char[] name)
2989{
2990 ReplaceString(name, MAX_NAME_LENGTH, "#", "?");
2991}
2992
2993bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
2994{
2995 if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
2996 {
2997 return false;
2998 }
2999 return true;
3000}
3001
3002bool IsPlayerSquadable(int client)
3003{
3004 if (!gcv_bTerroristOnly.BoolValue)
3005 {
3006 return true;
3007 }
3008
3009 return GetClientTeam(client) == 2;
3010}