From f88885bafc976be31122fd2215c5de7d1b34aa78 Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Thu, 2 Sep 2021 14:58:18 +0000 Subject: [PATCH] add another parameter to Shavit_OnReplayStart and Shavit_OnReplayEnd --- addons/sourcemod/scripting/include/shavit.inc | 8 ++++-- addons/sourcemod/scripting/shavit-replay.sp | 28 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 317ede8cd..4df4da23a 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -999,21 +999,25 @@ forward void Shavit_OnRankAssigned(int client, int rank, float points, bool firs /** * Called when replay playback starts. + * Will be called twice for every replay bot unless the replay is canceled before the second call. Use `delay_elapsed` to check for the first & second time. * * @param ent Entity index for the replay. * @param type The type of replay. Replay_Prop means `ent` is not a fakeclient, but instead a prop. + * @param delay_elapsed `false` when the replay bot just spawned but before the start delay has elapsed. `true` when the start delay has elapsed. * @noreturn */ -forward void Shavit_OnReplayStart(int ent, int type); +forward void Shavit_OnReplayStart(int ent, int type, bool delay_elapsed); /** * Called when replay playback ends. + * Will be called twice for most replay bots unless the replay bot is canceled before it finishes. See `actually_finished`. * * @param client Entity index for the replay. * @param type The type of replay. Replay_Prop means `ent` is not a fakeclient, but instead a prop. + * @param actually_finished `false` when the replay runs out of frames and is starting the timer to despawn. `true` when the replay bot is about to despawn. `true` will always run. * @noreturn */ -forward void Shavit_OnReplayEnd(int ent, int type); +forward void Shavit_OnReplayEnd(int ent, int type, bool actually_finished); /** * Called when all replays files have been loaded. diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 6b824efa5..cab0a699a 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -379,8 +379,8 @@ public void OnPluginStart() LoadTranslations("shavit-replay.phrases"); // forwards - gH_OnReplayStart = CreateGlobalForward("Shavit_OnReplayStart", ET_Event, Param_Cell, Param_Cell); - gH_OnReplayEnd = CreateGlobalForward("Shavit_OnReplayEnd", ET_Event, Param_Cell, Param_Cell); + gH_OnReplayStart = CreateGlobalForward("Shavit_OnReplayStart", ET_Event, Param_Cell, Param_Cell, Param_Cell); + gH_OnReplayEnd = CreateGlobalForward("Shavit_OnReplayEnd", ET_Event, Param_Cell, Param_Cell, Param_Cell); gH_OnReplaysLoaded = CreateGlobalForward("Shavit_OnReplaysLoaded", ET_Event); gH_ShouldSaveReplayCopy = CreateGlobalForward("Shavit_ShouldSaveReplayCopy", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell); gH_OnReplaySaved = CreateGlobalForward("Shavit_OnReplaySaved", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String); @@ -745,6 +745,12 @@ public void AdminMenu_DeleteReplay(Handle topmenu, TopMenuAction action, TopMenu void FinishReplay(bot_info_t info) { + Call_StartForward(gH_OnReplayEnd); + Call_PushCell(info.iEnt); + Call_PushCell(info.iType); + Call_PushCell(true); // actually_finished + Call_Finish(); + int starter = GetClientFromSerial(info.iStarterSerial); if (info.iType == Replay_Dynamic || info.iType == Replay_Prop) @@ -934,6 +940,12 @@ void StartReplay(bot_info_t info, int track, int style, int starter, float delay // It seems to use early steamids for pfps since I've noticed BAILPAN and EricS 's avatars... CreateTimer(0.2, Timer_SpectateMyBot, GetClientSerial(info.iEnt), TIMER_FLAG_NO_MAPCHANGE); } + + Call_StartForward(gH_OnReplayStart); + Call_PushCell(info.iEnt); + Call_PushCell(info.iType); + Call_PushCell(false); // delay_elapsed + Call_Finish(); } public int Native_IsReplayEntity(Handle handler, int numParams) @@ -2950,6 +2962,12 @@ Action ReplayOnPlayerRunCmd(bot_info_t info, int &buttons, int &impulse, float v info.iStatus = Replay_End; info.hTimer = CreateTimer((info.fDelay / 2.0), Timer_EndReplay, info.iEnt, TIMER_FLAG_NO_MAPCHANGE); + Call_StartForward(gH_OnReplayEnd); + Call_PushCell(info.iEnt); + Call_PushCell(info.iType); + Call_PushCell(false); // actually_finished + Call_Finish(); + return Plugin_Changed; } @@ -3183,11 +3201,6 @@ public Action Timer_EndReplay(Handle Timer, any data) data = GetBotInfoIndex(data); gA_BotInfo[data].hTimer = null; - Call_StartForward(gH_OnReplayEnd); - Call_PushCell(gA_BotInfo[data].iEnt); - Call_PushCell(gA_BotInfo[data].iType); - Call_Finish(); - FinishReplay(gA_BotInfo[data]); return Plugin_Stop; @@ -3202,6 +3215,7 @@ public Action Timer_StartReplay(Handle Timer, any data) Call_StartForward(gH_OnReplayStart); Call_PushCell(gA_BotInfo[data].iEnt); Call_PushCell(gA_BotInfo[data].iType); + Call_PushCell(true); // delay_elapsed Call_Finish(); return Plugin_Stop;