AlliedModders Donor
Join Date: May 2015
Location: Israel
|
04-19-2019
, 16:12
Re: [CS:GO/CSS?] VIP System
|
#31
|
Quote:
Originally Posted by lemonpaka
I just added a feature what I need about player can activate their own VIP via A Key, if someone need it just compile plugin with this code, and then what you need to do just generator keys and uplod it to MySQL. (not tested that code about table creation for KEYS, but I think it should work, because at first I create KEY table manualy)
Code:
public void OnPluginStart()
{
LoadTranslations("common.phrases");
g_cHealthBonus = CreateConVar("sm_vip_health", "10", "Health bonus amount, 0 = Disable", 0, true, 0.0);
g_cArmorBonus = CreateConVar("sm_vip_armor", "1", "Enable the armor bonus? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
g_cPistolBonus = CreateConVar("sm_vip_pistol", "1", "Enable the pistol bonus? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
g_cPlayerSkins = CreateConVar("sm_vip_skins", "1", "Enable the player skins? 0 = Disable, 1 = Enable", 0, true, 0.0, true, 1.0);
g_cTablePrefix = CreateConVar("sm_vip_table_prefix", "vip", "Prefix for the database table (Default: vip)");
g_cVipFlags = CreateConVar("sm_vip_flags", "", "Flags to give the vip users, empty for nothing");
AutoExecConfig();
SQL_MakeConnection(); //The table cvar required in here
g_aBlockedTags = new ArrayList(64);
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("round_start", Event_RoundStart);
RegAdminCmd("sm_addvip", Command_AddVIP, ADMFLAG_ROOT, "Gives a vip access");
RegAdminCmd("sm_removevip", Command_RemoveVIP, ADMFLAG_ROOT, "Removes a vip access");
RegConsoleCmd("sm_vip", Command_VIPMenu, "Opens the vip menu");
RegConsoleCmd("sm_getvip",Command_GetVIP,"Get VIP via A key");
}
Code:
public Action Command_GetVIP(int client, int args)
{
if (args != 1)
{
ReplyToCommand(client, "%s Usage: sm_getvip <cdkey>", PREFIX);
return Plugin_Handled;
}
char szArg[512];
char query[512];
char szQuery[512];
GetCmdArg(1, szArg, sizeof(szArg));
Format(query, sizeof(query),"SELECT DAYS FROM vipCode WHERE VIPKEY='%s';", szArg);
g_dDatabase.Query(DaysCallBack,query,client)
FormatEx(szQuery, sizeof(szQuery), "DELETE FROM `vipCode` WHERE `VIPKEY` = '%s'", szArg);
g_dDatabase.Query(SQL_CheckForErrors, szQuery, client);
return Plugin_Handled;
}
public void DaysCallBack(Database db, DBResultSet results, const char[] error, any data)
{
int client = data;
if (results.FetchRow())
{
int iDays = results.FetchInt(0);
if(iDays>0)
{
char szStamp[512];
char szNewStamp[512];
Format(szStamp, sizeof(szStamp), "%i", GetTime() + (iDays * 86400));
Format(szNewStamp, sizeof(szNewStamp), "%i", GetTime() + ((iDays+g_iDaysLeft[client]) * 86400));
PrintToChat(client, "%s Trying to give \x02%N \x01a vip access...", client);
char szQuery[512];
if (g_bVIP[client])
FormatEx(szQuery, sizeof(szQuery), "UPDATE `vipUsers` SET `expireStamp`= '%s' WHERE `authId` = '%s'", szNewStamp, g_szAuth[client]);
else
FormatEx(szQuery, sizeof(szQuery), "INSERT INTO `vipUsers` (`authId`, `expireStamp`) VALUES ('%s', '%s')", g_szAuth[client], szStamp);
g_dDatabase.Query(SQL_CheckForErrors, szQuery, GetClientSerial(client));
SQL_FetchUser(client);
PrintToChat(client, "%s Successfully gave \x02%N \x01a vip access...", PREFIX, client);
}
}
else
{
PrintToChat(client, "%s invalid key", PREFIX);
}
}
Code:
void SQL_MakeConnection()
{
if (g_dDatabase != null)
delete g_dDatabase;
char szError[512];
g_dDatabase = SQL_Connect("vip", true, szError, sizeof(szError));
if (g_dDatabase == null)
{
SetFailState("Cannot connect to datbase error: %s", szError);
}
char szPrefix[512];
g_cTablePrefix.GetString(szPrefix, sizeof(szPrefix));
char szQuery[512];
char szQuery2[512];
char szQuery3[512];
FormatEx(szQuery, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS `%sUsers` (`authId` VARCHAR(32) NOT NULL, `expireStamp` INT NOT NULL, UNIQUE (`authId`));", szPrefix);
g_dDatabase.Query(SQL_CheckForErrors, szQuery);
FormatEx(szQuery2, 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`))", szPrefix);
g_dDatabase.Query(SQL_CheckForErrors, szQuery2);
FormatEx(szQuery3, sizeof(szQuery), "CREATE TABLE IF NOT EXISTS `%sCode`(`VIPKEY` VARCHAR(32) NOT NULL, `DAYS` INT(10) NOT NULL DEFAULT 30)", szPrefix);
g_dDatabase.Query(SQL_CheckForErrors, szQuery3);
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
OnClientPostAdminCheck(i);
}
}
|
The idea seems nice, but the code has much things to be changed (such as creating the tables, no need in 3 different strings (chars), just use 1 as I did and edit it for each table)
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
|
|