#include <sourcemod>
#include <clientprefs>
#include <shop>
#pragma semicolon 1
public Plugin myinfo =
{
name = "[SHOP] Credits Multiplier",
author = "Ganter1234",
version = "1.0"
};
ItemId g_iID;
bool g_bUseItem[MAXPLAYERS+1];
int g_iPrice;
int g_iSellPrice;
int g_iTime;
float g_fMultiplier;
Handle g_hCookie;
public void OnPluginStart()
{
if(Shop_IsStarted())
{
Shop_Started();
}
g_hCookie = RegClientCookie("Shop_Multiplier_Credits", "Shop_Multiplier_Credits", CookieAccess_Private);
ConVar cvar;
(cvar = CreateConVar("sm_shop_credits_multiplier_price", "50000", "Цена покупки.", _, true, 0.0)).AddChangeHook(ChangeCvar_Buy);
g_iPrice = cvar.IntValue;
(cvar = CreateConVar("sm_shop_credits_multiplier_sell_price", "25000", "Цена продажи.", _, true, 0.0)).AddChangeHook(ChangeCvar_Sell);
g_iSellPrice = cvar.IntValue;
(cvar = CreateConVar("sm_shop_credits_multiplier_time", "86400", "Время действия покупки в секундах.", _, true, 0.0)).AddChangeHook(ChangeCvar_Time);
g_iTime = cvar.IntValue;
(cvar = CreateConVar("sm_shop_credits_multiplier_x", "2.0", "Множитель кредитов.", _, true, 0.0)).AddChangeHook(ChangeCvar_Multiplier);
g_fMultiplier = cvar.FloatValue;
AutoExecConfig(true, "shop_credits_multiplier", "shop");
}
public void OnPluginEnd()
{
Shop_UnregisterMe();
}
public void OnClientDisconnect(int iClient)
{
g_bUseItem[iClient] = false;
}
public void OnClientCookiesCached(int iClient)
{
char szValue[4];
GetClientCookie(iClient, g_hCookie, szValue, sizeof szValue);
if(szValue[0])
{
g_bUseItem[iClient] = view_as<bool>(StringToInt(szValue));
}
else
{
g_bUseItem[iClient] = true;
}
}
public void Shop_Started()
{
CategoryId category_id = Shop_RegisterCategory("stuff", "Разное", "");
if(Shop_StartItem(category_id, "shop_cm"))
{
Shop_SetInfo("Умножитель кредитов", "", g_iPrice, g_iSellPrice, Item_Togglable, g_iTime);
Shop_SetCallbacks(OnItemRegistered, OnEquipItem);
Shop_EndItem();
}
}
void ChangeCvar_Buy(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iPrice = convar.IntValue;
Shop_SetItemPrice(g_iID, g_iPrice);
}
void ChangeCvar_Sell(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iSellPrice = convar.IntValue;
Shop_SetItemSellPrice(g_iID, g_iSellPrice);
}
void ChangeCvar_Time(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iTime = convar.IntValue;
Shop_SetItemValue(g_iID, g_iTime);
}
void ChangeCvar_Multiplier(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_fMultiplier = convar.FloatValue;
}
void OnItemRegistered(CategoryId category_id, const char[] sCategory, const char[] sItem, ItemId item_id)
{
g_iID = item_id;
}
ShopAction OnEquipItem(int iClient, CategoryId category_id, const char[] szCategory, ItemId item_id, const char[] szItem, bool bIsOn, bool bElapsed)
{
if(bIsOn || bElapsed)
{
g_bUseItem[iClient] = false;
SetClientCookie(iClient, g_hCookie, "0");
return Shop_UseOff;
}
g_bUseItem[iClient] = true;
SetClientCookie(iClient, g_hCookie, "1");
return Shop_UseOn;
}
public Action Shop_OnCreditsGiven(int iClient, int &iCredits, int by_who)
{
if(g_bUseItem[iClient] && g_fMultiplier)
{
iCredits = RoundToCeil(float(iCredits) * g_fMultiplier);
return Plugin_Changed;
}
return Plugin_Continue;
}