From c6d13222aeba1df6ebc579e102e67699ac463deb Mon Sep 17 00:00:00 2001 From: jenz Date: Sun, 26 Nov 2023 23:19:21 +0100 Subject: [PATCH] redid ongameframe iteration again to skip all people not eligeble for hide --- _Hide/scripting/Hide.sp | 67 ++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/_Hide/scripting/Hide.sp b/_Hide/scripting/Hide.sp index a962f73..918af52 100644 --- a/_Hide/scripting/Hide.sp +++ b/_Hide/scripting/Hide.sp @@ -5,6 +5,7 @@ #include #include + /* BOOLS */ bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1]; bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1]; @@ -12,6 +13,9 @@ bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1]; /* INTEGERS */ int g_iHideRange[MAXPLAYERS+1]; int g_iLeader = 0; +int g_iCountHide = 0; +int g_iMaxHide = 5; +int previous_clients[5]; //has to match g_iMaxHide /* CONVARS */ ConVar g_hCVar_HideEnabled; @@ -45,26 +49,26 @@ public Plugin myinfo = //---------------------------------------------------------------------------------------------------- public void OnPluginStart() { - g_hCVar_HideEnabled = CreateConVar("sm_hide_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0); - g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged); - AutoExecConfig(true); + g_hCVar_HideEnabled = CreateConVar("sm_hide_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0); + g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged); + AutoExecConfig(true); - g_hCookie_HideRange = RegClientCookie("hide_range", "", CookieAccess_Private); + g_hCookie_HideRange = RegClientCookie("hide_range", "", CookieAccess_Private); - RegConsoleCmd("sm_hide", OnHideSettings, "Hiding near humans"); + RegConsoleCmd("sm_hide", OnHideSettings, "Hiding near humans"); - for(int client = 1; client <= MaxClients; client++) - { - if(IsClientInGame(client)) - { - OnClientPutInServer(client); + for(int client = 1; client <= MaxClients; client++) + { + if(IsClientInGame(client)) + { + OnClientPutInServer(client); - if(AreClientCookiesCached(client)) - OnClientCookiesCached(client); - } + if(AreClientCookiesCached(client)) + OnClientCookiesCached(client); + } - } - SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide"); + } + SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide"); } //---------------------------------------------------------------------------------------------------- @@ -152,7 +156,7 @@ public Action UpdateHide(Handle timer) { if(!g_hCVar_HideEnabled.BoolValue) return Plugin_Continue; - + g_iCountHide = 0; for(int client = 1; client <= MaxClients; client++) { if(g_iHideRange[client] == DISABLED) @@ -187,6 +191,7 @@ public Action UpdateHide(Handle timer) if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target)) { g_bHidePlayers[client][target] = true; + g_iCountHide++; } else { @@ -217,14 +222,21 @@ public Action Hook_SetTransmit(int target, int client) return Plugin_Continue; } - //October 2023 edit: using OnGameFrame to just hide 5 player per frame. supposedly (a rumor) that is good enough to actually work. public void OnGameFrame() { + int local_clients = 0; static int client = 0; - int iterate_amount = 5; - for (int i = 0; i < iterate_amount; i++) + int iterate_amount = g_iCountHide > g_iMaxHide ? g_iMaxHide : g_iCountHide; + for (int i = 0; i < iterate_amount;) { + if (local_clients > MAXPLAYERS) + { + //if nobody is using hide anymore since the last timer trigger just exit out of the loop + //this is after having simply iterated all possible clients on each OnGameFrame. + return; + } + //restart from the beginning if (client == MAXPLAYERS) { @@ -232,18 +244,15 @@ public void OnGameFrame() } client++; + local_clients++; //hide other players for this player? if (!IsClientInGame(client) || g_iHideRange[client] == DISABLED || !IsPlayerAlive(client) || !ZR_IsClientHuman(client)) { + //in our iteration of max 5 clients per OnGameFrame we skip all clients who are not eligble for hide anyways. continue; } - int previous_client = client - ((i * 2) + 1); //example if client starts at 43 in loop. 43 - 1 = 42; 44 - 3 = 41; 45 - 5 = 40; 46 - 7 = 39; 47 - 9 = 38 - if (previous_client < 1) - { - previous_client = MAXPLAYERS - (i + 1); //65 - 1 = 64; 65 - 2 = 63; 65 - 3 = 62 and so on - } for (int target = 1; target <= MaxClients; target++) { if (IsClientInGame(target) && IsPlayerAlive(target)) @@ -253,8 +262,16 @@ public void OnGameFrame() g_bNewHidePlayers[client][target] = true; } } - g_bNewHidePlayers[previous_client][target] = false; + if (iterate_amount == g_iMaxHide) + { + //for example we are processing 5 out of 20 players on this gameframe that use hide + //we reset hiding the previous 5 out of 20 clients from the last gameframe so that at any given time maximal 5 clients actually get hidden. + //the main purpose is that each OnGameFrame only focuses on rotating between 5 players who actually have hide enabled. + g_bNewHidePlayers[previous_clients[i]][target] = false; + } } + previous_clients[i] = client; + i++; } }