Skip to content

Commit

Permalink
add another parameter to Shavit_OnReplayStart and Shavit_OnReplayEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed Sep 2, 2021
1 parent c0eaba7 commit f88885b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
8 changes: 6 additions & 2 deletions addons/sourcemod/scripting/include/shavit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 21 additions & 7 deletions addons/sourcemod/scripting/shavit-replay.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f88885b

Please sign in to comment.