From 6bbef012bb24f8fa604302d13071aa48cb0e498e Mon Sep 17 00:00:00 2001 From: BotoX Date: Sun, 1 Sep 2019 16:49:24 +0200 Subject: [PATCH] AdvancedTargeting: Added @talking / @!talking and @speaking / @!speaking --- .../scripting/AdvancedTargeting.sp | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/AdvancedTargeting/scripting/AdvancedTargeting.sp b/AdvancedTargeting/scripting/AdvancedTargeting.sp index f602ffc8..6b644cab 100644 --- a/AdvancedTargeting/scripting/AdvancedTargeting.sp +++ b/AdvancedTargeting/scripting/AdvancedTargeting.sp @@ -8,9 +8,20 @@ #include #include +#undef REQUIRE_PLUGIN +#include +#define REQUIRE_PLUGIN + +#undef REQUIRE_EXTENSIONS +#tryinclude +#define REQUIRE_EXTENSIONS + #pragma newdecls required Handle g_FriendsArray[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; + +bool g_Plugin_voiceannounce_ex = false; +bool g_Extension_Voice = false; bool g_bLateLoad = false; #include //#define STEAM_API_KEY here @@ -20,7 +31,7 @@ public Plugin myinfo = name = "Advanced Targeting", author = "BotoX + Obus", description = "Adds extra targeting methods", - version = "1.2", + version = "1.3", url = "https://github.com/CSSZombieEscape/sm-plugins/tree/master/AdvancedTargeting/" } @@ -35,6 +46,10 @@ public void OnPluginStart() AddMultiTargetFilter("@randomt", Filter_RandomT, "a Random T", false); AddMultiTargetFilter("@alivect", Filter_AliveCT, "Alive Humans", false); AddMultiTargetFilter("@alivet", Filter_AliveT, "Alive Zombies", false); + AddMultiTargetFilter("@talking", Filter_Talking, "Talking", false); + AddMultiTargetFilter("@!talking", Filter_NotTalking, "Not Talking", false); + AddMultiTargetFilter("@speaking", Filter_Talking, "Talking", false); + AddMultiTargetFilter("@!speaking", Filter_NotTalking, "Not Talking", false); RegConsoleCmd("sm_admins", Command_Admins, "Currently online admins."); RegConsoleCmd("sm_friends", Command_Friends, "Currently online friends."); @@ -64,6 +79,10 @@ public void OnPluginEnd() RemoveMultiTargetFilter("@randomt", Filter_RandomT); RemoveMultiTargetFilter("@alivect", Filter_AliveCT); RemoveMultiTargetFilter("@alivet", Filter_AliveT); + RemoveMultiTargetFilter("@talking", Filter_Talking); + RemoveMultiTargetFilter("@!talking", Filter_NotTalking); + RemoveMultiTargetFilter("@speaking", Filter_Talking); + RemoveMultiTargetFilter("@!speaking", Filter_NotTalking); } public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) @@ -72,6 +91,13 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("ReadClientFriends", Native_ReadClientFriends); RegPluginLibrary("AdvancedTargeting"); + g_Plugin_voiceannounce_ex = LibraryExists("voiceannounce_ex"); + g_Extension_Voice = LibraryExists("Voice"); + + LogMessage("AdvancedTargeting capabilities:\nVoiceAnnounce: %s\nVoice: %s", + (g_Plugin_voiceannounce_ex ? "loaded" : "not loaded"), + (g_Extension_Voice ? "loaded" : "not loaded")); + g_bLateLoad = late; return APLRes_Success; } @@ -310,6 +336,47 @@ public bool Filter_RandomT(const char[] sPattern, Handle hClients, int client) return true; } +stock bool _IsClientSpeaking(int client) +{ + #if defined _voiceannounceex_included_ + if(g_Plugin_voiceannounce_ex) + return IsClientSpeaking(client); + #endif + + #if defined _voice_included + if(g_Extension_Voice) + return IsClientTalking(client); + #endif + + return false; +} + +public bool Filter_Talking(const char[] sPattern, Handle hClients, int client) +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientInGame(i) && !IsFakeClient(i) && _IsClientSpeaking(i)) + { + PushArrayCell(hClients, i); + } + } + + return true; +} + +public bool Filter_NotTalking(const char[] sPattern, Handle hClients, int client) +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientInGame(i) && !IsFakeClient(i) && !_IsClientSpeaking(i)) + { + PushArrayCell(hClients, i); + } + } + + return true; +} + public void OnClientAuthorized(int client, const char[] auth) { if(IsFakeClient(client))