· 6 years ago · Jun 27, 2019, 12:06 AM
1#include <sourcemod>
2#include <sdktools>
3#include <cstrike>
4#include <chat-processor>
5
6#pragma newdecls required
7
8#define PREFIX " \x04[VIP]\x01"
9#define PREFIX_MENU "[VIP]"
10#define CTARMS "models/weapons/ct_arms.mdl"
11#define TARMS "models/weapons/t_arms.mdl"
12#define MAX_SKINS 64
13#define VipGravity 0.2
14
15enum SkinSettings
16{
17 Skin_Name = 0,
18 Skin_Model,
19 Skin_Arms,
20 Skin_Team
21}
22
23enum SkinTeam
24{
25 Skin_Team_T = 0,
26 Skin_Team_CT
27}
28
29enum ColorType
30{
31 Color_Tag = 0,
32 Color_Name,
33 Color_Chat
34}
35
36enum TagType
37{
38 Tag_Chat = 0,
39 Tag_Clan
40}
41
42enum
43{
44 TagEdit_None = 0,
45 TagEdit_Chat,
46 TagEdit_Clan
47}
48
49Database g_dDatabase = null;
50
51ConVar g_cHealthBonus;
52ConVar g_cGravityBonus;
53ConVar g_cArmorBonus;
54ConVar g_cPistolBonus;
55ConVar g_cVIPmessage;
56ConVar g_cPlayerSkins;
57ConVar g_cTablePrefix;
58ConVar g_cVipFlags;
59ConVar g_Vip_slots;
60ConVar g_Vip_slots_enable;
61
62ArrayList g_aBlockedTags;
63
64char g_szSkins[MAX_SKINS][SkinSettings][512];
65char g_szAuth[MAXPLAYERS + 1][32];
66char g_szColors[MAXPLAYERS + 1][ColorType][16];
67char g_szPlayerTags[MAXPLAYERS + 1][TagType][256];
68char g_szPlayerSkins[MAXPLAYERS + 1][SkinTeam][512];
69
70bool g_bVIP[MAXPLAYERS + 1];
71bool g_bHealth[MAXPLAYERS + 1];
72bool g_bArmor[MAXPLAYERS + 1];
73bool g_bGravity[MAXPLAYERS + 1];
74
75
76int g_iSkins = 0;
77int g_iTagEditing[MAXPLAYERS + 1];
78int g_iDaysLeft[MAXPLAYERS + 1];
79
80public Plugin myinfo =
81{
82 name = "[CS:GO] VIPCore(modified by LemonPAKA)",
83 author = "S4muRaY'",
84 description = "original by S4muRaY', modified by LemonPAKA",
85 version = "1.0",
86 url = "http://steamcommunity.com/id/s4muray"
87};
88
89public void OnPluginStart()
90{
91 LoadTranslations("common.phrases");
92
93 g_cHealthBonus = CreateConVar("sm_vip_health", "10", "Health bonus amount, 0 = Disable", 0, true, 0.0);
94 g_cGravityBonus = CreateConVar("sm_vip_gravity", "100", "Gravity decrease amount, 0 = Disable", 0, true, 0.0);
95 g_cArmorBonus = CreateConVar("sm_vip_armor", "1", "Enable the armor bonus? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
96 g_cPistolBonus = CreateConVar("sm_vip_pistol", "1", "Enable the pistol bonus? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
97 g_cPlayerSkins = CreateConVar("sm_vip_skins", "1", "Enable the player skins? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
98 g_cVIPmessage = CreateConVar("sm_vip_message","0", "Enable the VIP join/leave Message? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
99 g_cTablePrefix = CreateConVar("sm_vip_table_aprefix", "vip", "Prefix for the database table (Default: vip)");
100 g_cVipFlags = CreateConVar("sm_vip_flags", "", "Flags to give the vip users, empty for nothing");
101 g_Vip_slots = CreateConVar("sm_vip_slots","0","Number of Vip player slots, if VIP slots feature disabled ,whatever you input will be 0", 0, true, 0.0);
102 g_Vip_slots_enable = CreateConVar("sm_slots_enable","1", "Enable the VIP slots feature? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
103
104 AutoExecConfig();
105
106 SQL_MakeConnection(); //The table cvar required in here
107
108 g_aBlockedTags = new ArrayList(64);
109
110 HookEvent("player_spawn", Event_PlayerSpawn);
111
112 RegAdminCmd("sm_addvip", Command_AddVIP, ADMFLAG_ROOT, "Gives a vip access");
113 RegAdminCmd("sm_removevip", Command_RemoveVIP, ADMFLAG_ROOT, "Removes a vip access");
114 RegConsoleCmd("sm_vip", Command_VIPMenu, "Opens the vip menu");
115 RegConsoleCmd("sm_getvip",Command_GetVIP,"Get VIP via cdkey");
116}
117
118/* Natives */
119
120public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
121{
122 CreateNative("VIP_IsVIP", Native_IsVip);
123
124 RegPluginLibrary("VIPCore");
125 return APLRes_Success;
126}
127
128public int Native_IsVip(Handle plugin, int numParams)
129{
130 int client = GetNativeCell(1);
131 if (client < 1 || client > MaxClients)
132 {
133 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%i)", client);
134 }
135 if (!IsClientConnected(client))
136 {
137 return ThrowNativeError(SP_ERROR_NATIVE, "Client %i is not connected", client);
138 }
139 return g_bVIP[client];
140}
141
142/* Hooks, Events */
143
144public void OnMapStart()
145{
146
147 g_iSkins = 0;
148 LoadSkins();
149 LoadBlockedTags();
150}
151
152public void OnClientPostAdminCheck(int client)
153{
154 if (!GetClientAuthId(client, AuthId_Steam2, g_szAuth[client], sizeof(g_szAuth)))
155 {
156 KickClient(client, "Verification problem, Please reconnect");
157 return;
158 }
159
160 SQL_FetchUser(client);
161}
162
163public void OnClientDisconnect(int client)
164{
165 if (g_bVIP[client]&& g_cVIPmessage.BoolValue)
166 {
167 SetHudTextParams(-1.0, 0.1, 7.0, 0, 255, 150, 255, 2, 6.0, 0.1, 0.2);
168 for (int i = 1; i <= MaxClients; i++)
169 {
170 if (IsValidClient(i))
171 {
172 ShowHudText(i, 0, "VIP %N has disconnected", client);
173 }
174 }
175 }
176
177 //Resetting the variables to prevent users to recieve another players' settings(Ex: as tag. clantag, tag color)
178 g_bVIP[client] = false;
179 g_bHealth[client] = false;
180 g_bGravity[client] = false;
181 g_bArmor[client] = false;
182 g_szPlayerTags[client][Tag_Chat][0] = 0;
183 g_szPlayerTags[client][Tag_Clan][0] = 0;
184 g_szColors[client][Color_Tag][0] = 0;
185 g_szColors[client][Color_Name][0] = 0;
186 g_szColors[client][Color_Chat][0] = 0;
187 g_iDaysLeft[client] = 0;
188 g_iTagEditing[client] = TagEdit_None;
189}
190
191
192
193public Action Event_PlayerSpawn(Event event, char[] name, bool dontBroadcast)
194{
195 int iClient = GetClientOfUserId(event.GetInt("userid"));
196 if (g_bVIP[iClient] && IsPlayerAlive(iClient))
197 {
198 CS_SetClientClanTag(iClient, g_szPlayerTags[iClient][Tag_Clan]);
199
200 if (g_bHealth[iClient] && g_cHealthBonus.IntValue)
201 {
202 PrintToChat(iClient, "%s You spawned with \x07%i HP Bonus\x01.", PREFIX, g_cHealthBonus.IntValue);
203 SetEntityHealth(iClient, GetClientHealth(iClient) + g_cHealthBonus.IntValue);
204 }
205
206 if (g_bGravity[iClient] && g_cGravityBonus.IntValue)
207 {
208 SetEntityGravity(iClient, 0.1);
209 }
210
211 if (g_bArmor[iClient] && g_cArmorBonus.BoolValue)
212 {
213 PrintToChat(iClient, "%s You spawned with \x07Full Armor\x01.", PREFIX);
214 SetEntProp(iClient, Prop_Send, "m_ArmorValue", 100, 1);
215 SetEntProp(iClient, Prop_Send, "m_bHasHelmet", 1);
216 }
217
218 if (g_cPistolBonus.BoolValue)
219 Menus_ShowPistols(iClient);
220
221 if (g_cPlayerSkins.BoolValue)
222 {
223 SkinTeam stTeam = GetClientTeam(iClient) == CS_TEAM_T ? Skin_Team_T:Skin_Team_CT;
224 if (!StrEqual(g_szPlayerSkins[iClient][stTeam], ""))
225 {
226 SetEntityModel(iClient, g_szPlayerSkins[iClient][stTeam]);
227 if(!StrEqual(GetSkinArms(g_szPlayerSkins[iClient][stTeam]), ""))
228 SetEntPropString(iClient, Prop_Send, "m_szArmsModel", GetSkinArms(g_szPlayerSkins[iClient][stTeam]));
229 }
230 }
231
232 }
233}
234
235public Action OnClientSayCommand(int client, const char[] command, const char[] szArgs)
236{
237 if (g_iTagEditing[client] != TagEdit_None)
238 {
239 if (StrEqual(szArgs, "-1"))
240 {
241 PrintToChat(client, "%s Operation aborted.", PREFIX);
242 g_iTagEditing[client] = TagEdit_None;
243 Menus_ShowGeneric(client);
244 return Plugin_Handled;
245 }
246
247 if (!IsTagAllowed(szArgs))
248 {
249 PrintToChat(client, "%s This tag contains forbidden words.", PREFIX);
250 g_iTagEditing[client] = TagEdit_None;
251 Menus_ShowGeneric(client);
252 return Plugin_Handled;
253 }
254
255 if (g_iTagEditing[client] == TagEdit_Chat)
256 {
257 strcopy(g_szPlayerTags[client][Tag_Chat], sizeof(g_szPlayerTags), szArgs);
258 }
259 else
260 {
261 strcopy(g_szPlayerTags[client][Tag_Clan], sizeof(g_szPlayerTags), szArgs);
262 CS_SetClientClanTag(client, g_szPlayerTags[client][Tag_Clan]);
263 }
264
265 SQL_UpdatePerk(client, g_iTagEditing[client] == TagEdit_Chat ? "chatTag":"clanTag", g_iTagEditing[client] == TagEdit_Chat ? g_szPlayerTags[client][Tag_Chat]:g_szPlayerTags[client][Tag_Clan]);
266
267 g_iTagEditing[client] = TagEdit_None;
268 PrintToChat(client, "%s Successfully changed your %s tag to \x02%s\x01.", PREFIX, g_iTagEditing[client] == TagEdit_Chat ? "chat":"clan", szArgs);
269 return Plugin_Handled
270 }
271 return Plugin_Continue;
272}
273
274public Action CP_OnChatMessage(int & author, ArrayList recipients, char[] flagstring, char[] name, char[] message, bool & processcolors, bool & removecolors)
275{
276 if (g_bVIP[author])
277 {
278 Format(name, MAX_NAME_LENGTH, " \x01%s[%s] \x03%s%s\x01", g_szColors[author][Color_Tag], (StrEqual(g_szPlayerTags[author][Tag_Chat], "") || StrEqual(g_szPlayerTags[author][Tag_Chat], "none")) ? "V.I.P":g_szPlayerTags[author][Tag_Chat], g_szColors[author][Color_Name], name);
279 Format(message, MAXLENGTH_MESSAGE, "%s %s", g_szColors[author][Color_Chat], message);
280 return Plugin_Changed;
281 }
282 return Plugin_Continue;
283}
284
285/* Commands */
286public Action Command_GetVIP(int client, int args)
287{
288 if (args != 1)
289 {
290 ReplyToCommand(client, "%s Usage: /getvip <cdkey>", PREFIX);
291 return Plugin_Handled;
292 }
293 char szArg[512];
294 char query[512];
295 char szQuery[512];
296 GetCmdArg(1, szArg, sizeof(szArg));
297 Format(query, sizeof(query),"SELECT `DAYS` FROM `%sCode` WHERE VIPKEY='%s';",GetTablePrefix(), szArg);
298 g_dDatabase.Query(DaysCallBack,query,client)
299
300 FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%sCode` WHERE `VIPKEY` = '%s'",GetTablePrefix(), szArg);
301 g_dDatabase.Query(SQL_CheckForErrors, szQuery, client);
302 return Plugin_Handled;
303}
304public void DaysCallBack(Database db, DBResultSet results, const char[] error, any data)
305{
306 int client = data;
307 if (results.FetchRow())
308 {
309 int iDays = results.FetchInt(0);
310 if(iDays>0)
311 {
312 char szStamp[512];
313 char szNewStamp[512];
314 Format(szStamp, sizeof(szStamp), "%i", GetTime() + (iDays * 86400));
315 Format(szNewStamp, sizeof(szNewStamp), "%i", GetTime() + ((iDays+g_iDaysLeft[client]) * 86400));
316 PrintToChat(client, "%s Trying to give \x02%N \x01a vip access...", PREFIX, client);
317 char szQuery[512];
318 if (g_bVIP[client])
319 FormatEx(szQuery, sizeof(szQuery), "UPDATE `%sUsers` SET `expireStamp`= '%s' WHERE `authId` = '%s'", GetTablePrefix(), szNewStamp, g_szAuth[client]);
320 else
321 FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `%sUsers` (`authId`, `expireStamp`) VALUES ('%s', '%s')", GetTablePrefix(), g_szAuth[client], szStamp);
322 g_dDatabase.Query(SQL_CheckForErrors, szQuery, GetClientSerial(client));
323
324 SQL_FetchUser(client);
325 PrintToChat(client, "%s Successfully gave \x02%N \x01a vip access...", PREFIX, client);
326 }
327 }
328 else
329 {
330 PrintToChat(client, "%s cdkey invalid", PREFIX);
331 }
332}
333public Action Command_AddVIP(int client, int args)
334{
335 if (args != 2)
336 {
337 ReplyToCommand(client, "%s Usage: sm_addvip <#userid|name> <days>", PREFIX);
338 return Plugin_Handled;
339 }
340
341 char szArg[32], szArg2[10];
342 GetCmdArg(1, szArg, sizeof(szArg));
343 int iTarget = FindTarget(client, szArg, true, true);
344 if (iTarget == -1)
345 return Plugin_Handled;
346
347 GetCmdArg(2, szArg2, sizeof(szArg2));
348 int iDays = StringToInt(szArg2);
349
350 if (iDays <= 0)
351 {
352 ReplyToCommand(client, "%s The time must be greater than zero.", PREFIX);
353 return Plugin_Handled;
354 }
355
356 char szStamp[32];
357 Format(szStamp, sizeof(szStamp), "%i", GetTime() + (iDays * 86400));
358
359 PrintToChat(client, "%s Trying to give \x02%N \x01a vip access...", PREFIX, iTarget);
360
361 char szQuery[512];
362 if (g_bVIP[iTarget])
363 FormatEx(szQuery, sizeof(szQuery), "UPDATE `%sUsers` SET `expireStamp`= '%s' WHERE `authId` = '%s'", GetTablePrefix(), szStamp, g_szAuth[iTarget]);
364 else
365 FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `%sUsers` (`authId`, `expireStamp`) VALUES ('%s', '%s')", GetTablePrefix(), g_szAuth[iTarget], szStamp);
366 g_dDatabase.Query(SQL_CheckForErrors, szQuery, GetClientSerial(iTarget));
367
368 SQL_FetchUser(iTarget);
369 PrintToChat(client, "%s Successfully gave \x02%N \x01a vip access...", PREFIX, iTarget);
370 return Plugin_Handled;
371}
372
373public Action Command_RemoveVIP(int client, int args)
374{
375 if (args != 1)
376 {
377 ReplyToCommand(client, "%s Usage: sm_removevip <#userid|name>", PREFIX);
378 return Plugin_Handled;
379 }
380
381 char szArg[32];
382 GetCmdArg(1, szArg, sizeof(szArg));
383 int iTarget = FindTarget(client, szArg, true, true);
384 if (iTarget == -1)
385 return Plugin_Handled;
386
387 if (!g_bVIP[iTarget])
388 {
389 ReplyToCommand(client, "%s Target does not have a vip access.", PREFIX);
390 return Plugin_Handled;
391 }
392
393 PrintToChat(client, "%s Trying to remove \x02%N\x01's vip access.", PREFIX, iTarget);
394
395 char szQuery[512];
396 FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%sUsers` WHERE `authId` = '%s'", GetTablePrefix(), g_szAuth[iTarget]);
397 g_dDatabase.Query(SQL_CheckForErrors, szQuery, GetClientSerial(iTarget));
398 FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%sPerks` WHERE `authId` = '%s'", GetTablePrefix(), g_szAuth[iTarget]);
399 g_dDatabase.Query(SQL_CheckForErrors, szQuery, GetClientSerial(iTarget));
400
401 PrintToChat(client, "%s Successfully removed \x02%N\x01's vip access.", PREFIX, iTarget);
402 return Plugin_Handled;
403}
404
405public Action Command_VIPMenu(int client, int args)
406{
407 if (!g_bVIP[client])
408 {
409 ReplyToCommand(client, "%s This command is for \x02VIP \x01users only.", PREFIX);
410 return Plugin_Handled;
411 }
412
413 Menus_ShowMain(client);
414 return Plugin_Handled;
415}
416
417/* Menus */
418
419void Menus_ShowMain(int client)
420{
421 Menu menu = new Menu(Handler_MainMenu);
422 menu.SetTitle("%s Main Menu [%i Days Left]\n ", PREFIX_MENU, g_iDaysLeft[client]);
423
424 menu.AddItem("generic", "Generic Perks");
425 menu.AddItem("special", "Special Perks");
426
427 menu.Display(client, MENU_TIME_FOREVER);
428}
429
430public int Handler_MainMenu(Menu menu, MenuAction action, int client, int itemNum)
431{
432 if (action == MenuAction_Select)
433 {
434 switch (itemNum)
435 {
436 case 0:Menus_ShowGeneric(client);
437 case 1:Menus_ShowSpecial(client);
438 }
439 }
440}
441
442void Menus_ShowGeneric(int client)
443{
444 Menu menu = new Menu(Handler_GenericMenu);
445 menu.SetTitle("%s Generic Menu\n ", PREFIX_MENU);
446
447 menu.AddItem("tag", "Manage Chat Tag");
448 menu.AddItem("ctag", "Manage Clan Tag");
449 menu.AddItem("tagcolor", "Manage Tag Color");
450 menu.AddItem("namecolor", "Manage Name Color");
451 menu.AddItem("chatcolor", "Manage Chat Color");
452
453 menu.ExitBackButton = true;
454 menu.Display(client, MENU_TIME_FOREVER);
455}
456
457public int Handler_GenericMenu(Menu menu, MenuAction action, int client, int itemNum)
458{
459 if (action == MenuAction_Cancel && itemNum == MenuCancel_ExitBack)
460 {
461 Menus_ShowMain(client);
462 } else if (action == MenuAction_Select) {
463 switch (itemNum)
464 {
465 case 0:
466 {
467 PrintToChat(client, "%s Type whatever you want in the chat or type \x02-1 \x01to abort.", PREFIX);
468 g_iTagEditing[client] = TagEdit_Chat;
469 }
470 case 1:
471 {
472 PrintToChat(client, "%s Type whatever you want in the chat or type \x02-1 \x01to abort.", PREFIX);
473 g_iTagEditing[client] = TagEdit_Clan;
474 }
475 case 2:
476 {
477 Menus_ShowColors(client, Color_Tag);
478 }
479 case 3:
480 {
481 Menus_ShowColors(client, Color_Name);
482 }
483 case 4:
484 {
485 Menus_ShowColors(client, Color_Chat);
486 }
487 }
488 }
489}
490
491void Menus_ShowColors(int client, ColorType color)
492{
493 Menu menu = new Menu(Handler_ColorsMenu);
494 menu.SetTitle("%s Select a Color\n ", PREFIX_MENU);
495
496 char szBuffer[10];
497 IntToString(view_as<int>(color), szBuffer, sizeof(szBuffer));
498 menu.AddItem(szBuffer, "Default");
499 menu.AddItem("\x02", "Strong Red");
500 menu.AddItem("\x03", "Team Color");
501 menu.AddItem("\x04", "Green");
502 menu.AddItem("\x05", "Turquoise");
503 menu.AddItem("\x06", "Yellow-Green");
504 menu.AddItem("\x07", "Light Red");
505 menu.AddItem("\x08", "Gray");
506 menu.AddItem("\x09", "Light Yellow");
507 menu.AddItem("\x0A", "Light Blue");
508 menu.AddItem("\x0C", "Purple");
509 menu.AddItem("\x0E", "Pink");
510 menu.AddItem("\x10", "Orange");
511
512 menu.ExitBackButton = true;
513 menu.Display(client, MENU_TIME_FOREVER);
514}
515
516public int Handler_ColorsMenu(Menu menu, MenuAction action, int client, int itemNum)
517{
518 if (action == MenuAction_Cancel && itemNum == MenuCancel_ExitBack)
519 {
520 Menus_ShowGeneric(client);
521 } else if (action == MenuAction_Select) {
522 char szColor[10], szColumn[32];
523 menu.GetItem(0, szColor, sizeof(szColor));
524
525 ColorType iColor = view_as<ColorType>(StringToInt(szColor));
526 switch (iColor)
527 {
528 case Color_Tag:Format(szColumn, sizeof(szColumn), "tagColor");
529 case Color_Name:Format(szColumn, sizeof(szColumn), "nameColor");
530 case Color_Chat:Format(szColumn, sizeof(szColumn), "chatColor");
531 }
532
533 char szInfo[32], szColorName[64];
534 menu.GetItem(itemNum, szInfo, sizeof(szInfo), _, szColorName, sizeof(szColorName));
535
536 strcopy(g_szColors[client][iColor], sizeof(g_szColors), szInfo);
537 SQL_UpdatePerk(client, szColumn, szInfo);
538
539 PrintToChat(client, "%s You changed your color to: %s%s\x01.", PREFIX, szInfo, szColorName);
540 }
541}
542
543void Menus_ShowSpecial(int client)
544{
545 Menu menu = new Menu(Handler_SpecialMenu);
546 menu.SetTitle("%s Special Perks\n ", PREFIX_MENU);
547
548 char szBuffer[128];
549 Format(szBuffer, sizeof(szBuffer), "[%s] HP Bonus", g_bHealth[client] ? "✔️" : "❌");
550 menu.AddItem("hpbonus", szBuffer, g_cHealthBonus.BoolValue ? ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
551
552 Format(szBuffer, sizeof(szBuffer), "[%s] Armor Bonus", g_bArmor[client] ? "✔️" : "❌");
553 menu.AddItem("armorbonus", szBuffer, g_cArmorBonus.BoolValue ? ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
554 menu.AddItem("skins", "Skins Menu", g_cPlayerSkins.BoolValue ? ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
555
556 Format(szBuffer, sizeof(szBuffer), "[%s] Gravity Bonus", g_bGravity[client] ? "✔️" : "❌");
557 menu.AddItem("gravitybonus", szBuffer, g_cGravityBonus.BoolValue ? ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
558
559 menu.ExitBackButton = true;
560 menu.Display(client, MENU_TIME_FOREVER);
561
562}
563
564public int Handler_SpecialMenu(Menu menu, MenuAction action, int client, int itemNum)
565{
566 if (action == MenuAction_Cancel && itemNum == MenuCancel_ExitBack)
567 {
568 Menus_ShowMain(client);
569 } else if (action == MenuAction_Select) {
570 switch (itemNum)
571 {
572 case 0:
573 {
574 g_bHealth[client] = !g_bHealth[client];
575 Menus_ShowSpecial(client);
576 PrintToChat(client, "%s Health bonus is now: %s\x01.", PREFIX, g_bHealth[client] ? "\x04Enabled":"\x02Disabled");
577 }
578 case 1:
579 {
580 g_bArmor[client] = !g_bArmor[client];
581 Menus_ShowSpecial(client);
582 PrintToChat(client, "%s Armor bonus is now: %s\x01.", PREFIX, g_bArmor[client] ? "\x04Enabled":"\x02Disabled");
583 }
584 case 2:
585 {
586 Menus_SkinsMain(client);
587 }
588 case 3:
589 {
590 g_bGravity[client] = !g_bGravity[client];
591 Menus_ShowSpecial(client);
592 PrintToChat(client, "%s Gravity bonus is now: %s\x01.", PREFIX, g_bGravity[client] ? "\x04Enabled":"\x02Disabled");
593 }
594 }
595 }
596}
597
598void Menus_SkinsMain(int client)
599{
600 Menu menu = new Menu(Handler_SkinsMenu);
601 menu.SetTitle("%s Choose a Team\n ", PREFIX_MENU);
602 menu.AddItem("ct", "Terrorist");
603 menu.AddItem("t", "Counter-Terrorist");
604 menu.ExitBackButton = true;
605 menu.Display(client, MENU_TIME_FOREVER);
606}
607
608public int Handler_SkinsMenu(Menu menu, MenuAction action, int client, int itemNum)
609{
610 if (action == MenuAction_Cancel && itemNum == MenuCancel_ExitBack)
611 {
612 Menus_ShowSpecial(client);
613 } else if (action == MenuAction_Select) {
614 Menus_SkinsSelection(client, itemNum);
615 }
616}
617
618void Menus_SkinsSelection(int client, int team)
619{
620 SkinTeam iTeam = view_as<SkinTeam>(team);
621 Menu menu = new Menu(Handler_SkinsSelection);
622 menu.SetTitle("%s Choose a Skin\n ", PREFIX_MENU);
623
624 char szBuffer[64], szType[10];
625 Format(szBuffer, sizeof(szBuffer), "No Skin%s", g_szPlayerSkins[client][iTeam][0] == 0 ? " [Equipped]":"");
626 IntToString(view_as<int>(iTeam), szType, sizeof(szType));
627 menu.AddItem(szType, szBuffer, g_szPlayerSkins[client][iTeam][0] == 0 ? ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
628
629 for (int i = 0; i < g_iSkins; i++)
630 {
631 if (view_as<SkinTeam>(StringToInt(g_szSkins[i][Skin_Team])) == iTeam)
632 {
633 Format(szBuffer, sizeof(szBuffer), "%s%s", g_szSkins[i][Skin_Name], StrEqual(g_szPlayerSkins[client][iTeam], g_szSkins[i][Skin_Model]) ? " [Equipped]":"");
634 menu.AddItem(g_szSkins[i][Skin_Model], szBuffer, StrEqual(g_szPlayerSkins[client][iTeam], g_szSkins[i][Skin_Model]) ? ITEMDRAW_DISABLED:ITEMDRAW_DEFAULT);
635 }
636 }
637
638 menu.ExitBackButton = true;
639 menu.Display(client, MENU_TIME_FOREVER);
640}
641
642public int Handler_SkinsSelection(Menu menu, MenuAction action, int client, int itemNum)
643{
644 if (action == MenuAction_Cancel && itemNum == MenuCancel_ExitBack)
645 {
646 Menus_SkinsMain(client);
647 } else if (action == MenuAction_Select) {
648 char szTeam[10];
649 menu.GetItem(0, szTeam, sizeof(szTeam));
650 SkinTeam iTeam = view_as<SkinTeam>(StringToInt(szTeam));
651
652 char szInfo[512], szName[64];
653 menu.GetItem(itemNum, szInfo, sizeof(szInfo), _, szName, sizeof(szName));
654
655 if (itemNum)
656 strcopy(g_szPlayerSkins[client][iTeam], sizeof(g_szPlayerSkins), szInfo);
657 else
658 {
659 g_szPlayerSkins[client][iTeam][0] = 0;
660 szInfo = ""; //fix database model set 0 crash server
661 }
662 SQL_UpdatePerk(client, iTeam == Skin_Team_T ? "tSkin":"ctSkin", szInfo);
663
664 Menus_SkinsSelection(client, view_as<int>(iTeam));
665 PrintToChat(client, "%s You changed your skin to: \x02%s\x01.", PREFIX, szName);
666 }
667}
668
669void Menus_ShowPistols(int client)
670{
671 Menu menu = new Menu(Handler_PistolsMenu);
672 menu.SetTitle("%s Select a Pistol\n ", PREFIX_MENU);
673
674 menu.AddItem("weapon_usp_silencer", "USP-S");
675 menu.AddItem("weapon_glock", "Glock");
676 menu.AddItem("weapon_p250", "P250");
677 menu.AddItem("weapon_deagle", "Desert Eagle");
678 menu.AddItem("weapon_cz75a", "CZ75");
679 menu.AddItem("weapon_fiveseven", "Five-Seven");
680 menu.AddItem("weapon_revolver", "Revolver");
681 menu.AddItem("weapon_elite", "Dual Berettas");
682 menu.AddItem("weapon_hkp2000", "P200");
683 menu.AddItem("weapon_tec9", "Tec-9");
684
685 menu.Display(client, MENU_TIME_FOREVER);
686}
687
688public int Handler_PistolsMenu(Menu menu, MenuAction action, int client, int itemNum)
689{
690 if (action == MenuAction_Select)
691 {
692 char szInfo[32], szName[32];
693 menu.GetItem(itemNum, szInfo, sizeof(szInfo), _, szName, sizeof(szName));
694
695 int iWeapon = GetPlayerWeaponSlot(client, CS_SLOT_SECONDARY);
696 if (iWeapon != -1)
697 AcceptEntityInput(iWeapon, "kill");
698
699 GivePlayerItem(client, szInfo);
700 PrintToChat(client, "%s You chose to play with: \x07%s\x01.", PREFIX, szName);
701 }
702}
703
704/* Database */
705
706void SQL_MakeConnection()
707{
708 if (g_dDatabase != null)
709 delete g_dDatabase;
710
711 char szError[512];
712 g_dDatabase = SQL_Connect("vip", true, szError, sizeof(szError));
713 if (g_dDatabase == null)
714 {
715 SetFailState("Cannot connect to datbase error: %s", szError);
716 }
717
718 char szQuery[512];
719 FormatEx(szQuery, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS `%sUsers` (`authId` VARCHAR(32) NOT NULL, `expireStamp` INT NOT NULL, UNIQUE (`authId`));", GetTablePrefix());
720 g_dDatabase.Query(SQL_CheckForErrors, szQuery);
721 FormatEx(szQuery, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS `%sPerks`(`authId` VARCHAR(32) NOT NULL PRIMARY KEY, `chatTag` VARCHAR(512) NOT NULL DEFAULT '', `clanTag` VARCHAR(512) NOT NULL DEFAULT '', `tagColor` VARCHAR(16) NOT NULL DEFAULT '', `nameColor` VARCHAR(16) NOT NULL DEFAULT '', `chatColor` VARCHAR(16) NOT NULL DEFAULT '', `hpBonus` INT(10) NOT NULL DEFAULT 0, `armorBonus` INT(10) NOT NULL DEFAULT 0, `tSkin` VARCHAR(512) NOT NULL DEFAULT '', `ctSkin` VARCHAR(512) NOT NULL DEFAULT '',UNIQUE (`authId`))", GetTablePrefix());
722 g_dDatabase.Query(SQL_CheckForErrors, szQuery);
723 FormatEx(szQuery, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS `%sCode`(`VIPKEY` VARCHAR(32) NOT NULL, `DAYS` INT(10) NOT NULL DEFAULT 30)", GetTablePrefix());
724 g_dDatabase.Query(SQL_CheckForErrors, szQuery);
725 for (int i = 1; i <= MaxClients; i++)
726 {
727 if (IsClientInGame(i))
728 OnClientPostAdminCheck(i);
729 }
730}
731
732void SQL_FetchUser(int client)
733{
734 char szQuery[512];
735 FormatEx(szQuery, sizeof(szQuery), "SELECT `expireStamp` FROM `%sUsers` WHERE `authId` = '%s'", GetTablePrefix(), g_szAuth[client]);
736 g_dDatabase.Query(SQL_FetchUser_CB, szQuery, GetClientSerial(client));
737}
738
739public void SQL_FetchUser_CB(Database db, DBResultSet results, const char[] error, any data)
740{
741 int iClient = GetClientFromSerial(data);
742 int onlineusers = GetClientCount(false);
743 int reserved = g_Vip_slots.IntValue;
744 if(!g_Vip_slots_enable)
745 reserved = 0;
746 int limit = GetMaxHumanPlayers() - reserved;
747 if (results == null)
748 {
749 if (iClient == 0)
750 {
751 LogError("Client is not valid. Reason: %s", error);
752 }
753 else
754 {
755 LogError("Cant use client data on insert. Reason: %s", error);
756 }
757 return;
758 }
759
760 if (results.FetchRow())
761 {
762 int iStamp = results.FetchInt(0);
763 int iDaysLeft = (iStamp - GetTime()) / 86400;
764 if (iDaysLeft > 0)
765 {
766 g_bVIP[iClient] = true;
767 g_iDaysLeft[iClient] = iDaysLeft;
768
769 SetHudTextParams(-1.0, 0.1, 7.0, 0, 255, 150, 255, 2, 6.0, 0.1, 0.2);
770 if (g_cVIPmessage.BoolValue)
771 {
772 for (int i = 1; i <= MaxClients; i++)
773 {
774 if (IsValidClient(i))
775 {
776 ShowHudText(i, 0, "VIP %N has connected", iClient);
777 }
778 }
779 }
780
781 /* Give Flags */
782 char szFlags[32];
783 g_cVipFlags.GetString(szFlags, sizeof(szFlags));
784 if (!StrEqual(szFlags, ""))
785 {
786 int iFlags = ReadFlagString(szFlags);
787 int iPlayerFlags = GetUserFlagBits(iClient);
788
789 bool bFlags[AdminFlags_TOTAL];
790 bool bPlayerFlags[AdminFlags_TOTAL];
791 bool bNewFlags[AdminFlags_TOTAL];
792
793 FlagBitsToBitArray(iFlags, bFlags, AdminFlags_TOTAL);
794 FlagBitsToBitArray(iPlayerFlags, bPlayerFlags, AdminFlags_TOTAL);
795
796 for (int i = 0; i < AdminFlags_TOTAL; i++)
797 {
798 if (bPlayerFlags[i] || bFlags[i])
799 bNewFlags[i] = true;
800 }
801
802 int iNewFlags = FlagBitArrayToBits(bNewFlags, AdminFlags_TOTAL)
803 SetUserFlagBits(iClient, iNewFlags);
804 }
805 /* */
806 /* kick someone in game*/
807
808 if ( limit< onlineusers)
809 {
810 int target = SelectKickClient();
811
812 if (target && g_Vip_slots_enable.BoolValue)
813 {
814 /* Kick public player to free the reserved slot again */
815 CreateTimer(0.1, OnTimedKick, target);
816 }
817 else
818 {
819 /* Kick player because there are no public slots left */
820 CreateTimer(0.1, OnTimedKick, iClient);
821 }
822 }
823 /* */
824 SQL_FetchPerks(iClient);
825 }
826 else if(iDaysLeft <= 0)
827 {
828 char szQuery[512];
829 FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `%sUsers` WHERE `authId` = '%s'", GetTablePrefix(), g_szAuth[iClient]);
830 g_dDatabase.Query(SQL_CheckForErrors, szQuery, GetClientSerial(iClient));
831
832 if ( limit< onlineusers)
833 {
834 CreateTimer(0.1, OnTimedKick, iClient);
835 }
836 }
837 }
838
839 else if ( limit< onlineusers)
840 {
841 CreateTimer(0.1, OnTimedKick, iClient);
842 }
843}
844
845public Action OnTimedKick(Handle timer, any client)
846{
847 if (!client || !IsClientInGame(client))
848 {
849 return Plugin_Handled;
850 }
851 if(g_Vip_slots_enable.BoolValue)
852 KickClient(client, "Server is full, join our community for VIP slots");
853 else
854 KickClient(client, "Server is full");
855
856 return Plugin_Handled;
857}
858void SQL_FetchPerks(int client)
859{
860 char szQuery[512];
861 FormatEx(szQuery, sizeof(szQuery), "SELECT * FROM `%sPerks` WHERE `authId` = '%s'", GetTablePrefix(), g_szAuth[client]);
862 g_dDatabase.Query(SQL_FetchPerks_CB, szQuery, GetClientSerial(client));
863}
864
865public void SQL_FetchPerks_CB(Database db, DBResultSet results, const char[] error, any data)
866{
867 int iClient = GetClientFromSerial(data);
868 if (results == null)
869 {
870 if (iClient == 0)
871 {
872 LogError("Client is not valid. Reason: %s", error);
873 }
874 else
875 {
876 LogError("Cant use client data on insert. Reason: %s", error);
877 }
878 return;
879 }
880 if (results.FetchRow())
881 {
882 results.FetchString(1, g_szPlayerTags[iClient][Tag_Chat], sizeof(g_szPlayerTags));
883 results.FetchString(2, g_szPlayerTags[iClient][Tag_Clan], sizeof(g_szPlayerTags));
884 results.FetchString(3, g_szColors[iClient][Color_Tag], sizeof(g_szColors));
885 results.FetchString(4, g_szColors[iClient][Color_Name], sizeof(g_szColors));
886 results.FetchString(5, g_szColors[iClient][Color_Chat], sizeof(g_szColors));
887 g_bHealth[iClient] = view_as<bool>(results.FetchInt(6));
888 g_bArmor[iClient] = view_as<bool>(results.FetchInt(7));
889 g_bGravity[iClient] = view_as<bool>(results.FetchInt(8));
890 results.FetchString(8, g_szPlayerSkins[iClient][Skin_Team_T], sizeof(g_szPlayerSkins));
891 results.FetchString(9, g_szPlayerSkins[iClient][Skin_Team_CT], sizeof(g_szPlayerSkins));
892
893 CS_SetClientClanTag(iClient, g_szPlayerTags[iClient][Tag_Clan]);
894 } else {
895 SQL_RegisterPerks(iClient);
896 }
897}
898
899void SQL_RegisterPerks(int client)
900{
901 char szQuery[512];
902 FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `%sPerks` (`authId`) VALUES ('%s')", GetTablePrefix(), g_szAuth[client]);
903 g_dDatabase.Query(SQL_CheckForErrors, szQuery);
904}
905
906void SQL_UpdatePerk(int client, char[] perk, char[] value)
907{
908 char szQuery[512];
909 FormatEx(szQuery, sizeof(szQuery), "UPDATE `%sPerks` SET `%s` = '%s' WHERE `authId` = '%s'", GetTablePrefix(), perk, value, g_szAuth[client]);
910 g_dDatabase.Query(SQL_CheckForErrors, szQuery);
911}
912
913public void SQL_CheckForErrors(Database db, DBResultSet results, const char[] error, any data)
914{
915 if (!StrEqual(error, ""))
916 {
917 LogError("Databse error, %s", error);
918 return;
919 }
920}
921
922/* Stocks, Functions */
923
924void LoadSkins()
925{
926 char szPath[512];
927 BuildPath(Path_SM, szPath, sizeof(szPath), "configs/vip/skins.txt");
928 if (!FileExists(szPath))
929 SetFailState("Couldn't find file: %s", szPath);
930
931 KeyValues kConfig = new KeyValues("");
932 kConfig.ImportFromFile(szPath);
933 kConfig.JumpToKey("Skins");
934 kConfig.GotoFirstSubKey();
935
936 do {
937 kConfig.GetString("name", g_szSkins[g_iSkins][Skin_Name], sizeof(g_szSkins));
938 kConfig.GetString("model", g_szSkins[g_iSkins][Skin_Model], sizeof(g_szSkins));
939 kConfig.GetString("arms", g_szSkins[g_iSkins][Skin_Arms], sizeof(g_szSkins));
940 kConfig.GetString("team", g_szSkins[g_iSkins][Skin_Team], sizeof(g_szSkins));
941 PrecacheModel(g_szSkins[g_iSkins][Skin_Model]);
942 g_iSkins++;
943 } while (kConfig.GotoNextKey())
944}
945
946void LoadBlockedTags()
947{
948 char szPath[512];
949 BuildPath(Path_SM, szPath, sizeof(szPath), "configs/vip/blockedtags.txt");
950 if (!FileExists(szPath))
951 SetFailState("Couldn't find file: %s", szPath);
952
953 Handle hFile = OpenFile(szPath, "r");
954 char szLine[64];
955 do {
956 if (IsValidString(szLine))
957 g_aBlockedTags.PushString(szLine);
958 } while (!IsEndOfFile(hFile) && ReadFileLine(hFile, szLine, sizeof(szLine)))
959}
960
961stock bool IsTagAllowed(const char[] tag)
962{
963 for (int i = 0; i < g_aBlockedTags.Length; i++)
964 {
965 char szBuffer[64];
966 g_aBlockedTags.GetString(i, szBuffer, sizeof(szBuffer));
967 if (StrContains(tag, szBuffer, false) != -1)
968 return false;
969 }
970 return true;
971}
972
973stock bool IsValidString(char[] string)
974{
975 int iCount;
976 for (int i = 0; i <= strlen(string); i++)
977 {
978 if (IsCharAlpha(string[i]) || IsCharNumeric(string[i]))
979 iCount++;
980 }
981
982 return iCount ? true:false;
983}
984
985stock bool IsValidClient(int client)
986{
987 if (client <= 0 || client > MaxClients || !IsClientConnected(client))
988 {
989 return false;
990 }
991 return IsClientInGame(client);
992}
993
994stock char GetTablePrefix()
995{
996 char szPrefix[512];
997 g_cTablePrefix.GetString(szPrefix, sizeof(szPrefix));
998 return szPrefix;
999}
1000
1001stock char GetSkinArms(char[] skinModel)
1002{
1003 char szArms[512];
1004 for (int i = 0; i < g_iSkins; i++)
1005 {
1006 if(StrEqual(g_szSkins[i][Skin_Model], skinModel))
1007 strcopy(szArms, sizeof(szArms), g_szSkins[i][Skin_Arms]);
1008 }
1009
1010 return szArms;
1011}
1012int SelectKickClient()
1013{
1014 float highestValue;
1015 int highestValueId;
1016
1017 float highestSpecValue;
1018 int highestSpecValueId;
1019
1020 bool specFound;
1021
1022 float value;
1023
1024 for (int i=1; i<=MaxClients; i++)
1025 {
1026 if (!IsClientConnected(i))
1027 {
1028 continue;
1029 }
1030
1031 if (IsFakeClient(i) || g_bVIP[i])
1032 {
1033 continue;
1034 }
1035
1036 value = 0.0;
1037
1038 if (IsClientInGame(i))
1039 {
1040 value = GetClientTime(i);
1041 if (IsClientObserver(i))
1042 {
1043 specFound = true;
1044
1045 if (value > highestSpecValue)
1046 {
1047 highestSpecValue = value;
1048 highestSpecValueId = i;
1049 }
1050 }
1051 }
1052
1053 if (value >= highestValue)
1054 {
1055 highestValue = value;
1056 highestValueId = i;
1057 }
1058 }
1059
1060 if (specFound)
1061 {
1062 return highestSpecValueId;
1063 }
1064
1065 return highestValueId;
1066}