· 8 years ago · Jul 28, 2018, 04:18 PM
1/*
2 * CSGO VIP System Plugin
3 * Required: Mysql\SQL Database, Simple Chat Proccesor, SourceMod.
4 * Version: 3.7
5 * Author: S4muRaY'(BraveFox)
6 * Remake of my old system https://forums.alliedmods.net/showthread.php?p=2541503
7*/
8//Includes
9#include <sourcemod>
10#include <cstrike>
11#include <clientprefs>
12#include <sdktools>
13#include <scp>
14#include <csgovip>
15#define prefix " \x07[V.I.P]\x03 "
16//Database
17Database DB = null;
18//Handles
19Handle g_hVIPTag = INVALID_HANDLE, g_hVIPClanTag = INVALID_HANDLE, g_hVIPTagColor = INVALID_HANDLE, g_hVIPNameColor = INVALID_HANDLE, g_hVIPChatColor = INVALID_HANDLE, g_hEnabled = INVALID_HANDLE, g_hSkins = INVALID_HANDLE, g_hHealth = INVALID_HANDLE, g_hDefuse = INVALID_HANDLE, g_hArmor = INVALID_HANDLE, g_hHealthAmount = INVALID_HANDLE;
20//Chars
21char sModel[512][512], sName[512][512], g_sBlockedTags[512][512];
22//Bools
23bool g_bEnabled = true;
24bool g_bSkins = true;
25bool g_bHP = true;
26bool g_bDefuse = true;
27bool g_bFullArmor = true;
28//Client's Chars
29char g_sClanTag[MAXPLAYERS + 1][512];
30char g_sChatColor[MAXPLAYERS + 1][512];
31char g_sNameColor[MAXPLAYERS + 1][512];
32char g_sTagColor[MAXPLAYERS + 1][512];
33char g_sTag[MAXPLAYERS + 1][512];
34char g_sClientSkin[MAXPLAYERS + 1][512];
35//Client's Bools
36bool g_bIsClientVIP[MAXPLAYERS + 1] = false;
37bool g_bArmor[MAXPLAYERS + 1] = false;
38bool g_bIsTypingTag[MAXPLAYERS + 1] = false;
39bool g_bIsTypingClanTag[MAXPLAYERS + 1] = false;
40bool g_bHealth[MAXPLAYERS + 1] = false;
41bool g_bDefusekit[MAXPLAYERS + 1] = false;
42//Client's Integers
43int g_iTimeLeft[MAXPLAYERS + 1] = 0;
44//Integer
45int g_iSkins;
46int g_iRounds = 0;
47int g_iBlockedTags = 0;
48int g_iHealthBonus = 1;
49public Plugin myinfo =
50{
51 name = "[CSGO]VIP System",
52 author = "S4muRaY'(BraveFox)",
53 description = "Advanced VIP system",
54 version = "3.7",
55 url = ""
56};
57
58public void OnPluginStart()
59{
60 SQL_StartConnection();
61 //Translations
62 LoadTranslations("common.phrases");
63 //Cvars
64 g_hEnabled = CreateConVar("sm_vipsystem_enabled", "1", "Enable the vip system?", 0, true, 0.0, true, 1.0);
65 g_hSkins = CreateConVar("sm_vipsystem_skins", "1", "Allow vip players to use player skins?", 0, true, 0.0, true, 1.0);
66 g_hHealth = CreateConVar("sm_vipsystem_health", "1", "Allow vip players to use hp bonus?", 0, true, 0.0, true, 1.0);
67 g_hDefuse = CreateConVar("sm_vipsystem_defuse", "1", "Allow vip players to use defuse kit bonus?", 0, true, 0.0, true, 1.0);
68 g_hArmor = CreateConVar("sm_vipsystem_armor", "1", "Allow vip players to use full armor bonus?", 0, true, 0.0, true, 1.0);
69 g_hHealthAmount = CreateConVar("sm_vipsystem_health_amount", "10", "How much hp bonus will VIP players can get if hp bonus is enabled? (Default 10)", 0, true, 1.0, true, 999999999.0);
70 //Hook Cvars Change
71 HookConVarChange(g_hEnabled, OnCvarChange_Enabled);
72 HookConVarChange(g_hSkins, OnCvarChange_Skins);
73 HookConVarChange(g_hHealth, OnCvarChange_Health);
74 HookConVarChange(g_hDefuse, OnCvarChange_Defuse);
75 HookConVarChange(g_hArmor, OnCvarChange_Armor);
76 HookConVarChange(g_hHealthAmount, OnCvarChange_HealthAmount);
77 //Auto exec config
78 AutoExecConfig(true, "s4muray_vipsystem");
79 //Cookies
80 g_hVIPTag = RegClientCookie("VIPSystemTags", "Saving the VIP's chat tags here", CookieAccess_Protected);
81 g_hVIPClanTag = RegClientCookie("VIPSystemCTags", "Saving the VIP's clan tags here", CookieAccess_Protected);
82 g_hVIPTagColor = RegClientCookie("VIPSystemTagColor", "Saving the VIP's tag colors here", CookieAccess_Protected);
83 g_hVIPNameColor = RegClientCookie("VIPSystemNameColor", "Saving the VIP's name colors here", CookieAccess_Protected);
84 g_hVIPChatColor = RegClientCookie("VIPSystemChatColor", "Saving the VIP's chat colors here", CookieAccess_Protected);
85 //Custom Tags From Menu
86 AddCommandListener(OnSay, "say");
87 AddCommandListener(OnSay, "say_team");
88 //Hooks
89 HookEvent("player_spawn", player_spawn);
90 HookEvent("round_start", rounds);
91 HookEvent("round_end", rounds);
92 //Commands
93 RegAdminCmd("sm_addvip", Command_AddVIP, ADMFLAG_ROOT);
94 RegAdminCmd("sm_removevip", Command_RemoveVIP, ADMFLAG_ROOT);
95 RegConsoleCmd("sm_vip", Command_VIPMenu);
96 RegConsoleCmd("sm_vips", Command_VIPMenu);
97 RegConsoleCmd("sm_tag", Command_Tag);
98 RegConsoleCmd("sm_tagcolor", Command_TagColor);
99 RegConsoleCmd("sm_namecolor", Command_NameColor);
100 RegConsoleCmd("sm_chatcolor", Command_ChatColor);
101 RegConsoleCmd("sm_clantag", Command_ClanTag);
102 //RegConsoleCmd("sm_skins", Command_Skins);
103 //For expire and time left
104 CreateTimer(60.0, Timer_CheckPlayersTime, _, TIMER_REPEAT);
105 for (int i = 0; i <= MaxClients; i++)
106 {
107 if (IsValidClient(i))
108 {
109 OnClientPostAdminCheck(i);
110 }
111 }
112}
113//Natives
114public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
115{
116 CreateNative("CSGOVIP_SetVIP", Native_SetVIP);
117 CreateNative("CSGOVIP_IsClientVIP", Native_IsClientVIP);
118 return APLRes_Success;
119}
120public int Native_SetVIP(Handle plugin, int numParams)
121{
122 int client = GetNativeCell(1);
123 if (client < 1 || client > MaxClients)
124 {
125 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client);
126 }
127 if (!IsClientConnected(client))
128 {
129 return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client);
130 }
131 bool test = GetNativeCell(2);
132 g_bIsClientVIP[client] = test;
133 return true;
134}
135public int Native_IsClientVIP(Handle plugin, int numParams)
136{
137 int client = GetNativeCell(1);
138 if (client < 1 || client > MaxClients)
139 {
140 return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index (%d)", client);
141 }
142 if (!IsClientConnected(client))
143 {
144 return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not connected", client);
145 }
146 return g_bIsClientVIP[client];
147}
148//Convars
149public void OnCvarChange_Enabled(ConVar cvar, char[] oldvalue, char[] newvalue)
150{
151 if (StrEqual(newvalue, "1"))
152 g_bEnabled = true;
153 else if (StrEqual(newvalue, "0"))
154 g_bEnabled = false;
155}
156public void OnCvarChange_Skins(ConVar cvar, char[] oldvalue, char[] newvalue)
157{
158 if (StrEqual(newvalue, "1"))
159 g_bSkins = true;
160 else if (StrEqual(newvalue, "0"))
161 g_bSkins = false;
162}
163public void OnCvarChange_Health(ConVar cvar, char[] oldvalue, char[] newvalue)
164{
165 if (StrEqual(newvalue, "1"))
166 g_bHP = true;
167 else if (StrEqual(newvalue, "0"))
168 g_bHP = false;
169}
170public void OnCvarChange_Defuse(ConVar cvar, char[] oldvalue, char[] newvalue)
171{
172 if (StrEqual(newvalue, "1"))
173 g_bDefuse = true;
174 else if (StrEqual(newvalue, "0"))
175 g_bDefuse = false;
176}
177public void OnCvarChange_Armor(ConVar cvar, char[] oldvalue, char[] newvalue)
178{
179 if (StrEqual(newvalue, "1"))
180 g_bFullArmor = true;
181 else if (StrEqual(newvalue, "0"))
182 g_bFullArmor = false;
183}
184public void OnCvarChange_HealthAmount(ConVar cvar, char[] oldvalue, char[] newvalue)
185{
186 if (!IsValueNumeric(newvalue))
187 {
188 g_iHealthBonus = StringToInt(oldvalue);
189 }
190 else {
191 g_iHealthBonus = StringToInt(newvalue);
192 }
193}
194//Voids
195public void OnMapStart()
196{
197 //Player Skins
198 g_iSkins = 0;
199 GetSkins();
200 ReadBlockedTags();
201}
202//Check Players
203public Action Timer_CheckPlayersTime(Handle timer)
204{
205 for (int i = 0; i <= MaxClients; i++)
206 {
207 if (IsValidClient(i))
208 {
209 OnClientPostAdminCheck(i);
210 }
211 }
212}
213public void OnClientPostAdminCheck(int client)
214{
215 if (!IsValidClient(client) || IsFakeClient(client))
216 {
217 return;
218 }
219 if (DB == null)
220 {
221 return;
222 }
223 char playername[MAX_NAME_LENGTH], steamid[32];
224 GetClientName(client, playername, MAX_NAME_LENGTH);
225 if (!GetClientAuthId(client, AuthId_Steam2, steamid, 32))
226 {
227 KickClient(client, "Verification problem please reconnect.");
228 return;
229 }
230
231 int iLength = ((strlen(playername) * 2) + 1);
232 char[] escapedname = new char[iLength];
233 DB.Escape(playername, escapedname, iLength);
234
235 char gB_ClientIP[64];
236 GetClientIP(client, gB_ClientIP, 64);
237
238 char gB_Query[512];
239 FormatEx(gB_Query, sizeof(gB_Query), "SELECT COUNT(*) FROM `users` WHERE expiredate > NOW() AND `steamid` = '%s'", steamid);
240 DB.Query(SQL_SelectPlayer_Callback, gB_Query, GetClientSerial(client), DBPrio_Normal);
241 //Other
242 Format(g_sTag[client], sizeof(g_sTag), "");
243 Format(g_sClanTag[client], sizeof(g_sTag), "");
244 char test[512];
245 GetClientCookie(client, g_hVIPTag, test, sizeof(test));
246 if (!StrEqual(test, "") && !StrEqual(test, "none"))
247 Format(g_sTag[client], sizeof(test), test);
248 GetClientCookie(client, g_hVIPClanTag, g_sClanTag[client], 512);
249 GetClientCookie(client, g_hVIPTagColor, test, sizeof(test));
250 if (!StrEqual(test, ""))
251 Format(g_sTagColor[client], sizeof(test), test);
252
253 GetClientCookie(client, g_hVIPNameColor, test, sizeof(test));
254 if (!StrEqual(test, ""))
255 Format(g_sNameColor[client], sizeof(test), test);
256
257 GetClientCookie(client, g_hVIPChatColor, test, sizeof(test));
258 if (!StrEqual(test, ""))
259 Format(g_sChatColor[client], sizeof(test), test);
260}
261public void OnClientDisconnect(int client)
262{
263 if (IsFakeClient(client))
264 {
265 return;
266 }
267 char steamid[32];
268 if (!GetClientAuthId(client, AuthId_Steam2, steamid, 32))
269 {
270 return;
271 }
272 if (!g_bIsClientVIP[client])
273 {
274 SQL_RemoveVIP(steamid);
275 }
276 if (g_bIsClientVIP[client])
277 {
278 SetHudTextParams(0.05, 0.1, 7.0, 0, 255, 150, 255, 2, 6.0, 0.1, 0.2);
279 for (int i = 1; i <= MaxClients; i++)
280 {
281 if (IsValidClient(i))
282 {
283 ShowHudText(i, -1, "VIP %N has disconnected from the server!", client);
284 }
285 }
286 g_bIsClientVIP[client] = false;
287 }
288 Format(g_sTag[client], sizeof(g_sTag), "");
289 Format(g_sClanTag[client], sizeof(g_sTag), "");
290}
291//Staff
292public Action OnSay(int client, const char[] command, int args)
293{
294 char text[4096];
295 GetCmdArgString(text, sizeof(text));
296 StripQuotes(text);
297 if (g_bIsTypingTag[client])
298 {
299 if (StrEqual(text, "!cancel") || StrEqual(text, "/cancel"))
300 {
301 PrintToChat(client, "%sTag Type Aborted", prefix);
302 g_bIsTypingTag[client] = false;
303 }
304 else {
305 bool block;
306 for (int k = 0; k <= g_iBlockedTags; k++)
307 {
308 if (StrEqual(g_sBlockedTags[k], text, false))
309 {
310 block = true;
311 }
312 }
313 if (block)
314 {
315 PrintToChat(client, "%sThis tag is not allowed!", prefix);
316 return Plugin_Handled;
317 }
318 Format(g_sTag[client], sizeof(g_sTag), text);
319 g_bIsTypingTag[client] = false;
320 if (StrEqual(text, "none"))
321 PrintToChat(client, "%sYou just reset your tag!", prefix);
322 else
323 PrintToChat(client, "%sYou changed your tag to '%s'", prefix, text);
324
325 SetClientCookie(client, g_hVIPTag, g_sTag[client]);
326 }
327 return Plugin_Handled;
328 }
329 if (g_bIsTypingClanTag[client])
330 {
331 if (StrEqual(text, "!cancel") || StrEqual(text, "/cancel"))
332 {
333 PrintToChat(client, "%sClan Tag Type Aborted", prefix);
334 g_bIsTypingClanTag[client] = false;
335 }
336 else {
337 bool block;
338 for (int k = 0; k <= g_iBlockedTags; k++)
339 {
340 if (StrEqual(g_sBlockedTags[k], text, false))
341 {
342 block = true;
343 }
344 }
345 if (block)
346 {
347 PrintToChat(client, "%sThis tag is not allowed!", prefix);
348 return Plugin_Handled;
349 }
350 Format(g_sClanTag[client], sizeof(g_sTag), text);
351 g_bIsTypingClanTag[client] = false;
352 if (StrEqual(text, "none"))
353 PrintToChat(client, "%sYou just reset your clan tag!", prefix);
354 else
355 {
356 PrintToChat(client, "%sYou changed your clan tag to '%s'", prefix, text);
357 CS_SetClientClanTag(client, g_sClanTag[client]);
358 }
359 SetClientCookie(client, g_hVIPClanTag, g_sClanTag[client]);
360 }
361 return Plugin_Handled;
362 }
363 return Plugin_Continue;
364}
365public Action rounds(Event event, char[] name, bool dontBroadcast)
366{
367 if (StrEqual(name, "round_start"))
368 g_iRounds++;
369}
370public Action player_spawn(Event event, char[] name, bool dontBroadcast)
371{
372 if (!g_bEnabled)return;
373 int client = GetClientOfUserId(event.GetInt("userid"));
374 if (g_bIsClientVIP[client])
375 {
376 if (g_bArmor[client] && g_bFullArmor)
377 {
378 SetEntProp(client, Prop_Send, "m_ArmorValue", 100, 1);
379 SetEntProp(client, Prop_Send, "m_bHasHelmet", 1);
380 PrintToChat(client, "%sYou spawned with \x04Full Armor\x01!", prefix);
381 }
382 if (g_bHealth[client] && g_bHP)
383 {
384 int hp = GetClientHealth(client);
385 SetEntityHealth(client, hp + 10);
386 PrintToChat(client, "%sYou recived a\x04 %d HP Bonus\x01!", prefix, g_iHealthBonus);
387 }
388 if (GetClientTeam(client) == CS_TEAM_CT && g_bDefusekit[client] && g_bDefuse)
389 {
390 PrintToChat(client, "%sYou recived a \x04defuse kit!", prefix);
391 SetEntProp(client, Prop_Send, "m_bHasDefuser", 1);
392 }
393 if (!StrEqual(g_sClanTag[client], "") && !StrEqual(g_sClanTag[client], "none"))
394 {
395 CS_SetClientClanTag(client, g_sClanTag[client]);
396 }
397 if (!StrEqual(g_sClientSkin[client], "") && g_bSkins)
398 CreateTimer(1.1, Timer_ApplySkin, client);
399 }
400}
401//Commands
402public int SkinsMenu(Menu menu, MenuAction action, int client, int itemNum)
403{
404 if (action == MenuAction_Select)
405 {
406 if (!g_bEnabled)
407 {
408 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
409 return;
410 }
411 if (!g_bSkins)
412 {
413 PrintToChat(client, "%sThe \x07Player Skins \x03option is disabled right now!", prefix);
414 return;
415 }
416 char sTest[512];
417 menu.GetItem(itemNum, sTest, sizeof(sTest));
418 menu.GetItem(itemNum, g_sClientSkin[client], 512);
419 if (itemNum == 0)
420 PrintToChat(client, "%sSuccessfuly Changed Your Player Skin To Default Skin!", prefix);
421 else
422 PrintToChat(client, "%sSuccessfuly Changed Your Player Skin To \"%s\"!", prefix, sName[itemNum]);
423
424 menu.Display(client, MENU_TIME_FOREVER);
425 }
426}
427public Action Command_Tag(int client, int args)
428{
429 if (!g_bEnabled)
430 {
431 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
432 return Plugin_Handled;
433 }
434 if (!g_bIsClientVIP[client])
435 {
436 PrintToChat(client, "%sThis command is for \x07VIP \x03members only!", prefix);
437 return Plugin_Handled;
438 }
439 if (args == 0)
440 {
441 PrintToChat(client, "%sWrong usage: sm_tag <Text | None = reset tag>", prefix);
442 return Plugin_Handled;
443 }
444 char arg[512];
445 GetCmdArgString(arg, sizeof(arg));
446 bool block;
447 for (int k = 0; k <= g_iBlockedTags; k++)
448 {
449 if (StrEqual(arg, g_sBlockedTags[k]))
450 {
451 block = true;
452 }
453 }
454 if (block)
455 {
456 PrintToChat(client, "%sThis tag is not allowed!", prefix);
457 return Plugin_Handled;
458 }
459 Format(g_sTag[client], sizeof(arg), arg);
460 SetClientCookie(client, g_hVIPTag, g_sTag[client]);
461
462 if (StrEqual(arg, "none"))
463 PrintToChat(client, "%sYou just reset your tag!", prefix);
464 else
465 PrintToChat(client, "%sYou changed your tag to '%s'", prefix, arg);
466 return Plugin_Handled;
467}
468public Action Command_TagColor(int client, int args)
469{
470 if (!g_bEnabled)
471 {
472 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
473 return Plugin_Handled;
474 }
475 if (!g_bIsClientVIP[client])
476 {
477 PrintToChat(client, "%sThis command is for \x07VIP \x03members only!", prefix);
478 return Plugin_Handled;
479 }
480 Menu menu = CreateMenu(TagMenu);
481 menu.SetTitle("Choose Your Color");
482 menu.AddItem("\x03", "Default");
483 menu.AddItem("\x02", "Strong Red");
484 menu.AddItem("\x03", "Team Color");
485 menu.AddItem("\x04", "Green");
486 menu.AddItem("\x05", "Turquoise");
487 menu.AddItem("\x06", "Yellow-Green");
488 menu.AddItem("\x07", "Light Red");
489 menu.AddItem("\x08", "Gray");
490 menu.AddItem("\x09", "Light Yellow");
491 menu.AddItem("\x0A", "Light Blue");
492 menu.AddItem("\x0C", "Purple");
493 menu.AddItem("\x0E", "Pink");
494 menu.AddItem("\x10", "Orange");
495 menu.Display(client, 30);
496 return Plugin_Handled;
497}
498public int TagMenu(Menu menu, MenuAction action, int client, int itemNum)
499{
500 if (action == MenuAction_Select)
501 {
502 if (!g_bEnabled)
503 {
504 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
505 return;
506 }
507 char info[64], sItemName[64];
508 GetMenuItem(menu, itemNum, info, sizeof(info), _, sItemName, sizeof(sItemName));
509 Format(g_sTagColor[client], sizeof(g_sTagColor), info);
510 PrintToChat(client, "%sYou changed your tag color to %s%s", prefix, info, sItemName);
511 SetClientCookie(client, g_hVIPTagColor, g_sTagColor[client]);
512 menu.DisplayAt(client, GetMenuSelectionPosition(), MENU_TIME_FOREVER);
513 }
514}
515public Action Command_NameColor(int client, int args)
516{
517 if (!g_bEnabled)
518 {
519 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
520 return Plugin_Handled;
521 }
522 if (!g_bIsClientVIP[client])
523 {
524 PrintToChat(client, "%sThis command is for \x07VIP \x03members only!", prefix);
525 return Plugin_Handled;
526 }
527 Menu menu = CreateMenu(NameMenu);
528 menu.SetTitle("Choose Your Color");
529 menu.AddItem("\x03", "Default");
530 menu.AddItem("\x02", "Strong Red");
531 menu.AddItem("\x03", "Team Color");
532 menu.AddItem("\x04", "Green");
533 menu.AddItem("\x05", "Turquoise");
534 menu.AddItem("\x06", "Yellow-Green");
535 menu.AddItem("\x07", "Light Red");
536 menu.AddItem("\x08", "Gray");
537 menu.AddItem("\x09", "Light Yellow");
538 menu.AddItem("\x0A", "Light Blue");
539 menu.AddItem("\x0C", "Purple");
540 menu.AddItem("\x0E", "Pink");
541 menu.AddItem("\x10", "Orange");
542 menu.Display(client, 30);
543 return Plugin_Handled;
544}
545public int NameMenu(Menu menu, MenuAction action, int client, int itemNum)
546{
547 if (action == MenuAction_Select)
548 {
549 if (!g_bEnabled)
550 {
551 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
552 return;
553 }
554 char info[64], sItemName[64];
555 GetMenuItem(menu, itemNum, info, sizeof(info), _, sItemName, sizeof(sItemName));
556 Format(g_sNameColor[client], sizeof(g_sNameColor), info);
557 PrintToChat(client, "%sYou changed your name color to %s%s", prefix, info, sItemName);
558 SetClientCookie(client, g_hVIPNameColor, g_sNameColor[client]);
559 menu.DisplayAt(client, GetMenuSelectionPosition(), MENU_TIME_FOREVER);
560 }
561}
562public Action Command_ChatColor(int client, int args)
563{
564 if (!g_bEnabled)
565 {
566 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
567 return Plugin_Handled;
568 }
569 if (!g_bIsClientVIP[client])
570 {
571 PrintToChat(client, "%sThis command is for \x07VIP \x03members only!", prefix);
572 return Plugin_Handled;
573 }
574 Menu menu = CreateMenu(ChatMenu);
575 menu.SetTitle("Choose Your Color");
576 menu.AddItem("\x01", "Default");
577 menu.AddItem("\x02", "Strong Red");
578 menu.AddItem("\x03", "Team Color");
579 menu.AddItem("\x04", "Green");
580 menu.AddItem("\x05", "Turquoise");
581 menu.AddItem("\x06", "Yellow-Green");
582 menu.AddItem("\x07", "Light Red");
583 menu.AddItem("\x08", "Gray");
584 menu.AddItem("\x09", "Light Yellow");
585 menu.AddItem("\x0A", "Light Blue");
586 menu.AddItem("\x0C", "Purple");
587 menu.AddItem("\x0E", "Pink");
588 menu.AddItem("\x10", "Orange");
589 menu.Display(client, 30);
590 return Plugin_Handled;
591}
592public int ChatMenu(Menu menu, MenuAction action, int client, int itemNum)
593{
594 if (action == MenuAction_Select)
595 {
596 if (!g_bEnabled)
597 {
598 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
599 return;
600 }
601 char info[64], sItemName[64];
602 GetMenuItem(menu, itemNum, info, sizeof(info), _, sItemName, sizeof(sItemName));
603 Format(g_sChatColor[client], sizeof(g_sChatColor), info);
604 PrintToChat(client, "%sYou changed your chat color to %s%s", prefix, info, sItemName);
605 SetClientCookie(client, g_hVIPChatColor, g_sChatColor[client]);
606 menu.DisplayAt(client, GetMenuSelectionPosition(), MENU_TIME_FOREVER);
607 }
608}
609public Action Command_ClanTag(int client, int args)
610{
611 if (!g_bEnabled)
612 {
613 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
614 return Plugin_Handled;
615 }
616 if (!g_bIsClientVIP[client])
617 {
618 PrintToChat(client, "%sThis command is for \x07VIP \x03members only!", prefix);
619 return Plugin_Handled;
620 }
621 if (args == 0)
622 {
623 PrintToChat(client, "%sWrong usage: sm_clantag <Text | None=reset>", prefix);
624 return Plugin_Handled;
625 }
626 char arg[512];
627 GetCmdArgString(arg, sizeof(arg));
628 bool block;
629 for (int k = 0; k <= g_iBlockedTags; k++)
630 {
631 if (StrEqual(g_sBlockedTags[k], arg, false))
632 {
633 block = true;
634 }
635 }
636 if (block)
637 {
638 PrintToChat(client, "%sThis tag is not allowed!", prefix);
639 return Plugin_Handled;
640 }
641 Format(g_sClanTag[client], sizeof(arg), arg);
642 CS_SetClientClanTag(client, g_sClanTag[client]);
643 SetClientCookie(client, g_hVIPClanTag, g_sClanTag[client]);
644 if (StrEqual(arg, "none"))
645 PrintToChat(client, "%sYou just reset your tag!", prefix);
646 else
647 PrintToChat(client, "%sYou changed your tag to '%s'", prefix, arg);
648 return Plugin_Handled;
649}
650public Action Command_VIPMenu(int client, int args)
651{
652 if (!g_bEnabled)
653 {
654 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
655 return Plugin_Handled;
656 }
657 if (!g_bIsClientVIP[client])
658 {
659 PrintToChat(client, "%sThis command is for \x07VIP \x03members only!", prefix);
660 return Plugin_Handled;
661 }
662 ShowVIPMenu(client, 0);
663 return Plugin_Handled;
664}
665public int VIPMenu(Menu menu, MenuAction action, int client, int itemNum)
666{
667 if (action == MenuAction_Select)
668 {
669 if (!g_bEnabled)
670 {
671 PrintToChat(client, "%sThe \x07VIP System \x03is disabled right now!", prefix);
672 return;
673 }
674 char info[64];
675 GetMenuItem(menu, itemNum, info, sizeof(info));
676 if (StrEqual(info, "skins"))
677 {
678 FakeClientCommand(client, "say /skins");
679 }
680 if (StrEqual(info, "clantag"))
681 {
682 PrintToChat(client, "%sType your clan tag in the chat or type !cancel to abort(Tip: type 'none' to reset your clan tag)", prefix);
683 g_bIsTypingClanTag[client] = true;
684 ShowVIPMenu(client, itemNum);
685 }
686 if (StrEqual(info, "tag"))
687 {
688 PrintToChat(client, "%sType your tag in the chat or type !cancel to abort(Tip: type 'none' to reset your tag)", prefix);
689 g_bIsTypingTag[client] = true;
690 ShowVIPMenu(client, itemNum);
691 }
692 if (StrEqual(info, "tagcolor"))
693 {
694 FakeClientCommand(client, "say /tagcolor");
695 }
696 if (StrEqual(info, "namecolor"))
697 {
698 FakeClientCommand(client, "say /namecolor");
699 }
700 if (StrEqual(info, "chatcolor"))
701 {
702 FakeClientCommand(client, "say /chatcolor");
703 }
704 if (StrEqual(info, "armor"))
705 {
706 if (g_bArmor[client])g_bArmor[client] = false;
707 else g_bArmor[client] = true;
708 PrintToChat(client, "%sYou just %s \x03the Full Armor bonus!", prefix, g_bArmor[client] ? "\x04Enabled" : "\x02Disabled");
709 ShowVIPMenu(client, itemNum);
710 }
711 if (StrEqual(info, "health"))
712 {
713 if (g_bHealth[client])g_bHealth[client] = false;
714 else g_bHealth[client] = true;
715 PrintToChat(client, "%sYou just %s \x03the %d HP bonus!", prefix, g_bHealth[client] ? "\x04Enabled" : "\x02Disabled", g_iHealthBonus);
716 ShowVIPMenu(client, itemNum);
717 }
718 if (StrEqual(info, "defuse"))
719 {
720 if (g_bDefusekit[client])g_bDefusekit[client] = false;
721 else g_bDefusekit[client] = true;
722 PrintToChat(client, "%sYou just %s \x03the Defuse Kit bonus!", prefix, g_bDefusekit[client] ? "\x04Enabled" : "\x02Disabled");
723 ShowVIPMenu(client, itemNum);
724 }
725 }
726}
727stock void ShowVIPMenu(int client, int itemNum)
728{
729 Menu menu = CreateMenu(VIPMenu);
730 menu.SetTitle("VIP Menu [%d Days Left]\n ", g_iTimeLeft[client]);
731 menu.AddItem("skins", "VIP Player Skins", g_bSkins ? 0 : 1);
732 menu.AddItem("clantag", "Manage Clan Tag");
733 menu.AddItem("tag", "Manage Chat Tag");
734 menu.AddItem("tagcolor", "Manage Tag Color");
735 menu.AddItem("namecolor", "Manage Name Color");
736 menu.AddItem("chatcolor", "Manage Chat Color");
737 if (g_bArmor[client])
738 menu.AddItem("armor", "Disable Full Armor", g_bFullArmor ? 0 : 1);
739 else
740 menu.AddItem("armor", "Enable Full Armor", g_bFullArmor ? 0 : 1);
741 char sHealth[64];
742 if (g_bHealth[client])
743 {
744 Format(sHealth, sizeof(sHealth), "Disable %d HP Bonus", g_iHealthBonus);
745 menu.AddItem("health", sHealth, g_bHP ? 0 : 1);
746 }
747 else
748 {
749 Format(sHealth, sizeof(sHealth), "Enabled %d HP Bonus", g_iHealthBonus);
750 menu.AddItem("health", sHealth, g_bHP ? 0 : 1);
751 }
752 if (g_bDefusekit[client])
753 menu.AddItem("defuse", "Disable Defuse Kit Bonus", g_bDefuse ? 0 : 1);
754 else
755 menu.AddItem("defuse", "Enable Defuse Kit Bonus", g_bDefuse ? 0 : 1);
756 menu.AddItem("", "Automatic Perks:", ITEMDRAW_DISABLED);
757 menu.AddItem("", "Connect & Disconnect Messages", ITEMDRAW_DISABLED);
758 menu.AddItem("", "Reserved Slots", ITEMDRAW_DISABLED);
759 menu.AddItem("", "V.I.P Tag In Chat", ITEMDRAW_DISABLED);
760 menu.Display(client, MENU_TIME_FOREVER);
761}
762public Action Command_AddVIP(int client, int args)
763{
764 if (args != 2)
765 PrintToChat(client, "%sWrong usage: sm_addvip <name | steamid> <days>", prefix);
766 else {
767 char arg1[64], arg2[64];
768 GetCmdArg(1, arg1, sizeof(arg1));
769 GetCmdArg(2, arg2, sizeof(arg2));
770 if (StrContains(arg1, "STEAM_", false) != -1)
771 {
772 int time = StringToInt(arg2);
773 PrintToChat(client, "%sSteamID '%s' was added to a VIP for %d days!", prefix, arg1, time);
774 SQL_AddVIP_Steamid(arg1, time);
775 }
776 else
777 {
778 char target_name[MAX_TARGET_LENGTH];
779 int target_list[MAXPLAYERS], target_count;
780 bool tn_is_ml;
781
782 if ((target_count = ProcessTargetString(
783 arg1,
784 client,
785 target_list,
786 MAXPLAYERS,
787 0,
788 target_name,
789 sizeof(target_name),
790 tn_is_ml)) <= 0)
791 {
792 ReplyToTargetError(client, target_count);
793 return Plugin_Handled;
794 }
795
796 for (int i = 0; i < target_count; i++)
797 {
798 int time = StringToInt(arg2);
799 g_bIsClientVIP[target_list[i]] = true;
800 //Info
801 char playername[MAX_NAME_LENGTH], steamid[32];
802 GetClientName(target_list[i], playername, MAX_NAME_LENGTH);
803 if (!GetClientAuthId(target_list[i], AuthId_Steam2, steamid, 32))
804 {
805 PrintToChat(client, "%sError execued while getting target's info", prefix);
806 return Plugin_Handled;
807 }
808
809 int iLength = ((strlen(playername) * 2) + 1);
810 char[] escapedname = new char[iLength];
811 DB.Escape(playername, escapedname, iLength);
812
813 char gB_ClientIP[64];
814 GetClientIP(target_list[i], gB_ClientIP, 64);
815 //End of info
816 UpdatePlayer(target_list[i], time);
817 //Message
818 SetHudTextParams(0.05, 0.1, 7.0, 0, 255, 150, 255, 2, 6.0, 0.1, 0.2);
819 for (int targets = 1; targets <= MaxClients; targets++)
820 {
821 if (IsValidClient(targets))
822 {
823 ShowHudText(targets, -1, "%N is now a VIP!", target_list[i]);
824 }
825 }
826 //Confirm MSG
827 PrintToChat(client, "%s%N has been added to a VIP for %d days!", prefix, target_list[i], time);
828 }
829 }
830 }
831 return Plugin_Handled;
832}
833public Action Command_RemoveVIP(int client, int args)
834{
835 if (args != 1)
836 PrintToChat(client, "%sWrong usage: sm_removevip <name | steamid> ", prefix);
837 else {
838 char arg1[64];
839 GetCmdArg(1, arg1, sizeof(arg1));
840 if (StrContains(arg1, "STEAM_", false) != -1)
841 {
842 SQL_RemoveVIP(arg1);
843 PrintToChat(client, "%sSteamID '%s' has been removed from a VIP", prefix, arg1);
844 }
845 else
846 {
847 char target_name[MAX_TARGET_LENGTH];
848 int target_list[MAXPLAYERS], target_count;
849 bool tn_is_ml;
850
851 if ((target_count = ProcessTargetString(
852 arg1,
853 client,
854 target_list,
855 MAXPLAYERS,
856 0,
857 target_name,
858 sizeof(target_name),
859 tn_is_ml)) <= 0)
860 {
861 ReplyToTargetError(client, target_count);
862 return Plugin_Handled;
863 }
864
865 for (int i = 0; i < target_count; i++)
866 {
867 char steamid[64];
868 if (!GetClientAuthId(target_list[i], AuthId_Steam2, steamid, 32))
869 {
870 PrintToChat(client, "%sError execued while getting target's info", prefix);
871 return Plugin_Handled;
872 }
873 SQL_RemoveVIP(steamid);
874 g_bIsClientVIP[target_list[i]] = false;
875 PrintToChat(client, "%s%N has been removed from a VIP", prefix, target_list[i]);
876 }
877 }
878 }
879 return Plugin_Handled;
880}
881//Database
882void UpdatePlayer(int client, int days)
883{
884 if (DB == null)
885 {
886 return;
887 }
888 char gB_Query[512], steamid[32];
889 if (!GetClientAuthId(client, AuthId_Steam2, steamid, 32))
890 {
891 return;
892 }
893 FormatEx(gB_Query, sizeof(gB_Query), "INSERT INTO `users` (`expiredate`, `steamid`) VALUES (NOW() + INTERVAL %d DAY, '%s') ON DUPLICATE KEY UPDATE `expiredate` = NOW() + INTERVAL %d DAY;", days, steamid, days);
894 DB.Query(SQL_UpdatePlayer_Callback, gB_Query, GetClientSerial(client), DBPrio_Normal);
895}
896void SQL_AddVIP_Steamid(const char[] steamid, int days)
897{
898 if (DB == null)
899 {
900 return;
901 }
902 char gB_Query[512];
903 char test[512];
904 Format(test, sizeof(test), "NOW() + INTERVAL %d DAY", days);
905 FormatEx(gB_Query, sizeof(gB_Query), "INSERT INTO `users` (`expiredate`, `steamid`) VALUES (%s, '%s') ON DUPLICATE KEY UPDATE `expiredate` = %s;", test, steamid, test);
906 DB.Query(SQL_UpdatePlayer_Callback2, gB_Query, _, DBPrio_Normal);
907}
908public void SQL_UpdatePlayer_Callback(Database db, DBResultSet results, const char[] error, any data)
909{
910 int client = GetClientFromSerial(data);
911 if (results == null)
912 {
913 if (client == 0)
914 {
915 LogError("[Line 873] Client is not valid. Reason: %s", error);
916 }
917 else
918 {
919 LogError("[Line 877] Cant use client data. Reason: %s", error);
920 }
921 return;
922 }
923}
924public void SQL_UpdatePlayer_Callback2(Database db, DBResultSet results, const char[] error, any data)
925{
926 if (results == null)
927 {
928 LogError("[Line 886] Cant use client data. Reason: %s", error);
929 return;
930 }
931}
932void SQL_StartConnection()
933{
934 if (DB != null)
935 {
936 delete DB;
937 }
938
939 char gB_Error[255];
940 if (SQL_CheckConfig("vipsystem"))
941 {
942 DB = SQL_Connect("vipsystem", true, gB_Error, 255);
943
944 if (DB == null)
945 {
946 SetFailState("[CSGOVIP] Error on start. Reason: %s", gB_Error);
947 }
948 }
949 else
950 {
951 SetFailState("[CSGOVIP] Cant find `vipsystem` on database.cfg");
952 }
953
954 DB.SetCharset("utf8");
955
956 char gB_Query[512];
957 FormatEx(gB_Query, sizeof(gB_Query), "CREATE TABLE IF NOT EXISTS `users`( `steamid` VARCHAR(32) NOT NULL PRIMARY KEY, `expiredate` DATETIME NOT NULL, UNIQUE (`steamid`));");
958 if (!SQL_FastQuery(DB, gB_Query))
959 {
960 SQL_GetError(DB, gB_Error, 255);
961 LogError("[CSGOVIP] Cant create table. Error : %s", gB_Error);
962 }
963}
964void SQL_RemoveVIP(const char[] steamid)
965{
966 char gB_Query[512];
967 FormatEx(gB_Query, sizeof(gB_Query), "DELETE FROM `users` WHERE `steamid` = '%s'", steamid);
968 DB.Query(SQL_RemovePlayer_Callback, gB_Query, DBPrio_Normal);
969}
970public void SQL_RemovePlayer_Callback(Database db, DBResultSet results, const char[] error, any data)
971{
972 if (results == null)
973 {
974 LogError("Error: %s", error);
975 return;
976 }
977}
978public void SQL_SelectPlayer_Callback(Database db, DBResultSet results, const char[] error, any data)
979{
980 int client = GetClientFromSerial(data);
981 if (results == null)
982 {
983 if (client == 0)
984 {
985 LogError("[Line 988] Client is not valid. Reason: %s", error);
986 }
987 else
988 {
989 LogError("[CSGOVIP] Cant use client data on insert. Reason: %s", error);
990 }
991 return;
992 }
993 while (results.FetchRow())
994 {
995 int iCount = results.FetchInt(0);
996 if (!g_bIsClientVIP[client]) { //Client connected now
997 if (iCount != 0)
998 {
999 g_bIsClientVIP[client] = true;
1000 SetHudTextParams(0.05, 0.1, 7.0, 0, 255, 150, 255, 2, 6.0, 0.1, 0.2);
1001 for (int i = 1; i <= MaxClients; i++)
1002 {
1003 if (IsValidClient(i))
1004 {
1005 ShowHudText(i, -1, "VIP %N has connected to the server!", client);
1006 }
1007 }
1008 }
1009 if (iCount == 0 && GetMaxHumanPlayers() < GetOnlineUsers() && g_iRounds > 1)
1010 {
1011 KickClient(client, "Server is full, buy a V.I.P to join the server while full.");
1012 return;
1013 }
1014 if (iCount != 0 && GetMaxHumanPlayers() < GetOnlineUsers())
1015 {
1016 int iRandom = GetRandomPlayer();
1017 KickClient(iRandom, "You were kicked to make a space for a V.I.P user!");
1018 }
1019 CheckTimeLeft(client);
1020 }
1021 else {
1022 if (g_bIsClientVIP[client] && iCount == 0)
1023 {
1024 PrintToChat(client, "%sYour \x07VIP \x03has expired!", prefix);
1025 g_bIsClientVIP[client] = false;
1026 return;
1027 }
1028 CheckTimeLeft(client);
1029 }
1030 }
1031}
1032stock void CheckTimeLeft(int client)
1033{
1034 if (!IsValidClient(client))return;
1035 char authid[64];
1036 if (!GetClientAuthId(client, AuthId_Steam2, authid, 32))
1037 {
1038 return;
1039 }
1040 char gB_Query[512];
1041 FormatEx(gB_Query, sizeof(gB_Query), "SELECT TIMESTAMPDIFF(DAY, NOW(), expiredate) FROM `users` WHERE `steamid` = '%s';", authid);
1042 DB.Query(SQL_VIPTime, gB_Query, GetClientSerial(client), DBPrio_Normal);
1043}
1044public void SQL_VIPTime(Database db, DBResultSet results, const char[] error, any data)
1045{
1046 int client = GetClientFromSerial(data);
1047 if (results == null)
1048 {
1049 if (client == 0)
1050 {
1051 LogError("[Line 1059] Client is not valid. Reason: %s", error);
1052 }
1053 else
1054 {
1055 LogError("[CSGOVIP] Cant use client data on insert. Reason: %s", error);
1056 }
1057 return;
1058 }
1059 while (results.FetchRow())
1060 {
1061 g_iTimeLeft[client] = results.FetchInt(0);
1062 }
1063}
1064//Timers
1065//Apply Skin
1066public Action Timer_ApplySkin(Handle timer, any client)
1067{
1068 char sTest[512];
1069 Format(sTest, sizeof(sTest), "%s", g_sClientSkin[client]) // Should fix crashes
1070 if (StrEqual(sTest, ""))return;
1071 PrecacheModel(sTest);
1072 SetEntityModel(client, sTest);
1073}
1074//Chat
1075public Action OnChatMessage(&author, Handle recipients, char[] name, char[] message)
1076{
1077 if (g_bIsClientVIP[author])
1078 {
1079 if (StrEqual(g_sTag[author], "") || StrEqual(g_sTag[author], "none"))
1080 Format(name, MAX_NAME_LENGTH, " %s[V.I.P] \x03%s%s", g_sTagColor[author], g_sNameColor[author], name);
1081 else
1082 Format(name, MAX_NAME_LENGTH, " %s[%s] \x03%s%s", g_sTagColor[author], g_sTag[author], g_sNameColor[author], name);
1083 Format(message, MAXLENGTH_MESSAGE, "%s%s", g_sChatColor[author], message);
1084 return Plugin_Changed;
1085 }
1086 return Plugin_Continue;
1087}
1088//Stocks
1089stock void GetSkins()
1090{
1091 char sPath[512];
1092 BuildPath(Path_SM, sPath, sizeof(sPath), "configs/vipskins.txt");
1093 if (!FileExists(sPath))SetFailState("[CSGOVIP] - Couldn't Find configs/vipskins.txt");
1094 KeyValues kConfig = new KeyValues("");
1095 kConfig.ImportFromFile(sPath);
1096
1097 kConfig.JumpToKey("Skins");
1098 kConfig.GotoFirstSubKey();
1099 do {
1100 g_iSkins++;
1101 kConfig.GetString("name", sName[g_iSkins], 512);
1102 kConfig.GetString("location", sModel[g_iSkins], 512);
1103 AddFileToDownloadsTable(sModel[g_iSkins]);
1104 } while (kConfig.GotoNextKey());
1105}
1106stock void ReadBlockedTags()
1107{
1108 char sPath[512];
1109 BuildPath(Path_SM, sPath, sizeof(sPath), "configs/blockedtags.txt");
1110 if (!FileExists(sPath))SetFailState("[CSGOVIP] - Couldn't Find configs/blockedtags.txt");
1111 KeyValues kConfig = new KeyValues("");
1112 kConfig.ImportFromFile(sPath);
1113
1114 kConfig.JumpToKey("Blocked Tags");
1115 kConfig.GotoFirstSubKey();
1116 do {
1117 g_iBlockedTags++;
1118 kConfig.GetString("tag", g_sBlockedTags[g_iBlockedTags], sizeof(g_sBlockedTags));
1119 } while (kConfig.GotoNextKey());
1120}
1121stock int GetRandomPlayer()
1122{
1123 int[] clients = new int[MaxClients + 1];
1124 int clientCount;
1125 for (int i = 1; i <= MaxClients; i++)
1126 if (IsClientInGame(i) && IsValidClient(i) && !CheckCommandAccess(i, "", ADMFLAG_GENERIC) && !g_bIsClientVIP[i])
1127 clients[clientCount++] = i;
1128 return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount - 1)];
1129}
1130stock int GetOnlineUsers()
1131{
1132 int iCount = 0;
1133 for (int i = 1; i <= MaxClients; i++)
1134 {
1135 if (IsValidClient(i))
1136 iCount++;
1137 }
1138 return iCount;
1139}
1140stock bool IsValidClient(int client, bool alive = false, bool bots = false)
1141{
1142 if (client > 0 && client <= MaxClients && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)) && (bots == false && !IsFakeClient(client)))
1143 {
1144 return true;
1145 }
1146 return false;
1147}
1148//Taken from "SMLib"
1149stock bool IsValueNumeric(char[] str)
1150{
1151 int x = 0;
1152 int dotsFound = 0;
1153 int numbersFound = 0;
1154
1155 if (str[x] == '+' || str[x] == '-') {
1156 x++;
1157 }
1158
1159 while (str[x] != '\0') {
1160
1161 if (IsCharNumeric(str[x])) {
1162 numbersFound++;
1163 }
1164 else if (str[x] == '.') {
1165 dotsFound++;
1166
1167 if (dotsFound > 1) {
1168 return false;
1169 }
1170 }
1171 else {
1172 return false;
1173 }
1174
1175 x++;
1176 }
1177
1178 if (!numbersFound) {
1179 return false;
1180 }
1181 return true;
1182}