From 6a57a998f6ecd670deed7423c8178504a35910f5 Mon Sep 17 00:00:00 2001 From: neon <> Date: Tue, 4 Jun 2019 17:39:39 +0200 Subject: [PATCH] new plugin HostnameManager --- HappyHour/scripting/HappyHour.sp | 19 --- HostnameManager/scripting/HostnameManager.sp | 154 ++++++++++++++++++ StageDisplay/scripting/StageDisplay.sp | 50 +++--- .../scripting/include/StageDisplay.inc | 35 ++++ 4 files changed, 220 insertions(+), 38 deletions(-) create mode 100644 HostnameManager/scripting/HostnameManager.sp create mode 100644 StageDisplay/scripting/include/StageDisplay.inc diff --git a/HappyHour/scripting/HappyHour.sp b/HappyHour/scripting/HappyHour.sp index 092820eb..04c07b81 100644 --- a/HappyHour/scripting/HappyHour.sp +++ b/HappyHour/scripting/HappyHour.sp @@ -17,9 +17,6 @@ ConVar g_cvMorningEnd; ConVar g_cvNightStart; ConVar g_cvNightEnd; -ConVar g_cvHostName; -char g_sHostName[128]; - public Plugin myinfo = { name = "Happy Hour", @@ -50,8 +47,6 @@ public void OnPluginStart() g_cvNightStart = CreateConVar("sm_happyhour_night_start", "2300", "starttime of happy hour in the night (timezone UTC+1 in summer, UTC+2 in winter)"); g_cvNightEnd = CreateConVar("sm_happyhour_night_end", "0300", "endtime of happy hour in the night (timezone UTC+1 in summer, UTC+2 in winter)"); - g_cvHostName = FindConVar("hostname"); - RegConsoleCmd("sm_hh", Command_DisplayHappyHour, "Shows if happy hour is currently enabled or not"); RegAdminCmd("sm_forcehh", AdminCommand_HappyHour, ADMFLAG_GENERIC, "Toggle to enable/disable Happy Hour. Resets after Mapswitch."); @@ -73,11 +68,6 @@ public void ConVarChange(ConVar convar, char[] oldValue, char[] newValue) GetConVars(); } -public void OnConfigsExecuted() -{ - g_cvHostName.GetString(g_sHostName, sizeof(g_sHostName)); -} - public Action Timer_CheckTime(Handle timer) { if(g_bHappyHourAdmin) @@ -165,16 +155,7 @@ public void ToggleHappyHour(int client) public Action MessageHappyHour(Handle timer) { if(g_bHappyHour) - { CPrintToChatAll("{cyan}[UNLOZE] {red}Happy Hour {cyan}is currently active! Everyone gets 50%% Bonus on most rank points!"); - char sBuffer[sizeof(g_sHostName)]; - Format(sBuffer, sizeof(sBuffer), "[HappyHour] %s", g_sHostName); - g_cvHostName.SetString(sBuffer); - } - else - { - g_cvHostName.SetString(g_sHostName); - } return Plugin_Continue; } diff --git a/HostnameManager/scripting/HostnameManager.sp b/HostnameManager/scripting/HostnameManager.sp new file mode 100644 index 00000000..a7ee8722 --- /dev/null +++ b/HostnameManager/scripting/HostnameManager.sp @@ -0,0 +1,154 @@ +#pragma semicolon 1 + +#include + +#undef REQUIRE_PLUGIN +#tryinclude +#tryinclude +#define REQUIRE_PLUGIN + +#pragma newdecls required + +ConVar g_cvClasses; +ConVar g_cvHostname; +ConVar g_cvFormattedHostname; + +bool g_bHHLoaded; +bool g_bNemesis; +bool g_bSDLoaded; + + +public Plugin myinfo = +{ + name = "HostnameManager", + author = "Neon", + description = "", + version = "1.0", + url = "https://steamcommunity.com/id/n3ontm" +}; + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- + +public void OnPluginStart() +{ + g_cvHostname = FindConVar("hostname"); + g_cvFormattedHostname = CreateConVar("sm_hostname_format", "{HH}UNLOZE | {GM} | NoSteam{SD}", "HH = HappyHour, , GM = GameMode, SD = StageDisplay"); + + CreateTimer(60.0, TimerRepeat, INVALID_HANDLE, TIMER_REPEAT); + + HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnAllPluginsLoaded() +{ + g_bHHLoaded = LibraryExists("HappyHour"); + g_bSDLoaded = LibraryExists("StageDisplay"); + + if((g_cvClasses = FindConVar("zr_config_path_playerclasses")) == INVALID_HANDLE) + SetFailState("Failed to find zr_config_path_playerclasses cvar."); + + char sFile[PLATFORM_MAX_PATH]; + g_cvClasses.GetString(sFile, sizeof(sFile)); + OnClassesPathChange(g_cvClasses, "", sFile); + + HookConVarChange(g_cvClasses, OnClassesPathChange); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnLibraryAdded(const char[] sName) +{ + if (strcmp(sName, "HappyHour", false) == 0) + g_bHHLoaded = true; + + if (strcmp(sName, "StageDisplay", false) == 0) + g_bSDLoaded = true; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnLibraryRemoved(const char[] sName) +{ + if (strcmp(sName, "HappyHour", false) == 0) + g_bHHLoaded = false; + + if (strcmp(sName, "StageDisplay", false) == 0) + g_bSDLoaded = false; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnRoundStart(Event hEvent, const char[] sEvent, bool bDontBroadcast) +{ + CreateTimer(5.0, TimerRoundStart, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action TimerRoundStart(Handle timer) +{ + RefreshHostname(); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action TimerRepeat(Handle timer) +{ + RefreshHostname(); + return Plugin_Continue; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void RefreshHostname() +{ + char sFormattedHostname[128]; + g_cvFormattedHostname.GetString(sFormattedHostname, sizeof(sFormattedHostname)); + + if (g_bHHLoaded && HH_IsItHappyHour()) + ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{HH}", "[HappyHour] ", true); + else + ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{HH}", "", true); + + char sStage[64]; + if (g_bSDLoaded && SD_GetStage(sStage, sizeof(sStage))) + { + Format(sStage, sizeof(sStage), " | Stage: [%s]", sStage); + ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{SD}", sStage, true); + } + else + ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{SD}", "", true); + + if (g_bNemesis) + ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Nemesis Zombie Escape", true); + else + ReplaceString(sFormattedHostname, sizeof(sFormattedHostname), "{GM}", "Zombie Escape", true); + + g_cvHostname.SetString(sFormattedHostname, false, false); +} + + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnClassesPathChange(ConVar convar, const char[] oldValue, const char[] newValue) +{ + char sFile[PLATFORM_MAX_PATH]; + BuildPath(Path_SM, sFile, sizeof(sFile), "%s", newValue); + + if (StrContains(sFile, "nemesis", false) != -1) + g_bNemesis = true; + else + g_bNemesis = false; +} diff --git a/StageDisplay/scripting/StageDisplay.sp b/StageDisplay/scripting/StageDisplay.sp index e64f2040..579bf4a8 100644 --- a/StageDisplay/scripting/StageDisplay.sp +++ b/StageDisplay/scripting/StageDisplay.sp @@ -7,9 +7,7 @@ KeyValues g_Config; -ConVar g_cvHostName; - -char g_sHostName[128]; +char g_sStageName[32]; //---------------------------------------------------------------------------------------------------- // Purpose: @@ -28,16 +26,27 @@ public Plugin myinfo = //---------------------------------------------------------------------------------------------------- public void OnPluginStart() { - g_cvHostName = FindConVar("hostname"); - HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int errorSize) +{ + CreateNative("SD_GetStage", Native_GetStage); + + RegPluginLibrary("StageDisplay"); + return APLRes_Success; +} + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnMapStart() { + g_sStageName = "unknown"; + if(g_Config) delete g_Config; @@ -65,14 +74,6 @@ public void OnMapStart() g_Config.Rewind(); } -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public void OnConfigsExecuted() -{ - g_cvHostName.GetString(g_sHostName, sizeof(g_sHostName)); -} - //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -202,15 +203,26 @@ public void CheckStage() } } - - char sBuffer[sizeof(g_sHostName)]; - if(bHasDiffCounter) - Format(sBuffer, sizeof(sBuffer), "%s | Stage: [%s - %s]", g_sHostName, sStageName, sDiffName); + Format(g_sStageName, sizeof(g_sStageName), "%s - %s", sStageName, sDiffName); else - Format(sBuffer, sizeof(sBuffer), "%s | Stage: [%s]", g_sHostName, sStageName); + Format(g_sStageName, sizeof(g_sStageName), "%s", sStageName); +} - g_cvHostName.SetString(sBuffer, false, false); +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public int Native_GetStage(Handle hPlugin, int numParams) +{ + int length = GetNativeCell(2); + + char[] sStage = new char[length + 1]; + Format(sStage, length + 1, "%s", g_sStageName); + + if (strcmp(sStage, "unknown", true) == 0) + return 0; + + return !(SetNativeString(1, sStage, length + 1)); } //---------------------------------------------------------------------------------------------------- diff --git a/StageDisplay/scripting/include/StageDisplay.inc b/StageDisplay/scripting/include/StageDisplay.inc new file mode 100644 index 00000000..0c995774 --- /dev/null +++ b/StageDisplay/scripting/include/StageDisplay.inc @@ -0,0 +1,35 @@ +#if defined _StageDisplay_included + #endinput +#endif + +#define _StageDisplay_included + +/** + * Retrieve current stage name. + * + * @param name The buffer to write to. + * @param maxlength The maximum buffer length. + * + * @return True on success, false otherwise. + */ +native bool SD_GetStage(char[] name, int maxlength); + + +public SharedPlugin __pl_StageDisplay = +{ + name = "StageDisplay", + file = "StageDisplay.smx", + + #if defined REQUIRE_PLUGIN + required = 1 + #else + required = 0 + #endif +}; + +#if !defined REQUIRE_PLUGIN + public void __pl_StageDisplay_SetNTVOptional() + { + MarkNativeAsOptional("SD_GetStage"); + } +#endif