From c6af8a5f16c4289efb52febef1b0b3c5a07efa10 Mon Sep 17 00:00:00 2001 From: hermansimensen Date: Sat, 8 May 2021 22:28:15 +0200 Subject: [PATCH] Add support for pausing events. --- scripting/eventqueuefix.sp | 36 +++++++++++++++++++++++++++-- scripting/include/eventqueuefix.inc | 23 +++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/scripting/eventqueuefix.sp b/scripting/eventqueuefix.sp index 37170d2..bf2a094 100644 --- a/scripting/eventqueuefix.sp +++ b/scripting/eventqueuefix.sp @@ -33,8 +33,9 @@ native int Shavit_GetBhopStyle(int client); native float Shavit_GetStyleSettingFloat(int style, const char[] key); native float Shavit_GetClientTimescale(int client); -ArrayList g_aPlayerEvents[MAXPLAYERS+1]; -ArrayList g_aOutputWait[MAXPLAYERS+1]; +ArrayList g_aPlayerEvents[MAXPLAYERS + 1]; +ArrayList g_aOutputWait[MAXPLAYERS + 1]; +bool g_bPaused[MAXPLAYERS + 1]; bool g_bLateLoad; Handle g_hFindEntityByName; int g_iRefOffset; @@ -85,6 +86,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("SetClientEvents", Native_SetClientEvents); CreateNative("ClearClientEvents", Native_ClearClientEvents); CreateNative("SetEventsTimescale", Native_SetEventsTimescale); + CreateNative("IsClientEventsPaused", Native_IsClientPaused); + CreateNative("SetClientEventsPaused", Native_SetClientPaused); MarkNativeAsOptional("Shavit_GetBhopStyle"); MarkNativeAsOptional("Shavit_GetStyleSettingFloat"); @@ -115,6 +118,7 @@ public void OnMapStart() public void OnClientPutInServer(int client) { g_fTimescale[client] = 1.0; + g_bPaused[client] = false; if(g_aPlayerEvents[client] == null) { @@ -305,6 +309,9 @@ public void ServiceEvent(event_t event) public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2]) { + if(g_bPaused[client]) + return Plugin_Continue; + float timescale = g_fTimescale[client]; if(g_bBhopTimer) @@ -340,6 +347,8 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 i--; } } + + return Plugin_Continue; } public Action Hook_Button_OnTakeDamage(int victim, int& attacker, int& inflictor, float& damage, int& damagetype, int& weapon, float damageForce[3], float damagePosition[3], int damagecustom) @@ -414,3 +423,26 @@ public any Native_ClearClientEvents(Handle plugin, int numParams) return true; } + +public any Native_SetClientPaused(Handle plugin, int numParams) +{ + int client = GetNativeCell(1); + bool pauseState = GetNativeCell(2); + + if(client < 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client)) + return false; + + g_bPaused[client] = pauseState; + + return true; +} + +public any Native_IsClientPaused(Handle plugin, int numParams) +{ + int client = GetNativeCell(1); + + if(client < 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client)) + return ThrowNativeError(032, "Client is invalid."); + + return g_bPaused[client]; +} diff --git a/scripting/include/eventqueuefix.inc b/scripting/include/eventqueuefix.inc index 77a3151..eea7eab 100644 --- a/scripting/include/eventqueuefix.inc +++ b/scripting/include/eventqueuefix.inc @@ -76,6 +76,25 @@ native bool ClearClientEvents(int client); */ native bool SetEventsTimescale(int client, float timescale); +/* + * Pauses or unpauses events for a given client. + * + * @param client Client index. + * @param paused Pause state. + * + * @return True if action was successful, false otherwise. + */ +native bool SetClientEventsPaused(int client, bool paused); + +/* + * Check if events is paused + * + * @param client Client index. + * + * @return True if events are paused for client, false otherwise. Will throw native error if client is invalid. + */ +native bool IsClientEventsPaused(int client); + #if !defined REQUIRE_PLUGIN public void __pl_eventqueuefix_SetNTVOptional() { @@ -83,5 +102,7 @@ public void __pl_eventqueuefix_SetNTVOptional() MarkNativeAsOptional("SetClientEvents"); MarkNativeAsOptional("ClearClientEvents"); MarkNativeAsOptional("SetEventsTimescale"); + MarkNativeAsOptional("SetClientEventsPaused"); + MarkNativeAsOptional("IsClientEventsPaused"); } -#endif \ No newline at end of file +#endif