sm-zombiereloaded-3/src/zr/zhp.inc

227 lines
4.9 KiB
PHP
Raw Normal View History

/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: zhp.inc
* Type: Module
* Description: Displays HP to zombies.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* 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/>.
*
* ============================================================================
*/
/**
* Array for storing ZHP timer handles per client.
*/
new Handle:tZHP[MAXPLAYERS + 1];
/**
* Array for flagging client to display HP
*/
new bool:pZHP[MAXPLAYERS + 1];
/**
* Client is joining the server.
*
* @param client The client index.
*/
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;
// Reset timer handle.
tZHP[client] = INVALID_HANDLE;
}
/**
* 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;
}
/**
* Client has been infected.
*
* @param client The client index.
*/
ZHPOnClientInfected(client)
{
// If ZHP is disabled, then stop.
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
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);
}
/**
* Client has been hurt.
*
* @param client The client index.
*/
ZHPOnClientHurt(client)
{
// 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);
}
/**
* Toggle ZHP on a client.
*
* @param client The client index.
*/
bool:ZHPToggle(client)
{
// If ZHP is disabled, then stop.
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
if (!zhp)
{
// Tell client feature is disabled.
TranslationPrintToChat(client, "Feature is disabled");
// Stop.
return false;
}
// If ZHP is enabled, then tell client it's being disabled.
if (pZHP[client])
{
TranslationPrintToChat(client, "ZHP disable");
}
// If ZHP is disabled, then tell client it's being enabled.
else
{
TranslationPrintToChat(client, "ZHP enable");
// Update HP display.
ZHPUpdateHUD(client);
}
// Toggle ZHP flag.
pZHP[client] = !pZHP[client];
return true;
}
/**
* Update HP display for a player.
*
* @param client The client index.
*/
ZHPUpdateHUD(client)
{
// If ZHP is disabled, then stop.
new bool:zhp = GetConVarBool(g_hCvarsList[CVAR_ZHP]);
if (!zhp)
{
return;
}
// If player is a zombie, or has ZHP disabled, then stop.
if (!InfectIsClientInfected(client) || !pZHP[client])
{
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
TranslationPrintHUDText(client, "Display HP", health);
}
/**
* Timer callback. Repetitively calls ZHPUpdateHUD() until stopped.
*
* @param timer The timer handle.
* @param client The client index.
*/
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;
}