add shared selfmute + replace of RadioMuteCmd
This commit is contained in:
parent
cd9f3f8a7d
commit
7f5ec83506
@ -1,127 +0,0 @@
|
||||
#pragma semicolon 1
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <cstrike>
|
||||
#include <multicolors>
|
||||
|
||||
#define PLUGIN_VERSION "2.0"
|
||||
|
||||
#pragma newdecls required
|
||||
|
||||
bool g_bProtoBuf;
|
||||
bool g_bBlocked[MAXPLAYERS + 1];
|
||||
bool g_bIsEnabled[MAXPLAYERS + 1];
|
||||
|
||||
int g_iMessageClient = -1;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Toggle radio mute command",
|
||||
author = "Nano",
|
||||
description = "You can enable or disable the radio voice/text messages using a command",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "http://steamcommunity.com/id/marianzet1"
|
||||
};
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
LoadTranslations("common.phrases");
|
||||
|
||||
if(GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)
|
||||
g_bProtoBuf = true;
|
||||
|
||||
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_radio", Command_RadioMute);
|
||||
RegConsoleCmd("sm_smradio", Command_RadioMute);
|
||||
//RegConsoleCmd("sm_mr", Command_RadioMute);
|
||||
|
||||
HookUserMessage(RadioText, _hkRadioText, true);
|
||||
HookUserMessage(SendAudio, _hkSendAudio, true);
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
g_bIsEnabled[client] = false;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_bIsEnabled[client] = false;
|
||||
g_bBlocked[client] = false;
|
||||
}
|
||||
|
||||
public Action Command_RadioMute(int client, int args)
|
||||
{
|
||||
if(!g_bIsEnabled[client])
|
||||
{
|
||||
g_bIsEnabled[client] = true;
|
||||
g_bBlocked[client] = true;
|
||||
CPrintToChat(client, "{green}[{lightgreen}Mute-Radio{green}]{default} You have {purple}disabled the radio messages.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_bIsEnabled[client] = false;
|
||||
g_bBlocked[client] = false;
|
||||
CPrintToChat(client, "{green}[{lightgreen}Mute-Radio{green}]{default} You have {purple}enabled the radio messages.");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Action _hkRadioText(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init)
|
||||
{
|
||||
if (g_bProtoBuf)
|
||||
{
|
||||
g_iMessageClient = PbReadInt(bf, "client");
|
||||
}
|
||||
else
|
||||
{
|
||||
BfReadByte(bf);
|
||||
g_iMessageClient = BfReadByte(bf);
|
||||
}
|
||||
|
||||
if (g_bBlocked[g_iMessageClient])
|
||||
{
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public Action _hkSendAudio(UserMsg msg_id, Handle bf, const int[] players, int playersNum, bool reliable, bool init)
|
||||
{
|
||||
if (g_iMessageClient == -1)
|
||||
return Plugin_Continue;
|
||||
|
||||
char sSound[128];
|
||||
|
||||
if(g_bProtoBuf)
|
||||
PbReadString(bf, "radio_sound", sSound, sizeof(sSound));
|
||||
else
|
||||
BfReadString(bf, sSound, sizeof(sSound), false);
|
||||
|
||||
if (strncmp(sSound[6], "lock", 4, false) == 0)
|
||||
return Plugin_Continue;
|
||||
|
||||
if (g_bBlocked[g_iMessageClient])
|
||||
{
|
||||
g_iMessageClient = -1;
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
g_iMessageClient = -1;
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
1066
SelfMute/scripting/SelfMute.sp
Normal file
1066
SelfMute/scripting/SelfMute.sp
Normal file
File diff suppressed because it is too large
Load Diff
288
SelfMute/scripting/SelfMuteRadio.sp
Normal file
288
SelfMute/scripting/SelfMuteRadio.sp
Normal file
@ -0,0 +1,288 @@
|
||||
#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;
|
||||
|
||||
Handle g_hCookieStopRadio = 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
|
||||
|
||||
g_hCookieStopRadio = RegClientCookie("radio_blocked", "is the 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;
|
||||
|
||||
// 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])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
// 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])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
char sSoundFile[128];
|
||||
BfReadString(bf, sSoundFile, sizeof(sSoundFile), false);
|
||||
|
||||
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];
|
||||
CheckSelfMuteRadioHooks();
|
||||
|
||||
if(g_bStopRadioSounds[client])
|
||||
{
|
||||
ReplyToCommand(client, "You blocked Radio Messages and Sound");
|
||||
SetClientCookie(client, g_hCookieStopRadio, "1");
|
||||
}
|
||||
else
|
||||
{
|
||||
ReplyToCommand(client, "You unblocked Radio Messages and Sound");
|
||||
SetClientCookie(client, g_hCookieStopRadio, "");
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_bStopRadioSounds[client] = false;
|
||||
CheckSelfMuteRadioHooks();
|
||||
}
|
||||
|
||||
public void CheckSelfMuteRadioHooks()
|
||||
{
|
||||
bool bShouldHook = false;
|
||||
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(g_bStopRadioSounds[i])
|
||||
{
|
||||
bShouldHook = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_bStopRadioSoundsHooked = bShouldHook;
|
||||
}
|
Loading…
Reference in New Issue
Block a user