From 8fa71526aa3070de6d5cb911dc44066dd15deb6c Mon Sep 17 00:00:00 2001 From: rtldg Date: Sun, 22 Mar 2026 07:05:52 +0000 Subject: [PATCH] Handle OnUser1-4 outputs --- scripting/eventqueuefix.sp | 97 +++++++++++++++++++++++------ scripting/include/eventqueuefix.inc | 5 +- 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/scripting/eventqueuefix.sp b/scripting/eventqueuefix.sp index 87960df..c346136 100644 --- a/scripting/eventqueuefix.sp +++ b/scripting/eventqueuefix.sp @@ -4,7 +4,7 @@ #define PLUGIN_NAME "EventQueue fix" #define PLUGIN_AUTHOR "carnifex" #define PLUGIN_DESCRIPTION "" -#define PLUGIN_VERSION "1.3.3" +#define PLUGIN_VERSION "1.4.0" #define PLUGIN_URL "" #include @@ -29,6 +29,7 @@ ArrayList g_aPlayerEvents[MAXPLAYERS + 1]; ArrayList g_aOutputWait[MAXPLAYERS + 1]; +ArrayList g_aOnUser1_4[MAXPLAYERS + 1][4]; bool g_bPaused[MAXPLAYERS + 1]; bool g_bLateLoad; Handle g_hFindEntityByName; @@ -85,29 +86,16 @@ public void OnClientPutInServer(int client) g_fTimescale[client] = 1.0; g_bPaused[client] = false; - if(g_aPlayerEvents[client] == null) - { - g_aPlayerEvents[client] = new ArrayList(sizeof(event_t)); - } - else - { - g_aPlayerEvents[client].Clear(); - } - - if(g_aOutputWait[client] == null) - { - g_aOutputWait[client] = new ArrayList(sizeof(entity_t)); - } - else - { - g_aOutputWait[client].Clear(); - } + g_aPlayerEvents[client] = new ArrayList(sizeof(event_t)); + g_aOutputWait[client] = new ArrayList(sizeof(entity_t)); + for (int N = 0; N < 4; N++) g_aOnUser1_4[client][N] = new ArrayList(sizeof(event_t)); } public void OnClientDisconnect_Post(int client) { delete g_aPlayerEvents[client]; delete g_aOutputWait[client]; + for (int N = 0; N < 4; N++) delete g_aOnUser1_4[client][N]; } public void OnEntityCreated(int entity, const char[] classname) @@ -317,6 +305,31 @@ public void ServiceEvent(event_t event) if(!IsValidEntity(caller)) caller = -1; + + if (StrEqual(event.target, "!activator", false) && StrEqual(event.targetInput, "AddOutput", false)) + { + if (0 == strncmp(event.variantValue, "OnUser", 6, false) && '4' >= event.variantValue[6] >= '1') + { + int N = event.variantValue[6] - '1'; + + char buffers[5][64]; + // "OnUser1 anti_glitch_filter_d_1:testactivator::0:1" + ExplodeString(event.variantValue[8], ":", buffers, sizeof(buffers), sizeof(buffers[0]), true); + event.caller = event.activator; + event.target = buffers[0]; + event.targetInput = buffers[1]; + event.variantValue = buffers[2]; + event.delay = StringToFloat(buffers[3]); + // NOTE: we don't do "times to fire"... + + #if defined DEBUG + PrintToServer("[%i] AddOutput OnUser%d: %s, %s, %s, %f, %i, time: %f", GetGameTickCount(), N+1, event.target, event.targetInput, event.variantValue, event.delay, activator, GetGameTime()); + #endif + + g_aOnUser1_4[activator][N].PushArray(event); + return; + } + } bool byTargetname = false; @@ -380,8 +393,30 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 g_aPlayerEvents[client].SetArray(i, event); if(event.delay <= -1.0 * timescale) { - ServiceEvent(event); g_aPlayerEvents[client].Erase(i); + + if (0 == strncmp(event.targetInput, "FireUser", 8) && '4' >= event.targetInput[8] >= '1') + { + int N = event.targetInput[8] - '1'; + #if defined DEBUG + PrintToServer("[%i] OnUser%d", GetGameTickCount(), N+1); + #endif + for (int A = 0, B = g_aOnUser1_4[client][N].Length; A < B; A++) + { + event_t OnUser_event; + g_aOnUser1_4[client][N].GetArray(0, OnUser_event); + g_aOnUser1_4[client][N].Erase(0); + #if defined DEBUG + PrintToServer("%s, %s, %s", OnUser_event.target, OnUser_event.targetInput, OnUser_event.variantValue); + #endif + ServiceEvent(OnUser_event); + } + } + else + { + ServiceEvent(event); + } + i--; } } @@ -404,15 +439,22 @@ public any Native_GetClientEvents(Handle plugin, int numParams) if(client < 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client)) return false; + if(numParams != 3 || GetNativeCell(3) != sizeof(eventpack_t)) + return false; + ArrayList pe = g_aPlayerEvents[client].Clone(); ArrayList ow = g_aOutputWait[client].Clone(); + ArrayList ou[4]; + for (int N = 0; N < 4; N++) ou[N] = g_aOnUser1_4[client][N].Clone(); eventpack_t ep; ep.playerEvents = view_as(CloneHandle(pe, plugin)); ep.outputWaits = view_as(CloneHandle(ow, plugin)); + for (int N = 0; N < 4; N++) ep.OnUser1_4[N] = view_as(CloneHandle(ou[N], plugin)); delete pe; delete ow; + for (int N = 0; N < 4; N++) delete ou[N]; SetNativeArray(2, ep, sizeof(eventpack_t)); return true; @@ -424,15 +466,20 @@ public any Native_SetClientEvents(Handle plugin, int numParams) if(client < 0 || client > MaxClients || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client)) return false; + + if(numParams != 3 || GetNativeCell(3) != sizeof(eventpack_t)) + return false; eventpack_t ep; GetNativeArray(2, ep, sizeof(eventpack_t)); delete g_aPlayerEvents[client]; delete g_aOutputWait[client]; + for (int N = 0; N < 4; N++) delete g_aOnUser1_4[client][N]; g_aPlayerEvents[client] = ep.playerEvents.Clone(); g_aOutputWait[client] = ep.outputWaits.Clone(); + for (int N = 0; N < 4; N++) g_aOnUser1_4[client][N] = ep.OnUser1_4[N].Clone(); int length = g_aPlayerEvents[client].Length; @@ -443,6 +490,17 @@ public any Native_SetClientEvents(Handle plugin, int numParams) event.activator = EntIndexToEntRef(client); g_aPlayerEvents[client].SetArray(i, event); } + + for (int N = 0; N < 4; N++) + { + for (int A = 0, B = g_aOnUser1_4[client][N].Length; A < B; A++) + { + event_t event; + g_aOnUser1_4[client][N].GetArray(A, event); + event.activator = event.caller = EntIndexToEntRef(client); + g_aOnUser1_4[client][N].SetArray(A, event); + } + } return true; } @@ -468,6 +526,7 @@ public any Native_ClearClientEvents(Handle plugin, int numParams) g_aOutputWait[client].Clear(); g_aPlayerEvents[client].Clear(); + for (int N = 0; N < 4; N++) g_aOnUser1_4[client][N].Clear(); return true; } diff --git a/scripting/include/eventqueuefix.inc b/scripting/include/eventqueuefix.inc index 930d94d..f6b0962 100644 --- a/scripting/include/eventqueuefix.inc +++ b/scripting/include/eventqueuefix.inc @@ -29,6 +29,7 @@ enum struct eventpack_t { ArrayList playerEvents; ArrayList outputWaits; + ArrayList OnUser1_4[4]; } enum struct entity_t @@ -45,7 +46,7 @@ enum struct entity_t * * @return True if successful, false otherwise. */ -native bool GetClientEvents(int client, any[] eventpack); +native bool GetClientEvents(int client, any[] eventpack, int packsize=sizeof(eventpack_t)); /* * Sets the current pending events for a client. @@ -55,7 +56,7 @@ native bool GetClientEvents(int client, any[] eventpack); * * @return True if successful, false otherwise. */ -native bool SetClientEvents(int client, any[] eventpack); +native bool SetClientEvents(int client, any[] eventpack, int packsize=sizeof(eventpack_t)); /* * Clears the current pending events for a client.