You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

124 lines
4.0 KiB

#include <sourcemod>
#include <sdktools>
//#include "extra.sp"
int g_mute_player_votes[TF2_MAXPLAYERS][TF2_MAXPLAYERS];
bool g_mute_player_voted[TF2_MAXPLAYERS];
float g_mute_need_count = 0.3;
Handle g_mute_timer = INVALID_HANDLE;
char g_mute_votecmd[32] = "sm_votemute";
#define MUTE_VOTE_COMPLETE "Игрок %N был выключен микрофон по итогу подсчетов голосов!"
#define MUTE_VOTE_VOTED "Игрок %N проголосовал за выключение микрофона игрока %N. Проголосовать за: !votemute в чат или через меню."
stock MuteCheckState(int client){
if(GetClientListeningFlags(client) == VOICE_MUTED) g_mute_player_voted[client] = true;
}
stock bool MuteCheckVotes(int client){
if(ReturnVoteCount(client, g_mute_player_votes) >= CalcNeedCount(g_mute_need_count)){
MutePlayer(client);
return true;
} else {
return false;
}
}
stock MuteClearPlayerVotes(int client){
g_mute_player_voted[client] = false;
ClearPlayerVotes(client, g_mute_player_votes);
}
stock MutePlayer(int client){
PrintCenterTextAll(MUTE_VOTE_COMPLETE, client);
PrintToChatAll(MUTE_VOTE_COMPLETE, client);
MuteClearPlayerVotes(client);
g_mute_player_voted[client] = true;
if(CommandExists("sm_fsb_mute")){
ServerCommand("sm_fsb_mute #%i 900 vote", GetClientUserId(client));
} else {
SetClientListeningFlags(client, VOICE_MUTED);
}
}
stock MuteVoteOn(){
if(g_mute_timer != INVALID_HANDLE) KillTimer(g_mute_timer);
else g_mute_timer = CreateTimer(5.0, CallbackMuteTimer, _, TIMER_REPEAT);
RegConsoleCmd(g_mute_votecmd, CommandMuteVote, "Vote for mute player on server");
PrintToServer("[FV] [VoteMute] support enable");
for(int client = 1; client <= MaxClients; client++){
if(IsValidClient(client)) MuteCheckState(client);
}
}
stock MuteVoteOff(){
if(g_mute_timer != INVALID_HANDLE) KillTimer(g_mute_timer);
}
stock DisplayMuteMenu(int client){
Handle MuteMenu = CreateMenu(CallbackMuteBuildMenu);
SetMenuTitle(MuteMenu, "Выключить микрофон у:");
char menu_line[64];
char player_uid[32];
for(int player = 1; player <= MaxClients; player++){
if(IsValidClient(player)){
//if(player == client) continue;
if(CheckCommandAccess(player, "", ADMFLAG_BAN)) continue;
Format(player_uid, sizeof(player_uid), "%i", GetClientUserId(player));
if(g_mute_player_voted[player]){
Format(menu_line, sizeof(menu_line), "%N [Выключен микрофон]", player);
AddMenuItem(MuteMenu, player_uid, menu_line, ITEMDRAW_DISABLED);
}
else if(g_mute_player_votes[player][client] == 0) {
Format(menu_line, sizeof(menu_line), "%N [%i/%i]", player, ReturnVoteCount(player, g_mute_player_votes), CalcNeedCount(g_mute_need_count));
AddMenuItem(MuteMenu, player_uid, menu_line);
} else {
Format(menu_line, sizeof(menu_line), "%N [Ты проголосовал]", player);
AddMenuItem(MuteMenu, player_uid, menu_line, ITEMDRAW_DISABLED);
}
}
}
if(GetMenuItemCount(MuteMenu) == 0){
PrintCenterText(client, "Незакого голосовать, ты один на сервере");
return;
}
DisplayMenu(MuteMenu, client, 0);
return;
}
stock CallbackMuteBuildMenu(Handle MuteMenu, MenuAction action, int client, int pos){
switch(action){
case MenuAction_Select:{
char player_uid[32];
GetMenuItem(MuteMenu, pos, player_uid, sizeof(player_uid));
int player = GetClientOfUserId(StringToInt(player_uid));
if(player == 0){
PrintCenterText(client, "Увы игрок вышел!");
return;
}
g_mute_player_votes[player][client] = 1;
if(!MuteCheckVotes(player)) PrintCenterTextAll(MUTE_VOTE_VOTED, client, player);
}
case MenuAction_End: delete MuteMenu;
}
return;
}
stock Action CallbackMuteTimer(Handle timer){
for(int client = 1; client <= MaxClients; client++){
if(IsValidClient(client)) MuteCheckVotes(client);
}
}
public Action CommandMuteVote(int client, int args){
if (client == 0)
{
ReplyToCommand(client, "Cannot use command from RCON.");
return Plugin_Handled;
}
DisplayMuteMenu(client);
return Plugin_Handled;
}