From e7bdae2ad8d3a02b850bd4fecadd8050f13cadd3 Mon Sep 17 00:00:00 2001 From: Greyscale Date: Sat, 20 Jun 2009 00:15:43 -0700 Subject: [PATCH] Added forgotten cvar to the config. ZHP now uses client cookies. (Still need to make a menu and cookie-tize other settings. --- .../zombiereloaded/zombiereloaded.cfg | 4 ++ src/zombiereloaded.sp | 11 +++++ src/zr/cvars.inc | 2 +- src/zr/weapons/weapons.inc | 2 +- src/zr/zhp.inc | 48 +++++++++++++++---- src/zr/zombiereloaded.inc | 21 ++++++++ 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg b/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg index cdaa541..e7ef2b2 100644 --- a/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg +++ b/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg @@ -549,6 +549,10 @@ zr_zspawn_timelimit "1" // Time from the start of the round to allow ZSpawn. [Dependency: zr_zspawn_timelimit] // Default: "120.0" zr_zspawn_timelimit_time "120.0" + +// Spawn player on the zombie team AFTER the timelimit is up. ['-1' = Block ZSpawn | '0' = Spawn as human | '1' = Spawn as zombie | Dependency: zr_zspawn_timelimit] +// Default: "1" +zr_zspawn_timelimit_zombie "1" // ---------------------------------------------------------------------------- // ZTele (module) // ---------------------------------------------------------------------------- diff --git a/src/zombiereloaded.sp b/src/zombiereloaded.sp index 0a16839..1f6b2b6 100644 --- a/src/zombiereloaded.sp +++ b/src/zombiereloaded.sp @@ -28,6 +28,7 @@ #pragma semicolon 1 #include #include +#include #include #include @@ -45,6 +46,7 @@ #include "zr/serial" #include "zr/sayhooks" #include "zr/tools" +#include "zr/cookies" #include "zr/paramtools" #include "zr/models" #include "zr/downloads" @@ -116,6 +118,7 @@ public OnPluginStart() TranslationInit(); CvarsInit(); ToolsInit(); + CookiesInit(); CommandsInit(); WeaponsInit(); EventInit(); @@ -166,6 +169,14 @@ public OnConfigsExecuted() ClassOnModulesLoaded(); } +/** + * Client cookies just finished loading from the database. + */ +public OnClientCookiesCached() +{ + // Forward event to modules. +} + /** * Client is joining the server. * diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 09350dd..c3bc222 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -430,7 +430,7 @@ CvarsCreate() g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT] = CreateConVar("zr_zspawn_timelimit", "1", "Put a time limit on the use of ZSpawn."); g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_TIME] = CreateConVar("zr_zspawn_timelimit_time", "120.0", "Time from the start of the round to allow ZSpawn. [Dependency: zr_zspawn_timelimit]"); - g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE] = CreateConVar("zr_zspawn_timelimit_zombie", "1", "Spawn player on the zombie team AFTER the timelimit is up. ['-1' = Block ZSpawn | '0' = Spawn as human | '1' = Spawn as zombie | Dependency: zr_zspawn_timelimit]"); + g_hCvarsList[CVAR_ZSPAWN_TIMELIMIT_ZOMBIE] = CreateConVar("zr_zspawn_timelimit_zombie", "1", "Spawn player on the zombie team AFTER the timelimit is up. ['-1' = Block ZSpawn | '0' = Spawn as human | '1' = Spawn as zombie | Dependency: zr_zspawn_timelimit]"); // =========================== diff --git a/src/zr/weapons/weapons.inc b/src/zr/weapons/weapons.inc index 3c4a727..1b5c6db 100644 --- a/src/zr/weapons/weapons.inc +++ b/src/zr/weapons/weapons.inc @@ -88,7 +88,7 @@ new Handle:arrayWeapons = INVALID_HANDLE; /** * Weapons module init function. - */ + */ WeaponsInit() { // Forward event to sub-modules. diff --git a/src/zr/zhp.inc b/src/zr/zhp.inc index 226e5d9..40ba370 100644 --- a/src/zr/zhp.inc +++ b/src/zr/zhp.inc @@ -25,15 +25,20 @@ * ============================================================================ */ +/** + * Name of the cookie for toggle state of ZHP + */ +#define ZHP_COOKIE_ENABLED "zr_zhp" + /** * Array for storing ZHP timer handles per client. */ new Handle:tZHP[MAXPLAYERS + 1]; /** - * Array for flagging client to display HP + * Cookie handle for the toggle state of ZHP on a client. */ -new bool:pZHP[MAXPLAYERS + 1]; +new Handle:g_hZHPEnabledCookie = INVALID_HANDLE; /** * Create commands specific to ZHP. @@ -44,6 +49,19 @@ ZHPOnCommandsCreate() RegConsoleCmd(SAYHOOKS_KEYWORD_ZHP, ZHPCommand, "Shows real HP as zombie."); } +/** + * Create ZHP-related cookies here. + */ +ZHPOnCookiesCreate() +{ + // If cookie doesn't already exist, then create it. + g_hZHPEnabledCookie = FindClientCookie(ZHP_COOKIE_ENABLED); + if (g_hZHPEnabledCookie == INVALID_HANDLE) + { + g_hZHPEnabledCookie = RegClientCookie(ZHP_COOKIE_ENABLED, "The toggle state of ZHP", CookieAccess_Public); + } +} + /** * Client is joining the server. * @@ -54,8 +72,16 @@ ZHPClientInit(client) // Get default client setting from cvar. new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP_DEFAULT]); - // Set flag to default value. - pZHP[client] = zhp; + // Get ZHP enabled cookie value. + decl String:zhpenabled[8]; + GetClientCookie(client, g_hZHPEnabledCookie, zhpenabled, sizeof(zhpenabled)); + + // If the cookie is empty, then set the default value. + if (!zhpenabled[0]) + { + // Set cookie to default value from cvar. + CookiesSetClientCookieBool(client, g_hZHPEnabledCookie, zhp); + } // Reset timer handle. tZHP[client] = INVALID_HANDLE; @@ -162,8 +188,11 @@ bool:ZHPToggle(client) return false; } + // Get the cookie value. + new bool:zhpstate = CookiesGetClientCookieBool(client, g_hZHPEnabledCookie); + // If ZHP is enabled, then tell client it's being disabled. - if (pZHP[client]) + if (zhpstate) { TranslationPrintToChat(client, "ZHP disable"); } @@ -176,8 +205,8 @@ bool:ZHPToggle(client) ZHPUpdateHUD(client); } - // Toggle ZHP flag. - pZHP[client] = !pZHP[client]; + // Toggle the value. + CookiesSetClientCookieBool(client, g_hZHPEnabledCookie, !zhpstate); return true; } @@ -196,8 +225,11 @@ ZHPUpdateHUD(client) return; } + // Get ZHP enabled cookie as a bool. + new bool:zhpstate = CookiesGetClientCookieBool(client, g_hZHPEnabledCookie); + // If player is a zombie, or has ZHP disabled, then stop. - if (!InfectIsClientInfected(client) || !pZHP[client]) + if (!InfectIsClientInfected(client) || !zhpstate) { return; } diff --git a/src/zr/zombiereloaded.inc b/src/zr/zombiereloaded.inc index 2d27bd7..1b877d7 100644 --- a/src/zr/zombiereloaded.inc +++ b/src/zr/zombiereloaded.inc @@ -333,3 +333,24 @@ stock ZRPrintToConsoleLong(client, const String:text[], splitsize = 1022) pos += cellswritten; } } + +/** + * Converts a boolean value into a string. + * + * @param value The value to convert to string. + * @param output The converted string. + * @param maxlen The maximum length of the string. + */ +ZRBoolToString(bool:value, String:output[], maxlen) +{ + // If the value is true, then set string to "1". + if (value) + { + strcopy(output, maxlen, "1"); + } + // If the value is false, then set string to "0". + else + { + strcopy(output, maxlen, "0"); + } +}