From e34e4a839a003674956d3efc854b29f8aa4ec538 Mon Sep 17 00:00:00 2001 From: Altair Sossai Date: Mon, 16 Dec 2024 12:16:54 -0300 Subject: [PATCH] Refactor BeQuiet plugin: streamline CVar handling, improve command listeners, and update plugin metadata --- addons/sourcemod/scripting/bequiet.sp | 244 +++++++----------- .../scripting/l4d2_tank_props_glow.sp | 3 - .../scripting/l4d_tank_control_eq.sp | 29 --- cfg/cfgogl/zonemod/shared_settings.cfg | 2 +- 4 files changed, 97 insertions(+), 181 deletions(-) diff --git a/addons/sourcemod/scripting/bequiet.sp b/addons/sourcemod/scripting/bequiet.sp index e8dc9d4bb..befeb6dc5 100644 --- a/addons/sourcemod/scripting/bequiet.sp +++ b/addons/sourcemod/scripting/bequiet.sp @@ -1,176 +1,124 @@ #pragma semicolon 1 -#pragma newdecls required +#include +#pragma newdecls required #include -#define PLUGIN_VERSION "2.0.2" + +ConVar hCvarCvarChange, hCvarNameChange, hCvarSpecNameChange, hCvarSpecSeeChat; +bool bCvarChange, bNameChange, bSpecNameChange, bSpecSeeChat; public Plugin myinfo = { - name = "[L4D & 2] BeQuiet", - author = "Sir, Forgetest", - description = "Please be Quiet! (Spec hearing chat, name/cvar change supress)", - version = PLUGIN_VERSION, - url = "https://github.com/Target5150/MoYu_Server_Stupid_Plugins" + name = "BeQuiet", + author = "Sir", + description = "Please be Quiet!", + version = "1.33.7", + url = "https://github.com/SirPlease/SirCoding" } -ConVar hCvarCvarChange, hCvarNameChange, hCvarSpecNameChange, hCvarSpecSeeChat; - public void OnPluginStart() { - //Player name change - HookUserMessage(GetUserMessageId("SayText2"), UserMsg_OnSayText2, true); - - //Server CVar - HookEvent("server_cvar", Event_ServerConVar, EventHookMode_Pre); - - //Cvars - hCvarCvarChange = CreateConVar("bq_cvar_change_suppress", "1", "Silence Server Cvars being changed, this makes for a clean chat with no disturbances.", FCVAR_SPONLY, true, 0.0, true, 1.0); - hCvarNameChange = CreateConVar("bq_name_change_suppress", "0", "Silence Player name Changes.", FCVAR_SPONLY, true, 0.0, true, 1.0); - hCvarSpecNameChange = CreateConVar("bq_name_change_spec_suppress", "0", "Silence Spectating Player name Changes.", FCVAR_SPONLY, true, 0.0, true, 1.0); - hCvarSpecSeeChat = CreateConVar("bq_show_player_team_chat_spec", "1", "Show Spectators Survivors and Infected Team chat?", FCVAR_SPONLY, true, 0.0, true, 1.0); - - AutoExecConfig(true); + AddCommandListener(Say_Callback, "say"); + AddCommandListener(TeamSay_Callback, "say_team"); + + //Server CVar + HookEvent("server_cvar", Event_ServerConVar, EventHookMode_Pre); + HookEvent("player_changename", Event_NameChange, EventHookMode_Pre); + + //Cvars + hCvarCvarChange = CreateConVar("bq_cvar_change_suppress", "1", "Silence Server Cvars being changed, this makes for a clean chat with no disturbances."); + hCvarNameChange = CreateConVar("bq_name_change_suppress", "1", "Silence Player name Changes."); + hCvarSpecNameChange = CreateConVar("bq_name_change_spec_suppress", "1", "Silence Spectating Player name Changes."); + hCvarSpecSeeChat = CreateConVar("bq_show_player_team_chat_spec", "1", "Show Spectators Survivors and Infected Team chat?"); + + bCvarChange = GetConVarBool(hCvarCvarChange); + bNameChange = GetConVarBool(hCvarNameChange); + bSpecNameChange = GetConVarBool(hCvarSpecNameChange); + bSpecSeeChat = GetConVarBool(hCvarSpecSeeChat); + + hCvarCvarChange.AddChangeHook(cvarChanged); + hCvarNameChange.AddChangeHook(cvarChanged); + hCvarSpecNameChange.AddChangeHook(cvarChanged); + hCvarSpecSeeChat.AddChangeHook(cvarChanged); + + AutoExecConfig(true); + LoadTranslations("bequiet.phrases"); } -public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs) +Action Say_Callback(int client, char[] command, int args) { - static char s_sPubChatTrigger[8] = "!", s_sPrivChatTrigger[8] = "/"; - static int s_iPubTriggerLen = 1, s_iPrivTriggerLen = 1; - -// 1.12.0.6944 -// https://github.com/alliedmodders/sourcemod/commit/3b4a343274286b31a9b3cf33c64f7ef -#if SOURCEMOD_V_MAJOR > 1 - || (SOURCEMOD_V_MAJOR == 1 && SOURCEMOD_V_MINOR >= 12 && SOURCEMOD_V_REV >= 6944) - static bool bInit = false; - if (!bInit) - { - s_iPubTriggerLen = GetPublicChatTriggers(s_sPubChatTrigger, sizeof(s_sPubChatTrigger)); - s_iPrivTriggerLen = GetSilentChatTriggers(s_sPrivChatTrigger, sizeof(s_sPrivChatTrigger)); - - if (!s_iPubTriggerLen) - s_iPubTriggerLen = strcopy(s_sPubChatTrigger, sizeof(s_sPubChatTrigger), "!"); - if (!s_iPrivTriggerLen) - s_iPrivTriggerLen = strcopy(s_sPrivChatTrigger, sizeof(s_sPrivChatTrigger), "/"); - - bInit = true; - } -#endif - - if (strncmp(sArgs, s_sPubChatTrigger, s_iPubTriggerLen) == 0 - || strncmp(sArgs, s_sPrivChatTrigger, s_iPrivTriggerLen) == 0) - return Plugin_Handled; - - return Plugin_Continue; + char sayWord[MAX_NAME_LENGTH]; + GetCmdArg(1, sayWord, sizeof(sayWord)); + + if(sayWord[0] == '!' || sayWord[0] == '/') + { + return Plugin_Handled; + } + return Plugin_Continue; } -public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs) +Action TeamSay_Callback(int client, char[] command, int args) { - if (!IsValidClient(client)) - return; - - if (!hCvarSpecSeeChat.BoolValue || strcmp(command, "say_team") != 0) - return; - - // TODO: Formats for dead players? Not really seen much. - static const char s_ChatFormats[][] = { - "L4D_Chat_Survivor", - "L4D_Chat_Infected", - /* "L4D_Chat_Survivor_Dead", - "L4D_Chat_Infected_Dead",*/ - }; - - int idxTeam = GetClientTeam(client) - 2; - if (idxTeam != 0 && idxTeam != 1) - return; - - /*if (!IsPlayerAlive(client)) - idxTeam += 2;*/ - - // collect all spectators + SourceTV - int[] clients = new int[MaxClients]; - int numClients = 0; - for (int i = 1; i <= MaxClients; ++i) - { - if (IsClientInGame(i) && GetClientTeam(i) == 1 && (!IsFakeClient(i) || IsClientSourceTV(i))) - clients[numClients++] = i; - } - - if (numClients <= 0) - return; - - char name[MAX_NAME_LENGTH]; - GetClientName(client, name, sizeof(name)); - UTIL_SayText2Filter(client, clients, numClients, true, s_ChatFormats[idxTeam], name, sArgs); + char sayWord[MAX_NAME_LENGTH]; + GetCmdArg(1, sayWord, sizeof(sayWord)); + + if(sayWord[0] == '!' || sayWord[0] == '/') + { + return Plugin_Handled; + } + + if (bSpecSeeChat && GetClientTeam(client) != 1) + { + char sChat[256]; + GetCmdArgString(sChat, 256); + StripQuotes(sChat); + int i = 1; + while (i <= 65) + { + if (IsValidClient(i) && GetClientTeam(i) == 1) + { + if (GetClientTeam(client) == 2) + { + CPrintToChat(i, "%t", "SurvivorSay", client, sChat); + } + else CPrintToChat(i, "%t", "InfectedSay", client, sChat); + } + i++; + } + } + return Plugin_Continue; } Action Event_ServerConVar(Event event, const char[] name, bool dontBroadcast) { - return hCvarCvarChange.BoolValue ? Plugin_Handled : Plugin_Continue; + if (bCvarChange) return Plugin_Handled; + return Plugin_Continue; } -// Thanks for help from HarryPotter (@fbef0102) IIRC -Action UserMsg_OnSayText2(UserMsg msg_id, BfRead msg, const int[] players, int playersNum, bool reliable, bool init) +Action Event_NameChange(Event event, const char[] name, bool dontBroadcast) { - int client = msg.ReadByte(); - if (!IsValidClient(client)) - return Plugin_Continue; - - msg.ReadByte(); // Skip the second byte - - // Read the message - static char sMessage[128]; - msg.ReadString(sMessage, sizeof(sMessage), true); - - if (GetClientTeam(client) == 1) - { - if (!hCvarSpecNameChange.BoolValue) - return Plugin_Continue; - } - else if (!hCvarNameChange.BoolValue) - return Plugin_Continue; - - if (strcmp(sMessage, "#Cstrike_Name_Change") != 0) - return Plugin_Continue; - - return Plugin_Handled; -} + int clientid = event.GetInt("userid"); + int client = GetClientOfUserId(clientid); -stock bool IsValidClient(int client) -{ - return client > 0 && client <= MaxClients && IsClientInGame(client); + if (IsValidClient(client)) + { + if (GetClientTeam(client) == 1 && bSpecNameChange) return Plugin_Handled; + else if (bNameChange) return Plugin_Handled; + } + return Plugin_Continue; } -stock void UTIL_SayText2Filter( int entity, const int[] recipients, int numRecipient, bool bChat, const char[] msg_name, const char[] param1 = NULL_STRING, const char[] param2 = NULL_STRING, const char[] param3 = NULL_STRING, const char[] param4 = NULL_STRING ) +void cvarChanged(Handle convar, const char[] oldValue, const char[] newValue) { - BfWrite bf = UserMessageToBfWrite(StartMessage( "SayText2", recipients, numRecipient, USERMSG_RELIABLE )); - - if ( entity < 0 ) - entity = 0; // world, dedicated server says - - bf.WriteByte( entity ); - bf.WriteByte( bChat ); - bf.WriteString( msg_name ); - - if ( !IsNullString(param1) ) - bf.WriteString( param1 ); - else - bf.WriteString( "" ); - - if ( !IsNullString(param2) ) - bf.WriteString( param2 ); - else - bf.WriteString( "" ); - - if ( !IsNullString(param3) ) - bf.WriteString( param3 ); - else - bf.WriteString( "" ); - - if ( !IsNullString(param4) ) - bf.WriteString( param4 ); - else - bf.WriteString( "" ); - - EndMessage(); -} \ No newline at end of file + bCvarChange = hCvarCvarChange.BoolValue; + bNameChange = hCvarNameChange.BoolValue; + bSpecNameChange = hCvarSpecNameChange.BoolValue; + bSpecSeeChat = hCvarSpecSeeChat.BoolValue; +} + +bool IsValidClient(int client) +{ + if (client <= 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client)) return false; + return true; +} diff --git a/addons/sourcemod/scripting/l4d2_tank_props_glow.sp b/addons/sourcemod/scripting/l4d2_tank_props_glow.sp index d23f7d561..a863bd6a2 100644 --- a/addons/sourcemod/scripting/l4d2_tank_props_glow.sp +++ b/addons/sourcemod/scripting/l4d2_tank_props_glow.sp @@ -374,9 +374,6 @@ void CreateTankPropGlow(int iTarget) SDKHook(iEntity, SDKHook_SetTransmit, OnTransmit); g_iEntityList[iTarget] = EntIndexToEntRef(iEntity); - - // Fix PVS glow issues while inside walls (by Mart) - SetEdictFlags(iTarget, GetEdictFlags(iTarget) | FL_EDICT_ALWAYS); } Action OnTransmit(int iEntity, int iClient) diff --git a/addons/sourcemod/scripting/l4d_tank_control_eq.sp b/addons/sourcemod/scripting/l4d_tank_control_eq.sp index 11eae274c..1119b995e 100644 --- a/addons/sourcemod/scripting/l4d_tank_control_eq.sp +++ b/addons/sourcemod/scripting/l4d_tank_control_eq.sp @@ -512,12 +512,6 @@ void chooseTank(any data) nextTankIndex = PeekNextTankIndexInTheQueue(); } - if (nextTankIndex == -1) - { - RequeueInfecteds(h_whosHadTank); - nextTankIndex = PeekNextTankIndexInTheQueue(); - } - if (nextTankIndex == -1) { RemoveAllInfectedFrom(h_tankQueue); @@ -690,29 +684,6 @@ void EnqueueNewInfectedPlayers() ShuffleArray(h_tankQueue, start, end); } -void RequeueInfecteds(ArrayList arrayList) -{ - if (arrayList.Length == 0) - return; - - char steamId[64]; - - for(int i = 0; i < arrayList.Length; i++) - { - arrayList.GetString(i, steamId, sizeof(steamId)); - - int client = getInfectedPlayerBySteamId(steamId); - if (client == -1 || h_tankQueue.FindString(steamId) != -1) - continue; - - h_tankQueue.PushString(steamId); - - int index = h_whosHadTank.FindString(steamId); - if (index != -1) - h_whosHadTank.Erase(index); - } -} - void RemoveAllInfectedFrom(ArrayList arrayList) { char steamId[64]; diff --git a/cfg/cfgogl/zonemod/shared_settings.cfg b/cfg/cfgogl/zonemod/shared_settings.cfg index 11df35e81..9d5b74860 100644 --- a/cfg/cfgogl/zonemod/shared_settings.cfg +++ b/cfg/cfgogl/zonemod/shared_settings.cfg @@ -127,7 +127,7 @@ confogl_addcvar vs_tank_pound_damage 36 confogl_addcvar vs_tank_rock_damage 24 // [l4d2_pickup.smx] -confogl_addcvar pickup_switch_flags 3 +confogl_addcvar pickup_switch_flags 2 confogl_addcvar pickup_incap_flags 2 // [l4d2_car_alarm_hittable_fix.smx]