From ce2397e8495a752d69649e3612ac6c0179efb49e Mon Sep 17 00:00:00 2001 From: zaCade Date: Fri, 7 Jul 2023 10:33:48 +0200 Subject: [PATCH] [AutoRecorder] Add two natives for information. --- AutoRecorder/scripting/AutoRecorder.sp | 30 +++++++++++++++++-- .../scripting/include/AutoRecorder.inc | 26 ++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 AutoRecorder/scripting/include/AutoRecorder.inc diff --git a/AutoRecorder/scripting/AutoRecorder.sp b/AutoRecorder/scripting/AutoRecorder.sp index 8ea8d012..46fbe938 100644 --- a/AutoRecorder/scripting/AutoRecorder.sp +++ b/AutoRecorder/scripting/AutoRecorder.sp @@ -15,6 +15,8 @@ bool g_bIsRecording = false; bool g_bIsManual = false; int g_iStartedRecording; +int g_iRecordingNumber = 1; +int g_iRecordingFromTick; // Default: o=rx,g=rx,u=rwx | 755 #define DIRECTORY_PERMISSIONS (FPERM_O_READ|FPERM_O_EXEC | FPERM_G_READ|FPERM_G_EXEC | FPERM_U_READ|FPERM_U_WRITE|FPERM_U_EXEC) @@ -28,6 +30,15 @@ public Plugin myinfo = url = "http://www.theville.org" } +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) +{ + CreateNative("GetDemoRecordingNumber", Native_GetDemoRecordingNumber); + CreateNative("GetDemoRecordingTick", Native_GetDemoRecordingTick); + + RegPluginLibrary("AutoRecorder"); + return APLRes_Success; +} + public void OnPluginStart() { g_hAutoRecord = CreateConVar("sm_autorecord_enable", "1", "Enable automatic recording", _, true, 0.0, true, 1.0); @@ -94,6 +105,8 @@ public void OnMapEnd() StopRecord(); g_bIsManual = false; } + + g_iRecordingNumber = 1; } public void OnClientPutInServer(int client) @@ -203,11 +216,14 @@ void StartRecord() // replace slashes in map path name with dashes, to prevent fail on workshop maps ReplaceString(sMap, sizeof(sMap), "/", "-", false); - ServerCommand("tv_record \"%s/auto-%s-%s\"", sPath, sTime, sMap); + ServerCommand("tv_record \"%s/auto-%s-%s-%d\"", sPath, sTime, sMap, g_iRecordingNumber); g_bIsRecording = true; g_iStartedRecording = GetTime(); - LogMessage("Recording to auto-%s-%s.dem", sTime, sMap); + g_iRecordingNumber++; + g_iRecordingFromTick = GetGameTickCount(); + + LogMessage("Recording to auto-%s-%s-%d.dem", sTime, sMap, g_iRecordingNumber); } } @@ -219,3 +235,13 @@ void StopRecord() g_bIsRecording = false; } } + +public int Native_GetDemoRecordingNumber(Handle hPlugin, int numParams) +{ + return g_iRecordingNumber; +} + +public int Native_GetDemoRecordingTick(Handle hPlugin, int numParams) +{ + return GetGameTickCount() - g_iRecordingFromTick; +} \ No newline at end of file diff --git a/AutoRecorder/scripting/include/AutoRecorder.inc b/AutoRecorder/scripting/include/AutoRecorder.inc new file mode 100644 index 00000000..40adbe2c --- /dev/null +++ b/AutoRecorder/scripting/include/AutoRecorder.inc @@ -0,0 +1,26 @@ +#if defined AutoRecorder_included + #endinput +#endif +#define AutoRecorder_included + +native int GetDemoRecordingNumber(); +native int GetDemoRecordingTick(); + +public SharedPlugin __pl_AutoRecorder = +{ + name = "AutoRecorder", + file = "AutoRecorder.smx", +#if defined REQUIRE_PLUGIN + required = 1 +#else + required = 0 +#endif +}; + +#if !defined REQUIRE_PLUGIN +public void __pl_AutoRecorder_SetNTVOptional() +{ + MarkNativeAsOptional("GetDemoRecordingNumber"); + MarkNativeAsOptional("GetDemoRecordingTick"); +} +#endif