From debbf4d87e513c201e7614616bf621b7f2dd639e Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Fri, 23 Jul 2021 05:55:18 +0000 Subject: [PATCH] add Shavit_GetLoopingBotByName --- addons/sourcemod/scripting/include/shavit.inc | 10 ++++++ addons/sourcemod/scripting/shavit-replay.sp | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index bb6d8177..8e031241 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -2413,6 +2413,15 @@ native void Shavit_GetPlainChatrank(int client, char[] buf, int buflen, bool inc */ native void Shavit_DeleteWR(int style, int track, const char[] map, int accountid, int recordid, bool delete_sql, bool update_cache); +/* + * Used to find a looping replay bot from the loop config name. + * + * @param name Looping bot config name. An example is "Other Styles" from the default set of looping bots in shavit-replay.cfg + * + * @return The client index of the looping replay bot. -1 if could not find the config name. 0 if could not find the replay bot client. + */ +native int Shavit_GetLoopingBotByName(const char[] name); + public SharedPlugin __pl_shavit = { name = "shavit", @@ -2565,5 +2574,6 @@ public void __pl_shavit_SetNTVOptional() MarkNativeAsOptional("Shavit_GetReplayPostFrame"); MarkNativeAsOptional("Shavit_GetReplayCachePreFrame"); MarkNativeAsOptional("Shavit_GetReplayCachePostFrame"); + MarkNativeAsOptional("Shavit_GetLoopingBotByName"); } #endif diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 9fd4e17c..899c8a89 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -329,6 +329,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("Shavit_GetClosestReplayVelocityDifference", Native_GetClosestReplayVelocityDifference); CreateNative("Shavit_StartReplayFromFrameCache", Native_StartReplayFromFrameCache); CreateNative("Shavit_StartReplayFromFile", Native_StartReplayFromFile); + CreateNative("Shavit_GetLoopingBotByName", Native_GetLoopingBotByName); // registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins RegPluginLibrary("shavit-replay"); @@ -1361,6 +1362,38 @@ public int Native_SetClosestReplayStyle(Handle plugin, int numParams) gI_TimeDifferenceStyle[GetNativeCell(1)] = GetNativeCell(2); } +public int Native_GetLoopingBotByName(Handle plugin, int numParams) +{ + char name[PLATFORM_MAX_PATH]; + GetNativeString(1, name, sizeof(name)); + + int configid = -1; + + for (int i = 0; i < MAX_LOOPING_BOT_CONFIGS; i++) + { + if (StrEqual(gA_LoopingBotConfig[i].sName, name)) + { + configid = i; + break; + } + } + + if (configid == -1) + { + return -1; + } + + for (int i = 1; i <= MAXPLAYERS; i++) + { + if (gA_BotInfo[i].iType == Replay_Looping && gA_BotInfo[i].iLoopingConfig == configid) + { + return i; + } + } + + return 0; +} + public Action Timer_Cron(Handle Timer) { for (int i = 1; i <= MaxClients; i++)