#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdktools_functions>
#include <shop>
new bool:g_bHasSP[MAXPLAYERS+1];
new Handle:g_hPrice,
Handle:g_hSellPrice,
Handle:g_hDuration,
ItemId:id;
public Plugin:myinfo =
{
name = "[Shop] Swap Team",
author = "Smoke",
version = "1.0"
};
public OnPluginStart()
{
RegConsoleCmd("sm_st", Command_St);
g_hPrice = CreateConVar("sm_shop_swapteam_price", "10000", "Стоимость покупки свободной смены команды.");
HookConVarChange(g_hPrice, OnConVarChange);
g_hSellPrice = CreateConVar("sm_shop_swapteam_sellprice", "5000", "Стоимость продажи свободной смены команды.");
HookConVarChange(g_hPrice, OnConVarChange);
g_hDuration = CreateConVar("sm_shop_swapteam_duration", "2592000", "Длительность свободной смены команды в секундах.");
HookConVarChange(g_hDuration, OnConVarChange);
AutoExecConfig(true, "shop_swapteam", "shop");
if (Shop_IsStarted()) Shop_Started();
}
public OnConVarChange(Handle:hCvar, const String:oldValue[], const String:newValue[])
{
if(id != INVALID_ITEM)
{
if(hCvar == g_hPrice) Shop_SetItemPrice(id, GetConVarInt(hCvar));
else if(hCvar == g_hSellPrice) Shop_SetItemSellPrice(id, GetConVarInt(hCvar));
else if(hCvar == g_hDuration) Shop_SetItemValue(id, GetConVarInt(hCvar));
}
}
public OnPluginEnd() Shop_UnregisterMe();
public Shop_Started()
{
new CategoryId:category_id = Shop_RegisterCategory("Stuff", "");
if (Shop_StartItem(category_id, "swapteam"))
{
Shop_SetInfo("Свободная смена команды [!st]", "", GetConVarInt(g_hPrice), GetConVarInt(g_hSellPrice), Item_Togglable, GetConVarInt(g_hDuration));
Shop_SetCallbacks(OnItemRegistered, OnItemUsed);
Shop_EndItem();
}
}
public OnItemRegistered(CategoryId:category_id, const String:category[], const String:item[], ItemId:item_id) id = item_id;
public Shop_OnClientAuthorized(iClient) g_bHasSP[iClient] = (Shop_IsClientHasItem(iClient, id) && Shop_IsClientItemToggled(iClient, id)) ? true:false;
public ShopAction:OnItemUsed(iClient, CategoryId:category_id, const String:category[], ItemId:item_id, const String:item[], bool:isOn, bool:elapsed)
{
if (isOn || elapsed)
{
g_bHasSP[iClient] = false;
return Shop_UseOff;
}
g_bHasSP[iClient] = true;
return Shop_UseOn;
}
public Action:Command_St(iClient, args)
{
if (g_bHasSP[iClient] && iClient && IsClientInGame(iClient) || IsPlayerAlive(iClient) && ForcePlayerSuicide(iClient))
{
new playerTeam = GetClientTeam(iClient);
if(playerTeam == CS_TEAM_T)
{
CS_SwitchTeam(iClient, CS_TEAM_CT);
PrintToChat(iClient,"\x04[Swap Team] \x01Вы сменили команду! \x03[T > CT]");
}
else if(playerTeam == CS_TEAM_CT)
{
CS_SwitchTeam(iClient, CS_TEAM_T);
PrintToChat(iClient,"\x04[Swap Team] \x01Вы сменили команду! \x03[CT > T]");
}
}
else
PrintToChat(iClient,"\x04[Swap Team] \x01Вы не купили данную возможность в \x03!shop \x01:)");
}