5ceea87a00
pretty sure it works
325 lines
7.3 KiB
SourcePawn
325 lines
7.3 KiB
SourcePawn
#pragma semicolon 1
|
|
|
|
#include <sourcemod>
|
|
#include <sdktools>
|
|
#include <cstrike>
|
|
#include <clientprefs>
|
|
|
|
#define MESSAGE_RADIOTEXT 1
|
|
#define MESSAGE_SENDAUDIO 2
|
|
|
|
bool g_bStopRadioSounds[MAXPLAYERS+1] = { false, ... };
|
|
bool g_bStopRadioSoundsHooked = false;
|
|
bool g_bStopNadeSounds[MAXPLAYERS+1] = { false, ...};
|
|
|
|
Handle g_hCookieStopRadio = null;
|
|
Handle g_hCookieStopNade = null;
|
|
|
|
public Plugin myinfo =
|
|
{
|
|
name = "SelfMuteRadio",
|
|
author = "Dogan + zaCade",
|
|
description = "Make it possible to self mute the radio (aka ignoread via command)",
|
|
version = "1.0.0",
|
|
url = ""
|
|
};
|
|
|
|
public void OnPluginStart()
|
|
{
|
|
UserMsg RadioText = GetUserMessageId("RadioText");
|
|
|
|
if (RadioText == INVALID_MESSAGE_ID)
|
|
SetFailState("This game does not support the \"RadioText\" UserMessage.");
|
|
|
|
UserMsg SendAudio = GetUserMessageId("SendAudio");
|
|
|
|
if (SendAudio == INVALID_MESSAGE_ID)
|
|
SetFailState("This game does not support the \"SendAudio\" UserMessage.");
|
|
|
|
RegConsoleCmd("sm_smradio", ToggleSelfMuteRadio, "Toggle Radio Self Mute");
|
|
//RegConsoleCmd("sm_radio", ToggleSelfMuteRadio, "Toggle Radio Self Mute"); //GFL only
|
|
RegConsoleCmd("sm_smradio_nades", ToggleSelfMuteNade, "Toggle only Radio 'Fire in the hole' Self Mute");
|
|
|
|
g_hCookieStopRadio = RegClientCookie("radio_blocked", "is the radio blocked", CookieAccess_Protected);
|
|
g_hCookieStopNade = RegClientCookie("nades_blocked", "is the 'fire in the hole' radio blocked", CookieAccess_Protected);
|
|
|
|
HookUserMessage(RadioText, Hook_RadioText, true);
|
|
HookUserMessage(SendAudio, Hook_SendAudio, true);
|
|
}
|
|
|
|
public Action Hook_RadioText(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init)
|
|
{
|
|
if(!g_bStopRadioSoundsHooked)
|
|
return Plugin_Continue;
|
|
|
|
int dest = BfReadByte(bf);
|
|
int client = BfReadByte(bf);
|
|
|
|
char sSoundType[128];
|
|
BfReadString(bf, sSoundType, sizeof(sSoundType), false);
|
|
|
|
char sSoundName[128];
|
|
BfReadString(bf, sSoundName, sizeof(sSoundName), false);
|
|
|
|
char sSoundFile[128];
|
|
BfReadString(bf, sSoundFile, sizeof(sSoundFile), false);
|
|
|
|
// Check which clients need to be excluded.
|
|
int[] newPlayers = new int[playersNum];
|
|
int newPlayersNum = 0;
|
|
|
|
for(int i = 0; i < playersNum; i++)
|
|
{
|
|
int player = players[i];
|
|
|
|
if(IsClientInGame(player) && !g_bStopRadioSounds[player] && !(g_bStopNadeSounds[player] && StrContains(sSoundFile, "hole", false) != -1))
|
|
{
|
|
newPlayers[newPlayersNum++] = player;
|
|
}
|
|
}
|
|
|
|
if (newPlayersNum == playersNum)
|
|
{
|
|
// No clients where excluded.
|
|
return Plugin_Continue;
|
|
}
|
|
else if (newPlayersNum == 0)
|
|
{
|
|
// All clients were excluded and there is no need to broadcast.
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
DataPack pack = new DataPack();
|
|
pack.WriteString(sSoundType);
|
|
pack.WriteString(sSoundName);
|
|
pack.WriteString(sSoundFile);
|
|
pack.WriteCell(dest);
|
|
pack.WriteCell(client);
|
|
pack.WriteCell(newPlayersNum);
|
|
|
|
for(int i = 0; i < newPlayersNum; i++)
|
|
{
|
|
pack.WriteCell(newPlayers[i]);
|
|
}
|
|
|
|
RequestFrame(OnRadioText, pack);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void OnRadioText(DataPack pack)
|
|
{
|
|
pack.Reset();
|
|
|
|
char sSoundType[128];
|
|
pack.ReadString(sSoundType, sizeof(sSoundType));
|
|
|
|
char sSoundName[128];
|
|
pack.ReadString(sSoundName, sizeof(sSoundName));
|
|
|
|
char sSoundFile[128];
|
|
pack.ReadString(sSoundFile, sizeof(sSoundFile));
|
|
|
|
int dest = pack.ReadCell();
|
|
int client = pack.ReadCell();
|
|
int newPlayersNum = pack.ReadCell();
|
|
|
|
int[] players = new int[newPlayersNum];
|
|
int playersNum = 0;
|
|
|
|
for(int i = 0; i < newPlayersNum; i++)
|
|
{
|
|
int player = pack.ReadCell();
|
|
|
|
if(IsClientInGame(player))
|
|
{
|
|
players[playersNum++] = player;
|
|
}
|
|
}
|
|
|
|
CloseHandle(pack);
|
|
|
|
Handle RadioText = StartMessage("RadioText", players, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
|
|
|
|
if (RadioText != INVALID_HANDLE)
|
|
{
|
|
BfWriteByte(RadioText, dest);
|
|
BfWriteByte(RadioText, client);
|
|
BfWriteString(RadioText, sSoundType);
|
|
BfWriteString(RadioText, sSoundName);
|
|
BfWriteString(RadioText, sSoundFile);
|
|
}
|
|
|
|
EndMessage();
|
|
}
|
|
|
|
public Action Hook_SendAudio(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init)
|
|
{
|
|
if(!g_bStopRadioSoundsHooked)
|
|
return Plugin_Continue;
|
|
|
|
char sSoundFile[128];
|
|
BfReadString(bf, sSoundFile, sizeof(sSoundFile), false);
|
|
|
|
// Check which clients need to be excluded.
|
|
int[] newPlayers = new int[playersNum];
|
|
int newPlayersNum = 0;
|
|
|
|
for(int i = 0; i < playersNum; i++)
|
|
{
|
|
int player = players[i];
|
|
|
|
if(IsClientInGame(player) && !g_bStopRadioSounds[player] && !(g_bStopNadeSounds[player] && StrContains(sSoundFile, "hole", false) != -1))
|
|
{
|
|
newPlayers[newPlayersNum++] = player;
|
|
}
|
|
}
|
|
|
|
if (newPlayersNum == playersNum)
|
|
{
|
|
// No clients where excluded.
|
|
return Plugin_Continue;
|
|
}
|
|
else if (newPlayersNum == 0)
|
|
{
|
|
// All clients were excluded and there is no need to broadcast.
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
DataPack pack = new DataPack();
|
|
pack.WriteString(sSoundFile);
|
|
pack.WriteCell(newPlayersNum);
|
|
|
|
for(int i = 0; i < newPlayersNum; i++)
|
|
{
|
|
pack.WriteCell(newPlayers[i]);
|
|
}
|
|
|
|
RequestFrame(OnSendAudio, pack);
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void OnSendAudio(DataPack pack)
|
|
{
|
|
pack.Reset();
|
|
|
|
char sSoundFile[128];
|
|
pack.ReadString(sSoundFile, sizeof(sSoundFile));
|
|
|
|
int newPlayersNum = pack.ReadCell();
|
|
|
|
int[] players = new int[newPlayersNum];
|
|
int playersNum = 0;
|
|
|
|
for(int i = 0; i < newPlayersNum; i++)
|
|
{
|
|
int player = pack.ReadCell();
|
|
|
|
if(IsClientInGame(player))
|
|
{
|
|
players[playersNum++] = player;
|
|
}
|
|
}
|
|
|
|
CloseHandle(pack);
|
|
|
|
Handle SendAudio = StartMessage("SendAudio", players, playersNum, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS);
|
|
|
|
if (SendAudio != INVALID_HANDLE)
|
|
{
|
|
BfWriteString(SendAudio, sSoundFile);
|
|
}
|
|
|
|
EndMessage();
|
|
}
|
|
|
|
public Action ToggleSelfMuteRadio(int client, int args)
|
|
{
|
|
g_bStopRadioSounds[client] = !g_bStopRadioSounds[client];
|
|
CheckHooks();
|
|
|
|
if(g_bStopRadioSounds[client])
|
|
{
|
|
ReplyToCommand(client, "You blocked all Radio Messages and Sound");
|
|
SetClientCookie(client, g_hCookieStopRadio, "1");
|
|
}
|
|
else
|
|
{
|
|
ReplyToCommand(client, "You unblocked all Radio Messages and Sound");
|
|
SetClientCookie(client, g_hCookieStopRadio, "");
|
|
g_bStopNadeSounds[client] = false;
|
|
}
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public Action ToggleSelfMuteNade(int client, int args)
|
|
{
|
|
g_bStopNadeSounds[client] = !g_bStopNadeSounds[client];
|
|
CheckHooks();
|
|
|
|
if(g_bStopNadeSounds[client])
|
|
{
|
|
ReplyToCommand(client, "You blocked 'Fire in the Hole' Radio Messages and Sound");
|
|
SetClientCookie(client, g_hCookieStopNade, "1");
|
|
}
|
|
else
|
|
{
|
|
ReplyToCommand(client, "You unblocked 'Fire in the Hole' Radio Messages and Sound");
|
|
SetClientCookie(client, g_hCookieStopNade, "");
|
|
}
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void OnClientCookiesCached(int client)
|
|
{
|
|
char sBuffer[2];
|
|
|
|
GetClientCookie(client, g_hCookieStopRadio, sBuffer, sizeof(sBuffer));
|
|
|
|
if(sBuffer[0] != '\0')
|
|
{
|
|
g_bStopRadioSounds[client] = true;
|
|
g_bStopRadioSoundsHooked = true;
|
|
}
|
|
else
|
|
{
|
|
g_bStopRadioSounds[client] = false;
|
|
}
|
|
|
|
GetClientCookie(client, g_hCookieStopRadio, sBuffer, sizeof(sBuffer));
|
|
|
|
if(sBuffer[0] != '\0')
|
|
{
|
|
g_bStopNadeSounds[client] = true;
|
|
g_bStopRadioSoundsHooked = true;
|
|
}
|
|
else
|
|
{
|
|
g_bStopNadeSounds[client] = false;
|
|
}
|
|
}
|
|
|
|
public void OnClientDisconnect(int client)
|
|
{
|
|
g_bStopRadioSounds[client] = false;
|
|
g_bStopNadeSounds[client] = false;
|
|
CheckHooks();
|
|
}
|
|
|
|
public void CheckHooks()
|
|
{
|
|
bool bShouldHook = false;
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(g_bStopRadioSounds[i] || g_bStopNadeSounds[i])
|
|
{
|
|
bShouldHook = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
g_bStopRadioSoundsHooked = bShouldHook;
|
|
}
|