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);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -80,24 +80,27 @@ public void OnMapStart()
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{ {
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))
{ {
if(g_hCVar_HideEnabled.BoolValue) if(g_hCVar_HideEnabled.BoolValue)
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit); SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
else else
SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit); SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit);
} }
} }
if(g_hCVar_HideEnabled.BoolValue) if(g_hCVar_HideEnabled.BoolValue)
CPrintToChatAll("{cyan}[Hide] {white}has been allowed."); CPrintToChatAll("{cyan}[Hide] {white}has been allowed.");
else else
CPrintToChatAll("{cyan}[Hide] {white}has been disabled."); CPrintToChatAll("{cyan}[Hide] {white}has been disabled.");
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -116,11 +119,12 @@ public void OnClientPutInServer(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client) public void OnClientDisconnect(int client)
{ {
g_iHideRange[client] = 0; g_iHideRange[client] = 0;
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;
}
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -146,50 +150,59 @@ public void OnClientCookiesCached(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public Action UpdateHide(Handle timer) public Action UpdateHide(Handle timer)
{ {
if(!g_hCVar_HideEnabled.BoolValue) if(!g_hCVar_HideEnabled.BoolValue)
return Plugin_Continue; return Plugin_Continue;
for(int client = 1; client <= MaxClients; client++) for(int client = 1; client <= MaxClients; client++)
{ {
if(g_iHideRange[client] == DISABLED) if(g_iHideRange[client] == DISABLED)
{ {
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); //PrintToChatAll("%N--%N::::::%f", client, target, GetVectorDistance(fOriginTarget, fOriginClient, false));
GetClientAbsOrigin(client, fOriginClient); if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target))
//PrintToChatAll("%N--%N::::::%f", client, target, GetVectorDistance(fOriginTarget, fOriginClient, false)); {
if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (iLeader != target)) g_bHidePlayers[client][target] = true;
g_bHidePlayers[client][target] = true; }
else else
g_bHidePlayers[client][target] = false; {
} g_bHidePlayers[client][target] = false;
else g_bNewHidePlayers[client][target] = false;
g_bHidePlayers[client][target] = false; }
} }
} else
return Plugin_Continue; {
g_bHidePlayers[client][target] = false;
g_bNewHidePlayers[client][target] = false;
}
}
}
g_iLeader = Leader_CurrentLeader()
return Plugin_Continue;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -197,10 +210,52 @@ 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;
}
}
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -248,43 +303,44 @@ public void ShowSettingsMenu(int client)
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection) public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
{ {
switch(action) switch(action)
{ {
case(MenuAction_Select): case(MenuAction_Select):
{ {
switch(selection) switch(selection)
{ {
case(0): case(0):
{ {
g_iHideRange[client] = DISABLED g_iHideRange[client] = DISABLED
} }
case(1): case(1):
{ {
g_iHideRange[client] = SHORT g_iHideRange[client] = SHORT
} }
case(2): case(2):
{ {
g_iHideRange[client] = MEDIUM g_iHideRange[client] = MEDIUM
} }
case(3): case(3):
{ {
g_iHideRange[client] = LONG g_iHideRange[client] = LONG
} }
} }
char sBuffer[16]; char sBuffer[16];
Format(sBuffer, sizeof(sBuffer), "%d", g_iHideRange[client]); Format(sBuffer, sizeof(sBuffer), "%d", g_iHideRange[client]);
SetClientCookie(client, g_hCookie_HideRange, sBuffer); SetClientCookie(client, g_hCookie_HideRange, sBuffer);
ShowSettingsMenu(client); ShowSettingsMenu(client);
} }
case(MenuAction_Cancel): case(MenuAction_Cancel):
{ {
ShowCookieMenu(client); ShowCookieMenu(client);
} }
case(MenuAction_End): case(MenuAction_End):
{ {
delete menu; delete menu;
} }
} }
return 0;
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -303,4 +359,6 @@ public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info
ShowSettingsMenu(client); ShowSettingsMenu(client);
} }
} }
} }