diff --git a/README.md b/README.md index 73d744e..a2fedd7 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Useful things: * [l4d2_autorestart](#l4d2_autorestart) * [l4d2_TKStopper](#l4d2_TKStopper) * [l4d2_crescendo_control](#l4d2_crescendo_control) +* [l4d2_vocalize_control](#l4d2_vocalize_control) ### Modified Others * [200IQBots_FlyYouFools](#200IQBots_FlyYouFools) @@ -325,4 +326,10 @@ _This plugin is currently in **development.**_ Current implementation may be lac * **Cvars:** * `l4d2_crescendo_percent` - * `l4d2_crescendo_range` \ No newline at end of file + * `l4d2_crescendo_range` + +### l4d2_vocalize_control +A very small plugin that simply allows a player to mute another player's vocalizations only for them. + +* **Commands:** + * `sm_vgag ` - Vocalize gag or ungags selected player(s) \ No newline at end of file diff --git a/plugins/l4d2_vocalize_control.smx b/plugins/l4d2_vocalize_control.smx new file mode 100644 index 0000000..bc159cf Binary files /dev/null and b/plugins/l4d2_vocalize_control.smx differ diff --git a/scripting/l4d2_vocalize_control.sp b/scripting/l4d2_vocalize_control.sp new file mode 100644 index 0000000..c2ac7fa --- /dev/null +++ b/scripting/l4d2_vocalize_control.sp @@ -0,0 +1,112 @@ +#pragma semicolon 1 +#pragma newdecls required + +//#define DEBUG + +#define PLUGIN_VERSION "1.0" + +#include +#include +//#include + +public Plugin myinfo = +{ + name = "L4D2 Vocalize Control", + author = "jackzmc", + description = "", + version = PLUGIN_VERSION, + url = "" +}; + +ArrayList gaggedPlayers[MAXPLAYERS]; + +public void OnPluginStart() +{ + EngineVersion g_Game = GetEngineVersion(); + if(g_Game != Engine_Left4Dead2) + { + SetFailState("This plugin is for L4D2 only."); + } + + for(int i = 0; i < sizeof(gaggedPlayers); i++) { + gaggedPlayers[i] = new ArrayList(MAXPLAYERS - 1); + } + + HookEvent("player_disconnect", Event_PlayerDisconnect); + + RegConsoleCmd("sm_vgag", Cmd_Gag, "Gags a player\'s vocalizations locally"); + AddNormalSoundHook(view_as(SoundHook)); +} + +public void Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast) { + int client = GetClientOfUserId(event.GetInt("userid")); + if(client > 0) { + //Clear the player's list of gagged + gaggedPlayers[client].Clear(); + //Remove this player from any other player's gag list + for(int i = 0; i <= MaxClients; i++) { + int index = gaggedPlayers[i].FindValue(client); + if(index > -1) { + gaggedPlayers[i].Erase(index); + } + } + } +} + +public Action Cmd_Gag(int client, int args) { + if(args < 1) { + ReplyToCommand(client, "Usage: sm_vgag "); + } else { + char arg1[32]; + GetCmdArg(1, arg1, sizeof(arg1)); + char target_name[MAX_TARGET_LENGTH]; + int target_list[MAXPLAYERS], target_count; + bool tn_is_ml; + if ((target_count = ProcessTargetString( + arg1, + client, + target_list, + MAXPLAYERS, + COMMAND_FILTER_ALIVE, /* Only allow alive players */ + target_name, + sizeof(target_name), + tn_is_ml)) <= 0) + { + /* This function replies to the admin with a failure message */ + ReplyToTargetError(client, target_count); + return Plugin_Handled; + } + for (int i = 0; i < target_count; i++) + { + int playerIndex = gaggedPlayers[client].FindValue(target_list[i]); + if(playerIndex > -1) { + gaggedPlayers[client].Erase(playerIndex); + ReplyToCommand(client, "locally vocalize ungagged %s", target_name[i]); + }else{ + gaggedPlayers[client].Push(target_list[i]); + ReplyToCommand(client, "locally vocalize gagged %s", target_name[i]); + } + } + } + return Plugin_Handled; +} + +public Action SoundHook(int[] clients, int& numClients, char sample[PLATFORM_MAX_PATH], int& entity, int& channel, float& volume, int& level, int& pitch, int& flags, char[] soundEntry, int& seed) { + if(numClients > 0 && entity > 0 && entity <= MaxClients) { + if(StrContains(sample, "survivor\\voice") > -1) { + for(int i = 0; i < numClients; i++) { + int client = clients[i]; + if(gaggedPlayers[client].FindValue(entity) > -1) { + int swap = clients[numClients - 1]; + clients[numClients - 1] = client; + clients[i] = swap; + numClients -= 1; + return Plugin_Handled; + //Remove client from clients + } + } + } + + } + return Plugin_Continue; +}