updated Hide to only have a single client being not transmitted at a time
This commit is contained in:
parent
8c673f4401
commit
0394a2a402
@ -5,12 +5,13 @@
|
||||
#include <zombiereloaded>
|
||||
#include <leader>
|
||||
|
||||
|
||||
/* BOOLS */
|
||||
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
|
||||
bool g_bNewHidePlayers[MAXPLAYERS + 1][MAXPLAYERS + 1];
|
||||
|
||||
/* INTEGERS */
|
||||
int g_iHideRange[MAXPLAYERS+1];
|
||||
int g_iLeader = 0;
|
||||
|
||||
/* CONVARS */
|
||||
ConVar g_hCVar_HideEnabled;
|
||||
@ -33,9 +34,9 @@ int LONG = LONG_RANGE * LONG_RANGE;
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Hide Teammates",
|
||||
author = "Neon",
|
||||
author = "Neon, minor edits by jenz",
|
||||
description = "A plugin that can !hide teammates with individual distances",
|
||||
version = "2.0.1",
|
||||
version = "2.1.1",
|
||||
url = "https://steamcommunity.com/id/n3ontm"
|
||||
};
|
||||
|
||||
@ -44,7 +45,6 @@ public Plugin myinfo =
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginStart()
|
||||
{
|
||||
|
||||
g_hCVar_HideEnabled = CreateConVar("sm_hide_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged);
|
||||
AutoExecConfig(true);
|
||||
@ -72,7 +72,7 @@ public void OnPluginStart()
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
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)
|
||||
{
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
g_bHidePlayers[client][target] = false;
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
g_bHidePlayers[client][target] = false;
|
||||
g_bNewHidePlayers[client][target] = false;
|
||||
}
|
||||
|
||||
if(IsClientInGame(client))
|
||||
{
|
||||
if(g_hCVar_HideEnabled.BoolValue)
|
||||
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
|
||||
else
|
||||
SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit);
|
||||
}
|
||||
}
|
||||
if(IsClientInGame(client))
|
||||
{
|
||||
if(g_hCVar_HideEnabled.BoolValue)
|
||||
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
|
||||
else
|
||||
SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit);
|
||||
}
|
||||
}
|
||||
|
||||
if(g_hCVar_HideEnabled.BoolValue)
|
||||
CPrintToChatAll("{cyan}[Hide] {white}has been allowed.");
|
||||
else
|
||||
CPrintToChatAll("{cyan}[Hide] {white}has been disabled.");
|
||||
if(g_hCVar_HideEnabled.BoolValue)
|
||||
CPrintToChatAll("{cyan}[Hide] {white}has been allowed.");
|
||||
else
|
||||
CPrintToChatAll("{cyan}[Hide] {white}has been disabled.");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -116,11 +119,12 @@ public void OnClientPutInServer(int client)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
g_iHideRange[client] = 0;
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
g_bHidePlayers[client][target] = false;
|
||||
}
|
||||
g_iHideRange[client] = 0;
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
g_bHidePlayers[client][target] = false;
|
||||
g_bNewHidePlayers[client][target] = false;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -146,50 +150,59 @@ public void OnClientCookiesCached(int client)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action UpdateHide(Handle timer)
|
||||
{
|
||||
if(!g_hCVar_HideEnabled.BoolValue)
|
||||
return Plugin_Continue;
|
||||
if(!g_hCVar_HideEnabled.BoolValue)
|
||||
return Plugin_Continue;
|
||||
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(g_iHideRange[client] == DISABLED)
|
||||
{
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
g_bHidePlayers[client][target] = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for(int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if(g_iHideRange[client] == DISABLED)
|
||||
{
|
||||
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) || IsFakeClient(client))
|
||||
{
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
g_bHidePlayers[client][target] = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientHuman(client) || IsFakeClient(client))
|
||||
{
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
g_bHidePlayers[client][target] = false;
|
||||
g_bNewHidePlayers[client][target] = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
float fOriginClient[3];
|
||||
float fOriginTarget[3];
|
||||
int iLeader = Leader_CurrentLeader()
|
||||
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
if(IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target) && target != client)
|
||||
{
|
||||
GetClientAbsOrigin(target, fOriginTarget);
|
||||
GetClientAbsOrigin(client, fOriginClient);
|
||||
//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;
|
||||
else
|
||||
g_bHidePlayers[client][target] = false;
|
||||
}
|
||||
else
|
||||
g_bHidePlayers[client][target] = false;
|
||||
}
|
||||
}
|
||||
return Plugin_Continue;
|
||||
float fOriginClient[3];
|
||||
float fOriginTarget[3];
|
||||
GetClientAbsOrigin(client, fOriginClient);
|
||||
for(int target = 1; target <= MaxClients; target++)
|
||||
{
|
||||
if(IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target) && target != client)
|
||||
{
|
||||
GetClientAbsOrigin(target, fOriginTarget);
|
||||
//PrintToChatAll("%N--%N::::::%f", client, target, GetVectorDistance(fOriginTarget, fOriginClient, false));
|
||||
if((GetVectorDistance(fOriginTarget, fOriginClient, true) <= float(g_iHideRange[client])) && (g_iLeader != target))
|
||||
{
|
||||
g_bHidePlayers[client][target] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -197,10 +210,52 @@ public Action UpdateHide(Handle timer)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Hook_SetTransmit(int target, int client)
|
||||
{
|
||||
if(g_bHidePlayers[client][target])
|
||||
return Plugin_Handled;
|
||||
if(g_bNewHidePlayers[client][target])
|
||||
{
|
||||
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)
|
||||
{
|
||||
switch(action)
|
||||
{
|
||||
case(MenuAction_Select):
|
||||
{
|
||||
switch(selection)
|
||||
{
|
||||
case(0):
|
||||
{
|
||||
g_iHideRange[client] = DISABLED
|
||||
}
|
||||
case(1):
|
||||
{
|
||||
g_iHideRange[client] = SHORT
|
||||
}
|
||||
case(2):
|
||||
{
|
||||
g_iHideRange[client] = MEDIUM
|
||||
}
|
||||
case(3):
|
||||
{
|
||||
g_iHideRange[client] = LONG
|
||||
}
|
||||
}
|
||||
char sBuffer[16];
|
||||
Format(sBuffer, sizeof(sBuffer), "%d", g_iHideRange[client]);
|
||||
SetClientCookie(client, g_hCookie_HideRange, sBuffer);
|
||||
ShowSettingsMenu(client);
|
||||
}
|
||||
case(MenuAction_Cancel):
|
||||
{
|
||||
ShowCookieMenu(client);
|
||||
}
|
||||
case(MenuAction_End):
|
||||
{
|
||||
delete menu;
|
||||
}
|
||||
}
|
||||
switch(action)
|
||||
{
|
||||
case(MenuAction_Select):
|
||||
{
|
||||
switch(selection)
|
||||
{
|
||||
case(0):
|
||||
{
|
||||
g_iHideRange[client] = DISABLED
|
||||
}
|
||||
case(1):
|
||||
{
|
||||
g_iHideRange[client] = SHORT
|
||||
}
|
||||
case(2):
|
||||
{
|
||||
g_iHideRange[client] = MEDIUM
|
||||
}
|
||||
case(3):
|
||||
{
|
||||
g_iHideRange[client] = LONG
|
||||
}
|
||||
}
|
||||
char sBuffer[16];
|
||||
Format(sBuffer, sizeof(sBuffer), "%d", g_iHideRange[client]);
|
||||
SetClientCookie(client, g_hCookie_HideRange, sBuffer);
|
||||
ShowSettingsMenu(client);
|
||||
}
|
||||
case(MenuAction_Cancel):
|
||||
{
|
||||
ShowCookieMenu(client);
|
||||
}
|
||||
case(MenuAction_End):
|
||||
{
|
||||
delete menu;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -303,4 +359,6 @@ public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info
|
||||
ShowSettingsMenu(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user