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 */ /* BOOLS */
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1]; bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1]; bool g_bHasSomebodyToHide[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_iHideCapacity = 8;
int g_iMaxHide = 5;
int previous_clients[5]; //has to match g_iMaxHide /* HANDLES */
Handle g_hTimer;
/* CONVARS */ /* CONVARS */
ConVar g_hCVar_HideEnabled; ConVar g_hCVar_HideEnabled;
@ -69,14 +70,13 @@ public void OnPluginStart()
} }
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide"); SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide");
g_hTimer = CreateTimer(0.5, UpdateHide, INVALID_HANDLE, TIMER_REPEAT);
} }
//---------------------------------------------------------------------------------------------------- public void OnPluginEnd()
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{ {
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++) for(int client = 1; client <= MaxClients; client++)
{ {
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++) for(int target = 1; target <= MaxClients; target++)
{ {
g_bHidePlayers[client][target] = false; g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
} }
if(IsClientInGame(client)) if(IsClientInGame(client))
@ -127,8 +127,8 @@ public void OnClientDisconnect(int client)
for(int target = 1; target <= MaxClients; target++) for(int target = 1; target <= MaxClients; target++)
{ {
g_bHidePlayers[client][target] = false; 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) if(!g_hCVar_HideEnabled.BoolValue)
return Plugin_Continue; 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++) for(int client = 1; client <= MaxClients; client++)
{ {
if(g_iHideRange[client] == DISABLED) if(g_iHideRange[client] == DISABLED)
{ {
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++) for(int target = 1; target <= MaxClients; target++)
{ {
g_bHidePlayers[client][target] = false; g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
} }
continue; continue;
} }
if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientHuman(client) || IsFakeClient(client)) if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientHuman(client) || IsFakeClient(client))
{ {
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++) for(int target = 1; target <= MaxClients; target++)
{ {
g_bHidePlayers[client][target] = false; g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
} }
continue; 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 fOriginClient[3];
float fOriginTarget[3]; float fOriginTarget[3];
GetClientAbsOrigin(client, fOriginClient); GetClientAbsOrigin(client, fOriginClient);
g_bHasSomebodyToHide[client] = false;
for(int target = 1; target <= MaxClients; target++) for(int target = 1; target <= MaxClients; target++)
{ {
if(IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target) && target != client) 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)) if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target))
{ {
g_bHidePlayers[client][target] = true; g_bHidePlayers[client][target] = true;
g_iCountHide++; g_bHasSomebodyToHide[client] = true;
} }
else else
{ {
g_bHidePlayers[client][target] = false; g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
} }
} }
else else
{ {
g_bHidePlayers[client][target] = false; 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) public Action Hook_SetTransmit(int target, int client)
{ {
if(g_bNewHidePlayers[client][target]) if (g_bHidePlayers[client][target])
{ {
return Plugin_Handled; return Plugin_Handled;
} }
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.
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: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -289,30 +249,41 @@ public Action OnHideSettings(int client, int args)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu(int client) public void ShowSettingsMenu(int client)
{ {
Menu menu = new Menu(MenuHandler_MainMenu); int CountPlayersUsingHide = 0;
for(int clienti = 1; clienti <= MaxClients; clienti++)
{
if (g_bHasSomebodyToHide[clienti])
{
CountPlayersUsingHide++;
}
}
menu.SetTitle("Hide", client); Menu menu = new Menu(MenuHandler_MainMenu);
char sBuffer[128]; char titlemsg[256];
Format(titlemsg, sizeof(titlemsg), "Hide: Currently limited to %i players. Used by %i", g_iHideCapacity, CountPlayersUsingHide);
menu.SetTitle(titlemsg, client);
Format(sBuffer, sizeof(sBuffer), "Disabled%s", (g_iHideRange[client] == DISABLED) ? " [Selected]" : ""); char sBuffer[128];
menu.AddItem("", sBuffer, (g_iHideRange[client] == DISABLED));
Format(sBuffer, sizeof(sBuffer), "Short Range%s", (g_iHideRange[client] == SHORT) ? " [Selected]" : ""); Format(sBuffer, sizeof(sBuffer), "Disabled%s", (g_iHideRange[client] == DISABLED) ? " [Selected]" : "");
menu.AddItem("", sBuffer, (g_iHideRange[client] == SHORT)); menu.AddItem("", sBuffer, (g_iHideRange[client] == DISABLED));
Format(sBuffer, sizeof(sBuffer), "Medium Range%s", (g_iHideRange[client] == MEDIUM) ? " [Selected]" : ""); Format(sBuffer, sizeof(sBuffer), "Short Range%s", (g_iHideRange[client] == SHORT) ? " [Selected]" : "");
menu.AddItem("", sBuffer, (g_iHideRange[client] == MEDIUM)); menu.AddItem("", sBuffer, (g_iHideRange[client] == SHORT));
Format(sBuffer, sizeof(sBuffer), "Long Range%s", (g_iHideRange[client] == LONG) ? " [Selected]" : ""); Format(sBuffer, sizeof(sBuffer), "Medium Range%s", (g_iHideRange[client] == MEDIUM) ? " [Selected]" : "");
menu.AddItem("", sBuffer, (g_iHideRange[client] == LONG)); menu.AddItem("", sBuffer, (g_iHideRange[client] == MEDIUM));
if(!g_hCVar_HideEnabled.BoolValue) Format(sBuffer, sizeof(sBuffer), "Long Range%s", (g_iHideRange[client] == LONG) ? " [Selected]" : "");
menu.AddItem("", "Warning: Hide is currently disabled on the server", ITEMDRAW_DISABLED); menu.AddItem("", sBuffer, (g_iHideRange[client] == LONG));
menu.ExitBackButton = true; if(!g_hCVar_HideEnabled.BoolValue)
menu.AddItem("", "Warning: Hide is currently disabled on the server", ITEMDRAW_DISABLED);
menu.Display(client, MENU_TIME_FOREVER); menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------