updated Hide to only have a single client being not transmitted at a time

This commit is contained in:
jenz 2023-11-03 16:42:57 +01:00
parent 8c673f4401
commit 0394a2a402

View File

@ -5,12 +5,13 @@
#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];
/* INTEGERS */ /* INTEGERS */
int g_iHideRange[MAXPLAYERS+1]; int g_iHideRange[MAXPLAYERS+1];
int g_iLeader = 0;
/* CONVARS */ /* CONVARS */
ConVar g_hCVar_HideEnabled; ConVar g_hCVar_HideEnabled;
@ -33,9 +34,9 @@ int LONG = LONG_RANGE * LONG_RANGE;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "Hide Teammates", name = "Hide Teammates",
author = "Neon", author = "Neon, minor edits by jenz",
description = "A plugin that can !hide teammates with individual distances", description = "A plugin that can !hide teammates with individual distances",
version = "2.0.1", version = "2.1.1",
url = "https://steamcommunity.com/id/n3ontm" url = "https://steamcommunity.com/id/n3ontm"
}; };
@ -44,7 +45,6 @@ public Plugin myinfo =
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnPluginStart() public void OnPluginStart()
{ {
g_hCVar_HideEnabled = CreateConVar("sm_hide_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0); g_hCVar_HideEnabled = CreateConVar("sm_hide_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged); g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged);
AutoExecConfig(true); AutoExecConfig(true);
@ -72,7 +72,7 @@ public void OnPluginStart()
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnMapStart() public void OnMapStart()
{ {
CreateTimer(0.3, UpdateHide, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); CreateTimer(0.5, UpdateHide, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -83,7 +83,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++)
{ {
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))
{ {
@ -120,6 +123,7 @@ 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;
} }
} }
@ -156,39 +160,48 @@ public Action UpdateHide(Handle timer)
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) || IsFakeClient(client)) if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientHuman(client) || IsFakeClient(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;
} }
continue; continue;
} }
float fOriginClient[3]; float fOriginClient[3];
float fOriginTarget[3]; float fOriginTarget[3];
int iLeader = Leader_CurrentLeader() GetClientAbsOrigin(client, fOriginClient);
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)
{ {
GetClientAbsOrigin(target, fOriginTarget); GetClientAbsOrigin(target, fOriginTarget);
GetClientAbsOrigin(client, fOriginClient);
//PrintToChatAll("%N--%N::::::%f", client, target, GetVectorDistance(fOriginTarget, fOriginClient, false)); //PrintToChatAll("%N--%N::::::%f", client, target, GetVectorDistance(fOriginTarget, fOriginClient, false));
if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (iLeader != target)) if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target))
{
g_bHidePlayers[client][target] = true; g_bHidePlayers[client][target] = true;
else
g_bHidePlayers[client][target] = false;
} }
else else
{
g_bHidePlayers[client][target] = false; g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
} }
} }
else
{
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
}
}
g_iLeader = Leader_CurrentLeader()
return Plugin_Continue; return Plugin_Continue;
} }
@ -197,12 +210,54 @@ public Action UpdateHide(Handle timer)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action Hook_SetTransmit(int target, int client) public Action Hook_SetTransmit(int target, int client)
{ {
if(g_bHidePlayers[client][target]) if(g_bNewHidePlayers[client][target])
{
return Plugin_Handled; return Plugin_Handled;
}
return Plugin_Continue; return Plugin_Continue;
} }
//October 2023 edit: using OnGameFrame to just hide 1 player per frame. supposedly (a rumor) that is good enough to actually work.
public void OnGameFrame()
{
static int client = 0;
int iterate_amount = 1;
for (int i = 0; i < iterate_amount; i++)
{
//restart from the beginning
if (client == MAXPLAYERS)
{
client = 0;
}
client++;
//hide other players for this player?
if (!IsClientInGame(client) || g_iHideRange[client] == DISABLED || !IsPlayerAlive(client) || !ZR_IsClientHuman(client))
{
continue;
}
int previous_client = client - 1;
if (previous_client < 1)
{
previous_client = MAXPLAYERS - 1;
}
for (int target = 1; target <= MaxClients; target++)
{
if (IsClientInGame(target) && IsPlayerAlive(target))
{
if (g_bHidePlayers[client][target])
{
g_bNewHidePlayers[client][target] = true;
}
}
g_bNewHidePlayers[previous_client][target] = false;
}
}
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -285,6 +340,7 @@ public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int se
delete menu; delete menu;
} }
} }
return 0;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -304,3 +360,5 @@ public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info
} }
} }
} }