diff --git a/BotTargeting/scripting/BotTargeting.sp b/BotTargeting/scripting/BotTargeting.sp index 69ddda5..761ee8d 100644 --- a/BotTargeting/scripting/BotTargeting.sp +++ b/BotTargeting/scripting/BotTargeting.sp @@ -6,13 +6,24 @@ bool g_bLateLoad = false; bool g_bIsAutismBot[MAXPLAYERS+1] = { false, ... }; +int g_iAutismBotIndex[MAXPLAYERS+1] = { 0, ... }; // 0 = not an autism bot, 1-4 = autism bot index + +// The position in this list is the autism bot index (first entry = 1). +// The index decides which UDP port the connection plugin talks to, so keep this order. +char g_sAutismBotAuthIDs[][] = +{ + "STEAM_0:1:60189040", // autism bot 1 + "STEAM_0:0:518094602", // autism bot 2 + "STEAM_0:0:204398871", // autism bot 3 + "STEAM_0:0:610560766" // autism bot 4 +}; public Plugin myinfo = { name = "Bot Targeting", author = "zaCade", description = "Adds extra targeting methods", - version = "1.0" + version = "1.1" }; public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) @@ -20,6 +31,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max g_bLateLoad = late; CreateNative("IsClientAutismBot", Native_IsAutismBot); + CreateNative("GetClientAutismBotIndex", Native_GetAutismBotIndex); RegPluginLibrary("BotTargeting"); return APLRes_Success; @@ -52,16 +64,24 @@ public void OnPluginEnd() public void OnClientAuthorized(int client, const char[] sAuthID) { - g_bIsAutismBot[client] = \ - StrEqual(sAuthID, "STEAM_0:1:60189040") || \ - StrEqual(sAuthID, "STEAM_0:0:204398871") || \ - StrEqual(sAuthID, "STEAM_0:0:518094602") || \ - StrEqual(sAuthID, "STEAM_0:0:610560766"); + g_iAutismBotIndex[client] = 0; + + for(int i = 0; i < sizeof(g_sAutismBotAuthIDs); i++) + { + if(StrEqual(sAuthID, g_sAutismBotAuthIDs[i])) + { + g_iAutismBotIndex[client] = i + 1; + break; + } + } + + g_bIsAutismBot[client] = g_iAutismBotIndex[client] != 0; } -public void OnClientDisconnected(int client) +public void OnClientDisconnect(int client) { g_bIsAutismBot[client] = false; + g_iAutismBotIndex[client] = 0; } public bool Filter_AutismBot(const char[] sPattern, Handle hClients, int client) @@ -90,10 +110,8 @@ public bool Filter_NonAutismBot(const char[] sPattern, Handle hClients, int clie return true; } -public int Native_IsAutismBot(Handle hPlugin, int numParams) +bool ValidateNativeClient(int client) { - int client = GetNativeCell(1); - if(client > MaxClients || client <= 0) { ThrowNativeError(SP_ERROR_NATIVE, "Client is not valid."); @@ -112,15 +130,29 @@ public int Native_IsAutismBot(Handle hPlugin, int numParams) return false; } + return true; +} + +public int Native_IsAutismBot(Handle hPlugin, int numParams) +{ + int client = GetNativeCell(1); + + if(!ValidateNativeClient(client)) + { + return false; + } + return g_bIsAutismBot[client]; } -/* -public Action ZR_OnClientMotherZombieEligible(int client) +public int Native_GetAutismBotIndex(Handle hPlugin, int numParams) { - if (g_bIsAutismBot[client]) - return Plugin_Handled; + int client = GetNativeCell(1); - return Plugin_Continue; + if(!ValidateNativeClient(client)) + { + return 0; + } + + return g_iAutismBotIndex[client]; } -*/ diff --git a/BotTargeting/scripting/include/BotTargeting.inc b/BotTargeting/scripting/include/BotTargeting.inc index dfc9125..036d427 100644 --- a/BotTargeting/scripting/include/BotTargeting.inc +++ b/BotTargeting/scripting/include/BotTargeting.inc @@ -3,8 +3,21 @@ #endif #define _BotTargeting_Included +/** + * Returns whether the client is one of the autism bots. + * Throws an error if the client is invalid, not in-game or not authorized. + */ native bool IsClientAutismBot(int client); +/** + * Returns which autism bot the client is. + * Throws an error if the client is invalid, not in-game or not authorized. + * + * @param client Client index. + * @return 1-4 for autism bot 1 to 4, 0 if the client is not an autism bot. + */ +native int GetClientAutismBotIndex(int client); + public SharedPlugin __pl_BotTargeting = { name = "BotTargeting", @@ -20,5 +33,6 @@ public SharedPlugin __pl_BotTargeting = public __pl_BotTargeting_SetNTVOptional() { MarkNativeAsOptional("IsClientAutismBot"); + MarkNativeAsOptional("GetClientAutismBotIndex"); } #endif