#include <sdktools_functions>
#include <shop>
#include <clientmod>
#include <clientmod/multicolors>
#pragma semicolon 1
#pragma newdecls required
bool g_fastplant[MAXPLAYERS + 1];
ItemId g_iID;
// ConVar
int g_Price;
int g_iSellPrice;
int g_iDuration;
//
public Plugin myinfo =
{
name = "[Shop] Fast Plant C4",
author = "_ws, (shop Synd1qate)",
version = "0.1",
url = "https://vk.com/syndiqate"
};
public void OnPluginStart()
{
ConVar cvar;
cvar = CreateConVar("sm_shop_s4plant_price", "10000", "Стоимость покупки.", _, true, 0.0, true, 1000000.0);
cvar.AddChangeHook(OnConVarChangePrice);
g_Price = cvar.IntValue;
cvar = CreateConVar("sm_shop_s4plant_sellprice", "8000", "Стоимость продажи.", _, true, 0.0, true, 1000000.0);
cvar.AddChangeHook(OnConVarChangeSellprice);
g_iSellPrice = cvar.IntValue;
cvar = CreateConVar("sm_shop_s4plant_duration", "86400", "Длительность в секундах.", _, true, 0.0, true, 1000000.0);
cvar.AddChangeHook(OnConVarChangeDuration);
g_iDuration = cvar.IntValue;
AutoExecConfig(true, "shop_s4plant", "shop");
HookEvent("bomb_beginplant", BombBP, EventHookMode_Post);
if (Shop_IsStarted())Shop_Started();
}
public void OnConVarChangePrice(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_Price = cvar.IntValue;
if (g_iID != INVALID_ITEM)
{
Shop_SetItemPrice(g_iID, cvar.IntValue);
}
}
public void OnConVarChangeSellprice(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_iSellPrice = cvar.IntValue;
if (g_iID != INVALID_ITEM)
{
Shop_SetItemSellPrice(g_iID, cvar.IntValue);
}
}
public void OnConVarChangeDuration(ConVar cvar, const char[] oldValue, const char[] newValue)
{
g_iDuration = cvar.IntValue;
if (g_iID != INVALID_ITEM)
{
Shop_SetItemValue(g_iID, cvar.IntValue);
}
}
public void OnPluginEnd()
{
Shop_UnregisterMe();
}
public void Shop_Started()
{
CategoryId category_id = Shop_RegisterCategory("stuff", "Способности", "");
if (Shop_StartItem(category_id, "shop_s4plant"))
{
Shop_SetInfo("Быстр. установка С4", "Быстр. установка С4", g_Price, g_iSellPrice, Item_Togglable, g_iDuration);
Shop_SetCallbacks(OnItemRegistered, OnGravUsed);
Shop_EndItem();
}
}
public void OnItemRegistered(CategoryId category_id, char[] category, char[] item, ItemId item_id)
{
g_iID = item_id;
}
public void Shop_OnAuthorized(int iClient)
{
g_fastplant[iClient] = false;
}
public ShopAction OnGravUsed(int iClient, CategoryId category_id, const char[] category, ItemId item_id, const char[] item, bool isOn, bool elapsed)
{
if (isOn || elapsed)
{
g_fastplant[iClient] = false;
//MC_PrintToChat(iClient, "{red}Быстрая установка {gold} C4 выключена");
//C_PrintToChat(iClient, "{green}Быстрая установка {default} C4 выключена");
return Shop_UseOff;
}
//MC_PrintToChat(iClient, "{red}Быстрая установка {gold} C4 включена");
//C_PrintToChat(iClient, "{green}Быстрая установка {default} C4 включена");
g_fastplant[iClient] = true;
return Shop_UseOn;
}
public Action BombBP(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (g_fastplant[client])
{
int weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if (weapon > 0)
{
char class[32];
if (GetEntityClassname(weapon, class, sizeof(class) && !strcmp(class[7], "c4", false)))
{
SetEntPropFloat(weapon, Prop_Send, "m_fArmedTime", GetGameTime());
MC_PrintToChatAll("{red}%N {gold}Использовал(а) фастплент!", client);
C_PrintToChatAll("{green}%N {default}Использовал(а) фастплент!", client);
}
}
}
}