removed most stuff again, just putting a hardcap to 8 players using hide

This commit is contained in:
jenz 2023-12-03 01:43:41 +01:00
parent 80a593a31d
commit 8c0bfb037b

View File

@ -8,14 +8,15 @@
/* BOOLS */
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1];
bool g_bHasSomebodyToHide[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
int g_iHideCapacity = 8;
/* HANDLES */
Handle g_hTimer;
/* CONVARS */
ConVar g_hCVar_HideEnabled;
@ -69,14 +70,13 @@ public void OnPluginStart()
}
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide");
g_hTimer = CreateTimer(0.5, UpdateHide, INVALID_HANDLE, TIMER_REPEAT);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
public void OnPluginEnd()
{
CreateTimer(0.5, UpdateHide, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
if (g_hTimer != INVALID_HANDLE)
delete g_hTimer;
}
//----------------------------------------------------------------------------------------------------
@ -86,10 +86,10 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n
{
for(int client = 1; client <= MaxClients; client++)
{
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++)
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
if(IsClientInGame(client))
@ -127,8 +127,8 @@ public void OnClientDisconnect(int client)
for(int target = 1; target <= MaxClients; target++)
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
g_bHasSomebodyToHide[client] = false;
}
//----------------------------------------------------------------------------------------------------
@ -156,32 +156,47 @@ public Action UpdateHide(Handle timer)
{
if(!g_hCVar_HideEnabled.BoolValue)
return Plugin_Continue;
g_iCountHide = 0;
int CountPlayersUsingHide = 0;
for(int client = 1; client <= MaxClients; client++)
{
if (g_bHasSomebodyToHide[client])
{
CountPlayersUsingHide++;
}
}
for(int client = 1; client <= MaxClients; client++)
{
if(g_iHideRange[client] == DISABLED)
{
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++)
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
continue;
}
if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientHuman(client) || IsFakeClient(client))
{
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++)
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
continue;
}
//technically players could cheat the timer here causing there to be more than 8 people using hide.
if (CountPlayersUsingHide >= g_iHideCapacity && !g_bHasSomebodyToHide[client])
{
continue;
}
float fOriginClient[3];
float fOriginTarget[3];
GetClientAbsOrigin(client, fOriginClient);
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++)
{
if(IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target) && target != client)
@ -191,18 +206,16 @@ public Action UpdateHide(Handle timer)
if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target))
{
g_bHidePlayers[client][target] = true;
g_iCountHide++;
g_bHasSomebodyToHide[client] = true;
}
else
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
}
else
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
}
}
@ -215,66 +228,13 @@ public Action UpdateHide(Handle timer)
//----------------------------------------------------------------------------------------------------
public Action Hook_SetTransmit(int target, int client)
{
if(g_bNewHidePlayers[client][target])
if (g_bHidePlayers[client][target])
{
return Plugin_Handled;
}
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 = 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)
{
client = 0;
}
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;
}
for (int target = 1; target <= MaxClients; target++)
{
if (IsClientInGame(target) && IsPlayerAlive(target))
{
if (g_bHidePlayers[client][target])
{
g_bNewHidePlayers[client][target] = true;
}
}
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++;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -289,9 +249,20 @@ public Action OnHideSettings(int client, int args)
//----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu(int client)
{
int CountPlayersUsingHide = 0;
for(int clienti = 1; clienti <= MaxClients; clienti++)
{
if (g_bHasSomebodyToHide[clienti])
{
CountPlayersUsingHide++;
}
}
Menu menu = new Menu(MenuHandler_MainMenu);
menu.SetTitle("Hide", client);
char titlemsg[256];
Format(titlemsg, sizeof(titlemsg), "Hide: Currently limited to %i players. Used by %i", g_iHideCapacity, CountPlayersUsingHide);
menu.SetTitle(titlemsg, client);
char sBuffer[128];