#include <amxmodx>
#include <reapi>
#include <amxmisc>
enum {
BLOCK_ONLINE = 1,
BLOCK_LIMIT
};
new g_iAw1kInTeam[TeamName: TEAM_SPECTATOR];
new g_iMinOnline, g_iAw1kAllowed;
public plugin_init() {
register_plugin("Awp Restrictions", "1.1", "wrx?!");
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "CBasePlayer_AddPlayerItem_Pre", false);
RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "CBasePlayer_HasRestrictItem_Pre", false);
RegisterHookChain(RG_CBasePlayer_RemovePlayerItem, "CBasePlayer_RemoveItem_Pre", false);
register_logevent("LogEvent_RestartRound", 2, "1&Restart_Round_");
new pCvar = create_cvar(
"awp_min_online",
"10",
.description = "Минимальное количество игроков для доступа к АВП",
.has_min = true, .min_val = 1.0,
.has_max = true, .max_val = 32.0
);
bind_pcvar_num(pCvar, g_iMinOnline);
pCvar = create_cvar(
"awp_allowed",
"2",
.description = "Сколько АВП на команду разрешено",
.has_min = true, .min_val = 1.0,
.has_max = true, .max_val = 16.0
);
bind_pcvar_num(pCvar, g_iAw1kAllowed);
AutoExecConfig(true, "awp_restrictions");
}
public plugin_natives() {
register_native("is_awp_blocked", "_is_awp_blocked", false);
}
public _is_awp_blocked(plugin, params) {
enum { arg_player = 1 };
new id = get_param(arg_player);
if (!(id >= 1 && id <= MaxClients) || !is_user_connected(id))
return 0;
return is_awp_blocked(id);
}
public plugin_cfg() {
register_dictionary("awp_restrictions.txt");
}
public LogEvent_RestartRound() {
g_iAw1kInTeam[TEAM_CT] = 0;
g_iAw1kInTeam[TEAM_TERRORIST] = 0;
}
public CBasePlayer_HasRestrictItem_Pre(id, ItemID: eItem, ItemRestType: eType) {
if (eItem != ITEM_AWP)
return HC_CONTINUE;
if (!is_awp_blocked(id)) {
g_iAw1kInTeam[get_member(id, m_iTeam)]++;
return HC_CONTINUE;
}
client_print(id, print_center, "%L", id, is_awp_blocked(id) == BLOCK_ONLINE ? "AWP_LOW_ONLINE" : "AWP_LIMIT");
SetHookChainReturn(ATYPE_BOOL, true);
return HC_SUPERCEDE;
}
public CBasePlayer_AddPlayerItem_Pre(id, pItem){
if (get_member(pItem, m_iId) != WEAPON_AWP)
return HC_CONTINUE;
if (!is_awp_blocked(id)) {
g_iAw1kInTeam[get_member(id, m_iTeam)]++;
return HC_CONTINUE;
}
client_print(id, print_center, "%L", id, is_awp_blocked(id) == BLOCK_ONLINE ? "AWP_LOW_ONLINE" : "AWP_LIMIT");
SetHookChainReturn(ATYPE_INTEGER, false);
return HC_SUPERCEDE;
}
public CBasePlayer_RemoveItem_Pre(id, pItem) {
if (get_member(pItem, m_iId) == WEAPON_AWP) {
g_iAw1kInTeam[get_member(id, m_iTeam)]--;
}
return HC_CONTINUE;
}
stock is_awp_blocked(id) {
new eType,
playersCount[2];
playersCount[0] = get_playersnum_ex(GetPlayers_ExcludeHLTV | GetPlayers_MatchTeam, "CT");
playersCount[1] = get_playersnum_ex(GetPlayers_ExcludeHLTV | GetPlayers_MatchTeam, "TERRORIST");
if ((playersCount[0] + playersCount[1]) < g_iMinOnline)
eType = BLOCK_ONLINE;
else if (g_iAw1kInTeam[get_member(id, m_iTeam)] >= g_iAw1kAllowed)
eType = BLOCK_LIMIT;
else
eType = 0;
return eType;
}