Senior Member
Join Date: Jul 2013
Location: Bulgaria
|
04-10-2018
, 06:49
Re: [CS:GO] Remove X key from KeyValue after X time(2 weeks, 1 month)
|
#8
|
PHP Code:
#include <sourcemod> #include <clientprefs> #include <cstrike> #include <sdktools>
#include <multicolors> #include <hextags> #include <mostactive> #include <shop> #include <vip_core>
#define TokensConfig "configs/minigames/tokenstore_config.cfg"
char UsedTokens[MAXPLAYERS+1]; char ConfigLocation[PLATFORM_MAX_PATH]; char SkinModelPath[MAXPLAYERS + 1][128]; Handle UsedTokensCookie = INVALID_HANDLE;
bool PlayerHasPrefix[MAXPLAYERS+1]; bool PlayerHasPaint[MAXPLAYERS+1]; bool PlayerHasSkin[MAXPLAYERS+1];
#pragma semicolon 1 #pragma newdecls required
public void OnPluginStart() { RegConsoleCmd("sm_mytokens", TokenShop); RegConsoleCmd("sm_tshop", TokenShop); RegConsoleCmd("sm_tokenshop", TokenShop);
UsedTokensCookie = RegClientCookie("Minigames Tokens Shop", "Used Tokens", CookieAccess_Private); for (int i = MaxClients; i > 0; --i) { if (!AreClientCookiesCached(i)) { continue; } OnClientCookiesCached(i); } HookEvent("player_spawn", PlayerSpawn); }
public void OnMapStart() { BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); if(!FileExists(ConfigLocation)) { KeyValues generatecfgfile = new KeyValues("tokenstore"); generatecfgfile.ExportToFile(ConfigLocation); delete generatecfgfile; } }
public void OnClientPutInServer(int client) { CheckPlayer(client); }
public void OnClientDisconnect(int client) { char tokenstostore[24]; IntToString(UsedTokens[client], tokenstostore, sizeof(tokenstostore)); SetClientCookie(client, UsedTokensCookie, tokenstostore); }
public void OnClientCookiesCached(int client) { char tokens[24]; GetClientCookie(client, UsedTokensCookie, tokens, 12); UsedTokens[client] = StringToInt(tokens); }
public Action PlayerSpawn(Handle event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(GetEventInt(event, "userid")); if(PlayerHasSkin[client]) { CreateTimer(1.75, ChangeVipModel, GetClientUserId(client)); } } public Action ChangeVipModel(Handle timer, int userid) { int client = GetClientOfUserId(userid); if(client == 0) return; SetEntityModel(client, SkinModelPath[client]); }
public Action TokenShop(int client, int args) { ShowShopInfo(client, args); return Plugin_Continue; }
public void ShowShopInfo(int client, int args) { int tokens = ((MostActive_GetPlayTimeTotalExceptSpec(client) / 3600) / 35) - UsedTokens[client]; int ingame = MostActive_GetPlayTimeTotalExceptSpec(client) / 3600; Menu menu = new Menu(InfoShop_Menu);
menu.SetTitle("[Server Name] You have: %i token(s). You have %i hours ingame.", tokens, ingame); menu.AddItem("yes", "Buy something."); menu.AddItem("no", "I just wanted to check my tokens.");
menu.ExitButton = false; menu.Display(client, 10); }
public void ShowShop(int client) { int tokens = ((MostActive_GetPlayTimeTotalExceptSpec(client) / 3600) / 35) - UsedTokens[client]; Menu menu = new Menu(CreditsShop_Menu);
menu.SetTitle("Server Name Minigames Tokens Shop [You have: %i token(s)]", tokens); menu.AddItem("2500", "2500 credits [1 token]"); menu.AddItem("6000", "6000 credits [2 tokens]"); menu.AddItem("prefix", "[Uber Player] prefix. [3 weeks | 2 tokens]"); menu.AddItem("14k", "12000 credits [25% change | 2 tokens]"); menu.AddItem("skins", "Special Skin [1 month | 4 tokens]"); menu.AddItem("gameraffle", "Steam game raffle -> [ 0/10 | 7 tokens] ~Under Construction~", ITEMDRAW_DISABLED); menu.AddItem("1vip", "VIP access [1 month | 10 tokens]");
menu.ExitButton = true; menu.Display(client, 10); }
public int CreditsShop_Menu(Menu menu, MenuAction action, int iClient, int param2) { int tokens = ((MostActive_GetPlayTimeTotalExceptSpec(iClient) / 3600) / 35) - UsedTokens[iClient]; char PlayerSteamID[64]; GetClientAuthId(iClient, AuthId_Steam2, PlayerSteamID, sizeof(PlayerSteamID));
switch(action) { case MenuAction_Select: { char info[32]; menu.GetItem(param2, info, sizeof(info));
if (StrEqual(info, "2500")) { if(tokens == 0) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You don't have enough tokens to buy this."); CPrintToChat(iClient, "[{lightred}Server Name{default}] You have: {green}%i {orange}| {default}Required: {green}1 {default}", tokens); } else { UsedTokens[iClient] += 1; CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}1 {default}token for {green}2500 {default}credits."); Shop_GiveClientCredits(iClient, 2500); } } if (StrEqual(info, "6000")) { if(tokens <= 1) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You don't have enough tokens to buy this."); CPrintToChat(iClient, "[{lightred}Server Name{default}] You have: {green}%i {orange}| {default}Required: {green}7 {default}", tokens); } else { UsedTokens[iClient] += 2; CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}2 {default}tokens for {green}6000 {default}credits."); Shop_GiveClientCredits(iClient, 6000); } } if (StrEqual(info, "14k")) { if(tokens <= 1) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You don't have enough tokens to buy this."); CPrintToChat(iClient, "[{lightred}Server Name{default}] You have: {green}%i {orange}| {default}Required: {green}2 {default}", tokens); } else { UsedTokens[iClient] += 2; switch (GetRandomInt(1, 4)) { case 1: CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}2 {default}token a change of {green}6000 {default}credits and you {lightred}lost{default}."); case 2: CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}2 {default}token a change of {green}6000 {default}credits and you {lightred}lost{default}."); case 3: CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}2 {default}token a change of {green}6000 {default}credits and you {lightred}lost{default}."); case 4: { CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}2 {default}tokens a change of {green}12000 {default}credits and you {green}!!!WON!!!{default}."); Shop_GiveClientCredits(iClient, 12000); } } } } if (StrEqual(info, "1vip")) { if(tokens <= 9) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You don't have enough tokens to buy this."); CPrintToChat(iClient, "[{lightred}Server Name{default}] You have: {green}%i {orange}| {default}Required: {green}10 {default}", tokens); } else { if(VIP_IsClientVIP(iClient)) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You already have a VIP status."); } else { UsedTokens[iClient] += 10; CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}10 {default}tokens for {green}a month of VIP access{default}."); VIP_GiveClientVIP(0, iClient, 2592000, "PremiumVIP", true); } } } if(StrEqual(info, "prefix")) { if(tokens <= 1) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You don't have enough tokens to buy this."); CPrintToChat(iClient, "[{lightred}Server Name{default}] You have: {green}%i {orange}| {default}Required: {green}2 {default}", tokens); } else { UsedTokens[iClient] += 2;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*21; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("prefix", "1"); addextras.SetString("prefix_expires", stringedtimer); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(iClient, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a special prefix{default}."); CheckPlayer(iClient); }
} if(StrEqual(info, "skins")) { if(tokens <= 3) { CPrintToChat(iClient, "[{lightred}Server Name{default}] You don't have enough tokens to buy this."); CPrintToChat(iClient, "[{lightred}Server Name{default}] You have: {green}%i {orange}| {default}Required: {green}4 {default}", tokens); } else { OpenSkinSelection(iClient); } } }
case MenuAction_End:{delete menu;} }
return 0; }
public int InfoShop_Menu(Menu menu, MenuAction action, int client, int param2) { switch(action) { case MenuAction_Select: { char info[32]; menu.GetItem(param2, info, sizeof(info));
if (StrEqual(info, "yes")) { ShowShop(client); } }
case MenuAction_End:{delete menu;} }
return 0; }
//*******************************************************// // EXTRAS // //*****************************************************//
public void HexTags_OnTagsUpdated(int iClient) { if (PlayerHasPrefix[iClient]) { HexTags_SetClientTag(iClient, ChatTag, "[{purble}Uber Player{grey}]"); } }
public void OpenSkinSelection(int client) { Menu menu = new Menu(SelectVipSkin);
menu.SetTitle("Which special skin do you want?"); menu.AddItem("flash", "The Flash [VIPs Only]"); menu.AddItem("flashcw", "The Flash (CW) [VIPs Only]"); menu.AddItem("revflash", "Reverse Flash [VIPs Only]"); menu.AddItem("kruger", "Freddy Krueger [VIPs Only]"); menu.AddItem("letherface", "Letherface [VIPs Only]"); menu.AddItem("jigsaw", "Jigsaw [VIPs Only]"); menu.AddItem("goku", "Goku [VIPs Only]"); menu.AddItem("trager", "Dr. Trager [VIPs Only]"); menu.AddItem("kotor", "Kotori Itsuka [VIPs Only]");
menu.ExitButton = false; menu.Display(client, 15); }
public int SelectVipSkin(Menu menu, MenuAction action, int client, int param2) { char PlayerSteamID[64]; GetClientAuthId(client, AuthId_Steam2, PlayerSteamID, sizeof(PlayerSteamID)); switch(action) { case MenuAction_Select: { char info[32]; menu.GetItem(param2, info, sizeof(info));
if (StrEqual(info, "flash")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kodua/flash52/flash.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "flashcw")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kodua/flash52/flash_cw.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "revflash")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kodua/flash52/reverse_flash.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "kruger")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kuristaja/krueger/krueger.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "letherface")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kuristaja/leatherface/leatherface.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "jigsaw")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kuristaja/billy/billy_normal.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "goku")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kodua/goku/goku.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "trager")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/kuristaja/trager/tragerv2.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } if (StrEqual(info, "kotor")) { UsedTokens[client] += 4;
char stringedtimer[128]; int whentoexpire = GetTime() + 60*60*24*30; IntToString(whentoexpire, stringedtimer, sizeof(stringedtimer)); BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues addextras = new KeyValues("tokenstore"); addextras.JumpToKey(PlayerSteamID, true); addextras.SetString("skins", "1"); addextras.SetString("skins_expires", stringedtimer); addextras.SetString("skin_path", "models/player/custom_player/monsterko/qinli/qinli.mdl"); addextras.Rewind(); addextras.ExportToFile(ConfigLocation); delete addextras;
CPrintToChat(client, "[{lightred}Server Name{default}] You successfully redeemed {green}4 {default}tokens for {green}a month with a special skin{default}."); CheckPlayer(client); } }
case MenuAction_End:{delete menu;} }
return 0; }
void CheckPlayer(int client) { char PlayerSteamID[64]; GetClientAuthId(client, AuthId_Steam2, PlayerSteamID, sizeof(PlayerSteamID));
PlayerHasPrefix[client] = false; PlayerHasPaint[client] = false; PlayerHasSkin[client] = false;
BuildPath(Path_SM, ConfigLocation, sizeof(ConfigLocation), TokensConfig); KeyValues checkplayer = new KeyValues("tokenstore"); if (KvJumpToKey(checkplayer, PlayerSteamID)) { int currenttime = GetTime(); char path[128];
//// Prefix ///// int prefixenabled = KvGetNum(checkplayer, "prefix"); int prefixstatus = KvGetNum(checkplayer, "prefix_expires"); //// Paint ///// int paintenabled = KvGetNum(checkplayer, "paint"); int paintmakerstatus = KvGetNum(checkplayer, "paint_expires");
//// Skin ///// int skinenabled = KvGetNum(checkplayer, "skins"); int skinstatus = KvGetNum(checkplayer, "skins_paintexpires"); KvGetString(checkplayer, "skin_path", path, sizeof(path));
if(prefixenabled && currenttime < prefixstatus) { PlayerHasPrefix[client] = true; } if(paintenabled && currenttime < paintmakerstatus) { PlayerHasPaint[client] = true; } if(skinenabled && currenttime < skinstatus) { PlayerHasSkin[client] = true; SkinModelPath[client] = path; } } delete checkplayer; }
However... It doesnt create the config on map start and I guess all the keyvalues in the plugins won't work, I don't know why.
__________________
Last edited by PinHeaDi; 04-10-2018 at 06:54.
|
|