#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <shop>
#include <colors>
#define PLUGIN_VERSION "2.1.2"
new ItemId:id;
#define TEHNIC_SOUND "weapons/armor1.wav"
#define CATEGORY "stuff"
#define ARMOKIT "armokit"
#define ADD 0
#define SET 1
new Handle:g_hArmor, g_iArmor,
Handle:g_hMaxArmor, g_iMaxArmor,
Handle:g_hRoundUse, g_iRoundUse,
Handle:g_hPrice, g_iPrice;
new Handle:g_hSellPrice, g_iSellPrice;
new g_iArmokitMode = SET;
new iRoundUsed[MAXPLAYERS+1];
public Plugin:myinfo =
{
name = "[Shop] Armokit",
author = "FrozDark (HLModders LLC)",
description = "Armokit component for Shop",
version = PLUGIN_VERSION,
url = "http://www.hlmod.ru/"
};
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
MarkNativeAsOptional("GetUserMessageType");
}
public OnPluginStart()
{
g_hArmor = CreateConVar("sm_shop_armokit_armor", "10", "Armokit armor. Raw numbers just set armor to that value and + adds");
g_iArmor = GetConVarInt(g_hArmor);
HookConVarChange(g_hArmor, OnConVarChange);
g_hMaxArmor = CreateConVar("sm_shop_armokit_max_armor", "+25", "Max amount of armor a player can hold", 0, true, 0.0);
g_iMaxArmor = GetConVarInt(g_hMaxArmor);
HookConVarChange(g_hMaxArmor, OnConVarChange);
g_hRoundUse = CreateConVar("sm_shop_armokit_per_round", "1", "How many armokits available per round.");
g_iRoundUse = GetConVarInt(g_hRoundUse);
HookConVarChange(g_hRoundUse, OnConVarChange);
g_hPrice = CreateConVar("sm_shop_armokit_price", "265", "The price of the armokit.");
g_iPrice = GetConVarInt(g_hPrice);
HookConVarChange(g_hPrice, OnConVarChange);
g_hSellPrice = CreateConVar("sm_shop_armokit_sellprice", "5", "Sell price for the armokit. -1 to make unsaleable");
g_iSellPrice = GetConVarInt(g_hSellPrice);
HookConVarChange(g_hSellPrice, OnConVarChange);
AutoExecConfig(true, "shop_armokit", "shop");
RegConsoleCmd("sm_armor", Command_Tehnic);
RegConsoleCmd("sm_armokit", Command_Tehnic);
LoadTranslations("shop_armokit.phrases.txt");
HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
if (Shop_IsStarted()) Shop_Started();
}
public OnConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (convar == g_hArmor)
{
g_iArmor = StringToInt(newValue);
if (newValue[0] == '+')
{
g_iArmokitMode = ADD;
}
else
{
g_iArmokitMode = SET;
}
}
else if (convar == g_hMaxArmor)
{
g_iMaxArmor = StringToInt(newValue);
}
else if (convar == g_hRoundUse)
{
g_iRoundUse = StringToInt(newValue);
}
else if (convar == g_hPrice)
{
g_iPrice = StringToInt(newValue);
if (id != INVALID_ITEM)
{
Shop_SetItemPrice(id, g_iPrice);
}
}
else if (convar == g_hSellPrice)
{
g_iSellPrice = StringToInt(newValue);
if (id != INVALID_ITEM)
{
Shop_SetItemSellPrice(id, g_iSellPrice);
}
}
}
public OnRoundStart(Handle:event, const String:name[], bool:donBroadcast)
{
for (new i = 1; i <= MaxClients; i++)
{
iRoundUsed[i] = 0;
}
}
public Action:Command_Tehnic(client, args)
{
if (!client)
{
return Plugin_Continue;
}
if (!Shop_UseClientItem(client, id))
{
CPrintToChat(client, "%t", "NoArmokit");
}
return Plugin_Handled;
}
public OnMapStart()
{
PrecacheSound(TEHNIC_SOUND, true);
}
public OnPluginEnd()
{
Shop_UnregisterMe();
}
public Shop_Started()
{
new CategoryId:category_id = Shop_RegisterCategory(CATEGORY, "Stuff", "", OnCategoryDisplay, OnCategoryDescription);
if (Shop_StartItem(category_id, ARMOKIT))
{
Shop_SetInfo("Armokit", "", g_iPrice, g_iSellPrice, Item_Finite);
Shop_SetCallbacks(OnItemRegistered, OnArmokitChoose, _, OnDisplay, OnDescription, _, _);
Shop_EndItem();
}
}
public OnItemRegistered(CategoryId:category_id, const String:category[], const String:item[], ItemId:item_id)
{
id = item_id;
}
public bool:OnCategoryDisplay(client, CategoryId:category_id, const String:category[], const String:name[], String:buffer[], maxlen)
{
FormatEx(buffer, maxlen, "%T", "display", client);
return true;
}
public bool:OnCategoryDescription(client, CategoryId:category_id, const String:category[], const String:description[], String:buffer[], maxlen)
{
FormatEx(buffer, maxlen, "%T", "description", client);
return true;
}
public bool:OnDisplay(client, CategoryId:category_id, const String:category[], ItemId:item_id, const String:item[], ShopMenu:menu, &bool:disabled, const String:name[], String:buffer[], maxlen)
{
FormatEx(buffer, maxlen, "%T", "armokit", client);
return true;
}
public bool:OnDescription(client, CategoryId:category_id, const String:category[], ItemId:item_id, const String:item[], ShopMenu:menu, const String:description[], String:buffer[], maxlen)
{
FormatEx(buffer, maxlen, "%T", "armokit_description", client);
return true;
}
public ShopAction:OnArmokitChoose(client, CategoryId:category_id, const String:category[], ItemId:item_id, const String:item[])
{
if (g_iRoundUse > 0 && iRoundUsed[client] >= g_iRoundUse)
{
CPrintToChat(client, "%t", "RoundUsed", g_iRoundUse);
return Shop_Raw;
}
if (IsPlayerAlive(client))
{
new armor = GetClientArmor(client);
if (armor < g_iMaxArmor)
{
if (g_iArmokitMode == ADD)
{
armor += g_iArmor;
}
else
{
armor = g_iArmor;
}
if (armor > g_iMaxArmor)
{
armor = g_iMaxArmor;
}
//SetEntityArmor(client, armor); //не работает
SetEntProp(client,Prop_Send, "m_ArmorValue", armor+g_iMaxArmor); //Работает , но пополняет броню до фулла, а надо с конфига "sm_shop_armokit_max_armor", "+25"
CPrintToChat(client, "%t", "UsedArmokit");
EmitSoundToAll(TEHNIC_SOUND, client);
iRoundUsed[client]++;
return Shop_UseOn;
}
else
{
CPrintToChat(client, "%t", "EnoughArmor");
}
}
else
{
CPrintToChat(client, "%t", "MustAlive");
}
return Shop_Raw;
}