From 11f0999f3f074faa8223b7fa877bb6a7111b01a3 Mon Sep 17 00:00:00 2001 From: neon Date: Tue, 20 Apr 2021 11:24:43 +0100 Subject: [PATCH] Hide: big update --- _Hide/scripting/Hide.sp | 236 ++++++++++++++++++++++++++-------------- 1 file changed, 153 insertions(+), 83 deletions(-) diff --git a/_Hide/scripting/Hide.sp b/_Hide/scripting/Hide.sp index d6156351..b68a5dee 100644 --- a/_Hide/scripting/Hide.sp +++ b/_Hide/scripting/Hide.sp @@ -1,20 +1,25 @@ +#include #include -#include #include +#include #include /* BOOLS */ -bool g_bHideEnabled; bool g_bHidePlayers[MAXPLAYERS+1][MAXPLAYERS+1]; /* INTEGERS */ -int g_iHideDistance[MAXPLAYERS+1]; +int g_iHideRange[MAXPLAYERS+1]; /* CONVARS */ ConVar g_hCVar_HideEnabled; -ConVar g_hCVar_HideMinimumDistance; -ConVar g_hCVar_HideMaximumDistance; -ConVar g_hCVar_HideDefaultDistance; + +/* COOKIES */ +Handle g_hCookie_HideRange; + +#define DISABLED -1 +#define SHORT 120 +#define MEDIUM 250 +#define LONG 500 //---------------------------------------------------------------------------------------------------- // Purpose: @@ -24,7 +29,7 @@ public Plugin myinfo = name = "Hide Teammates", author = "Neon", description = "A plugin that can !hide teammates with individual distances", - version = "1.0.0", + version = "2.0.0", url = "https://steamcommunity.com/id/n3ontm" }; @@ -34,21 +39,26 @@ public Plugin myinfo = public void OnPluginStart() { - 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 = CreateConVar("sm_hide_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0); 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++) { if(IsClientInGame(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) { - g_bHideEnabled = convar.BoolValue; - for(int client = 1; client <= MaxClients; client++) { 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(g_bHideEnabled) + if(g_hCVar_HideEnabled.BoolValue) SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit); else SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit); } } - if(g_bHideEnabled) + if(g_hCVar_HideEnabled.BoolValue) CPrintToChatAll("{cyan}[Hide] {white}has been allowed."); else 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) { + if(!g_hCVar_HideEnabled.BoolValue) + return; + SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit); } @@ -99,7 +110,7 @@ public void OnClientPutInServer(int client) //---------------------------------------------------------------------------------------------------- public void OnClientDisconnect(int client) { - g_iHideDistance[client] = 0; + g_iHideRange[client] = 0; for(int target = 1; target <= MaxClients; target++) { g_bHidePlayers[client][target] = false; @@ -109,50 +120,15 @@ public void OnClientDisconnect(int client) //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- -public Action Command_Hide(int client, int args) +public void OnClientCookiesCached(int client) { - if(!g_bHideEnabled) - { - ReplyToCommand(client, "[Hide] is currently not allowed."); - return Plugin_Handled; - } + char sBuffer[16]; + GetClientCookie(client, g_hCookie_HideRange, sBuffer, sizeof(sBuffer)); - int iDistance; - - 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; - } + if (sBuffer[0]) + g_iHideRange[client] = StringToInt(sBuffer); else - { - 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; + g_iHideRange[client] = DISABLED; } //---------------------------------------------------------------------------------------------------- @@ -160,45 +136,40 @@ public Action Command_Hide(int client, int args) //---------------------------------------------------------------------------------------------------- public Action UpdateHide(Handle timer) { - if(!g_bHideEnabled) + if(!g_hCVar_HideEnabled.BoolValue) return Plugin_Continue; for(int client = 1; client <= MaxClients; client++) { - if(!IsClientInGame(client)) - 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)) + if(g_iHideRange[client] == DISABLED) { for(int target = 1; target <= MaxClients; target++) - { - if(target != client && IsClientInGame(target) && IsPlayerAlive(target) && ZR_IsClientHuman(target)) - { - g_bHidePlayers[client][target] = true - } + { + g_bHidePlayers[client][target] = false; } 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; + } + float fOriginClient[3]; float fOriginTarget[3]; 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(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; else g_bHidePlayers[client][target] = false; @@ -215,11 +186,110 @@ public Action UpdateHide(Handle timer) //---------------------------------------------------------------------------------------------------- public Action Hook_SetTransmit(int target, int client) { - if(!g_bHideEnabled) - return Plugin_Continue; - if(g_bHidePlayers[client][target]) return Plugin_Handled; 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); + } + } +} \ No newline at end of file