Hide: big update
This commit is contained in:
parent
2fde5f3061
commit
11f0999f3f
@ -1,20 +1,25 @@
|
|||||||
|
#include <clientprefs>
|
||||||
#include <multicolors>
|
#include <multicolors>
|
||||||
#include <sourcemod>
|
|
||||||
#include <sdkhooks>
|
#include <sdkhooks>
|
||||||
|
#include <sourcemod>
|
||||||
#include <zombiereloaded>
|
#include <zombiereloaded>
|
||||||
|
|
||||||
/* BOOLS */
|
/* BOOLS */
|
||||||
bool g_bHideEnabled;
|
|
||||||
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
|
bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1];
|
||||||
|
|
||||||
/* INTEGERS */
|
/* INTEGERS */
|
||||||
int g_iHideDistance[MAXPLAYERS+1];
|
int g_iHideRange[MAXPLAYERS+1];
|
||||||
|
|
||||||
/* CONVARS */
|
/* CONVARS */
|
||||||
ConVar g_hCVar_HideEnabled;
|
ConVar g_hCVar_HideEnabled;
|
||||||
ConVar g_hCVar_HideMinimumDistance;
|
|
||||||
ConVar g_hCVar_HideMaximumDistance;
|
/* COOKIES */
|
||||||
ConVar g_hCVar_HideDefaultDistance;
|
Handle g_hCookie_HideRange;
|
||||||
|
|
||||||
|
#define DISABLED -1
|
||||||
|
#define SHORT 120
|
||||||
|
#define MEDIUM 250
|
||||||
|
#define LONG 500
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
@ -24,7 +29,7 @@ public Plugin myinfo =
|
|||||||
name = "Hide Teammates",
|
name = "Hide Teammates",
|
||||||
author = "Neon",
|
author = "Neon",
|
||||||
description = "A plugin that can !hide teammates with individual distances",
|
description = "A plugin that can !hide teammates with individual distances",
|
||||||
version = "1.0.0",
|
version = "2.0.0",
|
||||||
url = "https://steamcommunity.com/id/n3ontm"
|
url = "https://steamcommunity.com/id/n3ontm"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,21 +39,26 @@ 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_HideMinimumDistance = CreateConVar("sm_hide_minimum_distance", "10", "", FCVAR_NONE, true, 1.0);
|
|
||||||
g_hCVar_HideMaximumDistance = CreateConVar("sm_hide_maximum_distance", "50000", "", FCVAR_NONE, true, 1.0);
|
|
||||||
g_hCVar_HideDefaultDistance = CreateConVar("sm_hide_default_distance", "10000", "", FCVAR_NONE, true, 1.0);
|
|
||||||
g_bHideEnabled = g_hCVar_HideEnabled.BoolValue;
|
|
||||||
g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged);
|
g_hCVar_HideEnabled.AddChangeHook(OnConVarChanged);
|
||||||
|
AutoExecConfig(true);
|
||||||
|
|
||||||
|
g_hCookie_HideRange = RegClientCookie("hide_range", "", CookieAccess_Private);
|
||||||
|
|
||||||
RegConsoleCmd("sm_hide", Command_Hide, "Hiding humans away");
|
RegConsoleCmd("sm_hide", OnHideSettings, "Hiding near humans");
|
||||||
|
|
||||||
for(int client = 1; client <= MaxClients; client++)
|
for(int client = 1; client <= MaxClients; client++)
|
||||||
{
|
{
|
||||||
if(IsClientInGame(client))
|
if(IsClientInGame(client))
|
||||||
|
{
|
||||||
OnClientPutInServer(client);
|
OnClientPutInServer(client);
|
||||||
|
|
||||||
|
if(AreClientCookiesCached(client))
|
||||||
|
OnClientCookiesCached(client);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -64,8 +74,6 @@ 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)
|
||||||
{
|
{
|
||||||
g_bHideEnabled = convar.BoolValue;
|
|
||||||
|
|
||||||
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++)
|
||||||
@ -73,14 +81,14 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n
|
|||||||
|
|
||||||
if(IsClientInGame(client))
|
if(IsClientInGame(client))
|
||||||
{
|
{
|
||||||
if(g_bHideEnabled)
|
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_bHideEnabled)
|
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.");
|
||||||
@ -91,6 +99,9 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnClientPutInServer(int client)
|
public void OnClientPutInServer(int client)
|
||||||
{
|
{
|
||||||
|
if(!g_hCVar_HideEnabled.BoolValue)
|
||||||
|
return;
|
||||||
|
|
||||||
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
|
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +110,7 @@ public void OnClientPutInServer(int client)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public void OnClientDisconnect(int client)
|
public void OnClientDisconnect(int client)
|
||||||
{
|
{
|
||||||
g_iHideDistance[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;
|
||||||
@ -109,50 +120,15 @@ public void OnClientDisconnect(int client)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
// Purpose:
|
// Purpose:
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public Action Command_Hide(int client, int args)
|
public void OnClientCookiesCached(int client)
|
||||||
{
|
{
|
||||||
if(!g_bHideEnabled)
|
char sBuffer[16];
|
||||||
{
|
GetClientCookie(client, g_hCookie_HideRange, sBuffer, sizeof(sBuffer));
|
||||||
ReplyToCommand(client, "[Hide] is currently not allowed.");
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
int iDistance;
|
if (sBuffer[0])
|
||||||
|
g_iHideRange[client] = StringToInt(sBuffer);
|
||||||
if(args == 0)
|
|
||||||
{
|
|
||||||
if(g_iHideDistance[client])
|
|
||||||
{
|
|
||||||
g_iHideDistance[client] = 0;
|
|
||||||
ReplyToCommand(client, "[Hide] is now disabled.");
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
iDistance = g_hCVar_HideDefaultDistance.IntValue;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
g_iHideRange[client] = DISABLED;
|
||||||
char sArgs[8];
|
|
||||||
GetCmdArg(1, sArgs, sizeof(sArgs));
|
|
||||||
iDistance = StringToInt(sArgs);
|
|
||||||
}
|
|
||||||
if (IsPlayerAlive(client) && ZR_IsClientZombie(client))
|
|
||||||
{
|
|
||||||
ReplyToCommand(client, "You are a zombie and therefore need to see the humans.");
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((iDistance == 0) || (iDistance < g_hCVar_HideMinimumDistance.IntValue) || (iDistance > g_hCVar_HideMaximumDistance.IntValue))
|
|
||||||
{
|
|
||||||
ReplyToCommand(client, "[Hide] Wrong input! Allowed range: %d-%d", g_hCVar_HideMinimumDistance.IntValue, g_hCVar_HideMaximumDistance.IntValue);
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
|
||||||
if (!IsPlayerAlive(client))
|
|
||||||
ReplyToCommand(client, "[Hide] All Humans are now hidden.");
|
|
||||||
else
|
|
||||||
ReplyToCommand(client, "[Hide] Humans within range %d are now hidden.", iDistance);
|
|
||||||
g_iHideDistance[client] = iDistance * iDistance;
|
|
||||||
return Plugin_Handled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -160,45 +136,40 @@ public Action Command_Hide(int client, int args)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public Action UpdateHide(Handle timer)
|
public Action UpdateHide(Handle timer)
|
||||||
{
|
{
|
||||||
if(!g_bHideEnabled)
|
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(!IsClientInGame(client))
|
if(g_iHideRange[client] == DISABLED)
|
||||||
continue;
|
|
||||||
if(!g_iHideDistance[client])
|
|
||||||
{
|
|
||||||
for(int target = 1; target <= MaxClients; target++)
|
|
||||||
{
|
|
||||||
if(target != client && IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target))
|
|
||||||
g_bHidePlayers[client][target] = false;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!IsPlayerAlive(client))
|
|
||||||
{
|
{
|
||||||
for(int target = 1; target <= MaxClients; target++)
|
for(int target = 1; target <= MaxClients; target++)
|
||||||
{
|
{
|
||||||
if(target != client && IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target))
|
g_bHidePlayers[client][target] = false;
|
||||||
{
|
|
||||||
g_bHidePlayers[client][target] = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!ZR_IsClientHuman(client))
|
|
||||||
|
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;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
float fOriginClient[3];
|
float fOriginClient[3];
|
||||||
float fOriginTarget[3];
|
float fOriginTarget[3];
|
||||||
|
|
||||||
for(int target = 1; target <= MaxClients; target++)
|
for(int target = 1; target <= MaxClients; target++)
|
||||||
{
|
{
|
||||||
if(target != client && IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target))
|
if(IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target) && target != client)
|
||||||
{
|
{
|
||||||
GetClientAbsOrigin(target, fOriginTarget);
|
GetClientAbsOrigin(target, fOriginTarget);
|
||||||
GetClientAbsOrigin(client, fOriginClient);
|
GetClientAbsOrigin(client, fOriginClient);
|
||||||
if(GetVectorDistance(fOriginTarget, fOriginClient, true) < float(g_iHideDistance[client]))
|
//PrintToChatAll("%N--%N::::::%f", client, target, GetVectorDistance(fOriginTarget, fOriginClient, false));
|
||||||
|
if(GetVectorDistance(fOriginTarget, fOriginClient, false) <= float(g_iHideRange[client]))
|
||||||
g_bHidePlayers[client][target] = true;
|
g_bHidePlayers[client][target] = true;
|
||||||
else
|
else
|
||||||
g_bHidePlayers[client][target] = false;
|
g_bHidePlayers[client][target] = false;
|
||||||
@ -215,11 +186,110 @@ public Action UpdateHide(Handle timer)
|
|||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
public Action Hook_SetTransmit(int target, int client)
|
public Action Hook_SetTransmit(int target, int client)
|
||||||
{
|
{
|
||||||
if(!g_bHideEnabled)
|
|
||||||
return Plugin_Continue;
|
|
||||||
|
|
||||||
if(g_bHidePlayers[client][target])
|
if(g_bHidePlayers[client][target])
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
|
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public Action OnHideSettings(int client, int args)
|
||||||
|
{
|
||||||
|
ShowSettingsMenu(client);
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void ShowSettingsMenu(int client)
|
||||||
|
{
|
||||||
|
Menu menu = new Menu(MenuHandler_MainMenu);
|
||||||
|
|
||||||
|
menu.SetTitle("Hide", client);
|
||||||
|
|
||||||
|
char sBuffer[128];
|
||||||
|
|
||||||
|
Format(sBuffer, sizeof(sBuffer), "Disabled%s", (g_iHideRange[client] == DISABLED) ? " [Selected]" : "");
|
||||||
|
menu.AddItem("", sBuffer, (g_iHideRange[client] == DISABLED));
|
||||||
|
|
||||||
|
Format(sBuffer, sizeof(sBuffer), "Short Range%s", (g_iHideRange[client] == SHORT) ? " [Selected]" : "");
|
||||||
|
menu.AddItem("", sBuffer, (g_iHideRange[client] == SHORT));
|
||||||
|
|
||||||
|
Format(sBuffer, sizeof(sBuffer), "Medium Range%s", (g_iHideRange[client] == MEDIUM) ? " [Selected]" : "");
|
||||||
|
menu.AddItem("", sBuffer, (g_iHideRange[client] == MEDIUM));
|
||||||
|
|
||||||
|
Format(sBuffer, sizeof(sBuffer), "Long Range%s", (g_iHideRange[client] == LONG) ? " [Selected]" : "");
|
||||||
|
menu.AddItem("", sBuffer, (g_iHideRange[client] == LONG));
|
||||||
|
|
||||||
|
if(!g_hCVar_HideEnabled.BoolValue)
|
||||||
|
menu.AddItem("", "Warning: Hide is currently disabled on the server", ITEMDRAW_DISABLED);
|
||||||
|
|
||||||
|
menu.ExitBackButton = true;
|
||||||
|
|
||||||
|
menu.Display(client, MENU_TIME_FOREVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
// Purpose:
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
|
||||||
|
{
|
||||||
|
switch(action)
|
||||||
|
{
|
||||||
|
case(CookieMenuAction_DisplayOption):
|
||||||
|
{
|
||||||
|
Format(buffer, maxlen, "Hide", client);
|
||||||
|
}
|
||||||
|
case(CookieMenuAction_SelectOption):
|
||||||
|
{
|
||||||
|
ShowSettingsMenu(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user