#include <amxmodx>
#include <cstrike>
#include <fun>
#define FLASH_PCS 4 // Максимальное кол-во закупаемых ослепляющих гранат.
#define FLASH_PRICE 200 // Цена за ослепляющие гранаты.
#define HEGREN_PCS 2 // Максимальное кол-во закупаемых осколочные гранат.
#define HEGREN_PRICE 300 // Цена за осколочные гранаты.
#define SGREN_PCS 2 // Максимальное кол-во закупаемых дымовых гранат.
#define SGREN_PRICE 300 // Цена за дымовые гранаты.
new g_iReturn, g_PurchaseTime, Float:g_iTime;
public plugin_init()
{
register_plugin("Grenade Limit", "0.0.1", "Albertio");
register_event("HLTV", "Event_RoundStart", "a", "1=0", "2=0");
register_dictionary("grenade_limit.txt");
}
public Event_RoundStart()
{
g_iTime = 60.0 * get_cvar_float("mp_buytime");
g_PurchaseTime = get_cvar_num("mp_freezetime") + floatround(g_iTime, floatround_round)
remove_task(3);
set_task(1.0, "PurchaseTime", 3, _, _, "a", g_PurchaseTime);
}
public PurchaseTime()
{
g_PurchaseTime--;
}
public client_command(id)
{
if(is_user_alive(id))
{
new szCommand[13];
if(read_argv(0, szCommand, charsmax(szCommand)) < 12)
{
return CheckBuyCmd(id, szCommand);
}
}
return PLUGIN_CONTINUE;
}
public CS_InternalCommand(id, const szCommand[])
{
if(is_user_alive(id))
{
new szCmd[13];
if(copy(szCmd, charsmax(szCmd), szCommand) < 12)
{
return CheckBuyCmd(id, szCmd);
}
}
return PLUGIN_CONTINUE;
}
public CheckBuyCmd(id, szCmd[])
{
new iItem = GetAliasId(szCmd);
if(iItem)
{
return CanBuyItem(id, iItem);
}
return PLUGIN_CONTINUE;
}
public CanBuyItem(id, iItem)
{
if(g_PurchaseTime > 0)
{
if(iItem == CSW_FLASHBANG && !user_has_weapon(id, CSW_FLASHBANG))
{
if(cs_get_user_money(id) >= FLASH_PRICE)
{
give_item(id, "weapon_flashbang");
cs_set_user_money(id, cs_get_user_money(id) - FLASH_PRICE);
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_FLASH_NOTMONEY");
}
g_iReturn = 1;
return PLUGIN_HANDLED;
}
else if(iItem == CSW_FLASHBANG && user_has_weapon(id, CSW_FLASHBANG))
{
if(cs_get_user_bpammo(id, CSW_FLASHBANG) < FLASH_PCS)
{
if(cs_get_user_money(id) >= FLASH_PRICE)
{
cs_set_user_bpammo(id, CSW_FLASHBANG, cs_get_user_bpammo(id, CSW_FLASHBANG) + 1);
cs_set_user_money(id, cs_get_user_money(id) - FLASH_PRICE);
g_iReturn = 0;
return PLUGIN_CONTINUE;
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_FLASH_NOTMONEY");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_FLASH_LIMIT");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
}
if(iItem == CSW_HEGRENADE && !user_has_weapon(id, CSW_HEGRENADE))
{
if(cs_get_user_money(id) >= HEGREN_PRICE)
{
give_item(id, "weapon_hegrenade");
cs_set_user_money(id, cs_get_user_money(id) - HEGREN_PRICE);
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_HEGREN_NOTMONEY");
}
g_iReturn = 1;
return PLUGIN_HANDLED;
}
else if(iItem == CSW_HEGRENADE && user_has_weapon(id, CSW_HEGRENADE))
{
if(cs_get_user_bpammo(id, CSW_HEGRENADE) < HEGREN_PCS)
{
if(cs_get_user_money(id) >= HEGREN_PRICE)
{
cs_set_user_bpammo(id, CSW_HEGRENADE, cs_get_user_bpammo(id, CSW_HEGRENADE) + 1);
cs_set_user_money(id, cs_get_user_money(id) - HEGREN_PRICE);
g_iReturn = 0;
return PLUGIN_CONTINUE;
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_HEGREN_NOTMONEY");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_HEGREN_LIMIT");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
}
if(iItem == CSW_SMOKEGRENADE && !user_has_weapon(id, CSW_SMOKEGRENADE))
{
if(cs_get_user_money(id) >= SGREN_PRICE)
{
give_item(id, "weapon_smokegrenade");
cs_set_user_money(id, cs_get_user_money(id) - SGREN_PRICE);
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_SMOKE_NOTMONEY");
}
g_iReturn = 1;
return PLUGIN_HANDLED;
}
else if(iItem == CSW_SMOKEGRENADE && user_has_weapon(id, CSW_SMOKEGRENADE))
{
if(cs_get_user_bpammo(id, CSW_SMOKEGRENADE) < SGREN_PCS)
{
if(cs_get_user_money(id) >= SGREN_PRICE)
{
cs_set_user_bpammo(id, CSW_SMOKEGRENADE, cs_get_user_bpammo(id, CSW_SMOKEGRENADE) + 1);
cs_set_user_money(id, cs_get_user_money(id) - SGREN_PRICE);
g_iReturn = 0;
return PLUGIN_CONTINUE;
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_SMOKE_NOTMONEY");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_SMOKE_LIMIT");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
}
}
else
{
client_print_color(id, print_team_default, "%L", id, "GL_PURCHASETIME");
g_iReturn = 1;
return PLUGIN_HANDLED;
}
if(g_iReturn != PLUGIN_CONTINUE)
{
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public GetAliasId(szAlias[])
{
static Trie:tAliasesIds = Invalid_Trie;
if(tAliasesIds == Invalid_Trie)
{
tAliasesIds = TrieCreate();
TrieSetCell(tAliasesIds, "flash", CSW_FLASHBANG);
TrieSetCell(tAliasesIds, "hegren", CSW_HEGRENADE);
TrieSetCell(tAliasesIds, "sgren", CSW_SMOKEGRENADE);
}
strtolower(szAlias);
new iId;
if(TrieGetCell(tAliasesIds, szAlias, iId))
{
return iId;
}
return 0;
}