Added forgotten cvar to the config.

ZHP now uses client cookies. (Still need to make a menu and cookie-tize other settings.
This commit is contained in:
Greyscale 2009-06-20 00:15:43 -07:00
parent 65beb9f0d0
commit e7bdae2ad8
6 changed files with 78 additions and 10 deletions

View File

@ -549,6 +549,10 @@ zr_zspawn_timelimit "1"
// Time from the start of the round to allow ZSpawn. [Dependency: zr_zspawn_timelimit] // Time from the start of the round to allow ZSpawn. [Dependency: zr_zspawn_timelimit]
// Default: "120.0" // Default: "120.0"
zr_zspawn_timelimit_time "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) // ZTele (module)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -28,6 +28,7 @@
#pragma semicolon 1 #pragma semicolon 1
#include <sourcemod> #include <sourcemod>
#include <sdktools> #include <sdktools>
#include <clientprefs>
#include <cstrike> #include <cstrike>
#include <zrtools> #include <zrtools>
@ -45,6 +46,7 @@
#include "zr/serial" #include "zr/serial"
#include "zr/sayhooks" #include "zr/sayhooks"
#include "zr/tools" #include "zr/tools"
#include "zr/cookies"
#include "zr/paramtools" #include "zr/paramtools"
#include "zr/models" #include "zr/models"
#include "zr/downloads" #include "zr/downloads"
@ -116,6 +118,7 @@ public OnPluginStart()
TranslationInit(); TranslationInit();
CvarsInit(); CvarsInit();
ToolsInit(); ToolsInit();
CookiesInit();
CommandsInit(); CommandsInit();
WeaponsInit(); WeaponsInit();
EventInit(); EventInit();
@ -166,6 +169,14 @@ public OnConfigsExecuted()
ClassOnModulesLoaded(); ClassOnModulesLoaded();
} }
/**
* Client cookies just finished loading from the database.
*/
public OnClientCookiesCached()
{
// Forward event to modules.
}
/** /**
* Client is joining the server. * Client is joining the server.
* *

View File

@ -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] = 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_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]");
// =========================== // ===========================

View File

@ -88,7 +88,7 @@ new Handle:arrayWeapons = INVALID_HANDLE;
/** /**
* Weapons module init function. * Weapons module init function.
*/ */
WeaponsInit() WeaponsInit()
{ {
// Forward event to sub-modules. // Forward event to sub-modules.

View File

@ -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. * Array for storing ZHP timer handles per client.
*/ */
new Handle:tZHP[MAXPLAYERS + 1]; 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. * Create commands specific to ZHP.
@ -44,6 +49,19 @@ ZHPOnCommandsCreate()
RegConsoleCmd(SAYHOOKS_KEYWORD_ZHP, ZHPCommand, "Shows real HP as zombie."); 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. * Client is joining the server.
* *
@ -54,8 +72,16 @@ ZHPClientInit(client)
// Get default client setting from cvar. // Get default client setting from cvar.
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP_DEFAULT]); new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP_DEFAULT]);
// Set flag to default value. // Get ZHP enabled cookie value.
pZHP[client] = zhp; 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. // Reset timer handle.
tZHP[client] = INVALID_HANDLE; tZHP[client] = INVALID_HANDLE;
@ -162,8 +188,11 @@ bool:ZHPToggle(client)
return false; 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 ZHP is enabled, then tell client it's being disabled.
if (pZHP[client]) if (zhpstate)
{ {
TranslationPrintToChat(client, "ZHP disable"); TranslationPrintToChat(client, "ZHP disable");
} }
@ -176,8 +205,8 @@ bool:ZHPToggle(client)
ZHPUpdateHUD(client); ZHPUpdateHUD(client);
} }
// Toggle ZHP flag. // Toggle the value.
pZHP[client] = !pZHP[client]; CookiesSetClientCookieBool(client, g_hZHPEnabledCookie, !zhpstate);
return true; return true;
} }
@ -196,8 +225,11 @@ ZHPUpdateHUD(client)
return; 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 player is a zombie, or has ZHP disabled, then stop.
if (!InfectIsClientInfected(client) || !pZHP[client]) if (!InfectIsClientInfected(client) || !zhpstate)
{ {
return; return;
} }

View File

@ -333,3 +333,24 @@ stock ZRPrintToConsoleLong(client, const String:text[], splitsize = 1022)
pos += cellswritten; 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");
}
}