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]
// 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)
// ----------------------------------------------------------------------------

View File

@ -28,6 +28,7 @@
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#include <cstrike>
#include <zrtools>
@ -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.
*

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_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.
*/
*/
WeaponsInit()
{
// 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.
*/
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;
}

View File

@ -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");
}
}