#include <amxmodx>
#include <reapi>
enum any:CVARS
{
BLOCK_GRENADE_MSG,
BLOCK_GRENADE_SOUND,
BLOCK_HUD_TEXT,
BLOCK_SPRAY,
BLOCK_LANTERN,
BLOCK_LANTERN_TIME,
Float:BLOCK_LANTERN_TIME_OUT,
Float:BLOCK_CHAT_TIME,
BLOCK_GRENADE_LIMIT,
BLOCK_GRENADE_FLASH,
BLOCK_GRENADE_HE,
BLOCK_GRENADE_SMOKE,
BLOCK_CHANGE_NAME,
Float:BLOCK_RADIO_FLOOD,
BLOCK_RADIO,
BLOCK_START_SOUND
};
new g_Cvar[CVARS];
enum (+=1) {
NADE_FLASHBANG = 0,
NADE_HEGRENADE,
NADE_SMOKEGRENADE,
NADE_NONE
}
new g_CountLimits[NADE_NONE];
new g_Counts[MAX_PLAYERS+1][NADE_NONE];
new const g_szMessages[][]=
{
"BLOCK_FLASHBANG",
"BLOCK_HEGRENADE",
"BLOCK_SMOKEGRENADE"
};
new Float:g_Flooding[MAX_PLAYERS+1] = {0.0, ...};
new g_Flood[MAX_PLAYERS+1] = {0, ...};
new const radio[][] = {"radio1", "radio2", "radio3"};
new const g_sFireInTheHole[] = "#Fire_in_the_hole", g_sFireInTheHoleSound[] = "%!MRAD_FIREINHOLE";
new sound[sizeof(g_sFireInTheHoleSound)], text[sizeof(g_sFireInTheHole)];
new Float:BlockTime[MAX_PLAYERS+1];
new gmsgSayText, gmsgTextMsg;
new HookChain: g_hCBasePlayer_Radio;
public plugin_init()
{
register_plugin("Block Manager", "1.1", "maFFyoZZyk");
register_dictionary("block_manager.txt");
RegisterCvars();
AutoExecConfig(true, "block_manager");
if(g_Cvar[BLOCK_GRENADE_MSG] == 1)
register_message(get_user_msgid("TextMsg"),"msgTextMsg");
if(g_Cvar[BLOCK_GRENADE_SOUND] == 1)
register_message(get_user_msgid("SendAudio"),"msgSendAudio");
if(g_Cvar[BLOCK_START_SOUND] == 1)
{
RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "CSGameRules_OnRoundFreezeEnd", .post=false);
DisableHookChain(g_hCBasePlayer_Radio = RegisterHookChain(RG_CBasePlayer_Radio, "CBasePlayer_Radio", .post=false));
}
if(g_Cvar[BLOCK_HUD_TEXT] == 1)
RegisterHookChain(RG_CBasePlayer_HintMessageEx, "CBasePlayer_HintMessageEx_Pre", false);
if(g_Cvar[BLOCK_HUD_TEXT] == 1)
{
RegisterHookChain(RG_CBasePlayer_SetClientUserInfoName, "CBasePlayer_SetUserInfoName")
gmsgSayText = get_user_msgid("SayText");
gmsgTextMsg = get_user_msgid("TextMsg");
}
RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "CPlayer_HasRestrictItem_Pre", .post=false);
RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn_Pre", .post=false);
RegisterHookChain(RG_CBasePlayer_Spawn, "CBasePlayer_Spawn_Post", .post=true);
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "CBasePlayer_AddPlayerItem_Post", .post=true);
RegisterHookChain(RG_CBasePlayer_ImpulseCommands, "CBasePlayer_ImpulseCommands", .post=false);
if(g_Cvar[BLOCK_RADIO] == 1 || g_Cvar[BLOCK_RADIO] == 2)
{
for (new i = 0; i < sizeof radio; i ++)
register_clcmd(radio[i], "chkFlood");
}
g_CountLimits[NADE_FLASHBANG] = g_Cvar[BLOCK_GRENADE_FLASH];
g_CountLimits[NADE_HEGRENADE] = g_Cvar[BLOCK_GRENADE_HE];
g_CountLimits[NADE_SMOKEGRENADE] = g_Cvar[BLOCK_GRENADE_SMOKE];
}
public msgTextMsg()
{
if(get_msg_args() == 5 && get_msg_argtype(5) == ARG_STRING)
{
get_msg_arg_string(5, text, sizeof text - 1);
if(equali(text, g_sFireInTheHole)) return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public msgSendAudio(msgId, msgDest, msgEnt)
{
get_msg_arg_string(2, sound, sizeof sound - 1);
return equali(sound, g_sFireInTheHoleSound);
}
public CBasePlayer_HintMessageEx_Pre(const id, const message[], Float:duration, bool:bDisplayIfPlayerDead, bool:bOverride)
{
SetHookChainReturn(ATYPE_BOOL, false);
return HC_SUPERCEDE;
}
public CBasePlayer_ImpulseCommands(const id)
{
static impulse;
impulse = get_entvar(id, var_impulse);
static Float:fLastTime[33], Float:fCurTime;
fCurTime = get_gametime();
if(g_Cvar[BLOCK_SPRAY] == 1 && impulse == 201)
{
if(is_user_alive( id ) && (fCurTime - fLastTime[id] > g_Cvar[BLOCK_CHAT_TIME]))
{
client_print(id, print_center, "%L", id, "BLOCK_SPRAY");
fLastTime[id] = fCurTime;
}
set_entvar(id, var_impulse, 0);
return HC_SUPERCEDE;
}
if(impulse == 100)
{
if(g_Cvar[BLOCK_LANTERN] == 1)
{
if(is_user_alive( id ) && (fCurTime - fLastTime[id] > g_Cvar[BLOCK_CHAT_TIME]))
{
client_print(id, print_center, "%L", id, "BLOCK_LANTERN");
fLastTime[id] = fCurTime;
}
set_entvar(id, var_impulse, 0);
return HC_SUPERCEDE;
}
if(g_Cvar[BLOCK_LANTERN_TIME] == 1 && g_Cvar[BLOCK_LANTERN] != 1)
{
new Float:gametime = get_gametime();
if(BlockTime[id] <= gametime)
{
BlockTime[id] = gametime + g_Cvar[BLOCK_LANTERN_TIME_OUT];
return HC_CONTINUE;
}
return HC_SUPERCEDE;
}
}
return HC_CONTINUE;
}
public CPlayer_HasRestrictItem_Pre(const id, const ItemID:item, const ItemRestType:type)
{
if(g_Cvar[BLOCK_GRENADE_LIMIT] != 1) return HC_CONTINUE;
if (type != ITEM_TYPE_BUYING) return HC_CONTINUE;
new key = getKeyByItemID(item);
if (key == NADE_NONE) return HC_CONTINUE;
if (g_Counts[id][key] < g_CountLimits[key]) return HC_CONTINUE;
if(++g_Counts[id][key] > g_CountLimits[key])
{
client_print(id, print_center, "%L", id, g_szMessages[key], g_CountLimits[key]);
SetHookChainReturn(ATYPE_BOOL, true);
return HC_SUPERCEDE;
}
return HC_CONTINUE;
}
public CBasePlayer_Spawn_Pre(const id)
{
if(g_Cvar[BLOCK_RADIO] == 1)
set_cvar_num("mp_radio_maxinround", 0);
if(g_Cvar[BLOCK_RADIO] == 0)
return HC_CONTINUE;
return HC_CONTINUE;
}
public CBasePlayer_Spawn_Post(const id)
{
if(g_Cvar[BLOCK_GRENADE_LIMIT] != 1) return HC_CONTINUE;
if(!is_user_connected(id)) return HC_CONTINUE;
arrayset(g_Counts[id], 0, sizeof(g_Counts[]));
return HC_CONTINUE;
}
public CBasePlayer_AddPlayerItem_Post(const id, const item)
{
if(g_Cvar[BLOCK_GRENADE_LIMIT] != 1) return HC_CONTINUE;
new key = getKeyByItem(item);
if (key != NADE_NONE) g_Counts[id][key]++;
return HC_CONTINUE;
}
getKeyByItemID(const ItemID:item)
{
switch (item)
{
case ITEM_FLASHBANG: return NADE_FLASHBANG;
case ITEM_HEGRENADE: return NADE_HEGRENADE;
case ITEM_SMOKEGRENADE: return NADE_SMOKEGRENADE;
}
return NADE_NONE;
}
getKeyByItem(const item)
{
switch (WeaponIdType:get_member(item, m_iId))
{
case WEAPON_FLASHBANG: return NADE_FLASHBANG;
case WEAPON_HEGRENADE: return NADE_HEGRENADE;
case WEAPON_SMOKEGRENADE: return NADE_SMOKEGRENADE;
}
return NADE_NONE;
}
public client_disconnected(id)
{
if(g_Cvar[BLOCK_LANTERN_TIME] == 1)
BlockTime[id] = 0.0;
}
public CBasePlayer_SetUserInfoName(const pPlayer, infobuffer[], szNewName[])
{
new szOldName[32]
get_entvar(pPlayer, var_netname, szOldName, charsmax(szOldName))
SetHookChainArg(3, ATYPE_STRING, szOldName)
console_print(pPlayer, "szOldName: %s | szNewName: %s", szOldName, szNewName)
set_msg_block(get_entvar(pPlayer, var_deadflag) != DEAD_NO ? gmsgTextMsg : gmsgSayText, BLOCK_ONCE)
}
public chkFlood(id)
{
if (g_Cvar[BLOCK_RADIO] == 1)
return PLUGIN_HANDLED;
if (g_Cvar[BLOCK_RADIO] == 2)
{
new Float:nexTime = get_gametime();
if (g_Flooding[id] > nexTime)
{
if (g_Flood[id] >= 5)
{
client_print(id, print_center, "%L", id, "BLOCK_RADIO_FLOOD");
g_Flooding[id] = nexTime + g_Cvar[BLOCK_RADIO_FLOOD] + 3.0;
return PLUGIN_HANDLED;
}
g_Flood[id] ++;
}
else if (g_Flood[id])
{
g_Flood[id] --;
}
g_Flooding[id] = nexTime + g_Cvar[BLOCK_RADIO_FLOOD];
}
return PLUGIN_CONTINUE;
}
public CSGameRules_OnRoundFreezeEnd()
{
EnableHookChain(g_hCBasePlayer_Radio);
}
public CBasePlayer_Radio()
{
// server_print("%n %s %s %i %i", this, msg_id, msg_verbose, pitch, showIcon);
DisableHookChain(g_hCBasePlayer_Radio);
return HC_SUPERCEDE;
}
RegisterCvars()
{
bind_pcvar_num(
create_cvar(
.name = "block_grenade_msg",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_GRENADE_MSG"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_GRENADE_MSG]
);
bind_pcvar_num(
create_cvar(
.name = "block_grenade_sound",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_GRENADE_SOUND"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_GRENADE_SOUND]
);
bind_pcvar_num(
create_cvar(
.name = "block_hud_text",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_HUD_TEXT"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_HUD_TEXT]
);
bind_pcvar_num(
create_cvar(
.name = "block_spray",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_SPRAY"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_SPRAY]
);
bind_pcvar_num(
create_cvar(
.name = "block_lantern",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_LANTERN"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_LANTERN]
);
bind_pcvar_num(
create_cvar(
.name = "block_lantern_time",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_LANTERN_TIME"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_LANTERN_TIME]
);
bind_pcvar_float(
create_cvar(
.name = "block_chat_time",
.string = "5.0",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_CHAT_TIME"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_CHAT_TIME]
);
bind_pcvar_float(
create_cvar(
.name = "block_lantern_time_out",
.string = "1.5",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_LANTERN_TIME_OUT"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_LANTERN_TIME_OUT]
);
bind_pcvar_num(
create_cvar(
.name = "block_grenade_limit",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_GRENADE_LIMIT"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_GRENADE_LIMIT]
);
bind_pcvar_num(
create_cvar(
.name = "block_grenade_flash",
.string = "2",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_GRENADE_FLASH"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_GRENADE_FLASH]
);
bind_pcvar_num(
create_cvar(
.name = "block_grenade_he",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_GRENADE_HE"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_GRENADE_HE]
);
bind_pcvar_num(
create_cvar(
.name = "block_grenade_smoke",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_GRENADE_SMOKE"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_GRENADE_SMOKE]
);
bind_pcvar_num(
create_cvar(
.name = "block_change_name",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_CHANGE_NAME"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_CHANGE_NAME]
);
bind_pcvar_float(
create_cvar(
.name = "block_radio_flood",
.string = "0.75",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_RADIO_FLOOD"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_RADIO_FLOOD]
);
bind_pcvar_num(
create_cvar(
.name = "block_radio",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_RADIO"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_RADIO]
);
bind_pcvar_num(
create_cvar(
.name = "block_start_snd",
.string = "1",
.flags = FCVAR_SERVER,
.description = fmt("%l", "BLOCK_CVAR_START_SND"),
.has_min = true,
.min_val = 0.0
), g_Cvar[BLOCK_START_SOUND]
);
}