redid ongameframe iteration again to skip all people not eligeble for hide
This commit is contained in:
parent
e10656b4d5
commit
c6d13222ae
@ -5,6 +5,7 @@
|
|||||||
#include <zombiereloaded>
|
#include <zombiereloaded>
|
||||||
#include <leader>
|
#include <leader>
|
||||||
|
|
||||||
|
|
||||||
/* BOOLS */
|
/* BOOLS */
|
||||||
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
|
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
|
||||||
bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1];
|
bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1];
|
||||||
@ -12,6 +13,9 @@ bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1];
|
|||||||
/* INTEGERS */
|
/* INTEGERS */
|
||||||
int g_iHideRange[MAXPLAYERS+1];
|
int g_iHideRange[MAXPLAYERS+1];
|
||||||
int g_iLeader = 0;
|
int g_iLeader = 0;
|
||||||
|
int g_iCountHide = 0;
|
||||||
|
int g_iMaxHide = 5;
|
||||||
|
int previous_clients[5]; //has to match g_iMaxHide
|
||||||
|
|
||||||
/* CONVARS */
|
/* CONVARS */
|
||||||
ConVar g_hCVar_HideEnabled;
|
ConVar g_hCVar_HideEnabled;
|
||||||
@ -152,7 +156,7 @@ public Action UpdateHide(Handle timer)
|
|||||||
{
|
{
|
||||||
if(!g_hCVar_HideEnabled.BoolValue)
|
if(!g_hCVar_HideEnabled.BoolValue)
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
|
g_iCountHide = 0;
|
||||||
for(int client = 1; client <= MaxClients; client++)
|
for(int client = 1; client <= MaxClients; client++)
|
||||||
{
|
{
|
||||||
if(g_iHideRange[client] == DISABLED)
|
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))
|
if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target))
|
||||||
{
|
{
|
||||||
g_bHidePlayers[client][target] = true;
|
g_bHidePlayers[client][target] = true;
|
||||||
|
g_iCountHide++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -217,14 +222,21 @@ public Action Hook_SetTransmit(int target, int client)
|
|||||||
return Plugin_Continue;
|
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.
|
//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()
|
public void OnGameFrame()
|
||||||
{
|
{
|
||||||
|
int local_clients = 0;
|
||||||
static int client = 0;
|
static int client = 0;
|
||||||
int iterate_amount = 5;
|
int iterate_amount = g_iCountHide > g_iMaxHide ? g_iMaxHide : g_iCountHide;
|
||||||
for (int i = 0; i < iterate_amount; i++)
|
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
|
//restart from the beginning
|
||||||
if (client == MAXPLAYERS)
|
if (client == MAXPLAYERS)
|
||||||
{
|
{
|
||||||
@ -232,18 +244,15 @@ public void OnGameFrame()
|
|||||||
}
|
}
|
||||||
|
|
||||||
client++;
|
client++;
|
||||||
|
local_clients++;
|
||||||
|
|
||||||
//hide other players for this player?
|
//hide other players for this player?
|
||||||
if (!IsClientInGame(client) || g_iHideRange[client] == DISABLED || !IsPlayerAlive(client) || !ZR_IsClientHuman(client))
|
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;
|
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++)
|
for (int target = 1; target <= MaxClients; target++)
|
||||||
{
|
{
|
||||||
if (IsClientInGame(target) && IsPlayerAlive(target))
|
if (IsClientInGame(target) && IsPlayerAlive(target))
|
||||||
@ -253,9 +262,17 @@ public void OnGameFrame()
|
|||||||
g_bNewHidePlayers[client][target] = true;
|
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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user