Thanks for the suggestion Relaxing.
I tried this below. Problem is if someone spams the key bound to +adminvoice longer than 2 seconds, the issue is still there. As soon g_bAdminVoice get false and true again in VTC_OnClientStartSpeak it gives the HUD message. For practical reasons (end users) I can't make it longer than 2 seconds. There must be another way to solve this. I am a coding rookie. I'm more of an electrician that compare this issue with a light bulb with a momentary switch connected. To solve the light flickering when someone repeatedly pressing the switch I would use a capacitor big enough for steady light.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <reapi>
#define PLUGIN "No Dead Mic ReAPI"
#define AUTHOR "fatal"
#define VERSION "0.2.1
#define MAX_PLAYERS 32
new bool:g_bAdmin[MAX_PLAYERS+1]
new bool:g_bEnforcer[MAX_PLAYERS+1]
new bool:g_bAdminVoice[MAX_PLAYERS+1]
new g_AdminVoiceDelay[MAX_PLAYERS+1]
public plugin_init()
{
register_plugin(PLUGIN,VERSION,AUTHOR)
register_forward(FM_Voice_SetClientListening,"VoiceSetListening")
register_clcmd("+adminvoice","AdminVoiceOn")
register_clcmd("-adminvoice","AdminVoiceOff")
set_cvar_num("sv_alltalk",1)
}
public client_authorized(id)
{
g_bAdmin[id] = bool:(get_user_flags(id) & ADMIN_LEVEL_G)
g_bEnforcer[id] = bool:(get_user_flags(id) & ADMIN_IMMUNITY)
}
public client_putinserver(id)
{
g_bAdminVoice[id] = false
}
public AdminVoiceOn(id)
{
if( !g_bAdmin[id] || is_user_alive(id) )
{
return PLUGIN_CONTINUE
}
if(get_systime() - g_AdminVoiceDelay[id] < 2)
{
client_print(id, print_chat, "[ADMIN VOCOM]: Please stop spamming the mic key.")
return PLUGIN_HANDLED
}
g_AdminVoiceDelay[id] = get_systime()
g_bAdminVoice[id] = true
return PLUGIN_CONTINUE
}
public AdminVoiceOff(id)
{
if(!g_bAdminVoice[id])
return PLUGIN_CONTINUE
g_bAdminVoice[id] = false
return PLUGIN_CONTINUE
}
public VoiceSetListening(iReceiver,iSender)
{
if(is_user_alive(iSender) || g_bEnforcer[iSender]) return 1
engfunc(EngFunc_SetClientListening,iReceiver,iSender, 0)
return 4;
}
public VTC_OnClientStartSpeak(const index)
{
if(!is_user_alive(index) && !g_bAdminVoice[index] && !g_bEnforcer[index])
{
set_hudmessage(0,255,0,-1.0,0.35,1,6.0,4.0,0.5,0.15,-1)
show_hudmessage(index,"Dead people can't talk on mic.")
client_cmd(index,"spk fvox/blip.wav")
}
}