2009-04-16 03:57:46 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: zhp.inc
|
|
|
|
* Type: Module
|
|
|
|
* Description: Displays HP to zombies.
|
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2009-06-12 05:51:26 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
2009-06-20 09:15:43 +02:00
|
|
|
/**
|
|
|
|
* Name of the cookie for toggle state of ZHP
|
|
|
|
*/
|
|
|
|
#define ZHP_COOKIE_ENABLED "zr_zhp"
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* Array for storing ZHP timer handles per client.
|
|
|
|
*/
|
|
|
|
new Handle:tZHP[MAXPLAYERS + 1];
|
|
|
|
|
|
|
|
/**
|
2009-06-20 09:15:43 +02:00
|
|
|
* Cookie handle for the toggle state of ZHP on a client.
|
2009-04-16 03:57:46 +02:00
|
|
|
*/
|
2009-06-20 09:15:43 +02:00
|
|
|
new Handle:g_hZHPEnabledCookie = INVALID_HANDLE;
|
2009-04-16 03:57:46 +02:00
|
|
|
|
2009-06-17 23:32:46 +02:00
|
|
|
/**
|
|
|
|
* Create commands specific to ZHP.
|
|
|
|
*/
|
|
|
|
ZHPOnCommandsCreate()
|
|
|
|
{
|
|
|
|
// Register ZHP command.
|
|
|
|
RegConsoleCmd(SAYHOOKS_KEYWORD_ZHP, ZHPCommand, "Shows real HP as zombie.");
|
|
|
|
}
|
|
|
|
|
2009-06-20 09:15:43 +02:00
|
|
|
/**
|
|
|
|
* Create ZHP-related cookies here.
|
|
|
|
*/
|
|
|
|
ZHPOnCookiesCreate()
|
|
|
|
{
|
2009-10-10 18:26:27 +02:00
|
|
|
// Create cookie handle if it doesn't exist.
|
|
|
|
if (g_hZHPEnabledCookie == INVALID_HANDLE)
|
2009-10-08 19:47:23 +02:00
|
|
|
{
|
2009-10-10 18:26:27 +02:00
|
|
|
g_hZHPEnabledCookie = RegClientCookie(ZHP_COOKIE_ENABLED, "The toggle state of ZHP.", CookieAccess_Protected);
|
2009-10-08 19:47:23 +02:00
|
|
|
}
|
2009-06-20 09:15:43 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* Client is joining the server.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPClientInit(client)
|
2010-02-20 02:41:24 +01:00
|
|
|
{
|
|
|
|
// Reset timer handle.
|
|
|
|
tZHP[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called once a client's saved cookies have been loaded from the database.
|
|
|
|
*
|
|
|
|
* @param client Client index.
|
|
|
|
*/
|
|
|
|
ZHPOnCookiesCached(client)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
// Get default client setting from cvar.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP_DEFAULT]);
|
2009-04-16 03:57:46 +02:00
|
|
|
|
2009-06-20 09:15:43 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2009-04-16 03:57:46 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 05:30:26 +02:00
|
|
|
/**
|
|
|
|
* Client is spawning into the game.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnClientSpawn(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tZHP[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tZHP[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZHP[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnClientDeath(client)
|
|
|
|
{
|
|
|
|
// If timer is running, kill it.
|
|
|
|
if (tZHP[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tZHP[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset timer handle.
|
|
|
|
tZHP[client] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
2009-05-14 02:28:26 +02:00
|
|
|
* Client has been infected.
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnClientInfected(client)
|
|
|
|
{
|
|
|
|
// If ZHP is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
|
2009-04-16 03:57:46 +02:00
|
|
|
if (!zhp)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update HP display.
|
|
|
|
ZHPUpdateHUD(client);
|
|
|
|
|
|
|
|
// If timer is currently running, kill it.
|
|
|
|
if (tZHP[client] != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
KillTimer(tZHP[client]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start repeating timer to update display.
|
|
|
|
tZHP[client] = CreateTimer(5.0, ZHPTimer, client, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-17 10:20:04 +02:00
|
|
|
* Client has been hurt.
|
2009-04-16 03:57:46 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-17 10:20:04 +02:00
|
|
|
ZHPOnClientHurt(client)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
// Update HP display.
|
|
|
|
ZHPUpdateHUD(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Zombie has gained health for infecting a player.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPOnHealthInfectGain(client)
|
|
|
|
{
|
|
|
|
// Update HP display.
|
|
|
|
ZHPUpdateHUD(client);
|
|
|
|
}
|
|
|
|
|
2009-04-17 10:20:04 +02:00
|
|
|
/**
|
|
|
|
* Toggle ZHP on a client.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-05-06 05:31:48 +02:00
|
|
|
bool:ZHPToggle(client)
|
2009-04-17 10:20:04 +02:00
|
|
|
{
|
|
|
|
// If ZHP is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
|
2009-04-17 10:20:04 +02:00
|
|
|
if (!zhp)
|
|
|
|
{
|
|
|
|
// Tell client feature is disabled.
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "Feature is disabled");
|
2009-04-17 10:20:04 +02:00
|
|
|
|
|
|
|
// Stop.
|
2009-05-06 05:31:48 +02:00
|
|
|
return false;
|
2009-04-17 10:20:04 +02:00
|
|
|
}
|
|
|
|
|
2009-06-20 09:15:43 +02:00
|
|
|
// Get the cookie value.
|
|
|
|
new bool:zhpstate = CookiesGetClientCookieBool(client, g_hZHPEnabledCookie);
|
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
// Toggle the value.
|
|
|
|
CookiesSetClientCookieBool(client, g_hZHPEnabledCookie, !zhpstate);
|
|
|
|
|
|
|
|
// If ZHP was enabled, then tell client it has been disabled.
|
2009-06-20 09:15:43 +02:00
|
|
|
if (zhpstate)
|
2009-04-17 10:20:04 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "ZHP disable");
|
2009-04-17 10:20:04 +02:00
|
|
|
}
|
2009-06-21 21:24:24 +02:00
|
|
|
// If ZHP was disabled, then tell client it has been enabled.
|
2009-04-17 10:20:04 +02:00
|
|
|
else
|
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "ZHP enable");
|
2009-04-17 10:20:04 +02:00
|
|
|
|
|
|
|
// Update HP display.
|
|
|
|
ZHPUpdateHUD(client);
|
|
|
|
}
|
|
|
|
|
2009-05-06 05:31:48 +02:00
|
|
|
return true;
|
2009-04-17 10:20:04 +02:00
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* Update HP display for a player.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
|
|
|
ZHPUpdateHUD(client)
|
|
|
|
{
|
|
|
|
// If ZHP is disabled, then stop.
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
|
2009-04-16 03:57:46 +02:00
|
|
|
if (!zhp)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-20 09:15:43 +02:00
|
|
|
// Get ZHP enabled cookie as a bool.
|
|
|
|
new bool:zhpstate = CookiesGetClientCookieBool(client, g_hZHPEnabledCookie);
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
// If player is a zombie, or has ZHP disabled, then stop.
|
2009-06-20 09:15:43 +02:00
|
|
|
if (!InfectIsClientInfected(client) || !zhpstate)
|
2009-04-16 03:57:46 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get health, and if below 0 then set back to 0. (for display purposes)
|
|
|
|
new health = GetClientHealth(client);
|
|
|
|
if (health < 0)
|
|
|
|
{
|
|
|
|
health = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display HP
|
2009-07-08 00:53:18 +02:00
|
|
|
TranslationPrintHintText(client, "Display HP", health);
|
2009-04-16 03:57:46 +02:00
|
|
|
}
|
|
|
|
|
2009-06-17 23:32:46 +02:00
|
|
|
/**
|
|
|
|
* Command callback (zhp)
|
|
|
|
* Shows real HP as zombie.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param argc Argument count.
|
|
|
|
*/
|
|
|
|
public Action:ZHPCommand(client, argc)
|
|
|
|
{
|
|
|
|
// If client is console, then stop and tell them this feature is for players only.
|
|
|
|
if (ZRIsConsole(client))
|
|
|
|
{
|
|
|
|
TranslationPrintToServer("Must be player");
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle ZHP setting.
|
|
|
|
ZHPToggle(client);
|
|
|
|
|
|
|
|
// This stops the "Unknown command" message in client's console.
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2009-04-16 03:57:46 +02:00
|
|
|
/**
|
|
|
|
* Timer callback. Repetitively calls ZHPUpdateHUD() until stopped.
|
|
|
|
*
|
|
|
|
* @param timer The timer handle.
|
|
|
|
* @param client The client index.
|
2009-05-05 06:56:34 +02:00
|
|
|
*/
|
2009-04-16 03:57:46 +02:00
|
|
|
public Action:ZHPTimer(Handle:timer, any:client)
|
|
|
|
{
|
|
|
|
// If client leaves, then stop timer.
|
|
|
|
if (!IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return Plugin_Stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update HP display.
|
|
|
|
ZHPUpdateHUD(client);
|
|
|
|
|
|
|
|
// Allow timer to continue.
|
|
|
|
return Plugin_Continue;
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|