Skip to content

Commit

Permalink
Fixed CTs getting muted
Browse files Browse the repository at this point in the history
- Redefined MutePlayer and UnmutePlayer
- CTs get unmuted when they spawn
- Minor optimization on string formatting
  • Loading branch information
1ci committed Jun 20, 2018
1 parent 8f713ca commit 6a71aaa
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 95 deletions.
175 changes: 90 additions & 85 deletions addons/sourcemod/scripting/hosties/muteprisoners.sp
Expand Up @@ -45,7 +45,7 @@ MutePrisoners_OnPluginStart()
gShadow_MuteLength = Float:30.0;

gH_Cvar_MuteImmune = CreateConVar("sm_hosties_mute_immune", "z", "Admin flags which are immune from getting muted: 0 - nobody, 1 - all admins, flag values: abcdefghijklmnopqrst", FCVAR_NONE);
Format(gShadow_MuteImmune, sizeof(gShadow_MuteImmune), "z");
FormatEx(gShadow_MuteImmune, sizeof(gShadow_MuteImmune), "z");

gH_Cvar_MuteCT = CreateConVar("sm_hosties_mute_ct", "0", "Setting for muting counter-terrorists automatically when they die (requires sm_hosties_mute 2 or 3): 0 - disable, 1 - enable", FCVAR_NONE, true, 0.0, true, 1.0);
gShadow_MuteCT = false;
Expand All @@ -55,6 +55,7 @@ MutePrisoners_OnPluginStart()
HookConVarChange(gH_Cvar_MuteImmune, MutePrisoners_CvarChanged);
HookConVarChange(gH_Cvar_MuteCT, MutePrisoners_CvarChanged);

// Why is this here? -ici
g_Offset_CollisionGroup = FindSendPropInfo("CBaseEntity", "m_CollisionGroup");
if (g_Offset_CollisionGroup == -1)
{
Expand Down Expand Up @@ -87,57 +88,71 @@ MutePrisoners_OnConfigsExecuted()
MutePrisoners_CalcImmunity();
}

bool:MutePlayer(client)
{
// Ignore punished players
if (BaseComm_IsClientMuted(client))
return true;

// Ignore immune players
if (GetUserFlagBits(client) & gAdmFlags_MuteImmunity)
return false;

SetClientListeningFlags(client, VOICE_MUTED);
return true;
}

bool:UnmutePlayer(client)
{
// Ignore punished players
if (BaseComm_IsClientMuted(client))
return false;

SetClientListeningFlags(client, VOICE_NORMAL);
return true;
}

stock MuteTs()
{
for(new i = 1; i <= MaxClients; i++)
for (new i = 1; i <= MaxClients; i++)
{
if ( (IsClientInGame(i)) && (IsPlayerAlive(i)) ) // if player is in game and alive
if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == CS_TEAM_T)
{
// if player is a terrorist
if (GetClientTeam(i) == CS_TEAM_T)
{
MutePlayer(i);
}
MutePlayer(i);
}
}
}

stock UnmuteAlive()
stock UnmuteTs()
{
for(new i = 1; i <= MaxClients; i++)
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && IsPlayerAlive(i)) // if player is in game and alive
if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == CS_TEAM_T)
{
if (!BaseComm_IsClientMuted(i))
{
UnmutePlayer(i);
}
UnmutePlayer(i);
}
}
}

stock bool:DoesContainBaseCommNatives()
stock UnmuteAll()
{
// 1.3.9 will have Native_IsClientMuted in basecomm.inc
if (GetFeatureStatus(FeatureType_Native, "BaseComm_IsClientMuted") == FeatureStatus_Available)
for (new i = 1; i <= MaxClients; i++)
{
return true;
if (IsClientInGame(i))
{
UnmutePlayer(i);
}
}
return false;
}

stock UnmuteAll()
stock bool:DoesContainBaseCommNatives()
{
for(new i = 1; i <= MaxClients; i++)
// 1.3.9 will have Native_IsClientMuted in basecomm.inc
if (GetFeatureStatus(FeatureType_Native, "BaseComm_IsClientMuted") == FeatureStatus_Available)
{
if (IsClientInGame(i)) // if player is in game
{
if (!BaseComm_IsClientMuted(i))
{
UnmutePlayer(i);
}
}
return true;
}
return false;
}

void MutePrisoners_CalcImmunity()
Expand All @@ -151,7 +166,7 @@ void MutePrisoners_CalcImmunity()
if(StrEqual(gShadow_MuteImmune, "1"))
{
// include everything but 'a': reservation slot
Format(gShadow_MuteImmune, sizeof(gShadow_MuteImmune), "bcdefghijklmnopqrstz");
FormatEx(gShadow_MuteImmune, sizeof(gShadow_MuteImmune), "bcdefghijklmnopqrstz");
}

gAdmFlags_MuteImmunity = ReadFlagString(gShadow_MuteImmune);
Expand All @@ -170,7 +185,7 @@ public MutePrisoners_CvarChanged(Handle:cvar, const String:oldValue[], const Str
}
else if (cvar == gH_Cvar_MuteImmune)
{
Format(gShadow_MuteImmune, sizeof(gShadow_MuteImmune), newValue);
FormatEx(gShadow_MuteImmune, sizeof(gShadow_MuteImmune), newValue);
MutePrisoners_CalcImmunity();
}
else if (cvar == gH_Cvar_MuteCT)
Expand All @@ -181,39 +196,25 @@ public MutePrisoners_CvarChanged(Handle:cvar, const String:oldValue[], const Str

public MutePrisoners_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));

