#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#tryinclude <reapi>
#if !defined _reapi_included
    #include <VtcApi>
#endif
#include <fakemeta>
new bool:blockVoise = false,ct_count = 0,tt_count = 0,bool:alert_tt = false,bool:alert_ct = false,userLastTT,userLastCT;
public plugin_init()
{
    register_plugin("Block All Voice For Last Player", "2.0", "uMk0");
    register_forward(FM_Voice_SetClientListening, "ClientListeng", false)
    RegisterHookChain(RG_CBasePlayer_Spawn, "round_update", true);
    RegisterHookChain(RG_CBasePlayer_Killed, "killed", true);
}
public killed(id){
    switch (TeamName:get_member(id, m_iTeam)) {
        case TEAM_TERRORIST: {
            tt_count--;
        }
        case TEAM_CT: {
            ct_count--;
        }
    }
    if(ct_count == 1 && !alert_ct){
        client_print_color(0, 0, "^1[^4BVP^1] ^4Выживший ^3контр-террорист ^4не слышит теперь всех!");
        alert_ct = true;
        userLastCT = getLastPlayer("CT");
    }
    if(tt_count == 1 && !alert_tt){
        client_print_color(0, 0, "^1[^4BVP^1] ^4Выживший ^3террорист ^4не слышит теперь всех!");
        alert_tt = true;
        userLastTT = getLastPlayer("TERRORIST");
    }
    if(ct_count <= 1 || tt_count <= 1){
        blockVoise = true;
    }
    
}
public ClientListeng(iReciever, iSender)
{
    if((iReciever == userLastTT || iReciever == userLastCT) && blockVoise){
        engfunc(EngFunc_SetClientListening, iReciever, iSender, false);
        forward_return(FMV_CELL, false);
        return FMRES_SUPERCEDE;
    }
    return FMRES_IGNORED;
}
getLastPlayer(const team[]) {
    new players[MAX_PLAYERS], num;
    get_players_ex(players, num, GetPlayers_ExcludeDead | GetPlayers_ExcludeBots | GetPlayers_ExcludeHLTV | GetPlayers_MatchTeam, team);
    return num == 1 ? players[0] : 0;
}
public round_update(){
    tt_count = get_member_game(m_iNumSpawnableTerrorist);
    ct_count = get_member_game(m_iNumSpawnableCT);
    alert_tt = false;
    alert_ct = false;
    blockVoise = false;
    userLastTT = 0;
    userLastCT = 0;
}