#include <amxmodx>
#include <reapi>
enum SectionBits
{
SECTION_WEAPONS,
SECTION_ITEMS
};
new g_BitsItemsBlocked[SectionBits];
public plugin_init()
{
register_plugin("Weapon Restrict", "2.1", "s1lent & neugomon");
LoadCfg();
RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "fwdHasRestrictItemPre", false);
}
public fwdHasRestrictItemPre(const id, const ItemID:item, ItemRestType:type)
{
if((item < ITEM_NVG) ? g_BitsItemsBlocked[SECTION_WEAPONS] & (1 << any:item) :
g_BitsItemsBlocked[SECTION_ITEMS] & (1 << any:(item % ITEM_NVG)))
{
if(type == ITEM_TYPE_BUYING)
client_print(id, print_center, "*** Покупка запрещена! ***");
SetHookChainReturn(ATYPE_INTEGER, 1);
return HC_SUPERCEDE;
}
return HC_CONTINUE;
}
LoadCfg()
{
new szPath[64];
new szMapName[32]
new szLoadedConfig[96];
get_localinfo("amxx_configsdir", szPath, charsmax(szPath));
rh_get_mapname(szMapName, charsmax(szMapName));
formatex(szLoadedConfig, charsmax(szLoadedConfig), "%s/weaponrest/%s.ini", szPath, szMapName);
new fp = fopen(szLoadedConfig, "rt");
if(!fp)
{
formatex(szLoadedConfig, charsmax(szLoadedConfig), "%s/weaponrest/default.ini", szPath);
if(!(fp = fopen(szLoadedConfig, "rt")))
set_fail_state("Configs not read :(");
}
new Trie:tWeapons = TrieCreate();
new Trie:tItems = TrieCreate();
TrieSetCell(tWeapons, "ITEM_SHIELDGUN",any:ITEM_SHIELDGUN);
TrieSetCell(tWeapons, "ITEM_P228",any:ITEM_P228);
TrieSetCell(tWeapons, "ITEM_GLOCK",any:ITEM_GLOCK);
TrieSetCell(tWeapons, "ITEM_SCOUT",any:ITEM_SCOUT);
TrieSetCell(tWeapons, "ITEM_HEGRENADE", any:ITEM_HEGRENADE);
TrieSetCell(tWeapons, "ITEM_XM1014", any:ITEM_XM1014);
TrieSetCell(tWeapons, "ITEM_C4", any:ITEM_C4);
TrieSetCell(tWeapons, "ITEM_MAC10", any:ITEM_MAC10);
TrieSetCell(tWeapons, "ITEM_AUG", any:ITEM_AUG);
TrieSetCell(tWeapons, "ITEM_SMOKEGRENADE", any:ITEM_SMOKEGRENADE);
TrieSetCell(tWeapons, "ITEM_ELITE", any:ITEM_ELITE);
TrieSetCell(tWeapons, "ITEM_FIVESEVEN", any:ITEM_FIVESEVEN);
TrieSetCell(tWeapons, "ITEM_UMP45", any:ITEM_UMP45);
TrieSetCell(tWeapons, "ITEM_SG550", any:ITEM_SG550);
TrieSetCell(tWeapons, "ITEM_GALIL", any:ITEM_GALIL);
TrieSetCell(tWeapons, "ITEM_FAMAS", any:ITEM_FAMAS);
TrieSetCell(tWeapons, "ITEM_USP", any:ITEM_USP);
TrieSetCell(tWeapons, "ITEM_GLOCK18", any:ITEM_GLOCK18);
TrieSetCell(tWeapons, "ITEM_AWP", any:ITEM_AWP);
TrieSetCell(tWeapons, "ITEM_MP5N", any:ITEM_MP5N);
TrieSetCell(tWeapons, "ITEM_M249", any:ITEM_M249);
TrieSetCell(tWeapons, "ITEM_M3", any:ITEM_M3);
TrieSetCell(tWeapons, "ITEM_M4A1", any:ITEM_M4A1);
TrieSetCell(tWeapons, "ITEM_TMP", any:ITEM_TMP);
TrieSetCell(tWeapons, "ITEM_G3SG1", any:ITEM_G3SG1);
TrieSetCell(tWeapons, "ITEM_FLASHBANG", any:ITEM_FLASHBANG);
TrieSetCell(tWeapons, "ITEM_DEAGLE", any:ITEM_DEAGLE);
TrieSetCell(tWeapons, "ITEM_SG552", any:ITEM_SG552);
TrieSetCell(tWeapons, "ITEM_AK47", any:ITEM_AK47);
TrieSetCell(tWeapons, "ITEM_KNIFE", any:ITEM_KNIFE);
TrieSetCell(tWeapons, "ITEM_P90", any:ITEM_P90);
TrieSetCell(tItems, "ITEM_NVG", any:ITEM_NVG);
TrieSetCell(tItems, "ITEM_DEFUSEKIT", any:ITEM_DEFUSEKIT);
TrieSetCell(tItems, "ITEM_KEVLAR", any:ITEM_KEVLAR);
TrieSetCell(tItems, "ITEM_ASSAULT", any:ITEM_ASSAULT);
TrieSetCell(tItems, "ITEM_LONGJUMP", any:ITEM_LONGJUMP);
TrieSetCell(tItems, "ITEM_SODACAN", any:ITEM_SODACAN);
TrieSetCell(tItems, "ITEM_HEALTHKIT", any:ITEM_HEALTHKIT);
TrieSetCell(tItems, "ITEM_ANTIDOTE", any:ITEM_ANTIDOTE);
TrieSetCell(tItems, "ITEM_BATTERY", any:ITEM_BATTERY);
new szBuff[32];
new aPos;
while(!feof(fp))
{
fgets(fp, szBuff, charsmax(szBuff));
trim(szBuff);
if(!szBuff[0] || szBuff[0] == ';')
continue;
if(TrieGetCell(tWeapons, szBuff, aPos))
g_BitsItemsBlocked[SECTION_WEAPONS] |= (1 << aPos);
else if(TrieGetCell(tItems, szBuff, aPos))
g_BitsItemsBlocked[SECTION_ITEMS] |= (1 << aPos % any:ITEM_NVG);
}
TrieDestroy(tWeapons);
TrieDestroy(tItems);
fclose(fp);
log_amx("Load items block from '%s'", szLoadedConfig);
}