if (gShadow_MuteStatus == 1 || gShadow_MuteStatus == 3)
{
// if the timer is anything but invalid, we should mute these new spawners
if (gH_Timer_Unmuter != INVALID_HANDLE)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (GetClientTeam(client) == CS_TEAM_T)
{
if (gAdmFlags_MuteImmunity == 0)
{
CreateTimer(0.1, Timer_Mute, client, TIMER_FLAG_NO_MAPCHANGE);
}
else
{
if (!(GetUserFlagBits(client) & gAdmFlags_MuteImmunity))
{
CreateTimer(0.1, Timer_Mute, client, TIMER_FLAG_NO_MAPCHANGE);
}
}
MutePlayer(client);
}
}
}
}

public Action:Timer_Mute(Handle:timer, any:client)
{
if (IsClientInGame(client))

// Unmute CTs fix
if (GetClientTeam(client) == CS_TEAM_CT)
{
MutePlayer(client);
PrintToChat(client, CHAT_BANNER, "Now Muted");
UnmutePlayer(client);
}

return Plugin_Stop;
}

public MutePrisoners_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
Expand All @@ -224,37 +225,51 @@ public MutePrisoners_PlayerDeath(Handle:event, const String:name[], bool:dontBro
}

new victim = GetClientOfUserId(GetEventInt(event, "userid"));
new team = GetClientTeam(victim);

if (gAdmFlags_MuteImmunity == 0 || !(GetUserFlagBits(victim) & gAdmFlags_MuteImmunity))
switch (team)
{
new team = GetClientTeam(victim);
switch (team)
case CS_TEAM_T:
{
case CS_TEAM_T:
{
CreateTimer(0.1, Timer_Mute, victim, TIMER_FLAG_NO_MAPCHANGE);
}
case CS_TEAM_CT:
CreateTimer(0.1, Timer_Mute, GetClientSerial(victim), TIMER_FLAG_NO_MAPCHANGE);
}
case CS_TEAM_CT:
{
if (gShadow_MuteCT)
{
if (gShadow_MuteCT)
{
CreateTimer(0.1, Timer_Mute, victim, TIMER_FLAG_NO_MAPCHANGE);
}
CreateTimer(0.1, Timer_Mute, GetClientSerial(victim), TIMER_FLAG_NO_MAPCHANGE);
}
}
}
}

public Action:Timer_Mute(Handle:timer, any:serial)
{
new client = GetClientFromSerial(serial);
if (!client)
{
// Player is no longer in game.
return Plugin_Stop;
}

if (MutePlayer(client))
{
PrintToChat(client, CHAT_BANNER, "Now Muted");
}
return Plugin_Stop;
}

public MutePrisoners_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
if (gShadow_MuteStatus)
{
// Unmute Timer
CreateTimer(0.2, Timer_UnmuteAll, _, TIMER_FLAG_NO_MAPCHANGE);
}

// In case the round ends earlier than gShadow_MuteLength
if (gH_Timer_Unmuter != INVALID_HANDLE)
{
CloseHandle(gH_Timer_Unmuter);
gH_Timer_Unmuter = INVALID_HANDLE;
}
}
Expand All @@ -263,21 +278,13 @@ public MutePrisoners_RoundStart(Handle:event, const String:name[], bool:dontBroa
{
if (gShadow_MuteStatus == 1 || gShadow_MuteStatus == 3)
{
if (gAdmFlags_MuteImmunity == 0)
{
// Mute All Ts
MuteTs();
}
else
MuteTs();

// In case the round gets restarted multiple times (mp_restartgame 1)
if (gH_Timer_Unmuter != INVALID_HANDLE)
{
// Mute non-flagged Ts
for (new idx = 1; idx <= MaxClients; idx++)
{
if (IsClientInGame(idx) && (GetClientTeam(idx) == CS_TEAM_T) && !(GetUserFlagBits(idx) & gAdmFlags_MuteImmunity))
{
MutePlayer(idx);
}
}
CloseHandle(gH_Timer_Unmuter);
gH_Timer_Unmuter = INVALID_HANDLE;
}

// Unmute Timer
Expand All @@ -289,12 +296,10 @@ public MutePrisoners_RoundStart(Handle:event, const String:name[], bool:dontBroa

public Action:Timer_UnmutePrisoners(Handle:timer)
{
if (gH_Timer_Unmuter == timer)
{
UnmuteAlive();
PrintToChatAll(CHAT_BANNER, "Ts Can Speak Again");
gH_Timer_Unmuter = INVALID_HANDLE;
}
UnmuteTs();

PrintToChatAll(CHAT_BANNER, "Ts Can Speak Again");
gH_Timer_Unmuter = INVALID_HANDLE;

return Plugin_Stop;
}
Expand Down
10 changes: 0 additions & 10 deletions addons/sourcemod/scripting/include/hosties.inc
Expand Up @@ -113,16 +113,6 @@ stock UnblockClientAll()
}
}

stock MutePlayer(client)
{
SetClientListeningFlags(client, VOICE_MUTED);
}

stock UnmutePlayer(client)
{
SetClientListeningFlags(client, VOICE_NORMAL);
}

stock CacheTheFile(const String:path[], MediaType:filetype)
{
decl String:sDownloadPath[PLATFORM_MAX_PATH];
Expand Down

0 comments on commit 6a71aaa

Please sign in to comment.